Image3d.azsl 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/SrgSemantics.azsli>
  9. #include <Atom/Features/ColorManagement/TransformColor.azsli>
  10. ShaderResourceGroup ImageSrg : SRG_PerDraw
  11. {
  12. Texture3D m_texture3D;
  13. uint m_sliceCount;
  14. float2 m_position;
  15. float2 m_size;
  16. uint2 m_resolution;
  17. }
  18. struct VSInput
  19. {
  20. uint m_vertexIndex :SV_VertexID;
  21. uint m_instanceIndex :SV_InstanceID;
  22. };
  23. struct VSOutput
  24. {
  25. float4 m_position : SV_Position;
  26. float2 m_uv : UV0;
  27. uint slice : SLICE;
  28. };
  29. struct PSOutput
  30. {
  31. float4 m_color : SV_Target0;
  32. };
  33. VSOutput MainVS(VSInput vsInput)
  34. {
  35. VSOutput OUT;
  36. float2 uvs[4] = { {0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}, {1.0, 1.0} };
  37. uint index = vsInput.m_vertexIndex%4;
  38. uint sliceIndex = vsInput.m_instanceIndex;
  39. float seam = 0.01;
  40. float2 startPosition = ImageSrg::m_position + float2((ImageSrg::m_size.x + seam) * sliceIndex, 0.0);
  41. OUT.m_position = float4(startPosition + uvs[index] * ImageSrg::m_size, 0, 1.0);
  42. OUT.m_uv = uvs[index];
  43. OUT.slice = sliceIndex;
  44. return OUT;
  45. }
  46. PSOutput MainPS(VSOutput psInput)
  47. {
  48. PSOutput OUT;
  49. // Get the image dimensions
  50. uint width;
  51. uint height;
  52. uint depth;
  53. uint numberOfLevels;
  54. ImageSrg::m_texture3D.GetDimensions(0, width, height, depth, numberOfLevels);
  55. float3 texColor = ImageSrg::m_texture3D.Load(int4(width * psInput.m_uv.x, height * psInput.m_uv.y, psInput.slice, 0)).xyz;
  56. OUT.m_color = float4(TransformColor(texColor, ColorSpaceId::LinearSRGB, ColorSpaceId::SRGB), 1.0);
  57. return OUT;
  58. }