Ui.ankiprog 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 // 0: no tex, 1: rgba tex
  6. #pragma anki technique vert pixel
  7. #include <AnKi/Shaders/Common.hlsl>
  8. struct VertIn
  9. {
  10. Vec2 m_position : POSITION;
  11. ANKI_RELAXED_PRECISION Vec4 m_color : COLOR;
  12. #if TEXTURE_TYPE > 0
  13. Vec2 m_uv : TEXCOORD;
  14. #endif
  15. };
  16. struct VertOut
  17. {
  18. #if TEXTURE_TYPE > 0
  19. Vec2 m_uv : TEXCOORD;
  20. #endif
  21. ANKI_RELAXED_PRECISION Vec4 m_color : COLOR;
  22. Vec4 m_svPosition : SV_POSITION;
  23. };
  24. #if ANKI_VERTEX_SHADER
  25. struct Constants
  26. {
  27. Vec4 m_transform; // x: x scale, y: y scale, z: x transl, w: y transl
  28. };
  29. ANKI_FAST_CONSTANTS(Constants, g_consts)
  30. VertOut main(VertIn input)
  31. {
  32. VertOut output;
  33. # if TEXTURE_TYPE > 0
  34. output.m_uv = input.m_uv;
  35. # endif
  36. output.m_color = input.m_color;
  37. const Vec2 pos = g_consts.m_transform.xy * input.m_position + g_consts.m_transform.zw;
  38. output.m_svPosition = Vec4(pos, 0.0, 1.0);
  39. return output;
  40. }
  41. #endif // ANKI_VERTEX_SHADER
  42. #if ANKI_PIXEL_SHADER
  43. # if TEXTURE_TYPE > 0
  44. SamplerState g_trilinearRepeatSampler : register(s0);
  45. Texture2D g_tex : register(t0);
  46. # endif
  47. Vec4 main(VertOut input) : SV_TARGET0
  48. {
  49. # if TEXTURE_TYPE == 0
  50. return input.m_color;
  51. # elif TEXTURE_TYPE == 1
  52. return input.m_color * g_tex.Sample(g_trilinearRepeatSampler, input.m_uv);
  53. # endif
  54. }
  55. #endif // ANKI_PIXEL_SHADER