So i am in the process of making my own water shader, writing it from scratch. Doing this for my own learning. I read the standard water script and i don’t understand one thing.
The standard script creates the clipping plane this way
I don’t understand why they calculated the dot product? The 4th term is supposed to be the distance from the origin. If that’s the case then shouldn’t the distance be just the magnitude of “cpos” as the position vector would go from the origin to the center of the plane? Also, i don’t understand why they negated it.
I didn’t follow the standard script and made the view matrix for the reflection matrix my own way ( defining the side, up and look at vectors as basis). And the result is good. However there is one small problem. I am getting this image.
I don’t know why the cube is getting distorted ;s The trees seem fine. The only difference between my and the standard water script is the way i created the reflection camera’s view matrix.
EDIT:- wait a sec, is this even distorted? or is the camera rendering the back faces only?
So i set Culling to Off in a custom shader and its giving the proper result. Anybody can tell me what’s the problem? Why do i have to set it to off and why is it rendering backfaces only, shouldn’t it render only the front faces by default?
Bump. Anybody? Also as everybody know the reflection camera’s up vector is in the opposite direction. If i set the up vector same as the original one, i don’t get the upside down picture, however there is no culling problem as mentioned above. What has the up vector to do with the camera mixing up the front and backfaces? Sorry i can’t understand
I also tried it with a standard shader and same result, so its supposed to be back.
If i explicitly set it to Off or Front then it gives the correct result. Apparently it’s messing up its back and front faces.
Same here, getting all objects rendered into the reflection ‘inside out’.
But I don’t know how to invert the culling in URP…
Would it not be possible to flip the matrix and then read from the reflection texture upside-down as well? (It’s the winding order that decides the culling, or am I mistaken?)
Even this asset (standard water for URP) is wrong when I use it in Unity 2022
EDIT: my linear algebra was too rusty to figure it out myself, but I found this little snippet and it works perfectly! (That is: flip the projection matrix to render upside down so that you don’t need to invert culling, then just read the reflection RenderTexture upside-down in the water surface shader as well)