I've been spending the better half of the last 2 weeks trying to get bump-mapping working, however I seem to be having a problem when combining a normal map with a texture.

Bump mapping seems to work fine, when I apply only the normal map, however when I try to also apply the colour map (regular texture) the results are somewhat strange. I am using GLSL shaders borrowed from existing tutorials, which seem to work fine and other users have reported that all is working well.

I suspect there is something wrong with my JOGL code, however I cant see what exactly.

Screenshots: (First is with just normal Map, other 2 are with normal map and texture)

http://imgur.com/a/ceDpg

Link to my shader and GL code snippets:

http://pastebin.com/9mPmSNX3

Any help would be greatly appreciated, I am only posting here as a last resort after trawling through pages of threads/tutorials over the last few weeks with no joy.

Hope someone out there can help.

Leo

thokra

10-31-2011, 05:01 AM

What exactly do you mean with "the results are somewhat strange"? What result are you expecting?

I find it hard to determine what's wrong with three entirely different camera angles and no clue as to what the outcome is supposed to look like. From what I can see, it seems there are blocky artefacts in the second shots where I suppose the lighting is to be smooth. Right?

How do you calculate your tangents?

BionicBytes

10-31-2011, 06:17 AM

Why has your normal mapped texture (first image) got white (specular?) highlights on it? If the camera (or the model) rotates, does the colour alter w.r.t the camera position/view.
It should do if your lighting calculations are in camera space.

Are you rotating the models? If so, are you recaululating the tangents or at least the tangent to world matrix.

leolol

10-31-2011, 06:41 AM

Hi There,

Thanks for replying,

Well initially the textures weren't rendering properly (I could get the bumpmap with no texture (that blue 1st screenshot) or the regular texture without bumpmap but not both (the blotchy artefact one was the attempt of rendering both)) I have since found that this was a problem with setting the textures to the right numbers, which brings me to my current problem:

Notice how the ActiveTexture always finishes at GL_TEXTURE0.
That's important because many of the other scene rendering objects rely upon the default state and assume the texture being bound is associated to ActiveTexture #0. So the golden rule is that you should preserve the state if you change it, or resetup the state for each draw call.

Also, notice that when shaders are used, there is no need to enable each texture target for each ActiveTexture. Only when using the fixed function do you have to do that.

leolol

10-31-2011, 09:52 AM

I think I'm having problems with this whole GL_TEXTURE thing.

As advised, I switched the active textures from 1, 2 to 1, 0, so it is counting downwards, however this totally messes everything up and I only see a dimly lit colour texture without any bump mapping.

I am totally confused. Does each unique texture have to have a unique GL_TEXTURE number?

> Well, you need to bind the skybox textures to the appropriate texture unit before rendering. In the simplest case it's
6 binding calls to the same unit (e.g. GL_TEXTURE0).

Is that only valid if all 6 textures are the same?

So sorry for bothering you all, every time I think I'm starting to understand this, something else breaks.

Several thing wrong here.
Firstly, you don't need to enable any texture if you are using shaders.
So this code:

normalMap.enable(gl);
is redundant if it does what I think it does which is glEnable (GL_TEXTURE2D);
as is
normalMap.disable(gl);

Secondly, changing the order of the glActiveTexture commands should never mess up your code becuase the same textures are being bound to the same texture units, so nothing has changed.
In your case however, you are not doing things correctly.

Your uniform parameters which you sent to the shaders should be the 'n' value in glActiveTexture (GL_TEXTURE0 +n ) not the texture ID.
Therefore, the following code

Check out http://www.opengl.org/sdk/docs/man4/xhtml/glActiveTexture.xml

Then there's the concept of "texture objects" in OpenGL. Basically it's a regular buffer holding some defined amount of data. Usually when it comes to textures this data comprises of values interpreted as color. What you get when callin glGenTextures() is one or a number of handles which uniquely identify a texture object.

At least with OpenGL you can have one texture object bound to one texture unit. The symbolic constants GL_TEXTUREi refer to a specific "texture unit". OpenGL maintains one active texture unit as the current state. So, if you want to change the texture a texture unit is working on, you will have to tell OpenGL which unit and which texture.

// for use in shader you associate a texture unit and uniform sampler -
// location named "NormalMap" will now use unit 0 which samples the texture
// defined in tex_object2
glUniform1i("NormalMap", 0);

I am totally confused. Does each unique texture have to have a unique GL_TEXTURE number?

No, kind of the other way around. Only one texture can be bound to a specific texture unit at a time. You can bind the same texture to multiple units, although probably not useful in most cases.

Is that only valid if all 6 textures are the same?

Now you can probably answer this yourself but I'll do it anyway. No, the textures are arbitrary, but in the case of a skybox, which can be implemented using 6 differently oriented planes with 6 different textures, you can use a single texture unit.