浏览代码

Finally got the flight helmet working with Babylon Native again. Required changing the names of a few function arguments that had been named the same things as uniforms, because those names end up getting replaced by the native shader preprocessor, which can then end up putting dot syntax (i.e., variable.xyz) in places where it can't go, like function argument declarations.

syntheticmagus 5 年之前
父节点
当前提交
959dd2d7aa

+ 1 - 1
src/Engines/Native/nativeShaderProcessor.ts

@@ -133,7 +133,7 @@ export class NativeShaderProcessor extends WebGL2ShaderProcessor {
         return code;
         return code;
     }
     }
 
 
-   public postProcessor(code: string, defines: string[], isFragment: boolean): string {
+    public postProcessor(code: string, defines: string[], isFragment: boolean): string {
         code = super.postProcessor(code, defines, isFragment);
         code = super.postProcessor(code, defines, isFragment);
         code = code.replace("<UNIFORM>", `layout(binding=0) uniform Frame {\n${this._uniforms.join("\n")}\n};`);
         code = code.replace("<UNIFORM>", `layout(binding=0) uniform Frame {\n${this._uniforms.join("\n")}\n};`);
         code = code.replace("out vec4 glFragColor", "layout(location=0) out vec4 glFragColor");
         code = code.replace("out vec4 glFragColor", "layout(location=0) out vec4 glFragColor");

+ 3 - 3
src/Engines/nativeEngine.ts

@@ -484,9 +484,6 @@ export class NativeEngine extends Engine {
     public createShaderProgram(pipelineContext: IPipelineContext, vertexCode: string, fragmentCode: string, defines: Nullable<string>, context?: WebGLRenderingContext, transformFeedbackVaryings: Nullable<string[]> = null): any {
     public createShaderProgram(pipelineContext: IPipelineContext, vertexCode: string, fragmentCode: string, defines: Nullable<string>, context?: WebGLRenderingContext, transformFeedbackVaryings: Nullable<string[]> = null): any {
         this.onBeforeShaderCompilationObservable.notifyObservers(this);
         this.onBeforeShaderCompilationObservable.notifyObservers(this);
 
 
-        vertexCode = ThinEngine._ConcatenateShader(vertexCode, defines);
-        fragmentCode = ThinEngine._ConcatenateShader(fragmentCode, defines);
-
         const vertexInliner = new ShaderCodeInliner(vertexCode);
         const vertexInliner = new ShaderCodeInliner(vertexCode);
         vertexInliner.processCode();
         vertexInliner.processCode();
         vertexCode = vertexInliner.code;
         vertexCode = vertexInliner.code;
@@ -495,6 +492,9 @@ export class NativeEngine extends Engine {
         fragmentInliner.processCode();
         fragmentInliner.processCode();
         fragmentCode = fragmentInliner.code;
         fragmentCode = fragmentInliner.code;
 
 
+        vertexCode = ThinEngine._ConcatenateShader(vertexCode, defines);
+        fragmentCode = ThinEngine._ConcatenateShader(fragmentCode, defines);
+
         const program = this._native.createProgram(vertexCode, fragmentCode);
         const program = this._native.createProgram(vertexCode, fragmentCode);
         this.onAfterShaderCompilationObservable.notifyObservers(this);
         this.onAfterShaderCompilationObservable.notifyObservers(this);
         return program;
         return program;

+ 2 - 2
src/Shaders/ShadersInclude/pbrBlockAlbedoOpacity.fx

@@ -8,7 +8,7 @@ void albedoOpacityBlock(
     const in vec4 vAlbedoColor,
     const in vec4 vAlbedoColor,
 #ifdef ALBEDO
 #ifdef ALBEDO
     const in vec4 albedoTexture,
     const in vec4 albedoTexture,
-    const in vec2 vAlbedoInfos,
+    const in vec2 albedoInfos,
 #endif
 #endif
 #ifdef OPACITY
 #ifdef OPACITY
     const in vec4 opacityMap,
     const in vec4 opacityMap,
@@ -32,7 +32,7 @@ void albedoOpacityBlock(
             surfaceAlbedo *= albedoTexture.rgb;
             surfaceAlbedo *= albedoTexture.rgb;
         #endif
         #endif
 
 
-        surfaceAlbedo *= vAlbedoInfos.y;
+        surfaceAlbedo *= albedoInfos.y;
     #endif
     #endif
 
 
     #ifdef VERTEXCOLOR
     #ifdef VERTEXCOLOR

+ 3 - 3
src/Shaders/ShadersInclude/pbrBlockReflectivity.fx

@@ -24,7 +24,7 @@ void reflectivityBlock(
     const in vec4 metallicReflectanceFactors,
     const in vec4 metallicReflectanceFactors,
 #endif
 #endif
 #ifdef REFLECTIVITY
 #ifdef REFLECTIVITY
-    const in vec3 vReflectivityInfos,
+    const in vec3 reflectivityInfos,
     const in vec4 surfaceMetallicOrReflectivityColorMap,
     const in vec4 surfaceMetallicOrReflectivityColorMap,
 #endif
 #endif
 #if defined(METALLICWORKFLOW) && defined(REFLECTIVITY)  && defined(AOSTOREINMETALMAPRED)
 #if defined(METALLICWORKFLOW) && defined(REFLECTIVITY)  && defined(AOSTOREINMETALMAPRED)
@@ -49,7 +49,7 @@ void reflectivityBlock(
 
 
             #ifdef AOSTOREINMETALMAPRED
             #ifdef AOSTOREINMETALMAPRED
                 vec3 aoStoreInMetalMap = vec3(surfaceMetallicOrReflectivityColorMap.r, surfaceMetallicOrReflectivityColorMap.r, surfaceMetallicOrReflectivityColorMap.r);
                 vec3 aoStoreInMetalMap = vec3(surfaceMetallicOrReflectivityColorMap.r, surfaceMetallicOrReflectivityColorMap.r, surfaceMetallicOrReflectivityColorMap.r);
-                outParams.ambientOcclusionColor = mix(ambientOcclusionColor, aoStoreInMetalMap, vReflectivityInfos.z);
+                outParams.ambientOcclusionColor = mix(ambientOcclusionColor, aoStoreInMetalMap, reflectivityInfos.z);
             #endif
             #endif
 
 
             #ifdef METALLNESSSTOREINMETALMAPBLUE
             #ifdef METALLNESSSTOREINMETALMAPBLUE
@@ -118,7 +118,7 @@ void reflectivityBlock(
 
 
             #ifdef MICROSURFACEFROMREFLECTIVITYMAP
             #ifdef MICROSURFACEFROMREFLECTIVITYMAP
                 microSurface *= surfaceMetallicOrReflectivityColorMap.a;
                 microSurface *= surfaceMetallicOrReflectivityColorMap.a;
-                microSurface *= vReflectivityInfos.z;
+                microSurface *= reflectivityInfos.z;
             #else
             #else
                 #ifdef MICROSURFACEAUTOMATIC
                 #ifdef MICROSURFACEAUTOMATIC
                     microSurface *= computeDefaultMicroSurface(microSurface, surfaceReflectivityColor);
                     microSurface *= computeDefaultMicroSurface(microSurface, surfaceReflectivityColor);