Browse Source

Fix texture loop usage when using a node material on a shadow caster+receiver

Popov72 4 years ago
parent
commit
a6172ecb68
2 changed files with 21 additions and 3 deletions
  1. 18 0
      src/Materials/effect.ts
  2. 3 3
      src/Materials/shadowDepthWrapper.ts

+ 18 - 0
src/Materials/effect.ts

@@ -172,6 +172,8 @@ export class Effect implements IDisposable {
     private _vertexSourceCodeOverride: string = "";
     private _fragmentSourceCodeOverride: string = "";
     private _transformFeedbackVaryings: Nullable<string[]> = null;
+    private _rawVertexSourceCode: string = "";
+    private _rawFragmentSourceCode: string = "";
     /**
      * Compiled shader to webGL program.
      * @hidden
@@ -286,7 +288,9 @@ export class Effect implements IDisposable {
         };
 
         this._loadShader(vertexSource, "Vertex", "", (vertexCode) => {
+            this._rawVertexSourceCode = vertexCode;
             this._loadShader(fragmentSource, "Fragment", "Pixel", (fragmentCode) => {
+                this._rawFragmentSourceCode = fragmentCode;
                 ShaderProcessor.Process(vertexCode, processorOptions, (migratedVertexCode) => {
                     if (processFinalCode) {
                         migratedVertexCode = processFinalCode("vertex", migratedVertexCode);
@@ -560,6 +564,20 @@ export class Effect implements IDisposable {
     }
 
     /**
+     * Gets the vertex shader source code before it has been processed by the preprocessor
+     */
+    public get rawVertexSourceCode(): string {
+        return this._rawVertexSourceCode;
+    }
+
+    /**
+     * Gets the fragment shader source code before it has been processed by the preprocessor
+     */
+    public get rawFragmentSourceCode(): string {
+        return this._rawFragmentSourceCode;
+    }
+
+    /**
      * Recompiles the webGL program
      * @param vertexSourceCode The source code for the vertex shader.
      * @param fragmentSourceCode The source code for the fragment shader.

+ 3 - 3
src/Materials/shadowDepthWrapper.ts

@@ -238,8 +238,8 @@ export class ShadowDepthWrapper {
         params.depthDefines = join;
 
         // the depth effect is either out of date or has not been created yet
-        let vertexCode = origEffect.vertexSourceCode,
-            fragmentCode = origEffect.fragmentSourceCode;
+        let vertexCode = origEffect.rawVertexSourceCode,
+            fragmentCode = origEffect.rawFragmentSourceCode;
 
         // vertex code
         const vertexNormalBiasCode = this._options && this._options.remappedVariables ? `#include<shadowMapVertexNormalBias>(${this._options.remappedVariables.join(",")})` : Effect.IncludesShadersStore["shadowMapVertexNormalBias"],
@@ -296,7 +296,7 @@ export class ShadowDepthWrapper {
             uniformsNames: uniforms,
             uniformBuffersNames: origEffect.getUniformBuffersNames(),
             samplers: origEffect.getSamplers(),
-            defines: join + "\n" + origEffect.defines,
+            defines: join + "\n" + origEffect.defines.replace("#define SHADOWS", "").replace(/#define SHADOW\d/g, ""),
             indexParameters: origEffect.getIndexParameters(),
         }, this._scene.getEngine());