PDA

View Full Version : texture not moving OGLES2



Johnathon332
04-26-2013, 02:12 PM
Hey guys I am having trouble with trying to get my normal map to pertubate the quad I have drawn and was wondering if anyone could give me any pointers as to where I have gone wrong? I will post my code below

Currently in my vertex shader I have


attribute highp vec3 inVertex;

uniform highp mat4 MVPMatrix;
uniform mediump vec3 LightDir;
uniform mediump vec3 EyePos;
uniform mediump vec2 watermovementX;
uniform mediump vec2 watermovementY;
uniform mediump vec2 waterSX;
uniform mediump vec2 waterSY;

varying mediump vec3 EyeDir;
varying mediump vec2 TexCoord;
varying mediump vec2 TexCoord2;

void main()
{
// Transform position
gl_Position = MVPMatrix * vec4(inVertex,1.0);

//this is used to save attributes meaning we will not be needing inTexCoord to pass in
mediump vec2 waterCoord = inVertex.xz;
TexCoord = waterCoord.xy * waterSX; //this line scales the bump map
TexCoord += watermovementX; //this line translates the bump map
TexCoord2 = waterCoord.xy * waterSY;
TexCoord2 += watermovementY;


and this is my fragment shader


uniform sampler2D n_mapTex;
uniform sampler2D dudv_map;
uniform sampler2D reflectionTex;
uniform float distortion
uniform lowp vec4 WaterColour;

varying mediump vec2 TexCoord;
varying mediump vec2 TexCoord1;

void main()
{
//calculate water movement
lowp vec3 aNormal = vec3(0.0, 0.0, 1.0);
aNormal = texture2D(n_mapTex, TexCoord).xyz;
aNormal += texture2D(n_mapTex, TexCoord1).xyz;
aNormal -= 1.0;
lowp watermovement = aNormal.st;
vec2 texMove = watermovement * distortion;
gl_FragColor = texture2D(reflectionTex, texMove);
}


and here is my code to update the values and these get passedinto the shaders


waterTran += water_Vel * DT;
waterTran = PVRTVec2( fmod(waterTran.x, 1.0f), fmod(waterTran.y, 1.0f));
waterTran2 += water_Vel2 * DT;
waterTran2 = PVRTVec2( fmod(waterTran2.x, 1.0f), fmod(waterTran2.y, 1.0f));


glUniform2fv(m_ShaderProgram.auiLoc[eW_Move],1, &waterTran.x);
glUniform2fv(m_ShaderProgram.auiLoc[eWaterS],1, &water_S.x);
glUniform2fv(m_ShaderProgram.auiLoc[eW_Move2],1, &waterTran2.x);
glUniform2fv(m_ShaderProgram.auiLoc[eWaterS2],1, &water_S2.x);
glUniform1f(m_ShaderProgram.auiLoc[eDist], pertubation);

Pertubation is set to 100.0f and DT stands for delta time. If more code is needed this can be provided :)