Commits

Anonymous committed b068788

Working on toons and metallic.

Comments (0)

Files changed (10)

     <None Include="homer.off" />
     <None Include="metalic.frag" />
     <None Include="metalic.vert" />
+    <None Include="metalic2.frag" />
+    <None Include="metalic2.vert" />
     <None Include="normal.frag" />
     <None Include="normal.vert" />
     <None Include="pencil.frag" />
     <None Include="Textures\artmap_vert.png" />
     <None Include="toon.frag" />
     <None Include="toon.vert" />
+    <None Include="toon2.frag" />
+    <None Include="toon2.vert" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Mesh.h" />

NPR/NPR.vcxproj.filters

     <None Include="metalic.vert">
       <Filter>Shaders\Vertex</Filter>
     </None>
+    <None Include="metalic2.frag">
+      <Filter>Shaders\Fragment</Filter>
+    </None>
+    <None Include="toon2.frag">
+      <Filter>Shaders\Fragment</Filter>
+    </None>
+    <None Include="metalic2.vert">
+      <Filter>Shaders\Vertex</Filter>
+    </None>
+    <None Include="toon2.vert">
+      <Filter>Shaders\Vertex</Filter>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Shaders.h">

NPR/Report.docx

Binary file modified.
 			clearShaders();
 			setShaders("phong", shaderOutlining);
 		}
-	} else if(key=='m' || key == 'M') { // normals shader
+	} else if(key=='m') { // normals shader
 		if (shaderFilename != "metalic") {
 			clearShaders();
 			setShaders("metalic", shaderOutlining);
 		}
-	}  else if(key=='n' || key == 'N') { // normals shader
+	} else if(key=='M') { // normals shader
+		if (shaderFilename != "metalic2") {
+			clearShaders();
+			setShaders("metalic2", shaderOutlining);
+		}
+	} else if(key=='n' || key == 'N') { // normals shader
 		if (shaderFilename != "normal") {
 			clearShaders();
 			setShaders("normal", shaderOutlining);
 			clearShaders();
 			setShaders("pencil", shaderOutlining);
 		}
-	} else if (key=='t' || key == 'T') {
+	} else if (key=='t') {
 		if (shaderFilename != "toon") {
 			clearShaders();
 			setShaders("toon", shaderOutlining);
 		}
+	}  else if (key=='T') {
+		if (shaderFilename != "toon2") {
+			clearShaders();
+			setShaders("toon2", shaderOutlining);
+		}
 	} else if (key=='[' || key == '{') {
-		if (toonLevels > 1) toonLevels--;
+		if (toonLevels > 1) {
+			toonLevels--;
+			string fn = shaderFilename;
+			clearShaders();
+			setShaders(fn, shaderOutlining);
+		}
 	} else if (key==']' || key == '}') {
 		toonLevels++;
+		string fn = shaderFilename;
+		clearShaders();
+		setShaders(fn, shaderOutlining);
 	} else if (key>='0' && key <='4') {
 		changeLightDirection(key - '0');
 	} else if (key == '+' || key == '=') {
 	if (EN < 0.1 && outlining > 0) {
 		finalColour = vec4(0.0, 0.0, 0.0, 1.0);
 	} else {
-		vec3 fromColour = vec3(0.9, 0.4, 0.6);
-		vec3 toColour = vec3(0.45, 0.2, 0.3);
+		vec3 mainColour = vec3(0.9, 0.4, 0.6);
+		vec3 shadowColour = vec3(0.45, 0.2, 0.3);
 		int i;
 		float low = 0.0, high = 0.0;
-		float criteria = (EN + 1.0) / 2.0;
+		float criteria = (RE + 1.0) / 2.0;
 
-		finalColour = vec4(toColour, 1.0);
+		finalColour = vec4(shadowColour, 1.0);
 
 		for (i = 1; i < levels; i++) {
 			low = high;
 			high = float(i) * (1.0 / float(levels));
-			if (RE > low && RE < high) {
-				finalColour = vec4(mix(fromColour, toColour, high), 1.0);
+			if (criteria > low && criteria < high) {
+				finalColour = vec4(mix(mainColour, shadowColour, high), 1.0);
 				break;
 			}
 		}

NPR/metalic2.frag

+uniform int outlining;
+uniform int levels;
+varying vec3 N;
+varying vec3 v;
+
+void main (void) 
+{  
+	vec3 L = normalize(gl_LightSource[0].position.xyz - v);
+	vec3 E = normalize(-v); // we are in Eye Coordinates, so EyePos is (0,0,0)
+	vec3 R = normalize(-reflect(L,N));
+	float NL = dot(N,L);
+	float gooch = (NL + 1.0) / 2.0;
+	float RE = dot(R,E);
+	float EN = dot(E,N);
+	vec4 finalColour;
+
+	if (EN < 0.1 && outlining > 0) {
+		finalColour = vec4(0.0, 0.0, 0.0, 1.0);
+	} else {
+		vec3 mainColour = vec3(0.9, 0.4, 0.6);
+		vec3 shadowColour = vec3(0.45, 0.2, 0.3);
+		int i;
+		float low = 0.0, high = 0.0;
+		float criteria = (NL + 1.0) / 2.0;
+
+		finalColour = vec4(shadowColour, 1.0);
+
+		for (i = 1; i < levels; i++) {
+			low = high;
+			high = float(i) * (1.0 / float(levels));
+			if (criteria > low && criteria < high) {
+				finalColour = vec4(mix(mainColour, shadowColour, high), 1.0);
+				break;
+			}
+		}
+
+		if (EN < 0.2 && outlining > 0) {
+			finalColour = vec4(finalColour.rgb * vec3(0.2, 0.2, 0.2), 1.0);
+		}
+	}
+	
+	gl_FragColor = finalColour;
+}

NPR/metalic2.vert

+varying vec3 N;
+varying vec3 v;
+
+void main(void) 
+{     
+	v = vec3(gl_ModelViewMatrix * gl_Vertex);
+	N = normalize(gl_NormalMatrix * gl_Normal);
+	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+}
 	if (EN < 0.1 && outlining > 0) {
 		finalColour = vec4(0.0, 0.0, 0.0, 1.0);
 	} else {
-		vec3 fromColour = vec3(0.9, 0.4, 0.6);
-		vec3 toColour = vec3(0.45, 0.2, 0.3);
+		vec3 mainColour = vec3(0.9, 0.4, 0.6);
+		vec3 shadowColour = vec3(0.45, 0.2, 0.3);
 		int i;
 		float low = 0.0, high = 0.0;
 		float criteria = (EN + 1.0) / 2.0;
 
-		finalColour = vec4(toColour, 1.0);
+		finalColour = vec4(shadowColour, 1.0);
 
 		for (i = 1; i < levels; i++) {
 			low = high;
 			high = float(i) * (1.0 / float(levels));
 			if (EN > low && EN < high) {
-				finalColour = vec4(mix(fromColour, toColour, high), 1.0);
+				finalColour = vec4(mix(mainColour, shadowColour, high), 1.0);
 				break;
 			}
 		}
+uniform int outlining;
+uniform int levels;
+varying vec3 N;
+varying vec3 v;
+
+void main (void) 
+{  
+	vec3 L = normalize(gl_LightSource[0].position.xyz - v);
+	vec3 E = normalize(-v); // we are in Eye Coordinates, so EyePos is (0,0,0)
+	vec3 R = normalize(-reflect(L,N));
+	float NL = dot(N,L);
+	float gooch = (NL + 1.0) / 2.0;
+	float RE = dot(R,E);
+	float EN = dot(E,N);
+	vec4 finalColour;
+
+	if (EN < 0.1 && outlining > 0) {
+		finalColour = vec4(0.0, 0.0, 0.0, 1.0);
+	} else {
+		vec3 mainColour = vec3(0.9, 0.4, 0.6);
+		vec3 shadowColour = vec3(0.45, 0.2, 0.3);
+		int i;
+		float low = 0.0, high = 0.0;
+		float criteria = (EN + 1.0) / 2.0;
+
+		finalColour = vec4(shadowColour, 1.0);
+
+		for (i = 1; i < levels; i++) {
+			low = high;
+			high = float(i) * (1.0 / float(levels));
+			if (NL > low && NL < high) {
+				finalColour = vec4(mix(mainColour, shadowColour, high), 1.0);
+				break;
+			}
+		}
+
+		if (EN < 0.2 && outlining > 0) {
+			finalColour = vec4(finalColour.rgb * vec3(0.2, 0.2, 0.2), 1.0);
+		}
+	}
+	
+	gl_FragColor = finalColour;
+}
+varying vec3 N;
+varying vec3 v;
+
+void main(void) 
+{     
+	v = vec3(gl_ModelViewMatrix * gl_Vertex);
+	N = normalize(gl_NormalMatrix * gl_Normal);
+	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+}