overlay.fx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //credits: ms d3d tutorials which I hacked apart
  2. Texture2D txDiffuse : register( t0 );
  3. SamplerState samLinear : register( s0 );
  4. cbuffer ConstantBuffer : register( b0 )
  5. {
  6. float4x4 rotation;
  7. float2 originpoint;
  8. float2 translation;
  9. float2 scaling;
  10. float transparency;
  11. float garbage;
  12. }
  13. //--------------------------------------------------------------------------------------
  14. struct VS_INPUT
  15. {
  16. float4 Pos : POSITION;
  17. float2 Tex : TEXCOORD0;
  18. };
  19. struct PS_INPUT
  20. {
  21. float4 Pos : SV_POSITION;
  22. float2 Tex : TEXCOORD0;
  23. };
  24. //--------------------------------------------------------------------------------------
  25. // Vertex Shader
  26. //--------------------------------------------------------------------------------------
  27. PS_INPUT VS( VS_INPUT input )
  28. {
  29. PS_INPUT r=input;
  30. float4 rp;
  31. r.Pos[0]-=originpoint[0];
  32. r.Pos[1]+=originpoint[1];
  33. r.Pos=mul(r.Pos, rotation);
  34. r.Pos[0]+=originpoint[0];
  35. r.Pos[1]-=originpoint[1];
  36. //scale to the required size (calculated by the renderer)
  37. r.Pos[0]=r.Pos[0]*scaling[0];
  38. r.Pos[1]=r.Pos[1]*scaling[1];
  39. //position the sprite so the origin is at the top left
  40. r.Pos[0]+=1.0f*scaling[0];
  41. r.Pos[1]-=1.0f*scaling[1];
  42. //now translate to the proper position (0,0=center)
  43. r.Pos[0]+=translation[0];
  44. r.Pos[1]-=translation[1];
  45. r.Pos[2]=0.0f;
  46. return r;
  47. }
  48. //--------------------------------------------------------------------------------------
  49. // Pixel Shader
  50. //--------------------------------------------------------------------------------------
  51. //For those wondering: Here used to be a secondary pixelshader. It's gone (yup, it's gone)
  52. float4 PSNormal( PS_INPUT input): SV_Target
  53. {
  54. //pixel shader for overlays that do not use the 255,255,255 = transparency rule
  55. float4 r;
  56. r=txDiffuse.Sample( samLinear, input.Tex );
  57. r[3]=r[3]*transparency;
  58. return r;
  59. // r[3]=r[3]*transparency;
  60. // return float4(0.0f, 1.0f, 0.0f, 1.0f);
  61. }