Skip to content

Conversation

@ellioman
Copy link
Contributor

@ellioman ellioman commented Sep 17, 2020

Purpose of this PR

This PR fixes these three issues:

  1. [LWRP] UNLIT PARTICLES SHADER IS NOT RENDERED WHEN SOFT PARTICLES ARE ENABLED ON BUILT APPLICATION
  2. URP TRANSPARENT PARTICLE SYSTEM IS NOT VISIBLE / DISAPPEARS WHEN 'DEPTH TEXTURE' IS OFF AND 'SOFT PARTICLES' ARE ENABLED
  3. [URP] DEPTH TEXTURE SAMPLE NODE DOES NOT USE CORRECT TEXTURE IN SOME FRAMES
  4. [URP] OBJECTS THAT ARE USING SOFT PARTICLES ARE RENDERED OPAQUE WHEN OPENGL IS USED

How?

Issue 1, 2 & 3

The solution is to assign a black or white texture as the depth texture, depending on whether we're on a platform with reverse-z or not, if the frame doesn't have a prepass or copydepth pass.

We now also display a warning message in the material inspector when soft particles are enabled but depth texture is not in the asset.

Issue 4

The fix is to use a different LinearEyeDepth() method inside Particles.hlsl. Instead of using the one that uses _ZBufferParams it now uses the one that requires world position and view matrix, which is recommended if we've already computed the world space position.

This ended up being a larger fix as I needed to get access to the world position and instead of simply adding that parameter to the SoftParticles function, I decided to refactor some of the code, create a new struct (ParticleParams) with the common variables used in our particle shaders and create new functions using that struct. That allows us to modify the functions implementations in the future without having to change the API hopefully again.

As all of the particle shaders used the same attributes and varyings, except the editor ones, I decided to move those in to a separate hlsl file to reduce duplicate code.

QA

What has been tested

  • Tested the three projects sent with the bug reports on Metal and OpenGL in editor
  • Tested them with Lit, SimpleLit and Unlit particle shaders
  • Compiled the particle shaders and made sure we don't have any errors or warnings
  • Ran URP Graphics Tests locally

What needs testing

  • Soft Particles with and without depth textures
  • Different Graphics API's (GLES, Vulkan, etc) on builds as I've only tested in editor

Yamato

master: https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fsoft-particle-fixes
2020.2: https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fsoft-particle-fixes/.yamato%252F_abv.yml%2523all_project_ci_CUSTOM-REVISION/3977446/job

@ellioman ellioman requested a review from phi-lira September 18, 2020 14:02

cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, m_CopyDepthMaterial);

cmd.SetGlobalVector(ShaderPropertyId.availableTexturesParams, new Vector4(0f, 0f, 0f, 1f));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is probably not a good enough solution if/when we want to add other texture types to this parameter, such as the opaque texture. Could we add the data to RenderingData? Other ideas welcome.

Copy link
Contributor

@phi-lira phi-lira left a comment

Choose a reason for hiding this comment

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

LGTM. We should ask for cross pipeline team / HDRP on what is the design regarding checking if a texture is available in the shader.

#ifndef UNIVERSAL_PARTICLES_INPUT_INCLUDED
#define UNIVERSAL_PARTICLES_INPUT_INCLUDED

#if PARTICLES_EDITOR
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it that we need different attributes/varyings for editor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know. We need to put that in our task list to look at that.

Copy link

Choose a reason for hiding this comment

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

This smells very strange :)

If i'm reading it correctly, you are saying lighting is totally disabled/broken in the Editor (because you disregard the normal + tangent inputs)

I don't think you want to ship this as-is unless it's already in this broken state in master.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could fix this in this PR as well but this how Editor Particles are currently on Master. I'm just moving the code into one separate file.

https://github.com/Unity-Technologies/Graphics/blob/master/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesEditorPass.hlsl

Copy link

@ghost ghost Sep 24, 2020

Choose a reason for hiding this comment

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

No this file you linked isn't for rendering of particles in the editor, it's for rendering the editor specific passes, namely the selection outline and the picking buffer passes.

Copy link

Choose a reason for hiding this comment

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

It seems like I should have added a comment in this file explaining this :)
(I added it when I added instanced particle rendering support, which needs custom passes for picking+selection outlines)

Copy link
Contributor Author

@ellioman ellioman Sep 24, 2020

Choose a reason for hiding this comment

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

Ahh!! My bad!
Wondering what's the best solution here. Would we be fine with moving the define into the relevant passes and keep my change of having all the Particle attributes/varyings in the same file?

Copy link

Choose a reason for hiding this comment

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

Perhaps add a define to the editor passes, then use it to exclude normal + tangents from the inputs?
You can find the passes by looking at any pass that uses the vertParticleEditor vertex program.

I was also thinking you could just wrap it in #if !UNITY_PASS_META but i think we use META passes for other stuff that may need those inputs. But im not sure about that. I don't know exactly what qualifies as a meta pass.

@phi-lira
Copy link
Contributor

When testing, please compile shaders in editor to see if there are no error / warnings in any platform.

@erikabar erikabar self-requested a review September 23, 2020 10:06
@ellioman ellioman marked this pull request as ready for review September 25, 2020 12:40
@ellioman ellioman requested a review from a team as a code owner September 25, 2020 12:40
@ellioman ellioman changed the title [10.x.x] Soft Particle bugfixes. Cases 1162556, 1256953 and 1226288 [10.x.x] Soft Particle bugfixes. Cases 1162556, 1256953& 1226288 + 1268079 Oct 13, 2020
Copy link
Contributor

@erikabar erikabar left a comment

Choose a reason for hiding this comment

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

Verified bug reports (1162556, 1256953, 1226288, 1268079)
Verified that a message is thrown when Soft Particles are enabled but Depth Texture is disabled
smoke tested Particles FTP project on Mac, Android (Vulkan, OpenGLES3, OpenGLES2) and iOS (Metal)

ellioman added a commit that referenced this pull request Oct 26, 2020
phi-lira added a commit that referenced this pull request Oct 26, 2020
commit ab21837
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Thu Oct 22 16:39:33 2020 +0200

    changelog

commit de2cb9f
Merge: 129a26a 8bc58a4
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Thu Oct 22 16:36:24 2020 +0200

    Merge branch 'master' into universal/soft-particle-fixes

commit 129a26a
Merge: 08aa34b ef305e5
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Tue Oct 20 20:37:30 2020 +0200

    Merge branch 'master' into universal/soft-particle-fixes

commit 08aa34b
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Mon Oct 19 20:59:53 2020 +0200

    Changelog

commit 8ef7ea2
Merge: 2ca7a38 74151b2
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Mon Oct 19 20:48:24 2020 +0200

    Merge branch 'master' into universal/soft-particle-fixes

commit 2ca7a38
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Mon Oct 19 09:57:52 2020 +0200

    Changing the message from info to warning

commit 7e116bc
Merge: 17c7e8a 2e401c6
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Mon Oct 19 09:23:33 2020 +0200

    Merge branch 'master' into universal/soft-particle-fixes

commit 17c7e8a
Merge: f0cc212 08aecf9
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Wed Oct 7 14:46:24 2020 +0200

    Merge branch 'master' into universal/soft-particle-fixes

commit f0cc212
Merge: 66a1f75 9c25c9f
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Mon Oct 5 15:38:28 2020 +0200

    Merge branch 'master' into universal/soft-particle-fixes

commit 66a1f75
Merge: b3dc096 168109e
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Fri Sep 25 14:42:28 2020 +0200

    Merge branch 'master' into universal/soft-particle-fixes

commit b3dc096
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Thu Sep 24 15:46:20 2020 +0200

    Renaming PARTICLES_EDITOR define to PARTICLES_EDITOR_META_PASS

commit 9ac74d1
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Thu Sep 24 14:08:58 2020 +0200

    Fixing things based on reviews

commit 4c3dc37
Merge: 5a15af0 b9696e6
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Wed Sep 23 10:31:23 2020 +0200

    Merge branch 'master' into universal/soft-particle-fixes

commit 5a15af0
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Wed Sep 23 10:30:56 2020 +0200

    Fixing an copy/paste error

commit 0fcaad0
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Tue Sep 22 15:45:03 2020 +0200

    Fixes based on review

commit 03d0a2e
Merge: 63af228 e35abbc
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Tue Sep 22 15:36:17 2020 +0200

    Merge branch 'master' into universal/soft-particle-fixes

commit 63af228
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Tue Sep 22 15:35:50 2020 +0200

    Fixing compile errors

commit 776f167
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Tue Sep 22 13:34:41 2020 +0200

    Removing HasDepthTexture() from the shaders and instead setting the depth texture to black/white if we're not doing a prepass or copydepth

commit 739160a
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Fri Sep 18 15:42:15 2020 +0200

    Minor fix to ParticlesEditorPass

commit ca416b1
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Fri Sep 18 15:41:37 2020 +0200

    Fixing issue 1226288

commit 77d80bf
Author: Elvar Örn Unnþórsson <[email protected]>
Date:   Thu Sep 17 15:45:47 2020 +0200

    Bugfix 1162556
@phi-lira phi-lira mentioned this pull request Oct 26, 2020
@ellioman ellioman changed the title [10.x.x] Soft Particle bugfixes. Cases 1162556, 1256953& 1226288 + 1268079 [11.x.x] Soft Particle bugfixes. Cases 1162556, 1256953& 1226288 + 1268079 Oct 26, 2020
@phi-lira phi-lira changed the base branch from master to universal/staging-v3 October 27, 2020 15:37
@phi-lira
Copy link
Contributor

merging to stage branch

@phi-lira phi-lira merged commit 09588b3 into universal/staging-v3 Oct 27, 2020
@phi-lira phi-lira deleted the universal/soft-particle-fixes branch October 27, 2020 15:37
phi-lira added a commit that referenced this pull request Oct 29, 2020
* [11.x.x] Fixing NullReferenceException with Lift Gamma Gain & upgrading URP Package (#2386)

* Fixing issue 1283588

* Similar fix to ShadowsMidtonesHighlightsEditor.cs

* Minor fixes

* More minor fixes

* [11.x.x] Soft Particle bugfixes. Cases 1162556, 1256953& 1226288 + 1268079 (#1922)

* Bugfix 1162556

* Fixing issue 1226288

* Minor fix to ParticlesEditorPass

* Removing HasDepthTexture() from the shaders and instead setting the depth texture to black/white if we're not doing a prepass or copydepth

* Fixing compile errors

* Fixes based on review

* Fixing an copy/paste error

* Fixing things based on reviews

* Renaming PARTICLES_EDITOR define to PARTICLES_EDITOR_META_PASS

* Changing the message from info to warning

* Changelog

* changelog

* Bugfix: The code was overriding the depth texture for overlay cameras, which is incorrect.

* [11.x.x] MSAA fix for Metal MacOS/Editor (#2391)

* Metal MacOS/Editor MSAA fix. Require an explicit MSAA resolve pass unless the platform is mobile

* Added changelog entry

* [11.x.x] Fixed per camera MSAA regression  (#2293)

* Default to XR off when creating the camera and no XR provider is installed.
Added runtime XR on/off check for XR camera.

* Updated CHANGELOG.md and small format fixes.

* Reverted changes in URPCameraEditor and URPCameraData.

* [11.x.x] Early camera color target assignment (#2377)

* Assign the camera color target early in case it is needed during AddRenderPasses

* Update to reflect PR feedback

* Get rid of warnings from accessing cameraColorTarget during AddRenderPasses

* Update CHANGELOG.md

* Removed tile shaders are currently unused. (#2383)

Co-authored-by: Elvar Örn Unnþórsson <[email protected]>
Co-authored-by: manuele-bonanno <[email protected]>
Co-authored-by: thomas-zeng <[email protected]>
Co-authored-by: Peter Bay Bastian <[email protected]>
Co-authored-by: Kay Chang <[email protected]>
phi-lira pushed a commit that referenced this pull request Oct 29, 2020
…68079 (#1922)

* Bugfix 1162556

* Fixing issue 1226288

* Minor fix to ParticlesEditorPass

* Removing HasDepthTexture() from the shaders and instead setting the depth texture to black/white if we're not doing a prepass or copydepth

* Fixing compile errors

* Fixes based on review

* Fixing an copy/paste error

* Fixing things based on reviews

* Renaming PARTICLES_EDITOR define to PARTICLES_EDITOR_META_PASS

* Changing the message from info to warning

* Changelog

* changelog

* Bugfix: The code was overriding the depth texture for overlay cameras, which is incorrect.
# Conflicts:
#	com.unity.render-pipelines.universal/CHANGELOG.md
phi-lira added a commit that referenced this pull request Oct 29, 2020
* [11.x.x] Fixing NullReferenceException with Lift Gamma Gain & upgrading URP Package (#2386)

* Fixing issue 1283588

* Similar fix to ShadowsMidtonesHighlightsEditor.cs

* Minor fixes

* More minor fixes
# Conflicts:
#	com.unity.render-pipelines.universal/CHANGELOG.md

* [11.x.x] Soft Particle bugfixes. Cases 1162556, 1256953& 1226288 + 1268079 (#1922)

* Bugfix 1162556

* Fixing issue 1226288

* Minor fix to ParticlesEditorPass

* Removing HasDepthTexture() from the shaders and instead setting the depth texture to black/white if we're not doing a prepass or copydepth

* Fixing compile errors

* Fixes based on review

* Fixing an copy/paste error

* Fixing things based on reviews

* Renaming PARTICLES_EDITOR define to PARTICLES_EDITOR_META_PASS

* Changing the message from info to warning

* Changelog

* changelog

* Bugfix: The code was overriding the depth texture for overlay cameras, which is incorrect.
# Conflicts:
#	com.unity.render-pipelines.universal/CHANGELOG.md

* [11.x.x] MSAA fix for Metal MacOS/Editor (#2391)

* Metal MacOS/Editor MSAA fix. Require an explicit MSAA resolve pass unless the platform is mobile

* Added changelog entry
# Conflicts:
#	com.unity.render-pipelines.universal/CHANGELOG.md

* [11.x.x] Fixed per camera MSAA regression  (#2293)

* Default to XR off when creating the camera and no XR provider is installed.
Added runtime XR on/off check for XR camera.

* Updated CHANGELOG.md and small format fixes.

* Reverted changes in URPCameraEditor and URPCameraData.
# Conflicts:
#	com.unity.render-pipelines.universal/CHANGELOG.md

* [11.x.x] Early camera color target assignment (#2377)

* Assign the camera color target early in case it is needed during AddRenderPasses

* Update to reflect PR feedback

* Get rid of warnings from accessing cameraColorTarget during AddRenderPasses

* Update CHANGELOG.md
# Conflicts:
#	com.unity.render-pipelines.universal/CHANGELOG.md

Co-authored-by: Elvar Örn Unnþórsson <[email protected]>
Co-authored-by: manuele-bonanno <[email protected]>
Co-authored-by: thomas-zeng <[email protected]>
Co-authored-by: Peter Bay Bastian <[email protected]>
@phi-lira phi-lira restored the universal/soft-particle-fixes branch July 13, 2021 16:03
phi-lira added a commit that referenced this pull request Jul 13, 2021
@phi-lira phi-lira mentioned this pull request Jul 13, 2021
@sebastienlagarde sebastienlagarde deleted the universal/soft-particle-fixes branch September 1, 2021 10:20
phi-lira added a commit that referenced this pull request Sep 21, 2021
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.

5 participants