Skip to content

Commit

Permalink
Added precisionSafeLength()
Browse files Browse the repository at this point in the history
  • Loading branch information
WestLangley committed Aug 23, 2019
1 parent 620fe4b commit b29b13b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/renderers/shaders/ShaderChunk/common.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ highp float rand( const in vec2 uv ) {
return fract(sin(sn) * c);
}
#ifdef HIGH_PRECISION
float precisionSafeLength( vec3 v ) { return length( v ); }
#else
float max3( vec3 v ) { return max( max( v.x, v.y ), v.z ); }
float precisionSafeLength( vec3 v ) {
float maxComponent = max3( abs( v ) );
return length( v / maxComponent ) * maxComponent;
}
#endif
struct IncidentLight {
vec3 color;
vec3 direction;
Expand Down
4 changes: 4 additions & 0 deletions src/renderers/webgl/WebGLProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters,
'precision ' + parameters.precision + ' float;',
'precision ' + parameters.precision + ' int;',

( parameters.precision === 'highp' ) ? '#define HIGH_PRECISION' : '',

'#define SHADER_NAME ' + shader.name,

customDefines,
Expand Down Expand Up @@ -488,6 +490,8 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters,
'precision ' + parameters.precision + ' float;',
'precision ' + parameters.precision + ' int;',

( parameters.precision === 'highp' ) ? '#define HIGH_PRECISION' : '',

'#define SHADER_NAME ' + shader.name,

customDefines,
Expand Down

0 comments on commit b29b13b

Please sign in to comment.