浏览代码

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;
     }
 
-   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 = 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");

+ 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 {
         this.onBeforeShaderCompilationObservable.notifyObservers(this);
 
-        vertexCode = ThinEngine._ConcatenateShader(vertexCode, defines);
-        fragmentCode = ThinEngine._ConcatenateShader(fragmentCode, defines);
-
         const vertexInliner = new ShaderCodeInliner(vertexCode);
         vertexInliner.processCode();
         vertexCode = vertexInliner.code;
@@ -495,6 +492,9 @@ export class NativeEngine extends Engine {
         fragmentInliner.processCode();
         fragmentCode = fragmentInliner.code;
 
+        vertexCode = ThinEngine._ConcatenateShader(vertexCode, defines);
+        fragmentCode = ThinEngine._ConcatenateShader(fragmentCode, defines);
+
         const program = this._native.createProgram(vertexCode, fragmentCode);
         this.onAfterShaderCompilationObservable.notifyObservers(this);
         return program;

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

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

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

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