SpriteImage.bslinc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. Parameters =
  2. {
  3. mat4x4 gWorldTransform;
  4. float gInvViewportWidth;
  5. float gInvViewportHeight;
  6. float gViewportYFlip;
  7. color gTint;
  8. Sampler2D gMainTexSamp : alias("gMainTexture");
  9. Texture2D gMainTexture;
  10. };
  11. Blocks =
  12. {
  13. Block GUIParams : auto("GUIParams");
  14. };
  15. Technique : base("SpriteImage") =
  16. {
  17. Language = "HLSL11";
  18. Pass =
  19. {
  20. DepthRead = false;
  21. DepthWrite = false;
  22. Common =
  23. {
  24. cbuffer GUIParams
  25. {
  26. float4x4 gWorldTransform;
  27. float gInvViewportWidth;
  28. float gInvViewportHeight;
  29. float gViewportYFlip;
  30. float4 gTint;
  31. }
  32. };
  33. Vertex =
  34. {
  35. void main(
  36. in float3 inPos : POSITION,
  37. in float2 uv : TEXCOORD0,
  38. out float4 oPosition : SV_Position,
  39. out float2 oUv : TEXCOORD0)
  40. {
  41. float4 tfrmdPos = mul(gWorldTransform, float4(inPos.xy, 0, 1));
  42. float tfrmdX = -1.0f + (tfrmdPos.x * gInvViewportWidth);
  43. float tfrmdY = (1.0f - (tfrmdPos.y * gInvViewportHeight)) * gViewportYFlip;
  44. oPosition = float4(tfrmdX, tfrmdY, 0, 1);
  45. oUv = uv;
  46. }
  47. };
  48. Fragment =
  49. {
  50. SamplerState gMainTexSamp : register(s0);
  51. Texture2D gMainTexture : register(t0);
  52. float4 main(in float4 inPos : SV_Position, float2 uv : TEXCOORD0) : SV_Target
  53. {
  54. float4 color = gMainTexture.Sample(gMainTexSamp, uv);
  55. return color * gTint;
  56. }
  57. };
  58. };
  59. };
  60. Technique : base("SpriteImage") =
  61. {
  62. Language = "GLSL";
  63. Pass =
  64. {
  65. DepthRead = false;
  66. DepthWrite = false;
  67. Common =
  68. {
  69. layout (binding = 0, std140) uniform GUIParams
  70. {
  71. mat4 gWorldTransform;
  72. float gInvViewportWidth;
  73. float gInvViewportHeight;
  74. float gViewportYFlip;
  75. vec4 gTint;
  76. };
  77. };
  78. Vertex =
  79. {
  80. layout (location = 0) in vec3 bs_position;
  81. layout (location = 1) in vec2 bs_texcoord0;
  82. layout (location = 0) out vec2 texcoord0;
  83. out gl_PerVertex
  84. {
  85. vec4 gl_Position;
  86. };
  87. void main()
  88. {
  89. vec4 tfrmdPos = gWorldTransform * vec4(bs_position.xy, 0, 1);
  90. float tfrmdX = -1.0f + (tfrmdPos.x * gInvViewportWidth);
  91. float tfrmdY = (1.0f - (tfrmdPos.y * gInvViewportHeight)) * gViewportYFlip;
  92. gl_Position = vec4(tfrmdX, tfrmdY, 0, 1);
  93. texcoord0 = bs_texcoord0;
  94. }
  95. };
  96. Fragment =
  97. {
  98. layout (binding = 1) uniform sampler2D gMainTexture;
  99. layout (location = 0) in vec2 texcoord0;
  100. layout (location = 0) out vec4 fragColor;
  101. void main()
  102. {
  103. vec4 color = texture(gMainTexture, texcoord0.st);
  104. fragColor = color * gTint;
  105. }
  106. };
  107. };
  108. };