Skip to content
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

Fire ‘shader:generate’ when a shader code gets generated #5524

Merged
merged 2 commits into from Jul 31, 2023

Conversation

mvaligursky
Copy link
Contributor

@mvaligursky mvaligursky commented Jul 31, 2023

The event shader:generate is fired on the GraphicsDevice when the shader definition is generated, just before the shader is compiled, to allow the user to inspect / modify the generated shader. Note that there is a further processing happening after this step, where defines are process (unused code is removed), a shader is converted to uniform format on some platforms (currently on WebGPU) and similar.

Typical use case:

  • give materials a userId to recognise when its shader is getting compiled:
myMaterial.userId = 'redMaterial';
  • listen to shader:generated events:
app.graphicsDevice.on('shader:generate', (info) => {
    if (info.userMaterialId)
        console.log('shader:generate', info);
});

This is the expected output, in this case the shader is compiled for a shadow pass and a forward pass. You can find relevant info in the `info.shaderPassInfo'. Note that there could be multiple shader compilations based on material settings / vertex format it's used on and similar.

Screenshot 2023-07-31 at 12 26 29

@mvaligursky mvaligursky self-assigned this Jul 31, 2023
@mvaligursky mvaligursky merged commit c0c8d6e into main Jul 31, 2023
7 checks passed
@mvaligursky mvaligursky deleted the mv-shader-generate-event branch July 31, 2023 15:19
userMaterialId,
shaderPassInfo,
definition: generatedShaderDef
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it would be great if this had a type so consumers could at least typecast the event as pc.ShaderGenerateEvent or similar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: graphics Graphics related issue feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants