Jump to content
  • Advertisement
Sign in to follow this  
digitalerr0r

FBO Cubemapping + normal mapping

This topic is 3409 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

Hello, im trying to create an normalmapped object with normalmapping, by using GLSL. What I want is to have one ColorMap that is just a normal 2d texture mapped on the object, and over this, I want to blend a CubeMap that uses the normals from a normal map to get the desired pixel from the normal map. I have created a CubeMap with FBO, and this works ok. But how do I pass in other textures to the shader so I can combine this? I have done this with normal 2d textures before, but not with a cubemap combined.
glUseProgramObjectARB(glContext);

glUniform1iARB(glslTextureCube, 0);
glUniform3fARB(glslEye, view.GetCamPos().m_X, view.GetCamPos().m_Y, view.GetCamPos().m_Z);

glEnable(GL_TEXTURE_CUBE_MAP);
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_CUBE_MAP);
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap);

// render object

I was thinking that it should be ok to create a new texture: glUniform1iARB(glslTextureColor, 1); and write the code as this:
glUniform1iARB(glslTextureCube, 0);
glUniform1iARB(glslTextureColor, 1);


// cubemap
glEnable(GL_TEXTURE_CUBE_MAP);
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_CUBE_MAP);
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap);

// colormap
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, colormap);


// render object

Then in the shader I just add colormap*0.5 + cubemap*0.5 as the output color. But this just gives me some very ugly artifacts. Anyone know how I can get my shadersetup to work correctly? The question is basically: How can I pass a cubemap texture and a 2d texture to a GLSL shader? Thank you for reading my post, if you need any clarifications, please ask and I will explain it better or give more code.

Share this post


Link to post
Share on other sites
Advertisement
your not really passing a texture into a shader.

when using glUniform1i(loc,0) all you are doing is specifying which texture unit the texture is bound to. And when using a nice descriptive name in the shader like

uniform samplerCube cubeMap;
uniform sampler2D normalMap;

its easy to tell what texture you are using when writing the shader.

that's literally all I do, define the texture variables in the shader and in the code tell the shader which texture unit the desired texture is using.

considering your problem is shader related it might be a good idea to post your shader source?

Share this post


Link to post
Share on other sites
Thank you for your answer!

I understand what you say, so when I bound a texture unit to say 0,1 and 2, I have 3 textures I can use in the shader. And outside the shader, I use glActiveTextureARB(GL_TEXTURE0_ARB), glActiveTextureARB(GL_TEXTURE1_ARB) and glActiveTextureARB(GL_TEXTURE2_ARB) combined with a glBindTexture to decide what texture I to bind to the different units?

I'm not on the right computer, but I can rewrite the shader:
vertex shader, GLSL:

varying vec2 texCoords;
varying vec3 vReflection;
uniform vec3 vEye;

void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
vec3 vView = gl_Vertex.xyz - vEye.xyz;
vReflection = reflect(vView, gl_Normal);
texCoords = gl_MultiTexCoord0.xy;
}



fragment shader, GLSL:

varying vec2 texCoords;
uniform samplerCube CubeMap;
uniform samplerCube ColorMap;
uniform float r;
varying vec3 vReflection;
void main (void)
{
gl_FragColor = lerp(textureCube(CubeMap, vReflection), texture2D(ColorMap,texCoords.st),r);
}

Share this post


Link to post
Share on other sites
r u using glGetUniformLocation(...) at all to get the correct uniform location?

also glUseProgramObjectARB etc is an opengl extension, since opengl2.0 shaders have become part of the core, i recommend using core functions (theyre slightly differencet WRT glsl)

also
glActiveTextureARB(XXX); //also dont need the ARB
should be the first line u use when youre setting up stuff

eg
below u have
glEnable(GL_TEXTURE_CUBE_MAP); <-- this is operating on who knows? it could be TEXTURE0 but it also could be TEXTURE13
glActiveTextureARB(GL_TEXTURE0_ARB);

Share this post


Link to post
Share on other sites
Thank you for your answers! I updated my code so It does not use the ARB on some of the functions and removed the glEnable(GL_TEXTURE_CUBE_MAP) above the active texture function and everything worked.

Now I just need to create the normal map functionality to the shader, but thats quite easy..


Thanks again :) This is now solved.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!