Advertisement
Guest User

Untitled

a guest
Sep 7th, 2012
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. #include "../../../Compile.fxh"
  2. #include "../VertexFormats.fxh"
  3. #include "../PerFrameVSData.fxh"
  4. #include "../PerFramePSData.fxh"
  5. #include "../Math.fxh"
  6.  
  7. float Tiling1
  8. <
  9. bool SasUiVisible = true;
  10. > = 10;
  11.  
  12. float Tiling2
  13. <
  14. bool SasUiVisible = true;
  15. > = 20;
  16.  
  17. float Tiling3
  18. <
  19. bool SasUiVisible = true;
  20. > = 30;
  21.  
  22. float StarSquareBrightness
  23. <
  24. bool SasUIVisible = true;
  25. > = 1.5;
  26.  
  27. float StarLinearBrightness
  28. <
  29. bool SasUIVisible = true;
  30. > = 0.25;
  31.  
  32.  
  33. /////////////////////////////////////////////////////////////////////////
  34. // textures
  35. textureCUBE NebulaMap
  36. <
  37. bool SasUiVisible = true;
  38. >;
  39. sampler NebulaMapSampler = sampler_state
  40. {
  41. Texture = <NebulaMap>;
  42. MinFilter = Linear;
  43. MagFilter = Linear;
  44. MipFilter = Linear;
  45. MipMapLodBias = -1;
  46. MaxMipLevel = 0;
  47. AddressU = Clamp;
  48. AddressV = Clamp;
  49. AddressW = Clamp;
  50. };
  51.  
  52. texture2D StarMap
  53. <
  54. bool SasUiVisible = true;
  55. >;
  56. sampler StarMapSampler = sampler_state
  57. {
  58. Texture = <StarMap>;
  59. SET_STANDARD_SAMPLER_STATES;
  60. MipMapLodBias = 0;
  61. MaxMipLevel = 0;
  62. };
  63.  
  64. float4x4 EnvMapTransform;
  65.  
  66. /////////////////////////////////////////////////////////////////////////
  67. // in/out structs
  68. struct NebulaVertex
  69. {
  70. float4 posClip : POSITION;
  71. float4 posView : TEXCOORD0;
  72. };
  73.  
  74.  
  75. float2 UVFromDir(float3 dir)
  76. {
  77. float2 uv;
  78. float3 absDir = abs( dir );
  79. float maxVal = max( absDir.x, max( absDir.y, absDir.z ) );
  80. float3 max = float3( step( float3( maxVal, maxVal, maxVal ), absDir ) );
  81.  
  82. float3 u = float3( dir.z, -dir.z, dir.x );
  83. float3 v = float3( dir.y, dir.x, -dir.y );
  84.  
  85. uv = float2( dot( max, u ), dot( max, v ) );
  86.  
  87. uv /= maxVal;
  88. return ( uv + 1 ) * 0.5;
  89. }
  90.  
  91. /////////////////////////////////////////////////////////////////////////
  92. // shaders
  93. NebulaVertex NebulaVS( BlitVertex inVtx )
  94. {
  95. NebulaVertex outVtx = (NebulaVertex) 0;
  96.  
  97. float3x3 inv = transpose( PerFrameVS.ViewInverseTransposeMat );
  98.  
  99. float4 a = float4( mul( inVtx.pos, inv ), 1 );
  100. a = mul( a, EnvMapTransform );
  101. outVtx.posView = a;
  102.  
  103. outVtx.posClip = mul( inVtx.pos, PerFrameVS.ProjectionMat );
  104.  
  105. // ensure that the vertex is at exactly the back clip plane and avoid numerical precision issues
  106. outVtx.posClip.z = outVtx.posClip.w;
  107.  
  108. return outVtx;
  109. }
  110.  
  111. float4 NebulaPS( NebulaVertex inVtx ) : COLOR
  112. {
  113. float4 nebulaColor = texCUBE( NebulaMapSampler, inVtx.posView );
  114.  
  115. #if HIDEF_SHADERS
  116. float4 starColor;
  117.  
  118. float2 starUV = UVFromDir( inVtx.posView );
  119. starColor = tex2D( StarMapSampler, starUV * Tiling1 );
  120. starColor += tex2D( StarMapSampler, starUV * Tiling2 );
  121. starColor += tex2D( StarMapSampler, starUV * Tiling3 );
  122.  
  123. starColor = starColor * (StarLinearBrightness + starColor * StarSquareBrightness);
  124. float luminosity = dot( nebulaColor, float3(0.299, 0.587, 0.114) );
  125. float nebulaBlock = 1 - saturate( 8 * pow( luminosity, 2 ) );
  126. return nebulaColor + starColor * nebulaBlock;
  127.  
  128. #else
  129.  
  130. float2 starUV = UVFromDir( inVtx.posView );
  131. float4 starColor = tex2D( StarMapSampler, starUV * Tiling2 );
  132. return nebulaColor * 0.8 + starColor * 0.5;// * starColor;
  133.  
  134. #endif
  135. }
  136.  
  137. /////////////////////////////////////////////////////////////////////////
  138. // main technique
  139. technique Main
  140. {
  141. pass P0
  142. {
  143. ZEnable = FALSE;
  144. ZWriteEnable = FALSE;
  145. ZFunc = ALWAYS;
  146. VertexShader = COMPILE_VS( NebulaVS );
  147. PixelShader = COMPILE_PS( NebulaPS );
  148. }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement