Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Here is Simple Water Shader

Author
Message
GrumpyOne
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 10th Jun 2010 18:25
Having just posted a problem of no use to anyone, I thought I'd make amends by posting something useful for the community. A simple working water shader.

The shader comprises two scrolling normal maps to generate waves and two specular maps to generate specular reflections. Or in plain english, it is wavy and sparkly. There are no reflections (which is why it is simple), but it is single pass and thus fast. Best used for RTS water.

The shader and the example media are attached in a zip file. I've commented the HLSL code with simple comments about what each bit does. Try changing the normal maps to get different looking waves. Photos of artex walls are perfect for making normal maps of waves (in fact that is ALL artex walls are good for).

You can add the shader to your code using the following:

You may need to use different image numbers and will need to declare the object number for the plane.

If you want the sparkly bits to move with the camera view then each time step update the camx, camy, camz variables like this:



Best, Mr Grumpy

GrumpyOne - the natural state of the programmer
GrumpyOne
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 10th Jun 2010 18:28
Oh here is the image of the effect.

GrumpyOne - the natural state of the programmer
luskos
19
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 10th Jun 2010 21:46
This suits more the Code Snippet Board than DBPRO...

Anyway...Good job for this!

Where there is a will, there is a way.
I often edit my posts, that`s who i am
bergice
19
Years of Service
User Offline
Joined: 5th Jun 2007
Location: Oslo,Norway
Posted: 11th Jun 2010 01:17
I will check this out as i certainly have issues with the fresnel water shader.

Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 11th Jun 2010 09:33
Looks cool, and straightforward too - been hoping for a less taxing water shader for top down games.


Health, Ammo, and bacon and eggs!
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 11th Jun 2010 10:52
Wow, great effect!

I'll be using this one at some point I'm sure!

bergice
19
Years of Service
User Offline
Joined: 5th Jun 2007
Location: Oslo,Norway
Posted: 11th Jun 2010 14:02
Wow, this is great!

Certainly will use this, thanks alot!

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 11th Jun 2010 14:24
Looks cool, a youtube video would be nice to see it in action!

My signature is NOT a moderator plaything! Stop changing it!
bergice
19
Years of Service
User Offline
Joined: 5th Jun 2007
Location: Oslo,Norway
Posted: 11th Jun 2010 14:32 Edited at: 11th Jun 2010 14:33
Got to test it out on my worldbuilder now, it looks nice:



However when i zoom out the big normal map replaces all the effects and it looks kind of odd:



Is the normal map issues something i am doing wrong or is it supposed to happen?

GrumpyOne
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 13th Jun 2010 02:31
My that is odd. Wish I knew why that was happening!

Even on your first image there is a hint of the normal map showing through (the yellows and purples). I know this isn't terribly helpful...but it doesn't do this on my implementation. You aren't accidently loading one of the normal maps into texture stage 0? That's the only thing I can think that might cause these symptoms.

GrumpyOne - the natural state of the programmer
bergice
19
Years of Service
User Offline
Joined: 5th Jun 2007
Location: Oslo,Norway
Posted: 13th Jun 2010 13:27 Edited at: 13th Jun 2010 13:28
Here is the function i use to set it up:



And the variables:



GrumpyOne
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 13th Jun 2010 16:48
You've defined both watertex2_1 and watertex2_2 to the same image number. The normal map is thus being loaded into stage 0 and this image is used as the texture that is modified by the normals and specular reflections. That is why you can see the normal map.

Just set watertex2_1 = 5 (if this image isn't already being used). I'm always doing this too, they are annoying errors to spot.

GrumpyOne - the natural state of the programmer
bergice
19
Years of Service
User Offline
Joined: 5th Jun 2007
Location: Oslo,Norway
Posted: 13th Jun 2010 17:39
Oh stupid me, works great now thanks alot!

Dia
21
Years of Service
User Offline
Joined: 16th Jan 2005
Location:
Posted: 20th Jun 2010 10:43 Edited at: 20th Jun 2010 11:03
Edited: Pleade disregard my previous post if you read it, I just had an attack of noobosity

This is not the Sig you are looking for....

Login to post a reply

Server time is: 2026-07-25 08:30:05
Your offset time is: 2026-07-25 08:30:05