소스 검색

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 년 전
부모
커밋
51f45e8bde
6개의 변경된 파일6개의 추가작업 그리고 6개의 파일을 삭제
  1. 0 0
      build/Three.js
  2. 0 0
      build/custom/ThreeExtras.js
  3. 0 0
      build/custom/ThreeWebGL.js
  4. 2 2
      examples/js/ShaderTerrain.js
  5. 2 2
      src/extras/ShaderUtils.js
  6. 2 2
      src/renderers/WebGLShaders.js

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
build/Three.js


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
build/custom/ThreeExtras.js


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 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",
 

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.