Commits

Anonymous committed 043a6c7

Renames and new shaders.

  • Participants
  • Parent commits 803c0dc

Comments (0)

Files changed (13)

File NPR/NPR.vcxproj

     <None Include="Textures\artmap_incl.png" />
     <None Include="Textures\artmap_point.png" />
     <None Include="Textures\artmap_vert.png" />
+    <None Include="toon.frag" />
+    <None Include="toon.vert" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Mesh.h" />

File NPR/NPR.vcxproj.filters

     <None Include="Textures\artmap_vert.png">
       <Filter>Textures</Filter>
     </None>
+    <None Include="toon.frag">
+      <Filter>Shaders\Fragment</Filter>
+    </None>
+    <None Include="toon.vert">
+      <Filter>Shaders\Vertex</Filter>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Shaders.h">

File NPR/Shaders.cpp

 
 GLuint vobj,fobj,pobj;  //vertex shader object, fragment shader objet, program object
 string shaderFilename;
+int toonLevels = 3;
 
 //=====================================================
 char *readShader(char *fn) {
 	} else {
 		glUniform1i(outlining, 0);
 	}
+
+	if (shaderFilename == "toon") {
+		GLint levels;
+		levels = glGetUniformLocation(pobj, "levels");
+		glUniform1i(levels, toonLevels);
+	}
 }
 
 void clearShaders() {

File NPR/Shaders.h

 using namespace std;
 
 extern string shaderFilename;
+extern int toonLevels;
 
 char *readShader(char *fn);
 void setShaders(string filename, bool enableOutlining = false);

File NPR/main.cpp

 			clearShaders();
 			setShaders("pencil", shaderOutlining);
 		}
+	}  else if (key=='t' || key == 'T') {
+		if (shaderFilename != "toon") {
+			clearShaders();
+			setShaders("toon", shaderOutlining);
+		}
 	} else if (key>='0' && key <='4') {
 		changeLightDirection(key - '0');
 	} else if (key == '+' || key == '=') {

File NPR/metalic.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 fromColour = vec3(0.9, 0.4, 0.6);
+		vec3 toColour = vec3(0.45, 0.2, 0.3);
+		int i;
+		float low = 0.0, high = 0.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);
+				break;
+			}
+		}
+
+		if (EN < 0.2 && outlining > 0) {
+			finalColour = vec4(finalColour.rgb * vec3(0.2, 0.2, 0.2), 1.0);
+		}
+	}
+	
+	gl_FragColor = finalColour;
+}

File NPR/metalic.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;
+}

File NPR/minimal.frag

-uniform int outlining;
-varying vec3 N;
-varying vec3 v;
-
-void main()
-{
-	vec3 E = normalize(-v); // we are in Eye Coordinates, so EyePos is (0,0,0)
-	float EN = dot(E,N);
-	vec4 finalColour;
-	
-	if (EN < 0.1 && outlining > 0) {
-		finalColour = vec4(0.0, 0.0, 0.0, 1.0);
-	} else {
-		finalColour = gl_Color;
-
-		if (EN < 0.2 && outlining > 0) {
-			finalColour = vec4(finalColour.rgb * vec3(0.2, 0.2, 0.2), 1.0);
-		}
-	}
-
-	gl_FragColor = finalColour;
-}

File NPR/minimal.vert

-varying vec3 N;
-varying vec3 v;
-
-void main()
-{
-	v = vec3(gl_ModelViewMatrix * gl_Vertex);
-	N = normalize(gl_NormalMatrix * gl_Normal);
-	gl_Position = ftransform();
-	gl_FrontColor = vec4(gl_Normal, 1.0);
-}

File NPR/normal.frag

+uniform int outlining;
+varying vec3 N;
+varying vec3 v;
+
+void main()
+{
+	vec3 E = normalize(-v); // we are in Eye Coordinates, so EyePos is (0,0,0)
+	float EN = dot(E,N);
+	vec4 finalColour;
+	
+	if (EN < 0.1 && outlining > 0) {
+		finalColour = vec4(0.0, 0.0, 0.0, 1.0);
+	} else {
+		finalColour = gl_Color;
+
+		if (EN < 0.2 && outlining > 0) {
+			finalColour = vec4(finalColour.rgb * vec3(0.2, 0.2, 0.2), 1.0);
+		}
+	}
+
+	gl_FragColor = finalColour;
+}

File NPR/normal.vert

+varying vec3 N;
+varying vec3 v;
+
+void main()
+{
+	v = vec3(gl_ModelViewMatrix * gl_Vertex);
+	N = normalize(gl_NormalMatrix * gl_Normal);
+	gl_Position = ftransform();
+	gl_FrontColor = vec4(gl_Normal, 1.0);
+}

File NPR/toon.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 fromColour = vec3(0.9, 0.4, 0.6);
+		vec3 toColour = vec3(0.45, 0.2, 0.3);
+		int i;
+		float low = 0.0, high = 0.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);
+				break;
+			}
+		}
+
+		if (EN < 0.2 && outlining > 0) {
+			finalColour = vec4(finalColour.rgb * vec3(0.2, 0.2, 0.2), 1.0);
+		}
+	}
+	
+	gl_FragColor = finalColour;
+}

File NPR/toon.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;
+}