Obi Official Forum
Strange shadow rendering issue when world-space UI element is visible (URP) - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Fluid (https://obi.virtualmethodstudio.com/forum/forum-3.html)
+--- Thread: Strange shadow rendering issue when world-space UI element is visible (URP) (/thread-2558.html)



Strange shadow rendering issue when world-space UI element is visible (URP) - Softscale - 29-10-2020

I'm in the process of upgrading a project to use URP, and ran into an odd issue with the fluid renderer - the shadows received by the fluid seem to render differently depending on whether there is a world-space UI element like image, text, button, etc. visible to the camera.

I noticed this in a project with Obi 5.6, Unity 2019.4.13f1, and URP 7.5.1, but confirmed that it also occurs on the latest versions (Unity 2020.1.11f1, URP 8.2.0).

I was able to recreate this in a new project, see a video showing the issue here:
https://i.imgur.com/UQhTqK3.mp4

To recreate this:
- make a solver and fluid emitter with default values (unchecking "Render" on the ObiParticleRenderer).
- create a Canvas with a render mode of World Space, and give it at least one child UI element like a Text. Make sure this text field is visible somewhere in the scene.
- set the Environment Lighting Source to Gradient or Color, instead of Skybox.
- in the ObiFluidRendererFeature, set Transparency to something less than 1. In the demo video, I set Transparency to 0. I had also set the Ambient Multiplier to 6 to exaggerate the effect, but it seems to occur whenever the Ambient Multiplier is non-zero.

The bug seems to be related to ambient lighting - when any camera (editor or game) has a world-space UI element within its view, any shadows falling on the fluid are tinted with the selected ambient color for the scene, but otherwise are very dark.


RE: Strange shadow rendering issue when world-space UI element is visible (URP) - josemendez - 29-10-2020

(29-10-2020, 01:04 PM)Softscale Wrote: I'm in the process of upgrading a project to use URP, and ran into an odd issue with the fluid renderer - the shadows received by the fluid seem to render differently depending on whether there is a world-space UI element like image, text, button, etc. visible to the camera.

I noticed this in a project with Obi 5.6, Unity 2019.4.13f1, and URP 7.5.1, but confirmed that it also occurs on the latest versions (Unity 2020.1.11f1, URP 8.2.0).

I was able to recreate this in a new project, see a video showing the issue here:
https://i.imgur.com/UQhTqK3.mp4

To recreate this:
- make a solver and fluid emitter with default values (unchecking "Render" on the ObiParticleRenderer).
- create a Canvas with a render mode of World Space, and give it at least one child UI element like a Text. Make sure this text field is visible somewhere in the scene.
- set the Environment Lighting Source to Gradient or Color, instead of Skybox.
- in the ObiFluidRendererFeature, set Transparency to something less than 1. In the demo video, I set Transparency to 0. I had also set the Ambient Multiplier to 6 to exaggerate the effect, but it seems to occur whenever the Ambient Multiplier is non-zero.

The bug seems to be related to ambient lighting - when any camera (editor or game) has a world-space UI element within its view, any shadows falling on the fluid are tinted with the selected ambient color for the scene, but otherwise are very dark.

Hi,

Will try to reproduce this and get back to you. The fluid shaders take ambient lighting, including any attenuation due to shadows, from Unity's own shader API (not calculating it ourselves), so chances are this is a bug in URP rather than the fluid renderer.

This is what the shader does to get ambient lighting:
Code:
half3 ambient = SampleSH(worldNormal) * _AmbientMultiplier;

_AmbientMultiplier is a material parameter, and SampleSH() is implemented by the URP, so it's a black box for us. Whatever color is returned by this function is used as the ambient color.


RE: Strange shadow rendering issue when world-space UI element is visible (URP) - Softscale - 20-12-2020

Not sure if this is related the the previous problem, but I just ran into another issue relating to world-space canvases. Fluids seem to render in front of any world-space UI, even if they are physically behind it:


[Image: clmN4Oo.png]


This was made by creating a new URP project, importing Obi and opening the FluidViscosity sample scene, and adding a button with a world-space canvas positioned between the camera and the fluids. I added an ObiFluidRendererFeature with the default settings and removed the ObiFluidRenderer component from the camera.

(Unity 2019.4.15f1, URP 7.5.2, Obi Fluid 5.6.1)

Is there some setting I need to enable for this to sort the rendering order correctly, or is this a bug?


RE: Strange shadow rendering issue when world-space UI element is visible (URP) - josemendez - 21-12-2020

Hi there!

You need to enable the depth/opaque texture generation in your pipeline for fluids to be rendered correctly. Right now, they're not transparent because the rendered does not have access to the scene's opaque texture, and won't perform correct depth-testing because they don't have access to the scene's depth texture. See:

https://www.youtube.com/watch?v=k5Uv5ecjVM0
http://obi.virtualmethodstudio.com/tutorials/fluidrendering.html

Even with these enabled sorting with UI won't work as expected. The reason for this is that in URP the opaque texture is generated during RenderPassEvent.BeforeRenderingTransparents, just as the default UI material (which is transparent) is being rendered. For fluid to have access to the opaque texture at all and blend correctly with the scene, it must be rendered after this event, that is, once world-space UI has been drawn. This is a URP limitation.

Things do not work the same way in the built-in pipeline (UI is rendered after all transparent objects), so there UI will be rendered correctly by default.

If you only need opaque fluids, you can work around this by opening ObiFluidRendererFeature.cs and setting the renderPassEvent in all fluid rendering passes to RenderPassEvent.BeforeRenderingTransparents, instead of RenderPassEvent.BeforeRenderingTransparents+1. This will prevent the fluid renderer from accessing the opaque texture, but will be rendered before the default UI material.

Another workaround would be using a custom shader for the UI, which renders together with opaque objects and uses alpha testing for transparency.

kind regards,