8000 Fix the bug of global variable dosn't work in multi-pass ShaderLab by Sway007 · Pull Request #2018 · galacean/engine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix the bug of global variable dosn't work in multi-pass ShaderLab #2018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/shader-lab/src/RuntimeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,18 @@ export default class RuntimeContext {
this.varyingTypeAstNode = undefined;
this._currentMainFnAst = undefined;
this.varyingStructInfo = {};
this._globalMapReset();
}

private _globalMapReset() {
const resetProp = (globals: IGlobal[]) => {
for (const gv of globals) {
gv.inspected = false;
gv.referenced = false;
}
};
this._shaderGlobalMap.forEach(resetProp);
this._subShaderGlobalMap.forEach(resetProp);
}

private _initShaderGlobalList(shaderAst: AstNode<IShaderAstContent>) {
Expand Down
5 changes: 5 additions & 0 deletions tests/src/shader-lab/ShaderLab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,9 @@ describe("ShaderLab", () => {
expect(err[0].token.startLine).to.eql(25);
}
});

it("multi-pass", () => {
const shaderSource = fs.readFileSync(path.join(__dirname, "shaders/multi-pass.shader")).toString();
glslValidate(shaderSource, shaderLab);
});
});
59 changes: 59 additions & 0 deletions tests/src/shader-lab/shaders/multi-pass.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Shader "Triangle" {
SubShader "Default" {
mat4 renderer_MVPMat;

Pass "0" {
vec3 u_color;

struct a2v {
vec4 POSITION;
}

struct v2f {
vec3 v_color;
}

VertexShader = vert;
FragmentShader = frag;

v2f vert(a2v v) {
v2f o;

gl_Position = renderer_MVPMat * v.POSITION;
o.v_color = u_color;
return o;
}

void frag(v2f i) {
gl_FragColor = vec4(i.v_color, 1.0);
}
}

Pass "1" {
vec3 u_color;

struct a2v {
vec4 POSITION;
}

struct v2f {
vec3 v_color;
}

VertexShader = vert;
FragmentShader = frag;

v2f vert(a2v v) {
v2f o;

gl_Position = renderer_MVPMat * v.POSITION;
o.v_color = u_color;
return o;
}

void frag(v2f i) {
gl_FragColor = vec4(i.v_color, 1.0);
}
}
}
}
0