diff --git a/src/renderers/shaders/ShaderChunk/bsdfs.glsl b/src/renderers/shaders/ShaderChunk/bsdfs.glsl index 55358dde7440b22b4caa84e2acef00d5fd7e8a3a..40a1cd9d8d94310ff06981107058d644cc8979e8 100644 --- a/src/renderers/shaders/ShaderChunk/bsdfs.glsl +++ b/src/renderers/shaders/ShaderChunk/bsdfs.glsl @@ -58,9 +58,9 @@ float G_GGX_Smith( const in float alpha, const in float dotNL, const in float do float a2 = alpha * alpha; - float gl = dotNL + pow( a2 + ( 1.0 - a2 ) * dotNL * dotNL, 0.5 ); + float gl = dotNL + pow( a2 + ( 1.0 - a2 ) * pow2( dotNL ), 0.5 ); - float gv = dotNV + pow( a2 + ( 1.0 - a2 ) * dotNV * dotNV, 0.5 ); + float gv = dotNV + pow( a2 + ( 1.0 - a2 ) * pow2( dotNV ), 0.5 ); return 1.0 / ( gl * gv ); @@ -72,11 +72,11 @@ float G_GGX_Smith( const in float alpha, const in float dotNL, const in float do // alpha is "roughness squared" in Disney’s reparameterization float D_GGX( const in float alpha, const in float dotNH ) { - float a2 = alpha * alpha; + float a2 = pow2( alpha ); - float denom = dotNH * dotNH * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1 + float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1 - return RECIPROCAL_PI * a2 / ( denom * denom ); + return RECIPROCAL_PI * a2 / pow2( denom ); } @@ -158,7 +158,7 @@ vec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in Ge // source: http://simonstechblog.blogspot.ca/2011/12/microfacet-brdf.html float GGXRoughnessToBlinnExponent( const in float ggxRoughness ) { - return ( 2.0 / square( ggxRoughness + 0.0001 ) - 2.0 ); + return ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 ); } float BlinnExponentToGGXRoughness( const in float blinnExponent ) { diff --git a/src/renderers/shaders/ShaderChunk/common.glsl b/src/renderers/shaders/ShaderChunk/common.glsl index 250fcbf4773ac8243d1ff2ee0f56b2a5543d08b5..9d795d88fde9409a420e651e461191258946c6bb 100644 --- a/src/renderers/shaders/ShaderChunk/common.glsl +++ b/src/renderers/shaders/ShaderChunk/common.glsl @@ -8,9 +8,9 @@ #define saturate(a) clamp( a, 0.0, 1.0 ) #define whiteCompliment(a) ( 1.0 - saturate( a ) ) -float square( const in float x ) { return x*x; } -float cube( const in float x ) { return x*x*x; } -float pow4( const in float x ) { return x*x*x*x; } +float pow2( const in float x ) { return x*x; } +float pow3( const in float x ) { return x*x*x; } +float pow4( const in float x ) { float x2 = x*x; return x2*x2; } float average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); } diff --git a/src/renderers/shaders/ShaderChunk/lights_pars.glsl b/src/renderers/shaders/ShaderChunk/lights_pars.glsl index 060f7015a3c1ce9cfc1bdd551e4a06fe112d753e..5e6c01d5b756c753e48b15404bc1c70ebc6cc003 100644 --- a/src/renderers/shaders/ShaderChunk/lights_pars.glsl +++ b/src/renderers/shaders/ShaderChunk/lights_pars.glsl @@ -210,10 +210,10 @@ float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) { //float envMapWidth = pow( 2.0, maxMIPLevelScalar ); - //float desiredMIPLevel = log2( envMapWidth * sqrt( 3.0 ) ) - 0.5 * log2( square( blinnShininessExponent ) + 1.0 ); + //float desiredMIPLevel = log2( envMapWidth * sqrt( 3.0 ) ) - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 ); float maxMIPLevelScalar = float( maxMIPLevel ); - float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( square( blinnShininessExponent ) + 1.0 ); + float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 ); // clamp to allowable LOD ranges. return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );