Im triying to create a water example and I know that the first thig requiered is to be able to make a reflection, that is done.
I'm stuck in the next step which is to combine the reflection with a normal map.
What I tried was to load the cube texture as I normally would, calculate the reflection and then load the normal map and combine them in the final step, but the water disappears.
Here's my code:
Vertex Shader
attribute vec3 a_normBT;
attribute vec3 a_normL;
attribute vec3 a_normTan;
attribute vec3 a_posL;
attribute vec2 a_uv;
uniform mat4 u_W;
uniform mat4 u_WVP;
varying vec3 v_normW;
varying vec3 v_normBT;
varying vec3 v_normTan;
varying vec3 v_posW;
varying vec2 v_uv;
void main()
{
gl_Position = u_WVP * vec4(a_posL, 1.0);
v_uv = a_uv;
v_normW = normalize((u_W*vec4(a_normL, 0.0)).xyz);
v_normBT = normalize((u_W*vec4(a_normBT,0.0)).xyz);
v_normTan = normalize((u_W*vec4(a_normTan,0.0)).xyz);
v_posW = (u_W*vec4(a_posL, 1.0)).xyz;
}
Fragment shader
precision mediump float;
uniform samplerCube u_s_texture;
uniform sampler2D u_s_normalMap;
uniform vec3 u_cpos;// the camera position is already in world space
varying vec3 v_normW;
varying vec3 v_normBT;
varying vec3 v_normTan;
varying vec3 v_posW;
varying vec2 v_uv;
void main()
{
vec4 tempText = texture2D(u_s_normalMap, v_uv);
vec3 Normal = normalize(v_normW);
vec3 totalDifusse = vec3(0.0,0.0,0.0);
vec3 totalSpecular = vec3(0.0,0.0,0.0);
vec3 toEye = u_cpos- v_posW;
vec3 reflectDir = reflect(normalize(-toEye), normalize(v_normW)); // reflect() in non linear
gl_FragColor = tempText*textureCube(u_s_texture,reflectDir);
}
What I expect to happen is that the quad I have should have static ripples. Thank you.