Texture3d.azsl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. ShaderResourceGroup ImageSrg : SRG_PerDraw
  10. {
  11. Texture3D m_texture3D;
  12. uint m_sliceIndex;
  13. float2 m_position;
  14. float2 m_size;
  15. }
  16. struct VSInput
  17. {
  18. uint m_vertexIndex : SV_VertexID;
  19. };
  20. struct VSOutput
  21. {
  22. float4 m_position : SV_Position;
  23. float2 m_uv : UV0;
  24. uint m_slice : SLICE;
  25. };
  26. struct PSOutput
  27. {
  28. float4 m_color : SV_Target0;
  29. };
  30. VSOutput MainVS(VSInput vsInput)
  31. {
  32. VSOutput OUT;
  33. float2 uvs[4] = { {-1.0, -1.0}, {1.0, -1.0}, {-1.0, 1.0}, {1.0, 1.0} };
  34. uint index = vsInput.m_vertexIndex%4;
  35. float seam = 0.01;
  36. float2 startPosition = ImageSrg::m_position;
  37. OUT.m_position = float4(startPosition + uvs[index] * ImageSrg::m_size, 0, 1.0);
  38. OUT.m_uv = (uvs[index]+1) * 0.5;
  39. OUT.m_slice = ImageSrg::m_sliceIndex;
  40. return OUT;
  41. }
  42. PSOutput MainPS(VSOutput psInput)
  43. {
  44. PSOutput OUT;
  45. // Get the image dimensions
  46. uint width;
  47. uint height;
  48. uint depth;
  49. uint numberOfLevels;
  50. ImageSrg::m_texture3D.GetDimensions(0, width, height, depth, numberOfLevels);
  51. OUT.m_color = ImageSrg::m_texture3D.Load(int4(width * psInput.m_uv.x, height * psInput.m_uv.y, psInput.m_slice, 0));
  52. return OUT;
  53. }