-
Notifications
You must be signed in to change notification settings - Fork 861
Add support for GPU instancing of mesh particle systems #904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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"
|
Changelog entry is missing. Also would be nice if the PR description would be finished. |
ellioman
left a comment
There was a problem hiding this 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:
- I'd really like a test scene in the URP Test project for this
- Changelog missing
If you need help with 1. then I or someone from the URP team can easily help :)
eh-unity
left a comment
There was a problem hiding this 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.
com.unity.render-pipelines.universal/Editor/ShaderGUI/ParticleGUI.cs
Outdated
Show resolved
Hide resolved
| #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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 :) )
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opted for worldToObject3x3
|
Hi @richardkettlewell , started on this, but getting errors like: Is there a custom binary branch I should be on? I'm on 2020.2.0a18.2359 from 2 days ago. |
|
…move color unpacking to a util function
ellioman
left a comment
There was a problem hiding this 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 :)
|
@Unity-Technologies/gfx-qa-foundation @VladNeykov any update on this one? |
VladNeykov
left a comment
There was a problem hiding this 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
VladNeykov
left a comment
There was a problem hiding this 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.
Done and done :) |
Please read
PR workflow guidelines
Checklist for PR maker
need-backport-*label. After you backport the PR, the label changes tobackported-*.CHANGELOG.mdfile.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?
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.