Forráskód Böngészése

Added clamping to specular term.

This is necessary for OpenGL where pow(0,0) is undefined and apparently can be negative, leading to negative specular light (in DirectX you just get zero).
alteredq 13 éve
szülő
commit
51f45e8bde

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
build/Three.js


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
build/custom/ThreeExtras.js


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
build/custom/ThreeWebGL.js


+ 2 - 2
examples/js/ShaderTerrain.js

@@ -173,7 +173,7 @@ THREE.ShaderTerrain = {
 						"float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
 						"float pointDiffuseWeight = max( dot( normal, lVector ), 0.0 );",
 
-						"float pointSpecularWeight = specularTex.r * pow( pointDotNormalHalf, uShininess );",
+						"float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, uShininess ), 0.0 );",
 
 						"pointDiffuse += pointDistance * pointLightColor[ i ] * uDiffuseColor * pointDiffuseWeight;",
 						"pointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;",
@@ -199,7 +199,7 @@ THREE.ShaderTerrain = {
 						"float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
 						"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",
 
-						"float dirSpecularWeight = specularTex.r * pow( dirDotNormalHalf, uShininess );",
+						"float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, uShininess ), 0.0 );",
 
 						"dirDiffuse += directionalLightColor[ i ] * uDiffuseColor * dirDiffuseWeight;",
 						"dirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;",

+ 2 - 2
src/extras/ShaderUtils.js

@@ -277,7 +277,7 @@ THREE.ShaderUtils = {
 
 							"vec3 pointHalfVector = normalize( vPointLight[ i ].xyz + viewPosition );",
 							"float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
-							"float pointSpecularWeight = specularTex.r * pow( pointDotNormalHalf, uShininess );",
+							"float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, uShininess ), 0.0 );",
 
 							"pointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;",
 
@@ -318,7 +318,7 @@ THREE.ShaderUtils = {
 
 							"vec3 dirHalfVector = normalize( lDirection.xyz + viewPosition );",
 							"float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
-							"float dirSpecularWeight = specularTex.r * pow( dirDotNormalHalf, uShininess );",
+							"float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, uShininess ), 0.0 );",
 
 							"dirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;",
 

+ 2 - 2
src/renderers/WebGLShaders.js

@@ -486,7 +486,7 @@ THREE.ShaderChunk = {
 
 				"vec3 pointHalfVector = normalize( lVector + viewPosition );",
 				"float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
-				"float pointSpecularWeight = pow( pointDotNormalHalf, shininess );",
+				"float pointSpecularWeight = max( pow( pointDotNormalHalf, shininess ), 0.0 );",
 
 				"#ifdef PHYSICALLY_BASED_SHADING",
 
@@ -534,7 +534,7 @@ THREE.ShaderChunk = {
 
 				"vec3 dirHalfVector = normalize( lDirection.xyz + viewPosition );",
 				"float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
-				"float dirSpecularWeight = pow( dirDotNormalHalf, shininess );",
+				"float dirSpecularWeight = max( pow( dirDotNormalHalf, shininess ), 0.0 );",
 
 				"#ifdef PHYSICALLY_BASED_SHADING",
 

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott