Parcourir la source

Optimizing a little

Panagiotis Christopoulos Charitos il y a 13 ans
Parent
commit
838c2dbe3c

+ 14 - 7
shaders/MaterialFragmentFunctions.glsl

@@ -3,8 +3,6 @@
 
 
 #pragma anki include "shaders/Pack.glsl"
 #pragma anki include "shaders/Pack.glsl"
 
 
-#define MAX_SHININESS 128.0
-
 /// Generic add
 /// Generic add
 #define add_DEFINED
 #define add_DEFINED
 #define add(a, b) (a + b)
 #define add(a, b) (a + b)
@@ -120,16 +118,25 @@ vec3 readRgbFromTexture(in sampler2D tex, in vec2 texCoords)
 void writeFais(
 void writeFais(
 	in vec3 diffCol, // Normalized
 	in vec3 diffCol, // Normalized
 	in vec3 normal, 
 	in vec3 normal, 
-	in vec2 specular, // Streangth and shininess
+	in float specularComponent, // Streangth and shininess
 	in float blurring)
 	in float blurring)
 {
 {
-#if 1
 	// Diffuse color and specular
 	// Diffuse color and specular
-	fMsFai0[0] = packUnorm4x8(vec4(diffCol, packSpecular(specular)));
+	fMsFai0[0] = packUnorm4x8(vec4(diffCol, specularComponent));
 	// Normal
 	// Normal
 	fMsFai0[1] = packHalf2x16(packNormal(normal));
 	fMsFai0[1] = packHalf2x16(packNormal(normal));
-#else
-	fMsFai0 = vec3(diffCol);
+}
 #endif
 #endif
+
+/// Write the data to FAIs
+#if defined(PASS_COLOR)
+#	define writeFaisPackSpecular_DEFINED
+void writeFaisPackSpecular(
+	in vec3 diffCol, // Normalized
+	in vec3 normal, 
+	in vec2 specular, // Streangth and shininess
+	in float blurring)
+{
+	writeFais(diffCol, normal, packSpecular(specular), blurring);
 }
 }
 #endif
 #endif

+ 2 - 5
shaders/MaterialFragmentVariables.glsl

@@ -20,17 +20,14 @@ in float vTangentW;
 #	define vTangentW_DEFINED
 #	define vTangentW_DEFINED
 in vec3 vVertPosViewSpace;
 in vec3 vVertPosViewSpace;
 #	define vVertPosViewSpace_DEFINED
 #	define vVertPosViewSpace_DEFINED
+flat in float vSpecularComponent;
+#	define vSpecularComponent_DEFINED
 #endif
 #endif
 /// @}
 /// @}
 
 
 /// @name Fragment out
 /// @name Fragment out
 /// @{
 /// @{
-#if defined(PASS_COLOR)
-#if 1
 layout(location = 0) out uvec2 fMsFai0;
 layout(location = 0) out uvec2 fMsFai0;
-#else
-layout(location = 0) out vec3 fMsFai0;
-#endif
 #	define fMsFai0_DEFINED
 #	define fMsFai0_DEFINED
 #endif
 #endif
 /// @}
 /// @}

+ 10 - 2
shaders/MaterialVertex.glsl

@@ -1,6 +1,8 @@
 /// @file
 /// @file
 /// Generic vertex shader for material passes (both color and depth)
 /// Generic vertex shader for material passes (both color and depth)
 
 
+#pragma anki include "shaders/Pack.glsl"
+
 /// @name Attributes
 /// @name Attributes
 /// @{
 /// @{
 layout(location = 0) in vec3 position;
 layout(location = 0) in vec3 position;
@@ -28,11 +30,10 @@ out vec3 vNormal;
 out vec3 vTangent;
 out vec3 vTangent;
 out float vTangentW;
 out float vTangentW;
 out vec3 vVertPosViewSpace; ///< For env mapping. AKA view vector
 out vec3 vVertPosViewSpace; ///< For env mapping. AKA view vector
+flat out float vSpecularComponent; ///< Calculate it per fragment
 #endif
 #endif
 /// @}
 /// @}
 
 
-
-//==============================================================================
 /// Calculate the position and the varyings
 /// Calculate the position and the varyings
 #define doVertex_DEFINED
 #define doVertex_DEFINED
 void doVertex()
 void doVertex()
@@ -53,3 +54,10 @@ void doVertex()
 	gl_Position = modelViewProjectionMat * vec4(position, 1.0);
 	gl_Position = modelViewProjectionMat * vec4(position, 1.0);
 }
 }
 
 
+/// Calculate the position and the varyings
+#define doVertexPrepackSpecular_DEFINED
+void doVertexPrepackSpecular(in vec2 specular)
+{
+	doVertex();
+	vSpecularComponent = packSpecular(specular);
+}