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

Material Shader Chunks Workflow #1262

Open
Maksims opened this issue Feb 12, 2025 · 2 comments
Open

Material Shader Chunks Workflow #1262

Maksims opened this issue Feb 12, 2025 · 2 comments

Comments

@Maksims
Copy link
Collaborator

Maksims commented Feb 12, 2025

Shader chunks - is a very powerful feature of the engine, which allows to extend material capabilities.
Would be amazing to have a workflow of working with material's shader chunks from UI.

Just a section like for material slots (after Lightmap, before Other), with ability to add as many chunks as needed, specifying chunk name and shader asset. Very similar to the way Sound Slots are added.
Slot has name (chunk name), and enabled toggle.
For now GLSL only. In the future add a checkbox, by enabling which it will also add a WGSL shader asset slot, that way you can specify WGSL chunk variation, which will be used if WebGPU is active. Both asset slots are optional, by not having necessary asset, it will simply ignore the slot.

In material data, it will look like this:

data: {
    // ...
    chunks: {
        'chunkName': { enabled: true, assetGlsl: 42 },
        // ...
    }
}

Engine would need to support this, with async loading in mind.
Adding/removing/enabling/disabling shader chunks, should be applied in real-time accordingly.
If shader asset content is updated, it should update materials accordingly, so editing shaders and seeing result - would be seamless (no refreshes needed).

For best UX, error reporting on shaders is in a good place atm, but it should support that if shader failed to compile, it would not break rendering, but ignore the shader (use default material?), and if chunk is updated again, it would try to re-compile again, so it is recoverable from broken state and would not require a page refresh.

Editor UI can help to mark materials accordingly if shader did not compile well. And on selecting material asset, it would mark a troubling chunk.
Important to not brick viewport rendering.

@Maksims Maksims changed the title Material Chunks Material Shader Chunks Workflow Feb 12, 2025
@leonidaspir
Copy link

That's a great idea actually, it will make shader development easier.

Just a note, if actual shader assets are to be used (which makes sense authoring wise), we would need a system to concatenate them since they add http requests. For the moment we avoid that asset type, and add the shader code in .js files instead so we get that for free when building.

@Maksims
Copy link
Collaborator Author

Maksims commented Feb 12, 2025

Just a note, if actual shader assets are to be used (which makes sense authoring wise), we would need a system to concatenate them since they add http requests. For the moment we avoid that asset type, and add the shader code in .js files instead so we get that for free when building.

Absolutely, we've used Bundles, they are ideal for that task: #1059

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants