wave-harmonic / crest

A class-leading water system implemented in Unity
MIT License
3.46k stars 476 forks source link

Planar Reflections issue with non-standard shaders using transparency #1147

Closed Revmatek closed 5 months ago

Revmatek commented 6 months ago

Is there an existing issue for this?

Have you checked the documentation to resolve your problem?

Current Behavior

Planar reflections texture does not show custom shaders / transparency. It may be custom shaders in general if I recall. I think it works for most standard shaders.

Note: that the palm leaves are not visible in the reflection. image

My primary concern for this is the tree leaves not showing up. This example has hidden shaders on the tree which I cannot redo easily. The example light blue cube is something I can modify to add support if that is possible.

Expected Behavior

There should be some sort of way to add support for transparency in custom shaders (seems to work fine for Standard Shaders with transparency, which may exclude all forms of tree shader)

Steps To Reproduce

1) Create a scene with Planar reflections 2) Add some objects using custom shaders and transparency or Speed Tree (or similar Tree Creator shader) 3) Observe missing reflections image

Unity Version

2021.3.26

Crest Version

4.19

Render Pipeline

Built-In

Editor or Standalone

Editor (Edit Mode), Editor (Play Mode), Standalone

Environment

No response

Anything else?

Filling this out here while investigating other issues, this was in my backlog, not terribly important but probably a bug somewhere. I investigated it a one point and ended up in a shader somewhere that was applying transparency to the planar reflection texture or something... I don't recall the specifics. I am not sure if there is some workaround to this I am unaware of, something I need to add in the shaders perhaps.

daleeidd commented 6 months ago

Does changing the Clear Flags to Skybox solve it?

Revmatek commented 6 months ago

Does changing the Clear Flags to Skybox solve it?

Changing the Clear Flags does not seem to have an effect. The clear flags for the image above is with Skybox.

daleeidd commented 6 months ago

Is that on the OceanPlanarReflections script? Otherwise can you remove the * saturate(refl.a) and see if it improves from the following line: https://github.com/wave-harmonic/crest/blob/0be7cca7660b44150ec2321825565ed626896b4a/crest/Assets/Crest/Crest/Shaders/OceanReflection.hlsl#L29

Revmatek commented 6 months ago

OceanPlanarReflections

This is OceanPlanarReflections script, yes. Disabling saturate does have an effect and makes the tree leaves appear, but causes other more obvious problems with reflections / darkness on the surface image image

daleeidd commented 6 months ago

That image looks like OceanPlanarReflections > Clear Flags is not set to Skybox. Unless your skybox does not write alpha which would be strange. Try testing with Unity's procedural skybox.

Revmatek commented 6 months ago

That image looks like OceanPlanarReflections > Clear Flags is not set to Skybox. Unless your skybox does not write alpha which would be strange. Try testing with Unity's procedural skybox.

It seems unrelated to the skybox. I tried it with default and a few others. Doesn't change. It also does not seem related to OceanPlanarReflections being on image

daleeidd commented 6 months ago

Can you provide a screenshot of the OceanPlanarReflections component?

Revmatek commented 6 months ago

Can you provide a screenshot of the OceanPlanarReflections component?

image

Revmatek commented 6 months ago

Can you provide a screenshot of the OceanPlanarReflections component?

Well I guess that solves that mystery. I was not aware you were referring to Clear flags on this script vs the camera. image image

image

Thanks for the help!

daleeidd commented 6 months ago

No worries. Does it work correctly if you remove the reflection alpha modification?

Revmatek commented 6 months ago

No worries. Does it work correctly if you remove the reflection alpha modification?

Yes, it does appear to be working correctly now.

image It does seem to wash out a bit after I stop moving the camera but it is mostly fine. Definitely an improvement. image

Seems to depend on the angles and only with trees image image

I'm not sure why there is a distinction between the transparency in the standard shaders and the custom / tree shaders, obviously depends on what each shader is doing I guess.

daleeidd commented 6 months ago

Perfect. That could be a combination of fresnel and colours blending.

I'll make Skybox the default as prefer to have things work over an optimisation. I'll document this in the tooltip and somewhere in the documentation too.

daleeidd commented 5 months ago

Fixed in 4.20.