| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- //-----------------------------------------------------------------------------
- // ©2006 Electronic Arts Inc
- //-----------------------------------------------------------------------------
- #define SUPPORT_FOG 1
- #include "Common.fxh"
- #include "CommonParticle.fxh"
- #if defined(_WW3D_)
- #if !defined(USE_INDIRECT_CONSTANT)
- float4x4 ViewProjection
- <
- string UIWidget = "None";
- string SasBindAddress = "Sas.Camera.WorldToProjection";
- >;
- float3 EyePosition
- <
- string UIWidget = "None";
- string SasBindAddress = "Sas.Camera.Position";
- >;
- #endif // #if !defined(USE_INDIRECT_CONSTANT)
- float4x4 GetViewProjection()
- {
- return ViewProjection;
- }
- float3 GetEyePosition()
- {
- return EyePosition;
- }
- #else // #if defined(_WW3D_)
- float4x4 Projection : Projection;
- float4x4 View : View;
- float4x3 ViewI : ViewInverse;
- float4x4 GetViewProjection()
- {
- return mul(View, Projection);
- }
- float3 GetEyePosition()
- {
- return ViewI[3];
- }
- #endif // #if defined(_WW3D_)
- // ----------------------------------------------------------------------------
- // Diffuse Texture
- // ----------------------------------------------------------------------------
- SAMPLER_2D_BEGIN( DiffuseTexture,
- string UIWidget = "None";
- string SasBindAddress = "Particle.Draw.Texture";
- )
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Clamp;
- AddressV = Clamp;
- SAMPLER_2D_END
- // ----------------------------------------------------------------------------
- // Fog
- // ----------------------------------------------------------------------------
- // Variationgs for handling fog in the pixel shader
- static const int FogMode_Disabled = 0;
- static const int FogMode_Opaque = 1;
- static const int FogMode_Additive = 2;
- // ----------------------------------------------------------------------------
- // Shroud
- // ----------------------------------------------------------------------------
- ShroudSetup Shroud
- <
- string UIWidget = "None";
- string SasBindAddress = "Terrain.Shroud";
- > = DEFAULT_SHROUD;
- SAMPLER_2D_BEGIN( ShroudTexture,
- string UIWidget = "None";
- string SasBindAddress = "Terrain.Shroud.Texture";
- string ResourceName = "ShaderPreviewShroud.dds";
- )
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Clamp;
- AddressV = Clamp;
- SAMPLER_2D_END
- //-----------------------------------------------------------------------------
- // Vertex Shader structure
- //-----------------------------------------------------------------------------
- struct VSInput
- {
- float3 Position : POSITION;
- float4 Color : COLOR0;
- float2 DiffuseTexCoord : TEXCOORD0;
- };
- struct VSOutput
- {
- float4 Position : POSITION;
- float4 Color : COLOR0;
- float3 Fog : COLOR1; // This is just a scalar, but PS1.1 can't replicate-swizzle, so replicate scalar into a vector in vertex shader
- float2 DiffuseTexCoord : TEXCOORD0;
- float2 ShroudTexCoord : TEXCOORD1;
- };
- //-----------------------------------------------------------------------------
- // Vertex Shader
- //-----------------------------------------------------------------------------
- VSOutput VS( VSInput Input )
- {
- VSOutput Output;
-
- // Input Position is already in world space
- Output.Position = mul( float4( Input.Position, 1 ), GetViewProjection() );
- Output.Color = Input.Color;
- Output.DiffuseTexCoord = Input.DiffuseTexCoord;
-
- // Calculate fog
- Output.Fog = CalculateFog( Fog, Input.Position, GetEyePosition() ).xxx;
- // Calculate Shroud UVs
- // Note: Input is already in world space
- Output.ShroudTexCoord = CalculateShroudTexCoord( Shroud, Input.Position );
- return Output;
- }
- //-----------------------------------------------------------------------------
- // Pixel Shader
- //-----------------------------------------------------------------------------
- float4 PS( VSOutput Input, uniform int fog_mode ) COLORTARGET
- {
- // Get the base color
- float4 diffuse_texture = tex2D( SAMPLER(DiffuseTexture), Input.DiffuseTexCoord );
- float4 color = diffuse_texture * Input.Color;
- // Apply fog
- if( fog_mode == FogMode_Opaque )
- {
- color.xyz = lerp( Fog.Color, color.xyz, Input.Fog );
- }
- else if( fog_mode == FogMode_Additive )
- {
- color.xyz *= Input.Fog;
- }
- // Apply shroud
- float shroud = tex2D( SAMPLER(ShroudTexture), Input.ShroudTexCoord ).x;
- shroud = BiasShroudValueForEffects( shroud );
- color.xyz *= shroud;
- return color;
- }
- //-----------------------------------------------------------------------------
- float4 PS_Xenon( VSOutput In ) : COLOR
- {
- return PS( In, Fog.IsEnabled ? ((Draw.ShaderType == ShaderType_Additive || Draw.ShaderType == ShaderType_AdditiveAlphaTest || Draw.ShaderType == ShaderType_Multiply) ? FogMode_Additive : FogMode_Opaque) : FogMode_Disabled );
- }
- //-----------------------------------------------------------------------------
- // Techniques
- //-----------------------------------------------------------------------------
- #define PS_ShaderType \
- compile PS_2_0 PS(FogMode_Disabled), \
- compile PS_2_0 PS(FogMode_Opaque), \
- compile PS_2_0 PS(FogMode_Additive)
- DEFINE_ARRAY_MULTIPLIER( PS_Multiplier_Final = 3 );
- #if SUPPORTS_SHADER_ARRAYS
- pixelshader PS_Array[PS_Multiplier_Final] =
- {
- PS_ShaderType
- };
- #endif
- //-----------------------------------------------------------------------------
- technique Default
- {
- pass pass0
- <
- USE_EXPRESSION_EVALUATOR("Particle")
- >
- {
- VertexShader = compile VS_2_0 VS();
- PixelShader = ARRAY_EXPRESSION_PS( PS_Array,
- Fog.IsEnabled ? ((Draw.ShaderType == ShaderType_Additive || Draw.ShaderType == ShaderType_AdditiveAlphaTest || Draw.ShaderType == ShaderType_Multiply) ? FogMode_Additive : FogMode_Opaque) : FogMode_Disabled,
- compile PS_VERSION PS_Xenon() );
- ZEnable = true;
- ZWriteEnable = false;
- ZFunc = ZFUNC_INFRONT;
- CullMode = none;
- SETUP_ALPHA_BLEND_AND_TEST(Draw.ShaderType);
- }
- }
|