- Home /
2D Pixelated water reflection with shaders
I've been trying to create a shader for a pixelated water reflection, but I'm new to Unity and especially new to shaders.
What I'm after is something like this: GIF
I've managed to use Grabpass and flip it to get the surface to distort, but i cant figure out how to do the distortion.
Been trying something like this where i changed _Offset in a script over time, but the best result i got with that was a single wave, which is not what i'm really after. I was considering checking the y-coordinate compared to _Offset and using modulus to change direction of every third/fourth pixel or something but there doesnt seem to be any modulus available for shaders. Completely lost at this point.
fixed4 frag(v2f IN) : SV_Target
{
fixed4 c = tex2D(_MainTex, IN.texcoord) * IN.color;
fixed4 up = tex2D(_MainTex, IN.texcoord + fixed2(0, _MainTex_TexelSize.y));
fixed4 down = tex2D(_MainTex, IN.texcoord - fixed2(0, _MainTex_TexelSize.y));
fixed4 left = tex2D(_MainTex, IN.texcoord - fixed2(_MainTex_TexelSize.x, 0));
fixed4 right = tex2D(_MainTex, IN.texcoord + fixed2(_MainTex_TexelSize.x, 0));
if(IN.texcoord.y > _Offset && IN.texcoord.y < _Offset + 0.01){
c.rgb = right;
}else{
c.rgb = left;
}
return c;
}
I realize this code is nowhere close to what i want to do, but that's about as far as my experiments has taken me.
Would appreciate some help or some pointers
Answer by tanoshimi · Jan 24, 2017 at 04:12 PM
There's a nice writeup of how the water shaders in Kingdom were created here (which, IMO, is one of the best examples of 2D pixelated water around).
Thanks for you reply. Thing is it seems i cant do this distortion with a distortion map, atleast it doesnt seem like it(i may be wrong), it simply gets too smooth. It was suggested to me to ins$$anonymous$$d of using a distortion map to use a sin function fort distortions. The experiements with sine so far arent looking much better though.
Your answer
Follow this Question
Related Questions
Texture rendering 1 Answer
2D Sprites Rendering Inconsistently Between Computers 0 Answers
Issue with Rendering Large Texture 0 Answers
Anti aliasing with sprites 0 Answers