SpriteImage.bslinc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 : base("SpriteImage") =
  11. {
  12. Language = "HLSL11";
  13. Pass =
  14. {
  15. DepthRead = false;
  16. DepthWrite = false;
  17. Vertex =
  18. {
  19. float invViewportWidth;
  20. float invViewportHeight;
  21. float4x4 worldTransform;
  22. void main(
  23. in float3 inPos : POSITION,
  24. in float2 uv : TEXCOORD0,
  25. out float4 oPosition : SV_Position,
  26. out float2 oUv : TEXCOORD0)
  27. {
  28. float4 tfrmdPos = mul(worldTransform, float4(inPos.xy, 0, 1));
  29. float tfrmdX = -1.0f + (tfrmdPos.x * invViewportWidth);
  30. float tfrmdY = 1.0f - (tfrmdPos.y * invViewportHeight);
  31. oPosition = float4(tfrmdX, tfrmdY, 0, 1);
  32. oUv = uv;
  33. }
  34. };
  35. Fragment =
  36. {
  37. SamplerState mainTexSamp : register(s0);
  38. Texture2D mainTexture : register(t0);
  39. float4 tint;
  40. float4 main(in float4 inPos : SV_Position, float2 uv : TEXCOORD0) : SV_Target
  41. {
  42. float4 color = mainTexture.Sample(mainTexSamp, uv);
  43. return color * tint;
  44. }
  45. };
  46. };
  47. };
  48. Technique : base("SpriteImage") =
  49. {
  50. Language = "GLSL";
  51. Pass =
  52. {
  53. DepthRead = false;
  54. DepthWrite = false;
  55. Vertex =
  56. {
  57. layout (binding = 0) uniform VertUBO
  58. {
  59. float invViewportWidth;
  60. float invViewportHeight;
  61. mat4 worldTransform;
  62. };
  63. layout (location = 0) in vec3 bs_position;
  64. layout (location = 1) in vec2 bs_texcoord0;
  65. layout (location = 0) out vec2 texcoord0;
  66. out gl_PerVertex
  67. {
  68. vec4 gl_Position;
  69. };
  70. void main()
  71. {
  72. vec4 tfrmdPos = worldTransform * vec4(bs_position.xy, 0, 1);
  73. float tfrmdX = -1.0f + (tfrmdPos.x * invViewportWidth);
  74. float tfrmdY = 1.0f - (tfrmdPos.y * invViewportHeight);
  75. gl_Position = vec4(tfrmdX, tfrmdY, 0, 1);
  76. texcoord0 = bs_texcoord0;
  77. }
  78. };
  79. Fragment =
  80. {
  81. layout (binding = 1) uniform FragUBO
  82. {
  83. vec4 tint;
  84. };
  85. layout (binding = 2) uniform sampler2D mainTexture;
  86. layout (location = 0) in vec2 texcoord0;
  87. layout (location = 0) out vec4 fragColor;
  88. void main()
  89. {
  90. vec4 color = texture2D(mainTexture, texcoord0.st);
  91. fragColor = color * tint;
  92. }
  93. };
  94. };
  95. };