Sign in to follow this  

water simulation not linking with shader

This topic is 2818 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all. Firstly I should point out that the code is in Java however implementation in similar to C. My first shader works well however then it gets to rendering the water using the second shader, nothing display as though the shader isn't linked to the program. Any help that is available would be much appreciated. public void display(GLAutoDrawable drawable) { ..... gl.glUseProgram(programObject); RenderReflection(gl); RenderRefractionAndDepth(gl); RenderScene(gl); gl.glUseProgram(programObjectW); System.out.print("water"); RenderWater(gl); } void RenderWater(GL gl){ // The Sea Maps uniform = gl.glGetUniformLocation(programObjectW, "waterTex0"); gl.glUniform1f(uniform, 0); uniform = gl.glGetUniformLocation(programObjectW, "waterTex1"); gl.glUniform1f(uniform, 1); uniform = gl.glGetUniformLocation(programObjectW, "waterTex2"); gl.glUniform1f(uniform, 2); uniform = gl.glGetUniformLocation(programObjectW, "waterTex3"); gl.glUniform1f(uniform, 3); uniform = gl.glGetUniformLocation(programObjectW, "waterTex4"); gl.glUniform1f(uniform, 4); // uniform = gl.glGetUniformLocation(programObjectW, "viewpos"); gl.glUniform4f(uniform, viewpos.x, viewpos.y, viewpos.z, 1.0f); uniform = gl.glGetUniformLocation(programObjectW, "lightpos"); gl.glUniform4f(uniform, light_position[0], light_position[1], light_position[2], 1.0f); uniform = gl.glGetUniformLocation(programObjectW, "time"); gl.glUniform1f(uniform, time); uniform = gl.glGetUniformLocation(programObjectW, "time2"); gl.glUniform1f(uniform, time2); uniform = gl.glGetUniformLocation(programObjectW, "waterColor"); gl.glUniform4f(uniform, 0.1f, 0.2f, 0.9f, 1.0f); uniform = gl.glGetUniformLocation(programObjectW, "waterDepth"); gl.glUniform4f(uniform, 0.0f, 5.0f, 0.0f, 1.0f); //bind all textures gl.glActiveTexture(GL.GL_TEXTURE0); gl.glBindTexture(GL.GL_TEXTURE_2D, reflection[0]); gl.glActiveTexture(GL.GL_TEXTURE1); gl.glBindTexture(GL.GL_TEXTURE_2D, refraction[0]); gl.glActiveTexture(GL.GL_TEXTURE2); gl.glBindTexture(GL.GL_TEXTURE_2D, normals[0]); gl.glActiveTexture(GL.GL_TEXTURE3); gl.glBindTexture(GL.GL_TEXTURE_2D, normals[1]); gl.glActiveTexture(GL.GL_TEXTURE4); gl.glBindTexture(GL.GL_TEXTURE_2D, depth[0]); //Render the water surface gl.glBegin(GL.GL_QUADS); gl.glMultiTexCoord2f(GL.GL_TEXTURE0, 0.0f, 5.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE1, 0.0f, 1.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE2, 0.0f, 1.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE3, 0.0f, 1.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE4, 0.0f, 1.0f); gl.glVertex3f(-5.0f, 0.0f, 5.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE0, 0.0f, 0.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE1, 0.0f, 1.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE2, 0.0f, 1.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE3, 0.0f, 1.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE4, 0.0f, 1.0f); gl.glVertex3f(-5.0f, 0.0f, -5.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE0, 5.0f, 0.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE1, 0.0f, 1.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE2, 0.0f, 1.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE3, 0.0f, 1.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE4, 0.0f, 1.0f); gl.glVertex3f(5.0f, 0.0f, -5.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE0, 5.0f, 5.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE1, 0.0f, 1.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE2, 0.0f, 1.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE3, 0.0f, 1.0f); gl.glMultiTexCoord2f(GL.GL_TEXTURE4, 0.0f, 1.0f); gl.glVertex3f(5.0f, 0.0f, 5.0f); gl.glEnd(); time += 0.002f; time2 += 0.003f; }

Share this post


Link to post
Share on other sites
Try drawing it without the shader. If you see something, then the problem is indeed the shader. Then, do a simple pass through shader (i.e., gl_FragData[0].rgba = vec4(1.0);) to make sure it really is your shader compiling. If you see something, the problem is probably in your water-shader's code, because, chances are, it compiled. If you're not sure, use the relevant callbacks to discover compilation/linking errors (you should be doing this anyway).
-G

Share this post


Link to post
Share on other sites
Drawing the vertex by itself works with shader, it goes blank the second it do multi-texturing.

After some testing i realise that only the The normal map and dudv map actually work. I create the reflection, refraction and depth to the water dynamically.

The reflection is first create then store within a texture, is then binded later. The reflection appears normally when rendered but will not become a texture

void RenderReflection(GL gl){
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

gl.glPushMatrix();
gl.glScalef(1.0f, -1.0f, 1.0f);
double plane[] = {0.0, 1.0, 0.0, 0.0};
gl.glEnable(GL.GL_CLIP_PLANE0);
gl.glClipPlane(GL.GL_CLIP_PLANE0, plane, 0);
RenderScene(gl);
gl.glDisable(GL.GL_CLIP_PLANE0);
gl.glPopMatrix();

gl.glGenTextures(1, reflection, 0);

//render reflection to texture
gl.glBindTexture(GL.GL_TEXTURE_2D, reflection[0]);
//glCopyTexSubImage2D copies the frame buffer
//to the bound texture
gl.glCopyTexSubImage2D(GL.GL_TEXTURE_2D,0,0,0,0,0, xSize, ySize);
}

Share this post


Link to post
Share on other sites
Quote:
Original post by gaming_enthusiast
This is a stupid error on my part, i am calling the varying vec4 as uniforms. What is the call to get varying vec4? I used glGetAttribLocation however unifrom still equals -1.


None. Varyings pass data from the vertex shader to thefragment shader. They don't have a location ID.

Share this post


Link to post
Share on other sites
Firstly thank you for your help so far, it has been very much appreciated. I have got the water panel to display on screen, however my building doesn't. I am using two separate glsl shaders for each.

public void display(GLAutoDrawable drawable) {

gl = drawable.getGL();

gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

gl.glLoadIdentity();

glu.gluLookAt(0.0f, 15.0f, 30.0f, 0.0f, 3.0f, 0.0f, 0.0f, 1.0f, 0.0f);


gl.glUseProgram(programObject);

RenderReflection(gl);

RenderScene(gl);

gl.glUseProgram(programObjectW);
//gl.glLoadIdentity();
gl.glTranslatef(-1.0f, 0.0f, 5.0f);
RenderWater(gl);
}

void RenderWater(GL gl){
//gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
uniform = gl.glGetUniformLocation(programObjectW, "reflection");
System.out.print(uniform);
gl.glUniform1i(uniform, 0);
uniform = gl.glGetUniformLocation(programObjectW, "normalmap");
System.out.print(uniform);
gl.glUniform1i(uniform, 1);
uniform = gl.glGetUniformLocation(programObjectW, "dudvmap");
System.out.print(uniform);
gl.glUniform1i(uniform, 2);

uniform = gl.glGetUniformLocation(programObjectW, "viewpos");
System.out.print(uniform);
gl.glUniform4f(uniform, viewpos.x, viewpos.y, viewpos.z, 1.0f);

uniform = gl.glGetUniformLocation(programObjectW, "lightpos");
System.out.print(uniform);
gl.glUniform4f(uniform, light_position[0], light_position[1], light_position[2], 1.0f);

uniform = gl.glGetUniformLocation(programObjectW, "time");
System.out.print(uniform);
gl.glUniform1f(uniform, time);

uniform = gl.glGetUniformLocation(programObjectW, "time2");
System.out.print(uniform);
gl.glUniform1f(uniform, -time);

//bind all textures
gl.glActiveTexture(GL.GL_TEXTURE0);
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glBindTexture(GL.GL_TEXTURE_2D, reflection[0]);

gl.glActiveTexture(GL.GL_TEXTURE1);
gl.glBindTexture(GL.GL_TEXTURE_2D, normals[0]);

gl.glActiveTexture(GL.GL_TEXTURE2);
gl.glBindTexture(GL.GL_TEXTURE_2D, normals[1]);



//Render the water surface
gl.glBegin(GL.GL_QUADS);
gl.glMultiTexCoord2f(GL.GL_TEXTURE0, 0.0f, 0.0f);
gl.glMultiTexCoord2f(GL.GL_TEXTURE1, 0.0f, 0.0f);
gl.glMultiTexCoord2f(GL.GL_TEXTURE2, 0.0f, 0.0f);
gl.glVertex3f(0.0f, 10.0f, 10.0f);
gl.glMultiTexCoord2f(GL.GL_TEXTURE0, 0.0f, 1.0f);
gl.glMultiTexCoord2f(GL.GL_TEXTURE1, 0.0f, 1.0f);
gl.glMultiTexCoord2f(GL.GL_TEXTURE2, 0.0f, 1.0f);
gl.glVertex3f(10.0f, 10.0f, 10.0f);
gl.glMultiTexCoord2f(GL.GL_TEXTURE0, 1.0f, 1.0f);
gl.glMultiTexCoord2f(GL.GL_TEXTURE1, 1.0f, 1.0f);
gl.glMultiTexCoord2f(GL.GL_TEXTURE2, 1.0f, 1.0f);
gl.glVertex3f(10.0f, 0.0f, 10.0f);
gl.glMultiTexCoord2f(GL.GL_TEXTURE0, 1.0f, 0.0f);
gl.glMultiTexCoord2f(GL.GL_TEXTURE1, 1.0f, 0.0f);
gl.glMultiTexCoord2f(GL.GL_TEXTURE2, 1.0f, 0.0f);
gl.glVertex3f(0.0f, 0.0f, 10.0f);
gl.glEnd();

time += 0.00001f;

//gl.glPopMatrix();
//gl.glDisable(GL.GL_TEXTURE_2D);
}

[Edited by - gaming_enthusiast on March 31, 2010 7:53:26 PM]

Share this post


Link to post
Share on other sites

This topic is 2818 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this