Browse Source

ShaderChunk: Added transmission alpha support (#22425)

* ShaderChunk: Added transmission alpha support.

* WebGLRenderer: Add support for GLTF opaque alpha_mode.

* Replaced material.blending = GLTFOpaqueBlending with material.format = RGBFormat.

* Clean up.

* ShaderChunk: Increase transmissionAlpha a bit.
Mr.doob 3 years ago
parent
commit
ee46b2899a

+ 6 - 5
src/renderers/shaders/ShaderChunk/output_fragment.glsl.js

@@ -1,11 +1,12 @@
 export default /* glsl */`
 export default /* glsl */`
 #ifdef OPAQUE
 #ifdef OPAQUE
+diffuseColor.a = 1.0;
+#endif
 
 
-gl_FragColor = vec4( outgoingLight, 1.0 );
-
-#else
+// https://github.com/mrdoob/three.js/pull/22425
+#ifdef USE_TRANSMISSION
+diffuseColor.a *= transmissionAlpha + 0.1;
+#endif
 
 
 gl_FragColor = vec4( outgoingLight, diffuseColor.a );
 gl_FragColor = vec4( outgoingLight, diffuseColor.a );
-
-#endif
 `;
 `;

+ 4 - 2
src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js

@@ -1,6 +1,7 @@
 export default /* glsl */`
 export default /* glsl */`
 #ifdef USE_TRANSMISSION
 #ifdef USE_TRANSMISSION
 
 
+	float transmissionAlpha = 1.0;
 	float transmissionFactor = transmission;
 	float transmissionFactor = transmission;
 	float thicknessFactor = thickness;
 	float thicknessFactor = thickness;
 
 
@@ -20,11 +21,12 @@ export default /* glsl */`
 	vec3 v = normalize( cameraPosition - pos );
 	vec3 v = normalize( cameraPosition - pos );
 	vec3 n = inverseTransformDirection( normal, viewMatrix );
 	vec3 n = inverseTransformDirection( normal, viewMatrix );
 
 
-	vec3 transmission = getIBLVolumeRefraction(
+	vec4 transmission = getIBLVolumeRefraction(
 		n, v, roughnessFactor, material.diffuseColor, material.specularColor, material.specularF90,
 		n, v, roughnessFactor, material.diffuseColor, material.specularColor, material.specularF90,
 		pos, modelMatrix, viewMatrix, projectionMatrix, ior, thicknessFactor,
 		pos, modelMatrix, viewMatrix, projectionMatrix, ior, thicknessFactor,
 		attenuationTint, attenuationDistance );
 		attenuationTint, attenuationDistance );
 
 
-	totalDiffuse = mix( totalDiffuse, transmission, transmissionFactor );
+	totalDiffuse = mix( totalDiffuse, transmission.rgb, transmissionFactor );
+	transmissionAlpha = transmission.a;
 #endif
 #endif
 `;
 `;

+ 7 - 7
src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js

@@ -53,17 +53,17 @@ export default /* glsl */`
 
 
 	}
 	}
 
 
-	vec3 getTransmissionSample( vec2 fragCoord, float roughness, float ior ) {
+	vec4 getTransmissionSample( vec2 fragCoord, float roughness, float ior ) {
 
 
 		float framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );
 		float framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );
 
 
 		#ifdef TEXTURE_LOD_EXT
 		#ifdef TEXTURE_LOD_EXT
 
 
-			return texture2DLodEXT( transmissionSamplerMap, fragCoord.xy, framebufferLod ).rgb;
+			return texture2DLodEXT( transmissionSamplerMap, fragCoord.xy, framebufferLod );
 
 
 		#else
 		#else
 
 
-			return texture2D( transmissionSamplerMap, fragCoord.xy, framebufferLod ).rgb;
+			return texture2D( transmissionSamplerMap, fragCoord.xy, framebufferLod );
 
 
 		#endif
 		#endif
 
 
@@ -87,7 +87,7 @@ export default /* glsl */`
 
 
 	}
 	}
 
 
-	vec3 getIBLVolumeRefraction( vec3 n, vec3 v, float roughness, vec3 diffuseColor, vec3 specularColor, float specularF90,
+	vec4 getIBLVolumeRefraction( vec3 n, vec3 v, float roughness, vec3 diffuseColor, vec3 specularColor, float specularF90,
 		vec3 position, mat4 modelMatrix, mat4 viewMatrix, mat4 projMatrix, float ior, float thickness,
 		vec3 position, mat4 modelMatrix, mat4 viewMatrix, mat4 projMatrix, float ior, float thickness,
 		vec3 attenuationColor, float attenuationDistance ) {
 		vec3 attenuationColor, float attenuationDistance ) {
 
 
@@ -101,14 +101,14 @@ export default /* glsl */`
 		refractionCoords /= 2.0;
 		refractionCoords /= 2.0;
 
 
 		// Sample framebuffer to get pixel the refracted ray hits.
 		// Sample framebuffer to get pixel the refracted ray hits.
-		vec3 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );
+		vec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );
 
 
-		vec3 attenuatedColor = applyVolumeAttenuation( transmittedLight, length( transmissionRay ), attenuationColor, attenuationDistance );
+		vec3 attenuatedColor = applyVolumeAttenuation( transmittedLight.rgb, length( transmissionRay ), attenuationColor, attenuationDistance );
 
 
 		// Get the specular component.
 		// Get the specular component.
 		vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );
 		vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );
 
 
-		return ( 1.0 - F ) * attenuatedColor * diffuseColor;
+		return vec4( ( 1.0 - F ) * attenuatedColor * diffuseColor, transmittedLight.a );
 
 
 	}
 	}
 #endif
 #endif