Skip to content

Commit d360627

Browse files
committed
adopt pow2, pow3, pow4
1 parent c2ea1ff commit d360627

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/renderers/shaders/ShaderChunk/bsdfs.glsl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ float G_GGX_Smith( const in float alpha, const in float dotNL, const in float do
5858

5959
float a2 = alpha * alpha;
6060

61-
float gl = dotNL + pow( a2 + ( 1.0 - a2 ) * dotNL * dotNL, 0.5 );
61+
float gl = dotNL + pow( a2 + ( 1.0 - a2 ) * pow2( dotNL ), 0.5 );
6262

63-
float gv = dotNV + pow( a2 + ( 1.0 - a2 ) * dotNV * dotNV, 0.5 );
63+
float gv = dotNV + pow( a2 + ( 1.0 - a2 ) * pow2( dotNV ), 0.5 );
6464

6565
return 1.0 / ( gl * gv );
6666

@@ -72,11 +72,11 @@ float G_GGX_Smith( const in float alpha, const in float dotNL, const in float do
7272
// alpha is "roughness squared" in Disney’s reparameterization
7373
float D_GGX( const in float alpha, const in float dotNH ) {
7474

75-
float a2 = alpha * alpha;
75+
float a2 = pow2( alpha );
7676

77-
float denom = dotNH * dotNH * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1
77+
float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1
7878

79-
return RECIPROCAL_PI * a2 / ( denom * denom );
79+
return RECIPROCAL_PI * a2 / pow2( denom );
8080

8181
}
8282

@@ -158,7 +158,7 @@ vec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in Ge
158158

159159
// source: http://simonstechblog.blogspot.ca/2011/12/microfacet-brdf.html
160160
float GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {
161-
return ( 2.0 / square( ggxRoughness + 0.0001 ) - 2.0 );
161+
return ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );
162162
}
163163

164164
float BlinnExponentToGGXRoughness( const in float blinnExponent ) {

src/renderers/shaders/ShaderChunk/common.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#define saturate(a) clamp( a, 0.0, 1.0 )
99
#define whiteCompliment(a) ( 1.0 - saturate( a ) )
1010

11-
float square( const in float x ) { return x*x; }
12-
float cube( const in float x ) { return x*x*x; }
13-
float pow4( const in float x ) { return x*x*x*x; }
11+
float pow2( const in float x ) { return x*x; }
12+
float pow3( const in float x ) { return x*x*x; }
13+
float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
1414
float average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }
1515

1616

src/renderers/shaders/ShaderChunk/lights_pars.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@
210210
float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {
211211

212212
//float envMapWidth = pow( 2.0, maxMIPLevelScalar );
213-
//float desiredMIPLevel = log2( envMapWidth * sqrt( 3.0 ) ) - 0.5 * log2( square( blinnShininessExponent ) + 1.0 );
213+
//float desiredMIPLevel = log2( envMapWidth * sqrt( 3.0 ) ) - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );
214214

215215
float maxMIPLevelScalar = float( maxMIPLevel );
216-
float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( square( blinnShininessExponent ) + 1.0 );
216+
float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );
217217

218218
// clamp to allowable LOD ranges.
219219
return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );

0 commit comments

Comments
 (0)