Browse Source

remove unused code (clear coat), oren-nayar, and make envmap work in world space properly while using local space coords.

Ben Houston 9 years ago
parent
commit
f89f27d097

+ 2 - 57
src/renderers/shaders/ShaderChunk/bsdfs.glsl

@@ -1,6 +1,5 @@
 //#define ENERGY_PRESERVING_MONOCHROME
 //#define ENERGY_PRESERVING_MONOCHROME
 
 
-#define DIELECTRIC_SPECULAR_F0 0.20
 
 
 float calcLightAttenuation( float lightDistance, float cutoffDistance, float decayExponent ) {
 float calcLightAttenuation( float lightDistance, float cutoffDistance, float decayExponent ) {
 
 
@@ -15,20 +14,6 @@ float calcLightAttenuation( float lightDistance, float cutoffDistance, float dec
 }
 }
 
 
 
 
-ReflectedLight BRDF_Mix( const in ReflectedLight base, const in ReflectedLight over, const in float weight ) {
-	return ReflectedLight(
-		mix( base.diffuse, over.diffuse, weight ),
-		mix( base.specular, over.specular, weight )
-	);
-}
-
-ReflectedLight BRDF_Add( const in ReflectedLight base, const in ReflectedLight over, const in float weight ) {
-	return ReflectedLight(
-		base.diffuse + over.diffuse,
-		base.specular + over.specular 
-	);
-}
-
 vec3 BRDF_Diffuse_Lambert( const in IncidentLight incidentLight, const in GeometricContext geometryContext, const in vec3 diffuseColor ) {
 vec3 BRDF_Diffuse_Lambert( const in IncidentLight incidentLight, const in GeometricContext geometryContext, const in vec3 diffuseColor ) {
 
 
 	// factor of 1/PI in BRDF omitted as incoming light intensity is scaled up by PI because it is considered a punctual light source
 	// factor of 1/PI in BRDF omitted as incoming light intensity is scaled up by PI because it is considered a punctual light source
@@ -37,22 +22,6 @@ vec3 BRDF_Diffuse_Lambert( const in IncidentLight incidentLight, const in Geomet
 
 
 } // validated
 } // validated
 
 
-// this roughness is a different property than specular roughness used in GGX.
-vec3 BRDF_Diffuse_OrenNayar( const in IncidentLight incidentLight, const in GeometricContext geometryContext, const in vec3 diffuseColor, const in float roughness ) {
-
-	vec3 halfDir = normalize( incidentLight.direction + geometryContext.viewDir );
-	float dotVH = saturate( dot( geometryContext.viewDir, halfDir ) );
-	float dotNV = saturate( dot( geometryContext.normal, geometryContext.viewDir ) );
-	float dotNL = saturate( dot( geometryContext.normal, incidentLight.direction ) );
-
-	float m2 = roughness * roughness;
-	float termA = 1.0 - 0.5 * m2 / (m2 + 0.33);
-	float Cosri = 2.0 * dotVH - 1.0 - dotNV * dotNL;
-	float termB = 0.45 * m2 / (m2 + 0.09) * Cosri * ( Cosri >= 0.0 ? min( 1.0, dotNL / dotNV ) : dotNL );
-
-	return diffuseColor * ( dotNL * termA + termB );
-
-}
 
 
 vec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {
 vec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {
 
 
@@ -66,6 +35,7 @@ vec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {
 
 
 } // validated
 } // validated
 
 
+
 // Microfacet Models for Refraction through Rough Surfaces - equation (34)
 // Microfacet Models for Refraction through Rough Surfaces - equation (34)
 // http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
 // http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
 // alpha is "roughness squared" in Disney’s reparameterization
 // alpha is "roughness squared" in Disney’s reparameterization
@@ -99,6 +69,7 @@ float D_GGX( in float alpha, in float dotNH ) {
 
 
 }
 }
 
 
+
 // GGX Distribution, Schlick Fresnel, GGX-Smith Visibility
 // GGX Distribution, Schlick Fresnel, GGX-Smith Visibility
 vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
 vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
 	
 	
@@ -123,32 +94,6 @@ vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in Geometric
 
 
 } // validated
 } // validated
 
 
-// useful for clear coat surfaces, use with Distribution_GGX.
-float G_Kelemen( float vDotH ) {
-
-	return 1.0 / ( 4.0 * vDotH * vDotH + 0.0000001 );
-
-}
-
-#define DIELECTRIC_SPECULAR_F0 0.20
-
-// this blends the existing reflected light with a clear coat.
-vec3 BRDF_Specular_ClearCoat( const in IncidentLight incidentLight, const in GeometricContext geometry, const in float clearCoatWeight, const in float clearCoatRoughness ) {
-
-	vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
-	float dotNH = saturate( dot( geometry.normal, halfDir ) );
-	float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
-	float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );
-	float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
-
-	vec3 F = F_Schlick( vec3( DIELECTRIC_SPECULAR_F0 ), dotLH );
-	float G = G_Kelemen( dotNV );
-	float D = D_GGX( clearCoatRoughness, dotNH );
-
-	
-	return F * ( G * D );
-
-}
 
 
 // ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile
 // ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile
 vec3 BRDF_Specular_GGX_Environment( const in IncidentLight incidentLight, const in GeometricContext geometry, vec3 specularColor, float roughness ) {
 vec3 BRDF_Specular_GGX_Environment( const in IncidentLight incidentLight, const in GeometricContext geometry, vec3 specularColor, float roughness ) {

+ 3 - 5
src/renderers/shaders/ShaderChunk/lights_pars.glsl

@@ -146,15 +146,13 @@ uniform vec3 ambientLightColor;
 
 
 		#endif
 		#endif
 
 
-		reflectVec = normalize( transformDirection( reflectVec, viewMatrix ) );
+		reflectVec = normalize( inverseTransformDirection( reflectVec, viewMatrix ) );
 
 
 		#ifdef ENVMAP_TYPE_CUBE
 		#ifdef ENVMAP_TYPE_CUBE
 
 
-			#if defined( TEXTURE_CUBE_LOD_EXT )
+			#if defined( TEXTURE_CUBE_LOD_EXT )				
 
 
-				float bias = pow( lodLevel, 0.5 ) * 7.0; // from bhouston - there are other models for this calculation (roughness; not roughnesFactor)
-
-				vec4 envMapColor = textureCubeLodEXT( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ), bias );
+				vec4 envMapColor = textureCubeLodEXT( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ), lodLevel );
 
 
 			#else
 			#else
 
 

+ 2 - 1
src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl

@@ -36,6 +36,7 @@ void PhysicalMaterial_RE_SpecularIndirectLight( const in IncidentLight indirectL
 
 
 }
 }
 
 
-#define Material_LightProbeLOD( material )   (material.specularRoughness)
+// from bhouston - there are other models for this calculation (roughness; not roughnesFactor)
+#define Material_LightProbeLOD( material )   (pow( ( material.specularRoughness - 0.5 ) * 2.0, 0.5 ) * 7.0)
 
 
 #define Material_RE_IndirectSpecularLight    PhysicalMaterial_RE_SpecularIndirectLight
 #define Material_RE_IndirectSpecularLight    PhysicalMaterial_RE_SpecularIndirectLight