WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-24-2013, 04:12 PM
TopazFrost TopazFrost is offline
Member
 
Join Date: Oct 2009
Posts: 23
Headlight only when bump mapping?

I have another lighting question. I already had bump mapping working when I started working on better lights. Any node that doesn't have a bump map is working fine, but any bump mapped node is not taking the new light(s). It is painfully obvious it is the head light that is being used (and it looks horrible with any shiny surface).

Turning it off didn't work. I even tried setting the head light color to [0,0,0]! So, is there something special I have to do to a bump mapped node to use user defined lighting?
Reply With Quote
  #2  
Old 09-24-2013, 04:51 PM
TopazFrost TopazFrost is offline
Member
 
Join Date: Oct 2009
Posts: 23
I forgot something.

I did find the last parameter with the light number, but that only uses one light. That is not enough with I am bump mapping the inside walls.
Reply With Quote
  #3  
Old 10-01-2013, 12:14 PM
TopazFrost TopazFrost is offline
Member
 
Join Date: Oct 2009
Posts: 23
Ok....The built in bump mapping still isn't working, but I found a work around. I made my own bump shader. For those looking for a solution here is the code. This uses 2 hard coded directional light positions, colors, and ambient light. That was all I needed.

Attaching the shader:
Code:
norm = viz.add(textureFilePath)
norm.wrap(viz.WRAP_T, viz.REPEAT)
norm.wrap(viz.WRAP_S, viz.REPEAT)
			
node.texture(norm,unit=1)

shader = viz.addShader( vert='bump.vert', frag='bump.frag')
node.apply(shader)
node.apply(viz.addUniformInt('normalMap',1))
The vertex shader (bump.vert):
Code:
attribute float lightNum1;
attribute float lightNum2;

varying vec3 lightVec;
varying vec3 lightVec2;
varying vec3 vPosition;
varying vec3 eyeVec;
varying vec2 texCoord;

void main(void)  
{     
	//lights positions and color  <----------------------Change this  code block if you want to use GL specified lights
        vec3 LightLocation = vec3(2,2,1);
	vec3 LightLocation2 = vec3(-1,2,-2);

	//put vertex in final render position, and grab texture coordinate for later use in fragment shader
        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
	texCoord = gl_MultiTexCoord0.xy;

	//get everything normalized and in place for later
	vPosition = normalize(vec3(gl_ModelViewMatrix *  gl_Vertex));
	lightVec = normalize(gl_NormalMatrix * LightLocation); 	    //since these are directional light, we only need the orientation
	lightVec2 = normalize(gl_NormalMatrix * LightLocation2); 	

	//the rest of this is getting the space ready for bump mapping which requires a different transform space

	// Building the transform matrix Eye Space (camera) -> Tangent Space (bump map)
        mat3 CameraToTangent;
	vec3 c1 = cross( gl_NormalMatrix * gl_Normal, vec3(0.0, 0.0, 1.0) ); 
	vec3 c2 = cross( gl_NormalMatrix * gl_Normal, vec3(0.0, 1.0, 0.0) ); 
	if( length(c1)>length(c2) )
	{
		CameraToTangent[0] = normalize(c1);
	}
	else
	{
		CameraToTangent[0] = normalize(c2);
	}
	CameraToTangent[2] = normalize (gl_NormalMatrix * gl_Normal);
	CameraToTangent[1] = cross(CameraToTangent[2],CameraToTangent[0]);
	
	// transform light and eye position vectors into tangent/bump space 
	eyeVec = -normalize(vPosition * CameraToTangent);
	lightVec = normalize (lightVec * CameraToTangent);
	lightVec2 = normalize (lightVec2 * CameraToTangent);
}
The fragment shader (bump.frag):
Code:
uniform sampler2D texMap;
uniform sampler2D normalMap;

varying vec3 lightVec;
varying vec3 lightVec2;
varying vec3 vPosition;
varying vec3 eyeVec;
varying vec2 texCoord;

void main (void) 
{ 
	//lights positions and color <------------------Change this  code block if you want to use GL specified lights
	float I = .8;
	float I2 = .6;
	vec4 LightColor = vec4(I,I,I, 1);
        vec4 LightColor2 = vec4(I2,I2,I2, 1);

	gl_FragColor = vec4(0.3,0.3,0.3,1.0);	//add in the ambient right away

	vec3 bump = normalize( texture2D(normalMap, texCoord).xyz * 2.0 - 1.0 );		//the bump mapped normal vector
	
	//calculate the diffuse color for each light (dot for the percentage applied and max to make sure it isn't negative)
	vec4 diffuse = gl_FrontMaterial.diffuse * LightColor *  max (dot (lightVec, bump), 0.0) ; 
	vec4 diffuse2 = gl_FrontMaterial.diffuse * LightColor2 *  max (dot (lightVec2, bump), 0.0) ; 

	//get the specular values for each light
	float specular = pow(clamp(dot(-reflect(lightVec, bump), eyeVec), 0.0, 1.0),  gl_FrontMaterial.shininess );
	float specular2 = pow(clamp(dot(-reflect(lightVec2, bump), eyeVec), 0.0, 1.0),  gl_FrontMaterial.shininess );
	vec4 spec =  gl_FrontMaterial.specular * LightColor * specular;
	vec4 spec2 = gl_FrontMaterial.specular * LightColor2 * specular2;

	//sum all light sources together
	gl_FragColor += diffuse + diffuse2 ;			
	gl_FragColor += spec + spec2;					
	
	gl_FragColor *= texture2D(texMap, texCoord);	//multiply in the texture
	gl_FragColor = clamp(gl_FragColor, 0.0, 1.0);
}
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bump mapping sleiN13 Vizard 3 09-27-2011 12:16 PM
Headlight Question new_horizon Vizard 5 03-04-2011 10:45 AM
mapping method FlyingFish Vizard 1 07-12-2007 10:06 AM
bump mapping cade_mccall Vizard 8 02-03-2006 03:48 PM
Bump mapping? FlyingWren Vizard 1 04-07-2003 12:07 PM


All times are GMT -7. The time now is 01:32 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC