SpriteText.bsl 2.4 KB

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