Sending Array of Data to GLSL

Started by jfbguy, April 07, 2012, 20:54:17

Previous topic - Next topic

jfbguy

Hi,
I've been trying to get bump mapping to work with lwjgl, it has been... difficult.  I've used just about every tutorial and example I can find on the web.  I think everything should be working fine except I'm not sure if I'm successsfully sending my array of tangent data to the vertex shader correctly.

In my InitGL (setting up Opengl):
VBOTangentid = createVBOID();
bufferData(VBOTangentid, VBOTangentData);

Where TangentData has all of the tangents calculated for the model in a correctly flipped FloatBuffer

Then in my render function I call
int loc = ARBVertexShader.glGetAttribLocationARB(shader.id,"tangent");
ARBVertexShader.glEnableVertexAttribArrayARB(VBOTangentid);
ARBVertexShader.glVertexAttribPointerARB(loc, 3, GL11.GL_FLOAT,false, 0, 0L);

ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, VBOid); // Bind my VBO

shader.bind();

GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, objects.get(0).count);

shader.unBind();


Now in my vertex shader I have an attribute
attribute vec3 tangent;
Should my tangent data be available in my shader now?  I've been trying to follow fabien's bumpmapping tutorial (http://fabiensanglard.net/bumpMapping/index.php) but my textures ends up just being extremely white.
If anyone had any success with this, any tips would be extremely helpful.  Thanks.



jfbguy

Got hopefully a solution from http://www.gamedev.net/topic/581082-glsl-bump-mapping-using-a-normal-map/
So, I might be able to just add my tangent data to my VBO.  I just have to enable one of the pointers for... looking at glsl cheat sheet.... attribute vec4  gl_MultiTexCoord0; in the vertex shader.
Having a tuff time now figuring out how to do this.  Anyone know?

Or one of the gl_MultiTexCoord#.. not sure which....because apparently I'm already using gl_MultiTexCoord0.
OK, so I believe glTexCoordPointer uses gl_MultiTexCoord0, so I think I need to activate the gl_MultiTexCoord1 pointer.  Still don't know how.  Went through all GL##... not finding...


Just in case anyone else needs to know how...
I think I found how to use the different gl_MultiTexCoord#
// textCoord
        offset = (3 + 3) * 4;
    	ARBMultitexture.glClientActiveTextureARB(ARBMultitexture.GL_TEXTURE0_ARB);
    	GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
    	GL11.glTexCoordPointer(2, GL11.GL_FLOAT, stride, offset);
//tangent
    	offset = (3 + 3 + 2) * 4;
    	ARBMultitexture.glClientActiveTextureARB(ARBMultitexture.GL_TEXTURE1_ARB);
        GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
        GL11.glTexCoordPointer(3, GL11.GL_FLOAT, stride, offset);


Bump is still half messed up, but I think that's my problem with calculating the tangents. --cheers--

Last update!  My bump mapping with normal maps is working lovely now.  Just wanted to give anyone who might run into the same problems a heads up.  Source code from http://www.dhpoware.com/demos/glslNormalMapping.html helped out a ton!  Their shader also worked while others didn't.  Also I was using a single VBO (Vertex,Normal,TextCoord,Tangent)