Просмотр исходного кода

Merge pull request #6354 from benaadams/revertish-glsl

Add defines for glsl functions
Ricardo Cabello 10 лет назад
Родитель
Сommit
839ee7a38d

+ 8 - 5
src/renderers/shaders/ShaderChunk/common.glsl

@@ -4,6 +4,9 @@
 #define LOG2 1.442695
 #define EPSILON 1e-6
 
+#define saturate(a) clamp( a, 0.0, 1.0 )
+#define whiteCompliment(a) ( 1.0 - saturate( a ) )
+
 vec3 transformDirection( in vec3 normal, in mat4 matrix ) {
 
 	return normalize( ( matrix * vec4( normal, 0.0 ) ).xyz );
@@ -41,7 +44,7 @@ float calcLightAttenuation( float lightDistance, float cutoffDistance, float dec
 
 	if ( decayExponent > 0.0 ) {
 
-	  return pow( clamp( -lightDistance / cutoffDistance + 1.0, 0.0, 1.0 ), decayExponent );
+	  return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );
 
 	}
 
@@ -75,10 +78,10 @@ vec3 BRDF_BlinnPhong( in vec3 specularColor, in float shininess, in vec3 normal,
 
 	vec3 halfDir = normalize( lightDir + viewDir );
 
-	//float dotNL = clamp( dot( normal, lightDir ), 0.0, 1.0 );
-	//float dotNV = clamp( dot( normal, viewDir ), 0.0, 1.0 );
-	float dotNH = clamp( dot( normal, halfDir ), 0.0, 1.0 );
-	float dotLH = clamp( dot( lightDir, halfDir ), 0.0, 1.0 );
+	//float dotNL = saturate( dot( normal, lightDir ) );
+	//float dotNV = saturate( dot( normal, viewDir ) );
+	float dotNH = saturate( dot( normal, halfDir ) );
+	float dotLH = saturate( dot( lightDir, halfDir ) );
 
 	vec3 F = F_Schlick( specularColor, dotLH );
 

+ 1 - 1
src/renderers/shaders/ShaderChunk/envmap_fragment.glsl

@@ -34,7 +34,7 @@
 
 	#elif defined( ENVMAP_TYPE_EQUIREC )
 		vec2 sampleUV;
-		sampleUV.y = clamp( flipNormal * reflectVec.y * 0.5 + 0.5, 0.0, 1.0 );
+		sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );
 		sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;
 		vec4 envColor = texture2D( envMap, sampleUV );
 

+ 1 - 1
src/renderers/shaders/ShaderChunk/fog_fragment.glsl

@@ -12,7 +12,7 @@
 
 	#ifdef FOG_EXP2
 
-		float fogFactor = 1.0 - clamp( exp2( - fogDensity * fogDensity * depth * depth * LOG2 ), 0.0, 1.0 );
+		float fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * depth * depth * LOG2 ) );
 
 	#else
 

+ 0 - 16
src/renderers/shaders/ShaderChunk/helper_funcs.glsl

@@ -1,16 +0,0 @@
-float square( in float a ) { return a * a; }
-vec2  square( in vec2 a )  { return a * a; }
-vec3  square( in vec3 a )  { return a * a; }
-vec4  square( in vec4 a )  { return a * a; }
-float saturate( in float a ) { return clamp( a, 0.0, 1.0 ); }
-vec2  saturate( in vec2 a )  { return clamp( a, 0.0, 1.0 ); }
-vec3  saturate( in vec3 a )  { return clamp( a, 0.0, 1.0 ); }
-vec4  saturate( in vec4 a )  { return clamp( a, 0.0, 1.0 ); }
-float average( in float a ) { return a; }
-float average( in vec2 a )  { return ( a.x + a.y) * 0.5; }
-float average( in vec3 a )  { return ( a.x + a.y + a.z) / 3.0; }
-float average( in vec4 a )  { return ( a.x + a.y + a.z + a.w) * 0.25; }
-float whiteCompliment( in float a ) { return saturate( 1.0 - a ); }
-vec2  whiteCompliment( in vec2 a )  { return saturate( 1.0 - a ); }
-vec3  whiteCompliment( in vec3 a )  { return saturate( 1.0 - a ); }
-vec4  whiteCompliment( in vec4 a )  { return saturate( 1.0 - a ); }

+ 1 - 1
src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl

@@ -78,7 +78,7 @@ vec3 totalSpecularLight = vec3( 0.0 );
 
 		if ( spotEffect > spotLightAngleCos[ i ] ) {
 
-			spotEffect = clamp( pow( clamp( spotEffect, 0.0, 1.0 ), spotLightExponent[ i ] ), 0.0, 1.0 );
+			spotEffect = saturate( pow( saturate( spotEffect ), spotLightExponent[ i ] ) );
 
 			// attenuation
 

+ 2 - 3
src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl

@@ -60,12 +60,11 @@ varying vec3 vViewPosition;
 vec3 calcCosineTerm( in vec3 normal, in vec3 lightDir ) {
 
 	float dotProduct = dot( normal, lightDir );
-
-	vec3 cosineTerm = vec3( clamp( dotProduct, 0.0, 1.0 ) );
+	vec3 cosineTerm = vec3( saturate( dotProduct ) );
 
 	#ifdef WRAP_AROUND
 
-		vec3 cosineTermHalf = vec3( clamp( 0.5 * dotProduct + 0.5, 0.0, 1.0 ) );
+		vec3 cosineTermHalf = vec3( saturate( 0.5 * dotProduct + 0.5 ) );
 
 		cosineTerm = mix( cosineTerm, cosineTermHalf, wrapRGB );
 

+ 1 - 1
src/renderers/shaders/ShaderLib.js

@@ -737,7 +737,7 @@ THREE.ShaderLib = {
 				// "	gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
 				"vec3 direction = normalize( vWorldPosition );",
 				"vec2 sampleUV;",
-				"sampleUV.y = clamp( tFlip * direction.y * -0.5 + 0.5, 0.0, 1.0 );",
+				"sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
 				"sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
 				"gl_FragColor = texture2D( tEquirect, sampleUV );",
 

+ 0 - 1
utils/build/includes/common.json

@@ -108,7 +108,6 @@
 	"src/renderers/shaders/ShaderChunk/envmap_vertex.glsl",
 	"src/renderers/shaders/ShaderChunk/fog_fragment.glsl",
 	"src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl",
-	"src/renderers/shaders/ShaderChunk/helper_funcs.glsl",
 	"src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl",
 	"src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl",
 	"src/renderers/shaders/ShaderChunk/lights_lambert_pars_vertex.glsl",