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

Split Materialpipeline - shader code into two files #18549

Open
wants to merge 4 commits into
base: development
Choose a base branch
from

Conversation

kh-huawei
Copy link
Contributor

What does this PR do?

This is one part of the material shader refactoring neccesary for RFC 152 (Support for multiple Material-Types in Raytracing Hit Shaders).

This PR adds the field "materialShaderDefines": "BasePBR_Defines.azsli" to the abstract materialtype, that will be included by the materialpipeline - shaders before any other files.

This allows us to define Pipeline-Callbacks, that are provided by the rendering-pipeline, and need a full definition of the material-defined structs and SRGs, but that are used in the material-defined functions.

With these Pipeline-Callback we can somewhat separate the material-functions from the rendering pipeline, which is necessary to use the materials in a raytracing-shader or a deferred pipeline.

Specific example from BasePBR_VertexEval.azsli:

previously:

    // GetObjectToWorldMatrix(uint instanceId) uses either the SceneSrg or the ObjectSrg to get the matrix: 
    // In a raytracing shader we don't have an Object-Srg, and the SceneSrg works differently, so this won't compile.
    // Also instancing will work differently, so likely the instanceId won't work either
    
    float4x4 objectToWorld = GetObjectToWorldMatrix(SV.m_instanceId);
    float4 worldPosition = mul(objectToWorld, float4(position, 1.0));

new:

    // VsSystemValues and GetObjectToWorldMatrix(VsSystemValues  SV) are now declared by the 
    // render-pipeline and opaque to the material shader code.

    float4x4 objectToWorld = GetObjectToWorldMatrix(SV);
    float4 worldPosition = mul(objectToWorld, float4(position, 1.0));

Since i had to change the existing shader - templates, this will break custom materials.
Custom materials that use the Material - canvas will work, but the shader-code needs to be recreated by the MaterialCanvas - Editor.

How was this PR tested?

Make sure all shaders from the engine compile, and everything still looks the same.
Tested with vulkan on windows.

@kh-huawei kh-huawei requested review from a team as code owners December 11, 2024 16:56
@kh-huawei
Copy link
Contributor Author

This PR touches quite a lot of files, so my suggestion for reviewers is to start at MainPipeline/ForwardPass_BaseLighting.azsli, with BaseBPR_Defines.azsli and BasePBR.azsli as the files that will be included there to give feedback on the approach, since everything else is mostly the same with minor modifications for other materials.

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

Successfully merging this pull request may close these issues.

1 participant