Modifying water shader to reflect environment

Joined
Oct 13, 2010
Messages
108
So I'm trying to modify water_pass2_ps20 to produce reflections and refractions, although with my limited knowledge of HLSL (which mostly stems from C++ anyways) I was unsuccessful.

Replacing
Code:
float3 envMapCol = texCUBE(envMap, rView);
with
Code:
float3 envMapCol = reflect(dp, rView);
does NOT work, and I'm not sure else to go about making the shader reflect. Any ideas?
 

Timbab

Administrator
Staff member
Administrator
Moderator
Joined
Oct 6, 2010
Messages
1,057
Location
Magna Germania
Go get a hold of Sytner, he had fully reflective water with waves working.

I still haven't invested the time to learn HLSL, too busy atm.
 
Joined
Oct 13, 2010
Messages
108
Timbab said:
Go get a hold of Sytner, he had fully reflective water with waves working.
Sytner, from what I hear, has a reputation for disappearing.

Timbab said:
I still haven't invested the time to learn HLSL, too busy atm.
I tried looking up online tutorials of the topic, and I think they all sucked. I should go over them again though just to be sure.
 

Uli

Moderator
Staff member
Moderator
Joined
Aug 30, 2010
Messages
208
Screw it I been doing this response way too many times, I suck at explaining stuff.

I been taught DX10/11 + PS/VS 4.0, can't apply my knowledge entirely to this unfortunately I do things completely differen't in shaders. Shader layouts in general in SWG are annoying to work with (well to read)

Anyway to jump straight in, for me in 4.0 pass in the incident and the normal of the 2 water and then sample it onto the map and get the reflected color.

Edit: The reflect function passes back "reflectW" and not the actual color, its different in 2.0 vs 4.0 but managed to find source which is a bit below to how to apply it properly.

Now looking around at what my University gave me to help with DirectX found some old DX9 (when they use to teach it) and its got some older stuff that is definitely relevant, my experience is pretty much useless on unique function calls, here is basicly what your trying to do:

This is from a water example (This is just a small snippet there is a lot more before hand):

Code:
float3 envMapTex = reflect(-toEyeW, normalW) + (normalT*2.0f);
float3 reflectedColor = texCUBE(EnvMap, envMapTex);
So basicly you want to keep the texCUBE code but you want to get the reflection before it and pass it into it, this will return the color to then to can use when calculating the ambient and diffuse material.

So now its just about replacing -toEyeW, normalW and normalT and tweaking the maths behind it.

I only can say for sure that NormalT is infact "norm"

Code:
float3 norm0 = 2*(tex2D(normalMap0, norm0tc)-0.5);
float3 norm1 = 2*(tex2D(normalMap1, norm1tc)-0.5);
float3 norm = normalize(norm0 + norm1);
For the rest you will have to work it out, hope this in some way helps. If I made no sense at one point then thats because I suck at explaining and rewritten this a bit because I kept talking with 4.0 rather then 2.0
 
Top Bottom