SpriteImage.bslinc 2.3 KB

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