2D - GrabPass Reflection

Hey Guys i want to build up a simple water shader for a 2D game, that well reflects everything in realtime.

i got it to a point there im just using the grabpass flipped on the y Axis but since the UNITY_MATRIX_MVP matrix also includes the rotation the final output image gets not only flipped but also a bit offsetted and rotated if im moving the camera (second part doesnt matters, since it’s a 2D game anyways)

But actually it looks really weird in game


Vertex Shader:

void vert (inout appdata_full v, out Input o)
			{
				float4 position = mul(UNITY_MATRIX_MVP, v.vertex);


				#if UNITY_UV_STARTS_AT_TOP
					float scale = -1.0;
				#else
					float scale = 1.0;
				#endif

				o.proj2.xy = (float2(position.x, (min(position.y+_ReflHeight,_ReflHeightMax)) * -scale) + position.w) * 0.5;
				o.proj2.zw = position.zw;
				
			}

(Im currently limitting the movement by those two values [_ReflHeight,_ReflHeightMax])

Surface:

half4 refl = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(IN.proj2));

Is there a way to stop the movement? since you wont see anything anyways if you are not near the water. it shouldnt matter if the screen renders it for the grab pass funktion

Thanks in Advance

anyone?

not aware of what the porblem is :neutral:

It’s just wrong Y uv.

You just need to change the uv offset by 0.5 i think along y. ie… add +0.5 in vert shader.

thats what im currently doing with that value dynamically

_ReflHeight

But doesnt helps much… just makes the reflection high acceptable

any other suggestions ?

Just render to texture, blit texture to 2nd copy. It’s not much slower (its faster on mobile actually), then just draw a 2nd pass with the reflective water mesh. I do this stuff in The Other Brothers without a problem so I’m sure you’ll be fine.