Trying to create a "water" shader

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Trying to create a "water" shader

Post by Jasoco »

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.

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;
}
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:

Code: Select all

half2 displacement1 = tex2D( _Displacement1Tex, i.uv.xy );
float2 adjusted = i.uv.xy + (displacement1.rg - .5);
half4 output = tex2D(_MainTex, adjusted);
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.

aoi_saboten
Prole
Posts: 2
Joined: Wed Oct 02, 2019 4:53 pm

Re: Trying to create a "water" shader

Post by aoi_saboten »

I think this is much better:

Code: Select all

  vec4 pixel = Texel(tex, vec2(tc.x, tc.y - 0.01*sin(time + tc.x*5)));
  return pixel;
  
But it is just my opinion
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 215 guests