MultilayerParallaxDepth.azsli 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Atom/Features/ParallaxMapping.azsli>
  9. #include "../MaterialInputs/ParallaxInput.azsli"
  10. #include <Atom/Features/MatrixUtility.azsli>
  11. #include "ParallaxShadowUtil.azsli"
  12. void MultilayerSetPixelDepth(
  13. const MaterialParameters params,
  14. real3 vertexBlendMask,
  15. inout float3 worldPosition,
  16. real3 normal,
  17. float3 tangents[UvSetCount],
  18. float3 bitangents[UvSetCount],
  19. inout float2 uvs[UvSetCount],
  20. bool isFrontFace,
  21. real4x4 objectToWorld,
  22. inout float depthNDC,
  23. inout float depthCS,
  24. out bool isClipped)
  25. {
  26. real3x3 uvMatrix = params.m_parallaxUvIndex == 0 ? real3x3(params.m_uvMatrix) : CreateIdentity3x3_real();
  27. real3x3 uvMatrixInverse = params.m_parallaxUvIndex == 0 ? real3x3(params.m_uvMatrixInverse) : CreateIdentity3x3_real();
  28. real parallaxOverallOffset = real(params.m_displacementMax);
  29. real parallaxOverallFactor = real(params.m_displacementMax) - real(params.m_displacementMin);
  30. AdjustParallaxShadowCaster(parallaxOverallFactor, parallaxOverallOffset, real(params.m_parallax_pdo_shadowFactor));
  31. s_blendMaskFromVertexStream = vertexBlendMask;
  32. // heightmap and heightmap sampler don't matter here: They get passed to the GetDepth() - function of the StandardMultiLayerPBR - material, where they are ignored.
  33. GetParallaxInput(
  34. params,
  35. GetMaterialTexture(params.m_layer1_m_heightmap), GetMaterialTextureSampler(), normal, tangents[params.m_parallaxUvIndex], bitangents[params.m_parallaxUvIndex],
  36. parallaxOverallFactor, parallaxOverallOffset,
  37. objectToWorld, uvMatrix, uvMatrixInverse,
  38. uvs[params.m_parallaxUvIndex], worldPosition, depthNDC, depthCS, isClipped);
  39. }
  40. void MultilayerSetPixelDepth(
  41. const MaterialParameters params,
  42. real3 vertexBlendMask,
  43. inout float3 positionWS,
  44. real3 normal,
  45. float3 tangents[UvSetCount],
  46. float3 bitangents[UvSetCount],
  47. inout float2 uvs[UvSetCount],
  48. bool isFrontFace,
  49. real4x4 objectToWorld,
  50. inout float depthNDC)
  51. {
  52. // Dummy variables to call the above function
  53. float depthCS = 1.0;
  54. bool isClipped = false;
  55. MultilayerSetPixelDepth(params, vertexBlendMask, positionWS, normal, tangents, bitangents, uvs, isFrontFace, objectToWorld, depthNDC, depthCS, isClipped);
  56. }