Re: Trying to create a "water" shader
Posted: Tue Jan 31, 2017 1:11 am
Heh, that code doesn't really work well at all. Creates too much of a wave and just looks like a broken TV.
But if I use a slightly modified version of the wave shader in veethree's project posted above it gives it enough of a wave to look like something, but not good enough for a finished project.
I still would love to replicate the method used in Kingdom sans the perspective correction (Since this isn't a side-scroller) but have no idea how I'd do the UV based offsetting. The code on that TIGSource page is hard to understand since it's not a full shader, just random snippets.
Like this code:
I mean I guess I could take the purple and blue displacement texture from that page and pass it as an image or something? I wouldn't even know where to begin with that.
Edit: Just for the heck of it, here's what I have so far. I added some randomly timed sparkle animations to give it more life. But it's not perfect of course. But it is good enough for a start. In time I'll write or find a really good shader to do it right.
But if I use a slightly modified version of the wave shader in veethree's project posted above it gives it enough of a wave to look like something, but not good enough for a finished project.
Code: Select all
extern vec2 size;
extern number time;
vec4 effect(vec4 color, Image tex, vec2 tc, vec2 sc)
{
tc.x = tc.x + sin((tc.y * 10.0) - time) * (size.x * 0.000005);
tc.y = tc.y + sin((tc.x * 10.0) - time) * (size.y * 0.000005);
vec4 pixel = Texel(tex, tc);
return pixel;
}
Like this code:
Code: Select all
half2 displacement1 = tex2D( _Displacement1Tex, i.uv.xy );
float2 adjusted = i.uv.xy + (displacement1.rg - .5);
half4 output = tex2D(_MainTex, adjusted);
Edit: Just for the heck of it, here's what I have so far. I added some randomly timed sparkle animations to give it more life. But it's not perfect of course. But it is good enough for a start. In time I'll write or find a really good shader to do it right.