Normal and parallax maps not responding to lighting

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Normal and parallax maps not responding to lighting

Post by 3DModelerMan »

If I use normal or parallax maps my object (lighting enabled). Doesn't respond to adjusting the specular or ambient colors. Why is this? And how can I fix it?
Here's my code

Code: Select all

road->setMesh( smgr->getMeshManipulator()->createMeshWithTangents( road->getMesh(), false, false, false ) );

  //{texture
  road->setMaterialFlag(EMF_NORMALIZE_NORMALS, true);
  road->setMaterialFlag(EMF_BILINEAR_FILTER, true);
  road->setMaterialType(EMT_PARALLAX_MAP_SOLID);

  ITexture* normalMap = driver->getTexture("media/images/road_bump_map.bmp");
  driver->makeNormalMapTexture(normalMap, 9.0f);

  road->setMaterialTexture( 0, driver->getTexture("media/images/road_tex.bmp") );
  road->setMaterialTexture(1, normalMap);

  road->getMaterial(0).AmbientColor.set(256,20,20,20);
  road->getMaterial(0).DiffuseColor.set(256,116,116,116);
  road->getMaterial(0).EmissiveColor.set(256,256,256,256);
  road->getMaterial(0).SpecularColor.set(256,50,50,50);
  road->getMaterial(0).Shininess = 1;
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Change the shaders.
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

How to change shaders.

Post by 3DModelerMan »

How do I change the shaders? If you mean try EMT_NORMAL_MAP_SOLID
I already did.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Re: How to change shaders.

Post by Halifax »

3DModelerMan wrote:How do I change the shaders? If you mean try EMT_NORMAL_MAP_SOLID
I already did.
No, I'm pretty sure he means that you should literally change the shader code.
TheQuestion = 2B || !2B
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, you have to dive into the shader code of the parallax/normal map shader and change that to support your requirements.
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

ummmm

Post by 3DModelerMan »

Ummm... I have no clue what all that code in the openGLnormalRenderer
or whatever it's called does. Is there any other way to have normal maps that actually respond to the lighting I want?
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, you have to code it...
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Post by zillion42 »

is that true for normal maps in directx aswell ?

is there a bug on the tracker, or is someone already involved with the issue being fixed for openGL ?

i mean, isn't that something that should be done or is there some technical problem in the way ?

thx
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

It's not really a "bug". We want to keep the performance requirements down for the built-in shaders so they can be supported by lower end machines, so we can't add too many features. By performance requirements I mean 14 instructions in the pixel shader, and by low end machines I mean the Radeon 9200 and older and Geforce 3 and older.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You don't really have to modify the existing shader code (which would require the library to be rebuilt). You can just copy the shader code into your own source file or shader files, modify that, and then load it just like any other shader.

Travis
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Post by zillion42 »

I am still absolutely unsure if I am really understanding you guys correctly. Can anyone please answer these question with yes or no ?

1. The directx normal map shader reacts to light angle (I mean vector, direction of light) ?
2. The GL normal map shader reacts to light angle (I mean vector, direction of light) ?
4. Both GL and DX normal map shaders dont reacts to specular, ambient ?

if it's really the direction of light which isn't updated it would explain why things look so strange in GL when the sun illuminates planets..., so without having done anything to it, I'll start by posting the irrlicht shader code from COpenGLNormalMapRenderer.cpp for consideration...
unfortunetly I haven't found a comment saying

//uncomment the following to update light angle at runtime

:lol:

no, seriously I think I'd take ages to get behind that vertex shader and understand even the slightest bit of math of tangent space, so yes, help would be nice. Maybe someone can point me to a link for a working normalmap shader...
cheers
Vertex Shader

Code: Select all

	#input
	# 0-3: transposed world matrix;
	#;12: Light01 position 
	#;13: x,y,z: Light01 color; .w: 1/LightRadius^2 
	#;14: Light02 position 
	#;15: x,y,z: Light02 color; .w: 1/LightRadius^2 
	
	ATTRIB InPos = vertex.position;
	ATTRIB InColor = vertex.color;
	ATTRIB InNormal = vertex.normal;
	ATTRIB InTexCoord = vertex.texcoord[0];
	ATTRIB InTangent = vertex.texcoord[1];
	ATTRIB InBinormal = vertex.texcoord[2];
	
	#output
	OUTPUT OutPos = result.position;
	OUTPUT OutLightColor1 = result.color.primary;
	OUTPUT OutLightColor2 = result.color.secondary;
	OUTPUT OutTexCoord = result.texcoord[0];
	OUTPUT OutLightVector1 = result.texcoord[1];
	OUTPUT OutLightVector2 = result.texcoord[2];
	
	PARAM MVP[4] = { state.matrix.mvp }; # modelViewProjection matrix.
	TEMP Temp;
	TEMP TempColor;
	TEMP TempNormal;
	TEMP TempTangent;
	TEMP TempBinormal;
	TEMP TempLightVector1;
	TEMP TempLightVector2;
	TEMP TempTransLightV1;
	TEMP TempTransLightV2;
	
	# transform position to clip space 
	DP4 OutPos.x, MVP[0], InPos;
	DP4 OutPos.y, MVP[1], InPos;
	DP4 OutPos.z, MVP[2], InPos;
	DP4 OutPos.w, MVP[3], InPos;
	
	# transform normal 
	DP3 TempNormal.x, InNormal.x, program.local[0];
	DP3 TempNormal.y, InNormal.y, program.local[1]; 
	DP3 TempNormal.z, InNormal.z, program.local[2];
	
	# transform tangent 
	DP3 TempTangent.x, InTangent.x, program.local[0];
	DP3 TempTangent.y, InTangent.y, program.local[1]; 
	DP3 TempTangent.z, InTangent.z, program.local[2];
	
	# transform binormal 
	DP3 TempBinormal.x, InBinormal.x, program.local[0];
	DP3 TempBinormal.y, InBinormal.y, program.local[1]; 
	DP3 TempBinormal.z, InBinormal.z, program.local[2];
	
	# vertex into world position 
	DP4 Temp.x, InPos, program.local[0];
	DP4 Temp.y, InPos, program.local[1];
	DP4 Temp.z, InPos, program.local[2];
	DP4 Temp.w, InPos, program.local[3];
	
	# vertex - lightpositions 
	SUB TempLightVector1, program.local[12], Temp; 
	SUB TempLightVector2, program.local[14], Temp; 
	
	# transform the light vector 1 with U, V, W 
	DP3 TempTransLightV1.x, TempTangent, TempLightVector1; 
	DP3 TempTransLightV1.y, TempBinormal, TempLightVector1; 
	DP3 TempTransLightV1.z, TempNormal, TempLightVector1; 
	
	# transform the light vector 2 with U, V, W 
	DP3 TempTransLightV2.x, TempTangent, TempLightVector2; 
	DP3 TempTransLightV2.y, TempBinormal, TempLightVector2; 
	DP3 TempTransLightV2.z, TempNormal, TempLightVector2; 
	
	# normalize light vector 1 
	DP3 TempTransLightV1.w, TempTransLightV1, TempTransLightV1; 
	RSQ TempTransLightV1.w, TempTransLightV1.w; 
	MUL TempTransLightV1, TempTransLightV1, TempTransLightV1.w;
	
	# normalize light vector 2 
	DP3 TempTransLightV2.w, TempTransLightV2, TempTransLightV2; 
	RSQ TempTransLightV2.w, TempTransLightV2.w; 
	MUL TempTransLightV2, TempTransLightV2, TempTransLightV2.w;
	
	
	# move light vectors out
	MAD OutLightVector1, TempTransLightV1, {0.5,0.5,0.5,0.5}, {0.5,0.5,0.5,0.5}; 
	MAD OutLightVector2, TempTransLightV2, {0.5,0.5,0.5,0.5}, {0.5,0.5,0.5,0.5}; 
	
	# calculate attenuation of light 1
	MOV TempLightVector1.w, {0,0,0,0}; 
	DP3 TempLightVector1.x, TempLightVector1, TempLightVector1; 
	MUL TempLightVector1.x, TempLightVector1.x, program.local[13].w;  
	RSQ TempLightVector1, TempLightVector1.x; 
	MUL OutLightColor1, TempLightVector1, program.local[13]; # resulting light color = lightcolor * attenuation 
	
	# calculate attenuation of light 2
	MOV TempLightVector2.w, {0,0,0,0}; 
	DP3 TempLightVector2.x, TempLightVector2, TempLightVector2; 
	MUL TempLightVector2.x, TempLightVector2.x, program.local[15].w;  
	RSQ TempLightVector2, TempLightVector2.x; 
	MUL OutLightColor2, TempLightVector2, program.local[15]; # resulting light color = lightcolor * attenuation 
	
	# move out texture coordinates and original alpha value
	MOV OutTexCoord, InTexCoord; 
	MOV OutLightColor1.w, InColor.w; 
	
	END
Pixel Shader

Code: Select all

	#Input
	ATTRIB inTexCoord = fragment.texcoord[0];   
	ATTRIB light1Vector = fragment.texcoord[1]; 
	ATTRIB light2Vector = fragment.texcoord[2];    
	ATTRIB light1Color = fragment.color.primary;   
	ATTRIB light2Color = fragment.color.secondary; 
	
	#Output
	OUTPUT outColor = result.color;
	TEMP temp;
	TEMP temp2;
	TEMP colorMapColor;
	TEMP normalMapColor;
	
	# fetch color and normal map; 
	TXP colorMapColor, inTexCoord, texture[0], 2D; 
	TXP normalMapColor, inTexCoord, texture[1], 2D; 
	
	# calculate color of light1; 
	MAD normalMapColor, normalMapColor, {2,2,2,2}, {-1,-1,-1,-1}; 
	MAD temp, light1Vector, {2,2,2,2}, {-1,-1,-1,-1}; 
	DP3_SAT temp, normalMapColor, temp; 
	MUL temp, light1Color, temp; 
	
	# calculate color of light2; 
	MAD temp2, light2Vector, {2,2,2,2}, {-1,-1,-1,-1}; 
	DP3_SAT temp2, normalMapColor, temp2; 
	MAD temp, light2Color, temp2, temp; 
	
	# luminance * base color; 
	MUL outColor, temp, colorMapColor; 
	MOV outColor.a, light1Color.a; #write interpolated vertex alpha value
	
	END
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, the comments in the first lines say 'Position and Color of Light'. As you can see, no direction. So there's no way to use the direction, if it's not passed into the shader.
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Post by zillion42 »

:roll: ähh, cant we calculate, or isn't it one of the purposes of a vertex shader, to calculate the light vector for each vertex by subtracting light position from vertex position ?
seriously still wondering if the whole thing is a joke... someone having a good laugh out there ? :shock:

OK, thinking about it again, I think my problems with the planets come from the fact that their rotation is not taken into account... I remember reading something like that in another thread...
I really dont care about ambient and specular but the shading (light and dark side) of a sphere should reflect the light direction otherwise 3d graphics really doesn't make sense and I think we were talking about something different here.
Can anyone follow with the rotation of a node, not being taken into account by the shader thing ? Any suggestions maybe ?
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=32487
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Didn't you just talk about directional light? In that case you don't have a position, at least no correct one. So you'd need to get the direction somehow, and skip over the direction calculation (because you already got the direction, in case you got it - got it?). So, no joke, just mentioning something you should note.
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Post by zillion42 »

well as it looks (or should I say I assume) the GL normal map renderer doesn't react to the rotation or the scale of a node, whereas the DX normal maps do that fine... now there is 2 threads about this issue on the forum:

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=32487

http://irrlicht.sourceforge.net/phpBB2/ ... ader+light

and since I'm quite convinced that this is the actual problem, I'm asking again:
Shouldn't this be considered a bug ?

I was just about to dig into the the other two threads to find a solution and use a custom shader, but then again, I think it should be fixed in COpenGLNormalMapRenderer.cpp aswell...
Post Reply