Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "../../../Compile.fxh"
- #include "../VertexFormats.fxh"
- #include "../PerFrameVSData.fxh"
- #include "../PerFramePSData.fxh"
- #include "../Math.fxh"
- float Tiling1
- <
- bool SasUiVisible = true;
- > = 10;
- float Tiling2
- <
- bool SasUiVisible = true;
- > = 20;
- float Tiling3
- <
- bool SasUiVisible = true;
- > = 30;
- float StarSquareBrightness
- <
- bool SasUIVisible = true;
- > = 1.5;
- float StarLinearBrightness
- <
- bool SasUIVisible = true;
- > = 0.25;
- /////////////////////////////////////////////////////////////////////////
- // textures
- textureCUBE NebulaMap
- <
- bool SasUiVisible = true;
- >;
- sampler NebulaMapSampler = sampler_state
- {
- Texture = <NebulaMap>;
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Linear;
- MipMapLodBias = -1;
- MaxMipLevel = 0;
- AddressU = Clamp;
- AddressV = Clamp;
- AddressW = Clamp;
- };
- texture2D StarMap
- <
- bool SasUiVisible = true;
- >;
- sampler StarMapSampler = sampler_state
- {
- Texture = <StarMap>;
- SET_STANDARD_SAMPLER_STATES;
- MipMapLodBias = 0;
- MaxMipLevel = 0;
- };
- float4x4 EnvMapTransform;
- /////////////////////////////////////////////////////////////////////////
- // in/out structs
- struct NebulaVertex
- {
- float4 posClip : POSITION;
- float4 posView : TEXCOORD0;
- };
- float2 UVFromDir(float3 dir)
- {
- float2 uv;
- float3 absDir = abs( dir );
- float maxVal = max( absDir.x, max( absDir.y, absDir.z ) );
- float3 max = float3( step( float3( maxVal, maxVal, maxVal ), absDir ) );
- float3 u = float3( dir.z, -dir.z, dir.x );
- float3 v = float3( dir.y, dir.x, -dir.y );
- uv = float2( dot( max, u ), dot( max, v ) );
- uv /= maxVal;
- return ( uv + 1 ) * 0.5;
- }
- /////////////////////////////////////////////////////////////////////////
- // shaders
- NebulaVertex NebulaVS( BlitVertex inVtx )
- {
- NebulaVertex outVtx = (NebulaVertex) 0;
- float3x3 inv = transpose( PerFrameVS.ViewInverseTransposeMat );
- float4 a = float4( mul( inVtx.pos, inv ), 1 );
- a = mul( a, EnvMapTransform );
- outVtx.posView = a;
- outVtx.posClip = mul( inVtx.pos, PerFrameVS.ProjectionMat );
- // ensure that the vertex is at exactly the back clip plane and avoid numerical precision issues
- outVtx.posClip.z = outVtx.posClip.w;
- return outVtx;
- }
- float4 NebulaPS( NebulaVertex inVtx ) : COLOR
- {
- float4 nebulaColor = texCUBE( NebulaMapSampler, inVtx.posView );
- #if HIDEF_SHADERS
- float4 starColor;
- float2 starUV = UVFromDir( inVtx.posView );
- starColor = tex2D( StarMapSampler, starUV * Tiling1 );
- starColor += tex2D( StarMapSampler, starUV * Tiling2 );
- starColor += tex2D( StarMapSampler, starUV * Tiling3 );
- starColor = starColor * (StarLinearBrightness + starColor * StarSquareBrightness);
- float luminosity = dot( nebulaColor, float3(0.299, 0.587, 0.114) );
- float nebulaBlock = 1 - saturate( 8 * pow( luminosity, 2 ) );
- return nebulaColor + starColor * nebulaBlock;
- #else
- float2 starUV = UVFromDir( inVtx.posView );
- float4 starColor = tex2D( StarMapSampler, starUV * Tiling2 );
- return nebulaColor * 0.8 + starColor * 0.5;// * starColor;
- #endif
- }
- /////////////////////////////////////////////////////////////////////////
- // main technique
- technique Main
- {
- pass P0
- {
- ZEnable = FALSE;
- ZWriteEnable = FALSE;
- ZFunc = ALWAYS;
- VertexShader = COMPILE_VS( NebulaVS );
- PixelShader = COMPILE_PS( NebulaPS );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement