ソースを参照

Fix light projection for PBR

David Catuhe 7 年 前
コミット
2ec4390755

+ 2 - 1
src/Lights/babylon.spotLight.ts

@@ -116,7 +116,8 @@
         }
 
         @serializeAsTexture("projectedLightTexture")
-        private _projectionTexture: Nullable<BaseTexture>;;
+        private _projectionTexture: Nullable<BaseTexture>;
+        
         /** 
          * Gets the projection texture of the light.
         */

+ 1 - 1
src/Materials/babylon.materialHelper.ts

@@ -220,7 +220,7 @@ module BABYLON {
                     if (light.getTypeID() === Light.LIGHTTYPEID_SPOTLIGHT) {
                         type = "SPOTLIGHT" + lightIndex;
                         let spotLight = light as SpotLight;
-                        defines["PROJECTEDLIGHTTEXTURE" + lightIndex] = spotLight.projectionTexture ? spotLight.projectionTexture.isReady() : false;
+                        defines["PROJECTEDLIGHTTEXTURE" + lightIndex] = spotLight.projectionTexture ? true : false;
                     } else if (light.getTypeID() === Light.LIGHTTYPEID_HEMISPHERICLIGHT) {
                         type = "HEMILIGHT" + lightIndex;
                     } else if (light.getTypeID() === Light.LIGHTTYPEID_POINTLIGHT) {

+ 0 - 3
src/Shaders/ShadersInclude/lightsFragmentFunctions.fx

@@ -113,8 +113,5 @@ vec3 computeProjectionTextureDiffuseLighting(sampler2D projectionLightSampler, m
 	vec4 strq = textureProjectionMatrix * vec4(vPositionW, 1.0);
 	strq /= strq.w;
 	vec3 textureColor = texture2D(projectionLightSampler, strq.xy).rgb;
-#ifdef PBR
-	textureColor = toLinearSpace(textureColor);
-#endif
 	return textureColor;
 }

+ 7 - 0
src/Shaders/ShadersInclude/pbrLightFunctions.fx

@@ -153,4 +153,11 @@ lightingInfo computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4
     #endif
 
     return result;
+}
+
+vec3 computeProjectionTextureDiffuseLighting(sampler2D projectionLightSampler, mat4 textureProjectionMatrix){
+	vec4 strq = textureProjectionMatrix * vec4(vPositionW, 1.0);
+	strq /= strq.w;
+	vec3 textureColor = texture2D(projectionLightSampler, strq.xy).rgb;
+	return toLinearSpace(textureColor);
 }