Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix phongshader

  • Loading branch information...
commit d579e7d63f2de99643cc35c3970708424361ae34 1 parent 3529811
Si Lam authored April 01, 2012
82  USTNoir4.cpp
@@ -653,44 +653,24 @@ void setupPoliceLight()
653 653
 {
654 654
 	//stack.push(mv);
655 655
 
656  
-		/*mv = mv * Translate(rightlampSource.x, 0, rightlampSource.z);
657  
-		mv = mv * RotateY(turnCarAngle);*/
  656
+		/*mv = mv * Translate(rightlampSource.x, 0, rightlampSource.z);*/
  657
+		//policeredlightlampDest = RotateY(turnPoliceLampAngle)*policeredlightlampDest;
658 658
 
659 659
 		glUniform4fv(policeredlight_position, 1, mv*policeredlightlampSource); 
660  
-		glUniform4fv(policeredspot_direction, 1, mv*policeredlightlampDest);
  660
+		glUniform4fv(policeredspot_direction, 1, mv*RotateY(turnPoliceLampAngle)*policeredlightlampDest);
661 661
 
662 662
 	//mv = stack.pop();
663 663
 
664  
-	glUniform4fv(policeredlight_color,    1, vec4(1.0f,.0f,.0f,1));
665  
-	glUniform4fv(policereddiffuse_color,  1, vec4(1.0f,.0f,.0f,1));
666  
-	glUniform4fv(policeredspecular_color, 1, vec4(1.0f,.0f,.0f,1));
  664
+	glUniform4fv(policeredlight_color,    1, vec4(1.0f,0.0f,.0f,1));
  665
+	glUniform4fv(policereddiffuse_color,  1, vec4(1.0f,0.0f,.0f,1));
  666
+	glUniform4fv(policeredspecular_color, 1, vec4(1.0f,0.0f,.0f,1));
667 667
 	glUniform4fv(policeredambient_light,  1, vec4(.2, .2, .2, 1));
668 668
 
669 669
 	
670  
-	glUniform1f(policeredspot_cutoff, 1);
671  
-	glUniform1f(policeredspot_exponent, 100);
672  
-
673  
-
674  
-
675  
-	//stack.push(mv);
676  
-
677  
-		/*mv = mv * Translate(rightlampSource.x, 0, rightlampSource.z);
678  
-		mv = mv * RotateY(turnCarAngle);*/
679  
-
680  
-		glUniform4fv(policebluelight_position, 1, mv*policebluelightlampSource); 
681  
-		glUniform4fv(policebluespot_direction, 1, mv*policebluelightlampDest);
682  
-
683  
-	//mv = stack.pop();
684  
-
685  
-	glUniform4fv(policebluelight_color, 1, vec4(0.0f,.0f,1.0f,1));
686  
-	glUniform4fv(policebluediffuse_color, 1, vec4(0.0f,.0f,1.0f,1));
687  
-	glUniform4fv(policebluespecular_color, 1, vec4(0.0f,.0f,1.0f,1));
688  
-	glUniform4fv(policeblueambient_light, 1, vec4(.2, .2, .2, 1));
  670
+	glUniform1f(policeredspot_cutoff, 15);
  671
+	glUniform1f(policeredspot_exponent, 120);
689 672
 
690 673
 	
691  
-	glUniform1f(policebluespot_cutoff, 45);
692  
-	glUniform1f(policebluespot_exponent, 10);
693  
-
694 674
 }
695 675
 
696 676
 void setupHeadLight()
@@ -1072,34 +1052,37 @@ void setupShader(GLuint prog){
1072 1052
 	vStageSpecularColor = glGetAttribLocation(prog, "vSpecularColor");
1073 1053
 	vStageSpecularExponent = glGetAttribLocation(prog, "vSpecularExponent");
1074 1054
 
1075  
-
  1055
+	///////////////////////////////////////////////////
1076 1056
 	// setup moonlight
  1057
+	///////////////////////////////////////////////////
1077 1058
 	moonlight_position = glGetUniformLocation(prog, "lights[0].position");
1078 1059
 	moondiffuse_color = glGetUniformLocation(prog, "lights[0].diffuse");
1079 1060
 	moonspecular_color = glGetUniformLocation(prog, "lights[0].specular");
1080 1061
 	moonambient_light = glGetUniformLocation(prog, "ambient_light");
1081 1062
 
  1063
+	///////////////////////////////////////////////////
1082 1064
 	//setup headlight
1083  
-	headlight_position = glGetUniformLocation(prog, "lights[1].position");
1084  
-	headdiffuse_color = glGetUniformLocation(prog, "lights[1].diffuse");
1085  
-	headspecular_color = glGetUniformLocation(prog, "lights[1].specular");
  1065
+	///////////////////////////////////////////////////
  1066
+	headlight_position = glGetUniformLocation(prog, "lights[2].position");
  1067
+	headdiffuse_color = glGetUniformLocation(prog, "lights[2].diffuse");
  1068
+	headspecular_color = glGetUniformLocation(prog, "lights[2].specular");
1086 1069
 	headambient_light = glGetUniformLocation(prog, "ambient_light");
1087 1070
 
1088  
-	headspot_direction = glGetUniformLocation(prog, "lights[1].spot_direction");
1089  
-	headspot_cutoff = glGetUniformLocation(prog, "lights[1].spot_cutoff");
1090  
-	headspot_exponent = glGetUniformLocation(prog, "lights[1].spot_exponent");
  1071
+	headspot_direction = glGetUniformLocation(prog, "lights[2].spot_direction");
  1072
+	headspot_cutoff = glGetUniformLocation(prog, "lights[2].spot_cutoff");
  1073
+	headspot_exponent = glGetUniformLocation(prog, "lights[2].spot_exponent");
1091 1074
  
1092 1075
 	///////////////////////////////////////////////////
1093 1076
 	// setup police light
1094 1077
 	//////////////////////////////////////////////////
1095  
-	policeredlight_position = glGetUniformLocation(prog, "lights[2].position");
1096  
-	policereddiffuse_color = glGetUniformLocation(prog, "lights[2].diffuse");
1097  
-	policeredspecular_color = glGetUniformLocation(prog, "lights[2].specular");
  1078
+	policeredlight_position = glGetUniformLocation(prog, "lights[1].position");
  1079
+	policereddiffuse_color = glGetUniformLocation(prog, "lights[1].diffuse");
  1080
+	policeredspecular_color = glGetUniformLocation(prog, "lights[1].specular");
1098 1081
 	policeredambient_light = glGetUniformLocation(prog, "ambient_light");
1099 1082
 
1100  
-	policeredspot_direction = glGetUniformLocation(prog, "lights[2].spot_direction");
1101  
-	policeredspot_cutoff = glGetUniformLocation(prog, "lights[2].spot_cutoff");
1102  
-	policeredspot_exponent = glGetUniformLocation(prog, "lights[2].spot_exponent");
  1083
+	policeredspot_direction = glGetUniformLocation(prog, "lights[1].spot_direction");
  1084
+	policeredspot_cutoff = glGetUniformLocation(prog, "lights[1].spot_cutoff");
  1085
+	policeredspot_exponent = glGetUniformLocation(prog, "lights[1].spot_exponent");
1103 1086
  
1104 1087
 
1105 1088
 
@@ -1156,7 +1139,7 @@ void setupPoliceLightShader(GLuint prog)
1156 1139
 	glGenBuffers( 2, &policeredvbo[0] );
1157 1140
     glBindBuffer( GL_ARRAY_BUFFER, policeredvbo[0] );
1158 1141
 	glBufferData( GL_ARRAY_BUFFER, 144*sizeof(vec4), policeLampRedVerts, GL_STATIC_DRAW);
1159  
-	glBindBuffer( GL_ARRAY_BUFFER, carvbo[1] );
  1142
+	glBindBuffer( GL_ARRAY_BUFFER, policeredvbo[1] );
1160 1143
 	glBufferData( GL_ARRAY_BUFFER, 144*sizeof(vec3), policeLampRedNormals, GL_STATIC_DRAW );
1161 1144
 
1162 1145
 
@@ -1166,7 +1149,7 @@ void setupPoliceLightShader(GLuint prog)
1166 1149
 	glEnableVertexAttribArray(vPosition);
1167 1150
 	glVertexAttribPointer(vPosition, 4, GL_FLOAT, GL_FALSE, 0, 0);
1168 1151
 
1169  
-	glBindBuffer( GL_ARRAY_BUFFER, carvbo[1] );
  1152
+	glBindBuffer( GL_ARRAY_BUFFER, policeredvbo[1] );
1170 1153
 	vNormal = glGetAttribLocation(prog, "vNormal");
1171 1154
 	glEnableVertexAttribArray(vNormal);
1172 1155
 	glVertexAttribPointer(vNormal, 3, GL_FLOAT, GL_FALSE, 0, 0);
@@ -1343,6 +1326,11 @@ void myIdle()
1343 1326
 			rightlampSource = vec4(rightlampSource.x,-0.90,rightlampSource.z,1); 
1344 1327
 			rightlampDest   = vec3(rightlampDest.x,-0.99,rightlampDest.z); 
1345 1328
 
  1329
+
  1330
+			
  1331
+			policeredlightlampSource = vec4(0.015, -0.905, 0.05, 1);
  1332
+			policeredlightlampDest   = vec3(0.015, -0.905, 5);
  1333
+
1346 1334
 			if ( currentX < -1.0 )
1347 1335
 			{
1348 1336
 				currentX = -1.00f;
@@ -1392,6 +1380,9 @@ void myIdle()
1392 1380
 			rightlampSource = vec4(rightlampSource.x,-0.90,rightlampSource.z,1); 
1393 1381
 			rightlampDest   = vec3(rightlampDest.x,-0.99,rightlampDest.z); 
1394 1382
 
  1383
+			policeredlightlampSource = vec4(0.015, -0.905, 0.05, 1);
  1384
+			policeredlightlampDest   = vec3(0.015, -0.905, -5);
  1385
+
1395 1386
 			if ( currentX < -1.0 )
1396 1387
 			{
1397 1388
 				currentX = -1.00f;
@@ -1658,9 +1649,8 @@ void init() {
1658 1649
   rightlampSource = vec4(rightlampSource.x,-0.90,rightlampSource.z,1); 
1659 1650
   rightlampDest   = vec3(rightlampDest.x,-0.99,rightlampDest.z); 
1660 1651
 
1661  
-  
1662  
-	policeredlightlampSource = vec4(0.015, -0.905, 0.05, 1);
1663  
-	policeredlightlampDest   = vec3(0.015, -0.905, -1);
  1652
+  policeredlightlampSource = vec4(0.015, -0.905, 0.05, 1);
  1653
+  policeredlightlampDest   = vec3(0.015, -0.905, -5);
1664 1654
 
1665 1655
   turnCarAngle = 0;
1666 1656
   turnAngle = 0;
6  fshader-phongshading.glsl
@@ -23,7 +23,7 @@ struct lightSource
23 23
 	float spot_cutoff, spotExponent,spotCosCutoff; // (range: [1.0,0.0],-1.0)
24 24
 	vec3 spot_direction;
25 25
 };
26  
-const int numberofLightSources = 2;
  26
+const int numberofLightSources = 3;
27 27
 uniform lightSource lights[numberofLightSources];
28 28
 
29 29
 vec4 scene_ambient = vec4(0.2, 0.2, 0.2, 1.0);
@@ -55,7 +55,7 @@ void main()
55 55
 		if ( lights[index].position.w == 0 ) // directional light
56 56
 		{
57 57
 			attenuation = 1;
58  
-			L = normalize( lights[index].position.xyz - position.xyz);
  58
+			L = normalize( lights[index].position.xyz);// - position.xyz);
59 59
 		}
60 60
 		else // spot light
61 61
 		{
@@ -89,7 +89,7 @@ void main()
89 89
 			spec = vec4(0,0,0,1);
90 90
 		}
91 91
 	
92  
-		final_color = amb + diff + spec;
  92
+		final_color += amb + diff + spec;
93 93
 	}
94 94
 	fColor = final_color;
95 95
 }

0 notes on commit d579e7d

Please sign in to comment.
Something went wrong with that request. Please try again.