Browse Source

Clean up formatting (#22296)

WestLangley 4 years ago
parent
commit
510705cde2

+ 11 - 14
src/renderers/shaders/ShaderChunk/bsdfs.glsl.js

@@ -73,6 +73,7 @@ vec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const
 
 	// See F_Schlick
 	float fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );
+
 	vec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;
 
 	return Fr * fresnel + F0;
@@ -326,30 +327,26 @@ vec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in Ge
 
 } // validated
 
-// source: http://simonstechblog.blogspot.ca/2011/12/microfacet-brdf.html
-float GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {
-	return ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );
-}
-
-float BlinnExponentToGGXRoughness( const in float blinnExponent ) {
-	return sqrt( 2.0 / ( blinnExponent + 2.0 ) );
-}
-
 #if defined( USE_SHEEN )
 
 // https://github.com/google/filament/blob/master/shaders/src/brdf.fs#L94
-float D_Charlie(float roughness, float NoH) {
+float D_Charlie( float roughness, float NoH ) {
+
 	// Estevez and Kulla 2017, "Production Friendly Microfacet Sheen BRDF"
 	float invAlpha = 1.0 / roughness;
 	float cos2h = NoH * NoH;
-	float sin2h = max(1.0 - cos2h, 0.0078125); // 2^(-14/2), so sin2h^2 > 0 in fp16
-	return (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);
+	float sin2h = max( 1.0 - cos2h, 0.0078125 ); // 2^(-14/2), so sin2h^2 > 0 in fp16
+
+	return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );
+
 }
 
 // https://github.com/google/filament/blob/master/shaders/src/brdf.fs#L136
-float V_Neubelt(float NoV, float NoL) {
+float V_Neubelt( float NoV, float NoL ) {
+
 	// Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886"
-	return saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));
+	return saturate( 1.0 / ( 4.0 * ( NoL + NoV - NoL * NoV ) ) );
+
 }
 
 vec3 BRDF_Specular_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {

+ 8 - 24
src/renderers/shaders/ShaderChunk/common.glsl.js

@@ -8,26 +8,30 @@ export default /* glsl */`
 
 #ifndef saturate
 // <tonemapping_pars_fragment> may have defined saturate() already
-#define saturate(a) clamp( a, 0.0, 1.0 )
+#define saturate( a ) clamp( a, 0.0, 1.0 )
 #endif
-#define whiteComplement(a) ( 1.0 - saturate( a ) )
+#define whiteComplement( a ) ( 1.0 - saturate( a ) )
 
 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 max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }
 float average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }
+
 // expects values in the range of [0,1]x[0,1], returns values in the [0,1] range.
 // do not collapse into a single function per: http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/
 highp float rand( const in vec2 uv ) {
+
 	const highp float a = 12.9898, b = 78.233, c = 43758.5453;
 	highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
-	return fract(sin(sn) * c);
+
+	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;
@@ -71,26 +75,6 @@ vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {
 
 }
 
-vec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
-
-	float distance = dot( planeNormal, point - pointOnPlane );
-
-	return - distance * planeNormal + point;
-
-}
-
-float sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
-
-	return sign( dot( point - pointOnPlane, planeNormal ) );
-
-}
-
-vec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {
-
-	return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;
-
-}
-
 mat3 transposeMat3( const in mat3 m ) {
 
 	mat3 tmp;

+ 2 - 2
src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js

@@ -29,13 +29,13 @@ export default /* glsl */`
 
 	#else
 
-		normal = perturbNormal2Arb( -vViewPosition, normal, mapN, faceDirection );
+		normal = perturbNormal2Arb( - vViewPosition, normal, mapN, faceDirection );
 
 	#endif
 
 #elif defined( USE_BUMPMAP )
 
-	normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd(), faceDirection );
+	normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );
 
 #endif
 `;

+ 4 - 3
src/renderers/shaders/ShaderChunk/packing.glsl.js

@@ -26,9 +26,10 @@ float unpackRGBAToDepth( const in vec4 v ) {
 }
 
 vec4 pack2HalfToRGBA( vec2 v ) {
-	vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ));
-	return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w);
+	vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );
+	return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );
 }
+
 vec2 unpackRGBATo2Half( vec4 v ) {
 	return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );
 }
@@ -45,7 +46,7 @@ float orthographicDepthToViewZ( const in float linearClipZ, const in float near,
 // NOTE: https://twitter.com/gonnavis/status/1377183786949959682
 
 float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {
-	return (( near + viewZ ) * far ) / (( far - near ) * viewZ );
+	return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );
 }
 float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {
 	return ( near * far ) / ( ( far - near ) * invClipZ - far );

+ 1 - 1
src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js

@@ -1,7 +1,7 @@
 export default /* glsl */`
 #ifndef saturate
 // <common> may have defined saturate() already
-#define saturate(a) clamp( a, 0.0, 1.0 )
+#define saturate( a ) clamp( a, 0.0, 1.0 )
 #endif
 
 uniform float toneMappingExposure;

+ 37 - 22
src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js

@@ -29,61 +29,76 @@ export default /* glsl */`
 
 	varying vec3 vWorldPosition;
 
-	vec3 getVolumeTransmissionRay(vec3 n, vec3 v, float thickness, float ior, mat4 modelMatrix) {
+	vec3 getVolumeTransmissionRay( vec3 n, vec3 v, float thickness, float ior, mat4 modelMatrix ) {
+
 		// Direction of refracted light.
-		vec3 refractionVector = refract(-v, normalize(n), 1.0 / ior);
+		vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );
 
 		// Compute rotation-independant scaling of the model matrix.
 		vec3 modelScale;
-		modelScale.x = length(vec3(modelMatrix[0].xyz));
-		modelScale.y = length(vec3(modelMatrix[1].xyz));
-		modelScale.z = length(vec3(modelMatrix[2].xyz));
+		modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );
+		modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );
+		modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );
 
 		// The thickness is specified in local space.
-		return normalize(refractionVector) * thickness * modelScale;
+		return normalize( refractionVector ) * thickness * modelScale;
+
 	}
 
-	float applyIorToRoughness(float roughness, float ior) {
+	float applyIorToRoughness( float roughness, float ior ) {
+
 		// Scale roughness with IOR so that an IOR of 1.0 results in no microfacet refraction and
 		// an IOR of 1.5 results in the default amount of microfacet refraction.
-		return roughness * clamp(ior * 2.0 - 2.0, 0.0, 1.0);
+		return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );
+
 	}
 
-	vec3 getTransmissionSample(vec2 fragCoord, float roughness, float ior) {
-		float framebufferLod = log2(transmissionSamplerSize.x) * applyIorToRoughness(roughness, ior);
-		return texture2DLodEXT(transmissionSamplerMap, fragCoord.xy, framebufferLod).rgb;
+	vec3 getTransmissionSample( vec2 fragCoord, float roughness, float ior ) {
+
+		float framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );
+
+		return texture2DLodEXT( transmissionSamplerMap, fragCoord.xy, framebufferLod ).rgb;
+
 	}
 
-	vec3 applyVolumeAttenuation(vec3 radiance, float transmissionDistance, vec3 attenuationColor, float attenuationDistance) {
-		if (attenuationDistance == 0.0) {
+	vec3 applyVolumeAttenuation( vec3 radiance, float transmissionDistance, vec3 attenuationColor, float attenuationDistance ) {
+
+		if ( attenuationDistance == 0.0 ) {
+
 			// Attenuation distance is +∞ (which we indicate by zero), i.e. the transmitted color is not attenuated at all.
 			return radiance;
+
 		} else {
+
 			// Compute light attenuation using Beer's law.
-			vec3 attenuationCoefficient = -log(attenuationColor) / attenuationDistance;
-			vec3 transmittance = exp(-attenuationCoefficient * transmissionDistance); // Beer's law
+			vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;
+			vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); // Beer's law
 			return transmittance * radiance;
+
 		}
+
 	}
 
-	vec3 getIBLVolumeRefraction(vec3 n, vec3 v, float perceptualRoughness, vec3 baseColor, vec3 specularColor,
+	vec3 getIBLVolumeRefraction( vec3 n, vec3 v, float perceptualRoughness, vec3 baseColor, vec3 specularColor,
 		vec3 position, mat4 modelMatrix, mat4 viewMatrix, mat4 projMatrix, float ior, float thickness,
-		vec3 attenuationColor, float attenuationDistance) {
-		vec3 transmissionRay = getVolumeTransmissionRay(n, v, thickness, ior, modelMatrix);
+		vec3 attenuationColor, float attenuationDistance ) {
+
+		vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
 		vec3 refractedRayExit = position + transmissionRay;
 
 		// Project refracted vector on the framebuffer, while mapping to normalized device coordinates.
-		vec4 ndcPos = projMatrix * viewMatrix * vec4(refractedRayExit, 1.0);
+		vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
 		vec2 refractionCoords = ndcPos.xy / ndcPos.w;
 		refractionCoords += 1.0;
 		refractionCoords /= 2.0;
 
 		// Sample framebuffer to get pixel the refracted ray hits.
-		vec3 transmittedLight = getTransmissionSample(refractionCoords, perceptualRoughness, ior);
+		vec3 transmittedLight = getTransmissionSample( refractionCoords, perceptualRoughness, ior );
+
+		vec3 attenuatedColor = applyVolumeAttenuation( transmittedLight, length( transmissionRay ), attenuationColor, attenuationDistance );
 
-		vec3 attenuatedColor = applyVolumeAttenuation(transmittedLight, length(transmissionRay), attenuationColor, attenuationDistance);
+		return ( 1.0 - specularColor ) * attenuatedColor * baseColor;
 
-		return (1.0 - specularColor) * attenuatedColor * baseColor;
 	}
 #endif
 `;