-
-
Notifications
You must be signed in to change notification settings - Fork 478
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
Underwater Fog Input #867
base: master
Are you sure you want to change the base?
Underwater Fog Input #867
Conversation
Renders anything after underwater effect and applies underwater fog. Useful for some transparent objects and particles.
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.
The sh code is interesting to see. Is it needed here? I'm aware it's used to light the underwater fog, but had thought it was evaluated at the camera position, and am wondering if we already have it evaluated somewhere else (in oceanrenderer maybe)
} | ||
|
||
return half4(wt * sceneColour, 1.0); | ||
} | ||
ENDHLSL | ||
} | ||
|
||
Pass |
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.
A comment above each pass might be useful to explain each one
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
I wasn't able to add a general comment without submitting the review. Nice one GitHub. |
Yeah the blending is worth talking through. I had the following in my head but I don't know if it works
Would that work? |
using UnityEngine; | ||
|
||
// TODO: Maybe rename. | ||
public class RegisterUnderwaterInput : MonoBehaviour |
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.
Yeah I think it may want to be distinct from the register input naming as it's quite different. Although that might just be my bias from knowing the internals. My brain initially went to something like "ApplyUnderwaterEffectToAlpha"
(Now that I'm commenting on a particular line, its forcing me to submit a new review 😅)
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 renamed to ApplyUnderwaterEffectToTransparent as that might be more recognisable.
Ah interesting! It may be worth trying min or max, but otherwise yeah tolerable I would vote. I don't think we should do anything special to render the original alpha geo. I have expanded my understanding notes above accordingly. |
BlendOp Min or Max? Neither produced good results.
I have added both for now for evaluating. Or maybe permanently if you think technical debt is not too high.
I have thought of another approach which might be closer to this. We render the fog before the transparent pass. And add the fog calculation to the ocean shader again. Then we just duplicate the "tagged" objects and then dilate them slightly. The duplicate will have our material which adds the fog and alpha blends. It should sort correctly and be similar in quality to the lower quality alpha blending above. And requires minimal intervention from us. |
Oh I meant use min or max density (of the three channels). Not confident it would help but just an idea. Would you be able to let me know where my notes are falling short or not going to work? I'm not following I'm afraid and am hoping we can use it as a tool to sync on the plan |
Fixes missing SH and missing shadows etc.
cca31e1
to
b452e34
Compare
b452e34
to
22961c1
Compare
Status: Experimental
Adds an input for underwater fog which renders whatever it is attached to after the underwater effect and applies the fog in a separate pass. I have named the component RegisterUnderwaterInput for consistency but it could be renamed.
The original idea was to use Blend and BlendOp to apply the fog but I wasn't able to work it out. I think using subtract might work if we somehow bake density fog and scatter colour into the fragment colour. Instead I rendered the object offscreen and provided texture to the fog pass so it samples itself to get the screen colour. This way it works like the underwater effect does.
Steps:
It didn't work out as nice as I hoped as it exposed us a little bit to render pipeline (SH and _MainTex). We need _MainTex to get the alpha value for blending; an example is the particles will be rendered as squares without it.
Also, I had to cull back faces as the example transparent objects in the test scene didn't like culling disabled (need to look into that), but some transparent objects want culling disable for them to look right.
I made the shader a separate pass rather than a separate file as it saves us another material and code reuse.
I have provided test data in the main scene.
Let me know what you think.