UiVisualizeImage.ankiprog 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma anki mutator TEXTURE_TYPE 0 1
  6. #pragma anki technique vert pixel
  7. #include <AnKi/Shaders/Common.hlsl>
  8. struct Constants
  9. {
  10. Vec4 m_transform; // x: x scale, y: y scale, z: x transl, w: y transl
  11. Vec4 m_colorScale;
  12. Vec4 m_depth; // Used in 3D textures.
  13. };
  14. ANKI_FAST_CONSTANTS(Constants, g_consts)
  15. struct VertIn
  16. {
  17. Vec2 m_position : POSITION;
  18. Vec4 m_color : COLOR;
  19. Vec2 m_uv : TEXCOORD;
  20. };
  21. struct VertOut
  22. {
  23. Vec2 m_uv : TEXCOORD;
  24. Vec4 m_color : COLOR;
  25. Vec4 m_svPosition : SV_POSITION;
  26. };
  27. #if ANKI_VERTEX_SHADER
  28. VertOut main(VertIn input)
  29. {
  30. VertOut output;
  31. output.m_uv = input.m_uv;
  32. output.m_uv.y = 1.0 - output.m_uv.y;
  33. output.m_color = input.m_color;
  34. const Vec2 pos = g_consts.m_transform.xy * input.m_position + g_consts.m_transform.zw;
  35. output.m_svPosition = Vec4(pos, 0.0, 1.0);
  36. return output;
  37. }
  38. #endif // ANKI_VERTEX_SHADER
  39. #if ANKI_PIXEL_SHADER
  40. SamplerState g_trilinearRepeatSampler : register(s0);
  41. # if TEXTURE_TYPE == 0
  42. Texture2D<Vec4> g_tex2d : register(t0);
  43. # else
  44. Texture3D<Vec4> g_tex3d : register(t0);
  45. # endif
  46. Vec4 main(VertOut input) : SV_TARGET0
  47. {
  48. # if TEXTURE_TYPE == 0
  49. const Vec4 rgba = g_tex2d.Sample(g_trilinearRepeatSampler, input.m_uv);
  50. # else
  51. const Vec4 rgba = g_tex3d.Sample(g_trilinearRepeatSampler, Vec3(input.m_uv, g_consts.m_depth.x));
  52. # endif
  53. Vec3 outColor = input.m_color.rgb * rgba.rgb * g_consts.m_colorScale.rgb;
  54. if(g_consts.m_colorScale.a == 1.0)
  55. {
  56. // Draw a pattern to visualize alpha
  57. F32 alphaPattern = ((U32(input.m_svPosition.x) / 16u) & 1u) == 1u ? 1.0 : 0.75;
  58. alphaPattern *= ((U32(input.m_svPosition.y) / 16u) & 1u) == 1u ? 1.0 : 0.75;
  59. outColor = lerp(Vec3(alphaPattern, alphaPattern, alphaPattern), outColor, rgba.a);
  60. }
  61. return Vec4(outColor, 1.0);
  62. }
  63. #endif // ANKI_PIXEL_SHADER