Browse Source

MeshPhysicalMaterial: Fix refraction shader code (#22224)

* MeshPhysicalMaterial: Fix refraction

* Update screenshot
Takahiro 4 years ago
parent
commit
361d9a201a

BIN
examples/screenshots/webgl_loader_gltf_transmission.jpg


BIN
examples/screenshots/webgl_materials_physical_transmission.jpg


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

@@ -18,10 +18,11 @@ export default /* glsl */`
 
 
 	vec3 pos = vWorldPosition.xyz / vWorldPosition.w;
 	vec3 pos = vWorldPosition.xyz / vWorldPosition.w;
 	vec3 v = normalize( cameraPosition - pos );
 	vec3 v = normalize( cameraPosition - pos );
+	vec3 n = inverseTransformDirection( normal, viewMatrix );
 	float ior = ( 1.0 + 0.4 * reflectivity ) / ( 1.0 - 0.4 * reflectivity );
 	float ior = ( 1.0 + 0.4 * reflectivity ) / ( 1.0 - 0.4 * reflectivity );
 
 
 	vec3 transmission = transmissionFactor * getIBLVolumeRefraction(
 	vec3 transmission = transmissionFactor * getIBLVolumeRefraction(
-		normal, v, roughnessFactor, material.diffuseColor, material.specularColor,
+		n, v, roughnessFactor, material.diffuseColor, material.specularColor,
 		pos, modelMatrix, viewMatrix, projectionMatrix, ior, thicknessFactor,
 		pos, modelMatrix, viewMatrix, projectionMatrix, ior, thicknessFactor,
 		attenuationTint, attenuationDistance );
 		attenuationTint, attenuationDistance );