Browse Source

Merge pull request #8124 from MackeyK24/master

StandardMaterial RGBD Shader Fix
David Catuhe 5 years ago
parent
commit
f22fdb2c37
1 changed files with 21 additions and 21 deletions
  1. 21 21
      src/Shaders/default.fragment.fx

+ 21 - 21
src/Shaders/default.fragment.fx

@@ -254,7 +254,7 @@ void main(void) {
 	float shadow = 1.;
 	float shadow = 1.;
 
 
 #ifdef LIGHTMAP
 #ifdef LIGHTMAP
-	vec3 lightmapColor = texture2D(lightmapSampler, vLightmapUV + uvOffset).rgb;
+	vec4 lightmapColor = texture2D(lightmapSampler, vLightmapUV + uvOffset);
     #ifdef RGBDLIGHTMAP
     #ifdef RGBDLIGHTMAP
         lightmapColor.rgb = fromRGBD(lightmapColor);
         lightmapColor.rgb = fromRGBD(lightmapColor);
     #endif
     #endif
@@ -264,7 +264,7 @@ void main(void) {
 #include<lightFragment>[0..maxSimultaneousLights]
 #include<lightFragment>[0..maxSimultaneousLights]
 
 
 	// Refraction
 	// Refraction
-	vec3 refractionColor = vec3(0., 0., 0.);
+	vec4 refractionColor = vec4(0., 0., 0., 1.);
 
 
 #ifdef REFRACTION
 #ifdef REFRACTION
 	vec3 refractionVector = normalize(refract(-viewDirectionW, normalW, vRefractionInfos.y));
 	vec3 refractionVector = normalize(refract(-viewDirectionW, normalW, vRefractionInfos.y));
@@ -272,7 +272,7 @@ void main(void) {
 		refractionVector.y = refractionVector.y * vRefractionInfos.w;
 		refractionVector.y = refractionVector.y * vRefractionInfos.w;
 
 
 		if (dot(refractionVector, viewDirectionW) < 1.0) {
 		if (dot(refractionVector, viewDirectionW) < 1.0) {
-			refractionColor = textureCube(refractionCubeSampler, refractionVector).rgb;
+			refractionColor = textureCube(refractionCubeSampler, refractionVector);
 		}
 		}
 	#else
 	#else
 		vec3 vRefractionUVW = vec3(refractionMatrix * (view * vec4(vPositionW + refractionVector * vRefractionInfos.z, 1.0)));
 		vec3 vRefractionUVW = vec3(refractionMatrix * (view * vec4(vPositionW + refractionVector * vRefractionInfos.z, 1.0)));
@@ -281,19 +281,19 @@ void main(void) {
 
 
 		refractionCoords.y = 1.0 - refractionCoords.y;
 		refractionCoords.y = 1.0 - refractionCoords.y;
 		
 		
-		refractionColor = texture2D(refraction2DSampler, refractionCoords).rgb;
+		refractionColor = texture2D(refraction2DSampler, refractionCoords);
 	#endif
 	#endif
     #ifdef RGBDREFRACTION
     #ifdef RGBDREFRACTION
         refractionColor.rgb = fromRGBD(refractionColor);
         refractionColor.rgb = fromRGBD(refractionColor);
     #endif
     #endif
 	#ifdef IS_REFRACTION_LINEAR
 	#ifdef IS_REFRACTION_LINEAR
-		refractionColor = toGammaSpace(refractionColor);
+		refractionColor.rgb = toGammaSpace(refractionColor.rgb);
 	#endif
 	#endif
-	refractionColor *= vRefractionInfos.x;
+	refractionColor.rgb *= vRefractionInfos.x;
 #endif
 #endif
 
 
 // Reflection
 // Reflection
-vec3 reflectionColor = vec3(0., 0., 0.);
+vec4 reflectionColor = vec4(0., 0., 0., 1.);
 
 
 #ifdef REFLECTION
 #ifdef REFLECTION
 	vec3 vReflectionUVW = computeReflectionCoords(vec4(vPositionW, 1.0), normalW);
 	vec3 vReflectionUVW = computeReflectionCoords(vec4(vPositionW, 1.0), normalW);
@@ -310,9 +310,9 @@ vec3 reflectionColor = vec3(0., 0., 0.);
 				#endif
 				#endif
 			#endif
 			#endif
 
 
-			reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW, bias).rgb;
+			reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW, bias);
 		#else
 		#else
-			reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb;
+			reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW);
 		#endif
 		#endif
 	#else
 	#else
 		vec2 coords = vReflectionUVW.xy;
 		vec2 coords = vReflectionUVW.xy;
@@ -322,26 +322,26 @@ vec3 reflectionColor = vec3(0., 0., 0.);
 		#endif
 		#endif
 
 
 		coords.y = 1.0 - coords.y;
 		coords.y = 1.0 - coords.y;
-		reflectionColor = texture2D(reflection2DSampler, coords).rgb;
+		reflectionColor = texture2D(reflection2DSampler, coords);
 	#endif
 	#endif
     #ifdef RGBDREFLECTION
     #ifdef RGBDREFLECTION
         reflectionColor.rgb = fromRGBD(reflectionColor);
         reflectionColor.rgb = fromRGBD(reflectionColor);
     #endif
     #endif
 	#ifdef IS_REFLECTION_LINEAR
 	#ifdef IS_REFLECTION_LINEAR
-		reflectionColor = toGammaSpace(reflectionColor);
+		reflectionColor.rgb = toGammaSpace(reflectionColor.rgb);
 	#endif
 	#endif
-	reflectionColor *= vReflectionInfos.x;
+	reflectionColor.rgb *= vReflectionInfos.x;
 	#ifdef REFLECTIONFRESNEL
 	#ifdef REFLECTIONFRESNEL
 		float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, reflectionRightColor.a, reflectionLeftColor.a);
 		float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, reflectionRightColor.a, reflectionLeftColor.a);
 
 
 		#ifdef REFLECTIONFRESNELFROMSPECULAR
 		#ifdef REFLECTIONFRESNELFROMSPECULAR
 			#ifdef SPECULARTERM
 			#ifdef SPECULARTERM
-				reflectionColor *= specularColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;
+				reflectionColor.rgb *= specularColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;
 			#else
 			#else
-				reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;
+				reflectionColor.rgb *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;
 			#endif
 			#endif
 		#else
 		#else
-			reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;
+			reflectionColor.rgb *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;
 		#endif
 		#endif
 	#endif
 	#endif
 #endif
 #endif
@@ -349,7 +349,7 @@ vec3 reflectionColor = vec3(0., 0., 0.);
 #ifdef REFRACTIONFRESNEL
 #ifdef REFRACTIONFRESNEL
 	float refractionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, refractionRightColor.a, refractionLeftColor.a);
 	float refractionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, refractionRightColor.a, refractionLeftColor.a);
 
 
-	refractionColor *= refractionLeftColor.rgb * (1.0 - refractionFresnelTerm) + refractionFresnelTerm * refractionRightColor.rgb;
+	refractionColor.rgb *= refractionLeftColor.rgb * (1.0 - refractionFresnelTerm) + refractionFresnelTerm * refractionRightColor.rgb;
 #endif
 #endif
 
 
 #ifdef OPACITY
 #ifdef OPACITY
@@ -425,23 +425,23 @@ vec3 reflectionColor = vec3(0., 0., 0.);
 #endif
 #endif
 
 
 #ifdef REFLECTIONOVERALPHA
 #ifdef REFLECTIONOVERALPHA
-	alpha = clamp(alpha + dot(reflectionColor, vec3(0.3, 0.59, 0.11)), 0., 1.);
+	alpha = clamp(alpha + dot(reflectionColor.rgb, vec3(0.3, 0.59, 0.11)), 0., 1.);
 #endif
 #endif
 
 
 	// Composition
 	// Composition
 #ifdef EMISSIVEASILLUMINATION
 #ifdef EMISSIVEASILLUMINATION
-	vec4 color = vec4(clamp(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor + emissiveColor + refractionColor, 0.0, 1.0), alpha);
+	vec4 color = vec4(clamp(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor.rgb + emissiveColor + refractionColor.rgb, 0.0, 1.0), alpha);
 #else
 #else
-	vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor + refractionColor, alpha);
+	vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor.rgb + refractionColor.rgb, alpha);
 #endif
 #endif
 
 
 //Old lightmap calculation method
 //Old lightmap calculation method
 #ifdef LIGHTMAP
 #ifdef LIGHTMAP
     #ifndef LIGHTMAPEXCLUDED
     #ifndef LIGHTMAPEXCLUDED
         #ifdef USELIGHTMAPASSHADOWMAP
         #ifdef USELIGHTMAPASSHADOWMAP
-            color.rgb *= lightmapColor;
+            color.rgb *= lightmapColor.rgb;
         #else
         #else
-            color.rgb += lightmapColor;
+            color.rgb += lightmapColor.rgb;
         #endif
         #endif
     #endif
     #endif
 #endif
 #endif