backdrop.fx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //-----------------------------------------------------------------------------
  2. // Backdrop.fx
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. //Input variables
  8. float4x4 world;
  9. float4x4 worldViewProjection;
  10. float layerFactor;
  11. float4 layer1Offset;
  12. float4 layer2Offset;
  13. texture layer1;
  14. sampler nebula1 = sampler_state
  15. {
  16. Texture = (layer1);
  17. ADDRESSU = CLAMP;
  18. ADDRESSV = CLAMP;
  19. MAGFILTER = LINEAR;
  20. MINFILTER = LINEAR;
  21. MIPFILTER = LINEAR;
  22. };
  23. texture layer2;
  24. sampler nebula2 = sampler_state
  25. {
  26. Texture = (layer2);
  27. ADDRESSU = CLAMP;
  28. ADDRESSV = CLAMP;
  29. MAGFILTER = LINEAR;
  30. MINFILTER = LINEAR;
  31. MIPFILTER = LINEAR;
  32. };
  33. texture layer3;
  34. sampler stars = sampler_state
  35. {
  36. Texture = (layer3);
  37. ADDRESSU = CLAMP;
  38. ADDRESSV = CLAMP;
  39. MAGFILTER = LINEAR;
  40. MINFILTER = LINEAR;
  41. MIPFILTER = LINEAR;
  42. };
  43. struct VS_OUTPUT
  44. {
  45. float4 pos : POSITION;
  46. float2 tex0 : TEXCOORD0;
  47. float2 tex1 : TEXCOORD1;
  48. float2 tex2 : TEXCOORD2;
  49. };
  50. //vertex shader
  51. VS_OUTPUT backdropVS(float4 Pos : POSITION)
  52. {
  53. VS_OUTPUT Out = (VS_OUTPUT)0;
  54. //Calculate texture coordinates for the 3 layers
  55. //The background coordinates are in the range 0.0-1.0 for easy tex lookup
  56. Out.tex0.x = Pos.x / 1480 + layer1Offset.x; //textures are 1480 need to only take 1280
  57. Out.tex0.y = Pos.y / 960 + layer1Offset.y; //textures are 920 need to only take 720
  58. Out.tex1.x = Pos.x / 1480 + layer2Offset.x; //textures are 1480 need to only take 1280
  59. Out.tex1.y = Pos.y / 960 + layer2Offset.y; //textures are 920 need to only take 720
  60. Out.tex2.x = Pos.x / 1280; //Star texture is the right size
  61. Out.tex2.y = Pos.y / 720;
  62. //And move to screen space
  63. Out.pos.x = (Pos.x - 640) / 640;
  64. Out.pos.y = (Pos.y - 360) / 360;
  65. Out.pos.z = 0;
  66. Out.pos.w = 1;
  67. return Out;
  68. }
  69. //pixel shader
  70. void backdropPS(in float2 tex0 : TEXCOORD0, in float2 tex1 : TEXCOORD1, in float2 tex2 : TEXCOORD2, out float4 outCol: COLOR0)
  71. {
  72. outCol = (tex2D(nebula1, tex0) * (.2 + layerFactor * .8));
  73. outCol += (tex2D(nebula2, tex1) * (1 - saturate(layerFactor * .8)));
  74. outCol += tex2D(stars, tex2);
  75. }
  76. //technique
  77. technique RenderBackdrop
  78. {
  79. pass P0
  80. {
  81. CULLMODE = NONE;
  82. ZWRITEENABLE = FALSE;
  83. VertexShader = compile vs_1_1 backdropVS();
  84. PixelShader = compile ps_2_0 backdropPS();
  85. }
  86. }