GLSL Object Space Normal Map Shader (Solved)

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

GLSL Object Space Normal Map Shader (Solved)

Post by Klunk »

out of interest has anyone managed to create one for irrlicht ? Though I've got a perfectly good tangent space version I was looking to get one working but it doesn't seem to be working correctly. The map is create in max and the fx shader I use in max works well but trying to replicate that in GLSL within irrlicht is proving problematic.
Last edited by Klunk on Wed Sep 02, 2015 9:27 am, edited 1 time in total.
The_Glitch
Competition winner
Posts: 523
Joined: Tue Jan 15, 2013 6:36 pm

Re: GLSL Object Space Normal Map Shader

Post by The_Glitch »

Are you asking for a shader or perhaps a link to some information so you can maybe find what's wrong with your shader?


http://www.google.com/url?sa=t&rct=j&q= ... 0829,d.eXY
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Re: GLSL Object Space Normal Map Shader

Post by Klunk »

yep I've seen that, i'm not animating the object and using a directional light, I was really after a yes or no.

but for what it's worth this would be the glsl shader equivalent to what I'm doing in max with hlsl shader (which works entirely as expected)

.vert

Code: Select all

uniform int  light;
 
varying vec3 lightdir; 
 
void main(void)
{
    gl_Position = ftransform();
    gl_TexCoord[0] = gl_MultiTexCoord0;
    lightdir = normalize(gl_ModelViewMatrixInverse * gl_LightSource[light].position).xyz;
    gl_FrontColor = gl_Color;  // pass vertex colour to the fragment shader 
}
.frag

Code: Select all

uniform int  light;
uniform vec4 ka;            
uniform vec4 kd;
varying vec3 lightdir;
 
uniform sampler2D diffmap;
uniform sampler2D normmap;
 
void main(void)
{
    vec4 diffuse = texture2D(diffmap, gl_TexCoord[0].xy);
    vec3 N = 2.0 * (texture2D(normmap,gl_TexCoord[0].xy).xyz - 0.5);
    float lambert = 0.5 * dot( normalize(lightdir),N.xyz) + 0.5;
    gl_FragColor = diffuse * (ka + kd * lambert * lambert) * gl_Color * gl_LightSource[light].diffuse;
    gl_FragColor.a = diffuse.a;                      
}
I've done some further tests (created a flat shader where the light is transformed into object space as above and I use the actual object normals to compute the lighting, which works) so it must be something todo with normal map or how it's handled

solved it....

Code: Select all

vec3 N = normalize(2.0 * (texture2D(normmap,gl_TexCoord[0].xy).xzy - 0.5));
I had previously tried the yz swap but without the normalize hey ho :D
Post Reply