DeferredPipelineScript.lua 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. --------------------------------------------------------------------------------------
  2. --
  3. -- Copyright (c) Contributors to the Open 3D Engine Project.
  4. -- For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. --
  6. -- SPDX-License-Identifier: Apache-2.0 OR MIT
  7. --
  8. --
  9. --
  10. ----------------------------------------------------------------------------------------------------
  11. function MaterialTypeSetup(context)
  12. lightingModel = context:GetLightingModelName()
  13. Print('Material type uses lighting model "' .. lightingModel .. '".')
  14. context:ExcludeAllShaders()
  15. -- TODO(MaterialPipeline): The deferred pipeline only supports a proof-of-concept set of g-buffers
  16. -- which are pretty limited, only a subset of the "Base" lighting model. The same shader and g-buffers
  17. -- are used regardless. For better demonstration, we should try to support the various lighting models.
  18. context:IncludeShader("DepthPass")
  19. context:IncludeShader("ShadowmapPass")
  20. if(lightingModel == "Base" or lightingModel == "Standard" or lightingModel == "Enhanced") then
  21. context:IncludeShader("DeferredMaterialPass")
  22. else
  23. Warning("The deferred pipeline does not support the " .. lightingModel .. " lighting model. This combination should not be used at runtime.")
  24. -- This allows returning 'true' to pass the build, but the surface won't be rendered at runtime.
  25. -- TODO(MaterialPipeline): Instead of rendering nothing, either render an error shader (like a magenta surface) or fall back to StandardLighting.
  26. -- For an error shader, .materialtype needs to have new field for an ObjectSrg azsli file separate from "materialShaderCode", so that
  27. -- the error shader can use the same ObjectSrg as the other shaders (depth/shadow) without including the unsupported materialShaderCode.
  28. -- Using StandardLighting as a fallback is even more difficult because it requires some kind of adapter to move data from the Surface that
  29. -- the material type wants to use, to the Surface that the lighting model supports. (It's a natural fit for downgrading from Enhanced to
  30. -- Standard but there is compatibility issues between Skin and Standard).
  31. end
  32. -- Unlike Standard and Enhanced, BaseLighting doesn't have "_CustomZ" just because BasePBR.materialtype doesn't use alpha cutout or POM PDO, so we don't need it right now.
  33. -- But that could be added if some other material type wants to use BaseLighting with one of these features, as they don't really relate to the lighting model.
  34. if(lightingModel ~= "Base" and lightingModel ~= "Skin") then
  35. context:IncludeShader("DeferredMaterialPass_CustomZ")
  36. context:IncludeShader("DepthPass_CustomZ")
  37. context:IncludeShader("ShadowmapPass_CustomZ")
  38. end
  39. -- Even though the enhanced lighting model is not supported by the deferred pass, since this pipeline
  40. -- uses the same transparent pass shaders as the main pipeline, we can actually support the Standard
  41. -- and Enhanced lighting models when they are transparent.
  42. if(lightingModel == "Standard") then
  43. context:IncludeShader("Transparent_StandardLighting")
  44. context:IncludeShader("TintedTransparent_StandardLighting")
  45. end
  46. if(lightingModel == "Enhanced") then
  47. context:IncludeShader("Transparent_EnhancedLighting")
  48. context:IncludeShader("TintedTransparent_EnhancedLighting")
  49. end
  50. return true
  51. end