Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Jun 15, 2020

Please read

PR workflow guidelines

  • SRP ABV will start automatically on Yamato when you open your PR
  • Changes to docs and md files will not trigger ABV jobs
  • Consider making use of draft PRs if you are not 100% sure that your PR is ready for review
  • ABV will restart if you add a new commit to a branch with an open PR (hence why you should consider using draft PRs)
  • Adding [skip ci] (case insensitive) to the title of PRs will stop any jobs being trigger automatically - you will need to open Yamato and find your branch to run ABV
  • You can also add [skip ci] to commit messages to prevent CI from running on that push
  • Add [cancel old ci] to your commit message if you've made changes you want to test and no longer need the previous jobs

Checklist for PR maker

  • Have you added a backport label (if needed)? For example, the need-backport-* label. After you backport the PR, the label changes to backported-*.
  • Have you updated the changelog? Each package has a CHANGELOG.md file.
  • Have you updated or added the documentation for your PR? When you add a new feature, change a property name, or change the behavior of a feature, it's best practice to include related documentation changes in the same PR.
  • Have you added a graphic test for your PR (if needed)? When you add a new feature, or discover a bug that tests don't cover, please add a graphic test.

Purpose of this PR

Adds support for GPU instanced mesh particles. Without this, the built-in renderer is far more efficient on some devices.

Testing status

Manual Tests: What did you do?

  • Opened test project + Run graphic tests locally
  • Built a player
  • Checked new UI names with UX convention
  • Tested UI multi-edition + Undo/Redo + Prefab overrides + Alignment in Preset
  • C# and shader warnings (supress shader cache to see them)
  • Checked new resources path for the reloader (in developer mode, you have a button at end of resources that check the paths)
  • Other:

Automated Tests: What did you setup? (Add a screenshot or the reference image of the test please)

Yamato: (Select your branch):
https://yamato.prd.cds.internal.unity3d.com/jobs/902-Graphics

Any test projects to go with this to help reviewers?


Comments to reviewers

Requires https://ono.unity3d.com/unity/unity/pull-request/108978/_/core/particles-expose-shadergui-api-for-urp, which hasn't quite landed in trunk at the time off writing this.

@ghost ghost self-requested a review as a code owner June 15, 2020 15:17
@ghost ghost requested a review from eh-unity June 15, 2020 15:17
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to the Unity SRP repo!
Please make sure to fill out the PR template as best you can to give reviewers as much information as possible.
If you have any questions (and you are a Unity employee) go to "#devs-renderpipe"

@ghost ghost assigned phi-lira Jun 15, 2020
@ellioman ellioman requested review from a team and ellioman June 30, 2020 09:55
@eh-unity
Copy link
Contributor

Changelog entry is missing. Also would be nice if the PR description would be finished.

Copy link
Contributor

@ellioman ellioman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!
Two things:

  1. I'd really like a test scene in the URP Test project for this
  2. Changelog missing

If you need help with 1. then I or someone from the URP team can easily help :)

@VladNeykov VladNeykov self-requested a review July 7, 2020 08:47
Copy link
Contributor

@eh-unity eh-unity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh. I added these comments days ago, but I always forget to "commit" reviews comments to make them visible. I'm just too used to other systems in the past, that just show the comment immediately after adding.

#if !defined(UNITY_PARTICLE_INSTANCE_DATA_NO_COLOR)
UNITY_PARTICLE_INSTANCE_DATA data = unity_ParticleInstanceData[unity_InstanceID];
color = lerp(half4(1.0, 1.0, 1.0, 1.0), color, unity_ParticleUseMeshColors);
color *= float4(data.color & 255, (data.color >> 8) & 255, (data.color >> 16) & 255, (data.color >> 24) & 255) * (1.0 / 255);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should and int/float4 packing/unpacking functions. In core/ShaderLibarary/Packing.hlsl there are similar functions (e.g. UnpackFromR11G11B10f). Consider adding pack/unpack for this case too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this is the same case as the matrix invert. I think it would be good to add a comment/TODO to replace with library implementation when available.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, i missed this comment when i read over the PR feedback, sorry. i think this one is actually more clear-cut than the matrix one - i don't see a reason why i cant move it to the Packing file. I'll sort that out :)

float index0 = floor(sheetIndex);
float vIdx0 = floor(index0 / numTilesX);
float uIdx0 = floor(index0 - vIdx0 * numTilesX);
float2 offset0 = float2(uIdx0 * animScale.x, (1.0 - animScale.y) - vIdx0 * animScale.y);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a Y-flip. If that's the case, then it would be good to have a comment why it's done (and if the comment has a word flip in it then it's searchable if someone is tracking down a chain of flips :) )

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honest answer: I dunno - it's copied from the built-in instancing code which is coped from the built-in cpu code which is really old. Something about UV space, I suppose :)

Copy link
Contributor

@eh-unity eh-unity Jul 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a bit unfortunate. Maybe at least add a comment that it's from built-in as is and it looks like upside-down flip. It wouldn't hurt to mention the flip in the comment (for searchability).
Ideally all flip chains should be removed/minimized, but that probably isn't realistic at this point and certainly not in the scope of this PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)


// inverse transform matrix
float3x3 w2oRotation;
w2oRotation[0] = objectToWorld[1].yzx * objectToWorld[2].zxy - objectToWorld[1].zxy * objectToWorld[2].yzx;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is just rotation, would just transpose be enough? That's inverse for rotations, but scales can be problem.
In any case we should have a function for generic matrix inverse, but I couldn't find any. Maybe use this to make generic matrix inverses for mat4,3,2 etc. While it's slow, it's sometimes necessary and useful for debugging spaces too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is just rotation, would just transpose be enough? That's inverse for rotations, but scales can be problem.
In any case we should have a function for generic matrix inverse, but I couldn't find any. Maybe use this to make generic matrix inverses for mat4,3,2 etc. While it's slow, it's sometimes necessary and useful for debugging spaces too.

It's not just rotation :)

I am super hesitant to add any code that is unused (as the mat4 and mat2 variants would be). It's best done at a time when they can be tested as being correct IMO. (i.e. when there is a use case)

If you would like me to move this code in a function called "invertMatrix" or similar, let me know the name and file you'd like, thanks :) (This is my first -and perhaps only- URP PR, so I don't know my way around your shader library)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I can agree that adding those isn't in the scope of this PR.
Perhaps add a todo comment to replace with a library implementation if/when available, so the info is not lost.
Also if it's not just rotation then perhaps the variable name 'w2oRotation' could be more clear.

Copy link
Author

@ghost ghost Jul 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opted for worldToObject3x3

@VladNeykov
Copy link
Contributor

Hi @richardkettlewell , started on this, but getting errors like:

'ShaderUtil' does not contain a definition for 'HasProceduralInstancing'
'ParticleSystemRenderer' does not contain a definition for 'supportsMeshInstancing'

Is there a custom binary branch I should be on? I'm on 2020.2.0a18.2359 from 2 days ago.

@ghost
Copy link
Author

ghost commented Jul 13, 2020

Hi @richardkettlewell , started on this, but getting errors like:

'ShaderUtil' does not contain a definition for 'HasProceduralInstancing'
'ParticleSystemRenderer' does not contain a definition for 'supportsMeshInstancing'

Is there a custom binary branch I should be on? I'm on 2020.2.0a18.2359 from 2 days ago.

Yes sorry! https://ono.unity3d.com/unity/unity/pull-request/108978/_/core/particles-expose-shadergui-api-for-urp

Copy link
Contributor

@ellioman ellioman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving as my comments have been addressed :)

@phi-lira
Copy link
Contributor

@Unity-Technologies/gfx-qa-foundation @VladNeykov any update on this one?

Copy link
Contributor

@VladNeykov VladNeykov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Occasional crash and visual glitches, very hard to repro, but should probably be addressed in this PR:
https://docs.google.com/document/d/16ez5yDhtTIEXy3rXGMTrZMmCcfJITZ0xus2HbqvnjvE/edit?usp=sharing

(will keep trying to find reliable repro, but @richardkettlewell if anything here rings a bell, maybe you can beat me to it)

…cing

# Conflicts:
#	com.unity.render-pipelines.universal/CHANGELOG.md
Copy link
Contributor

@VladNeykov VladNeykov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; some outstanding issues, but as discussed, they are not introduced by this PR.

@ghost
Copy link
Author

ghost commented Jul 16, 2020

Looks good!
Two things:

  1. I'd really like a test scene in the URP Test project for this
  2. Changelog missing

If you need help with 1. then I or someone from the URP team can easily help :)

Done and done :)

@ghost ghost closed this Jul 16, 2020
@ghost ghost reopened this Jul 16, 2020
@stramit stramit merged commit 7847a5c into master Jul 17, 2020
@stramit stramit deleted the universal/particle-shader-instancing branch July 17, 2020 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants