Jump to content
  • Advertisement
Sign in to follow this  
Nanoha

OpenGL Difficulty using multiple textures (normal mapping)[SOLVED...]

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

I have implemented some normal mapping in an app I am working on. When I first did it I had an odd issue which turned out to be the normal texture just not being used. I was setting the uniform for the samplers before binding so I bound then set and it worked. Now I have it working I am attempting to clean the code up prior to committing it but now I am back to my original issue! I can't for the life of me get it working correctly.

 

In my shader I have 2 samplers (diffuse and normal). The normals aren't correct, if I set both to be the normal map then my normals and lighting is correct (just the diffuse is the normal texture). If I set the diffuse to diffuse and the normal to normal then I get incorrect normals/lighting which I believe is because the shader is using is the diffuse texture instead of the normal map texture. That was the issue I originally had which I solved but now it's back!

 

It seems to me that I just have an issue with getting the shader to use the correct texture. It is using the same texture (0) for both samplers. I don't know if I am assigning to the uniforms at the wrong time or binding textures at the wrong time but something odd is going on. Unfortunately my code is fairly abstracted and spread out so I can't post it (though I can post specific parts if it'll help). I basically do:

Load textures
Load shader (compile/link)
Bind shader
Set attrib locations (this causes a relink)
Get all the uniform locations
Set uniform values (diffuse to texture 0, normal to 1)
unbind

Then when rendering:

Bind shader
Set per frame uniform values (matrices etc)
glActivetexture(0)
bind diffuse texture
glActiveTexture(1)
bind normal texture
bind vertex array object
render
unbind vao
glActiveTexture(1)
bind previous texture (I store previous textures when binding)
glActiveTexture(0)
bind previous texture
bind previous shader

Not sure what I am doing wrong here. I am aware that when setting a sampler I set it's active texture rather than the texture itself. I've confirmed that my uniforms exist and I also used glGetUniform on both to confirm they are the correct values (and not getting reset somehow). My shader is correct (it worked before rearranging code and works if I set both textures to be the normal map). I'm sure it's something odd like I am doing something in the wrong order or some opengl quirk. I've also put glGetError all over the place and have no errors. I've done a fair bit of Googling for multi-texturing but it has yet to shed any light on my issue.

 

What am I doing wrong?

Share this post


Link to post
Share on other sites
Advertisement

Problem solved; I am officially an idiot.

 

The issue was I had my material loading the diffuse texture for both diffuse and normal map...

Share this post


Link to post
Share on other sites


Set attrib locations (this causes a relink)
Get all the uniform locations

Not that it's important, but why do you get locations after setting them?

And if you're getting them anyway, why set it in the first place?

Share this post


Link to post
Share on other sites

 


Set attrib locations (this causes a relink)
Get all the uniform locations

Not that it's important, but why do you get locations after setting them?

And if you're getting them anyway, why set it in the first place?

 

I assign the actual attributes (e.g. position, normal etc) but I get the uniform locations (e.g. view matrix, light values and so on).

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!