I’ve added a permutation to the hair strands material pass by templating the FHairMaterialPS class. I’ve confirmed that mesh batches are being added for materials that use that permutation, but things aren’t rendering correctly. A PIX capture shows that the draw call is missing some shader bindings used by the shader- namely the HairStrandsVF buffer and the Material uniform buffer.
HairStrandsVF appears in the CompiledShaderInitializerType.ParameterMap, but the Material uniform buffer does not.
I’ve added a custom material parameter, including a custom getter in FHLSLMaterialTranslator::PrepareMaterialSourceStringParameters. In the debug output HairStrandsMaterialPS.usf, I see that this getter loads from Material.PreshaderBuffer, so the permutation define is applied correctly. I can even step through the code in PIX shader debugger, but everywhere it would load from that buffer, it loads 0- presumably because the buffer never gets bound.
It seems like there are a few things going wrong here- the shader compilation output doesn’t have the buffer I expect, but even when it does, it’s not being bound correctly. Here are some things I’ve tried:
I’ve rewritten the shader code to make sure the code using the Material.PreshaderBuffer gets run, but that doesn’t have any effect on the shader compilation output.
I’ve verified that PSOInitializers with my custom permutation enabled get picked up.
When I set r.ShaderCompiler.EmitWarningsOnLoad=1, no warnings are emitted for the hair strands material pass shaders.
Is there any other step I’m overlooking that could be causing this?
Steps to Reproduce
This is an engine customization, so I’m not providing a repro- just hoping for guidance on continuing to debug the issue I’m having.
This doesn’t ring a bell particularly. IIRC, MaterialResource is where the material binding data will be pulled from. So could it be this isn’t correctly retrieved for the new permutation? If the permutation is now found, it will fallback on a default shader I think.
As a test, could you try to replace your shader as a dynamic branch in the original MaterialPS (instead of a permutation) in order to test if the issue is on the setup side, or something else?
I have two materials, OriginalHairMat and ModifiedHairMat. OriginalHairMat+OriginalPermutation has all the right resources, but OriginalHairMat+ModifiedPermutation is missing the Materials buffer from its bound resources at the point of ExtractParameterMapFromD3DShader. I don’t compile ModifiedHairMat+OriginalPermutation, but ModifiedHairMat+ModifiedPermutation has the exact same resource bindings as OriginalHairMat+ModifiedPermutation. So it does seem like the permutation is what’s causing the bindings to go missing.
Converting from a permutation to a dynamic batch got me both of the missing Materials and the HairStrandsVF buffers! So I must have done something incorrectly setting up that permutation. Thank you so much for getting me unstuck! I feel like I should have tried this ages ago