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 / A water shader problem

Author
Message
GrumpyOne
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 10th Jun 2010 13:06
I am quite new to shaders, but have managed to rewrite GG's terrain shader to have more textures for height levels and created a simple water shader (i.e. two scrolling normal maps and two specular maps).

I am having a strange problem with the water shader. In my test code with just an advanced terrain and a plain for water it works great (see attached picture). In my (20,000 line) game code it doesn't work (see attached picture). The plane loses its transparency and I can see the normal maps as textures. The shader and terrain are created and updated by the same piece of code (in an included dba file). They are identical.

The shader (a bit messy and stolen from lots of places) is below. Is there a stupid mistake or can anyone suggest why a shader might work in one code and not another with the same implementation?:


Many thanks.

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 13:12
Oh I should explain. The specular maps are in ReflectMap1 and 2..I never changed the names and obviously the textures are in stages 0 to 5 not all in one (the dangers of copying and pasting without changing the comments).

GrumpyOne - the natural state of the programmer
luskos
19
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 10th Jun 2010 14:50
If your code is in included as separate file there is probably something that do not take effect, you need to be aware that some stuff need to be declared as global .

Can you move it in you main dba file to test if it`s working good?Or you can use your test application for this link it with the same dba that you use in your project to see if it`s the same.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
GrumpyOne
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 10th Jun 2010 16:15
That was my first guess too. All my globals are defined in my include file in a function, which I call at the top of both my test code and my game code. I've used a naming convention that means there aren't any variable name conflicts. However, I've already tried copying the included functions into the main dba and it still has the same effect.

The weird thing is the water shader effect is only passed the camera position each timestep. The effect is doing something, just the wrong thing. One of the normal textures is visible, at the wrong scale, and it scrolls. This is only specified in the vertex shader so I know it is running. I guess I'll have to rewrite the shader line by line to see what is running differently between the two implementations.

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 16:51
Ok, truly bizarre.

I've just rewrote the shader, replacing the last line of the pixel shader to only output the stage 0 texture with ambient lighting. In my test code this is displayed as expected. In my game code there is no change, the normal maps still appear as a texture, very slowly scrolling across the plane. The effect seems to exist but the shader is doing something odd....My instinct...which is so often wrong...is the shader is fine, its implementation isn't.

This is how I initiate the shader. Anyone see anything stupid? I can't.



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 17:16
Solved.

Simple mistake, like they always are.

if effect exist(2)=0 then load effect "shaders\watershader.fx", 2, 0

to

if effect exist(2)=1 then delete effect 2
load effect "shaders\watershader.fx", 2, 0

Solved it. I don't know why...because effect 2 shouldn't have already existed...but if it works it works.

GrumpyOne - the natural state of the programmer

Login to post a reply

Server time is: 2026-07-25 16:21:45
Your offset time is: 2026-07-25 16:21:45