| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- //////////////////////////////////////////////////////////////////////////////
- // ©2005 Electronic Arts Inc
- //
- // FX Shader for simple unlit rendering
- //////////////////////////////////////////////////////////////////////////////
- #define SUPPORT_FOG 1
- #include "Common.fxh"
- // ----------------------------------------------------------------------------
- // MATERIAL PARAMATERS
- // ----------------------------------------------------------------------------
- SAMPLER_2D_BEGIN( RiverTexture,
- string UIName = "River Texture";
- )
- MipFilter = LINEAR;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- AddressU = WRAP;
- AddressV = WRAP;
- SAMPLER_2D_END
- float4 Opacity
- <
- string UIName = "Opacity";
- > = float4(1, 1, 1, 1);
- // ----------------------------------------------------------------------------
- // Reflection
- // ----------------------------------------------------------------------------
- SAMPLER_2D_BEGIN( WaterReflectionTexture,
- string UIWidget = "None";
- string SasBindAddress = "Water.ReflectionTexture";
- )
- MipFilter = Point;
- MinFilter = Linear;
- MagFilter = Linear;
- AddressU = CLAMP;
- AddressV = CLAMP;
- SAMPLER_2D_END
- // ----------------------------------------------------------------------------
- // Environment map
- // ----------------------------------------------------------------------------
- SAMPLER_CUBE_BEGIN( EnvironmentTexture,
- string UIWidget = "None";
- string SasBindAddress = "Terrain.EnvironmentTexture";
- string ResourceType = "Cube";
- )
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Clamp;
- AddressV = Clamp;
- AddressW = Clamp;
- SAMPLER_CUBE_END
- // ----------------------------------------------------------------------------
- // 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
- // ----------------------------------------------------------------------------
- // Transformations
- // ----------------------------------------------------------------------------
- float4x4 WorldViewProjection : WorldViewProjection;
- float4x4 World : World;
- #if defined(_WW3D_)
- #if !defined(USE_INDIRECT_CONSTANT)
- float3 EyePosition
- <
- string UIWidget = "None";
- string SasBindAddress = "Sas.Camera.Position";
- >;
- #endif // #if !defined(USE_INDIRECT_CONSTANT)
- float3 GetEyePosition()
- {
- return EyePosition;
- }
- #else // #if defined(_WW3D_)
- float4x3 ViewI : ViewInverse;
- float3 GetEyePosition()
- {
- return ViewI[3];
- }
- #endif // #if defined(_WW3D_)
- float Time : Time;
- // ----------------------------------------------------------------------------
- // SHADER: Default (UltraHigh)
- // ----------------------------------------------------------------------------
- struct VSOutput
- {
- float4 Position : POSITION;
- float4 Color : COLOR0;
- float Fog : COLOR1;
- float2 RiverTexCoord : TEXCOORD0;
- float2 ShroudTexCoord : TEXCOORD1;
- float3 ReflectionTexCoord : TEXCOORD2;
- };
- // ----------------------------------------------------------------------------
- VSOutput VS( float3 Position : POSITION,
- float4 Color : COLOR0,
- float2 RiverTexCoord : TEXCOORD0,
- float2 NormalTexCoord : TEXCOORD1 )
- {
- VSOutput Out;
- // Position
- Out.Position = mul( float4(Position, 1), WorldViewProjection );
- // Color
- float4 color = Color;
- color.w *= Opacity.w;
- Out.Color = color;
- // Fog
- float3 worldPosition = mul( float4(Position, 1), World );
- Out.Fog = CalculateFog( Fog, worldPosition, GetEyePosition() );
- // RiverTexCoord
- Out.RiverTexCoord = NormalTexCoord;
- // ShroudTexCoord
- Out.ShroudTexCoord = CalculateShroudTexCoord( Shroud, worldPosition );
- // ReflectionTexCoord
- Out.ReflectionTexCoord.xy = 0.5 * ( Out.Position.xy + Out.Position.w * float2(1.0, 1.0) );
- Out.ReflectionTexCoord.z = Out.Position.w;
- return Out;
- }
- // ----------------------------------------------------------------------------
- float4 PS( VSOutput In ) : COLOR
- {
- // Sample the base texture
- float4 color = tex2D( SAMPLER(RiverTexture), In.RiverTexCoord );
- // Apply vertex color
- color *= In.Color;
- // Apply the reflection map
- float2 reflectionCoord = In.ReflectionTexCoord.xy / In.ReflectionTexCoord.z;
- float3 reflectionColor = tex2D( SAMPLER(WaterReflectionTexture), reflectionCoord );
- color.xyz *= reflectionColor;
- // Apply fog
- color.xyz *= In.Fog;
- // Apply shroud
- float3 shroud = tex2D( SAMPLER(ShroudTexture), In.ShroudTexCoord ).xyz;
- color.xyz *= shroud;
- return color;
- }
- // ----------------------------------------------------------------------------
- technique Default_U
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS();
- PixelShader = compile PS_2_0 PS();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = true;
- AlphaTestEnable = false;
- ColorWriteEnable = 7;
-
- SrcBlend = SrcAlpha;
- DestBlend = One;
- }
- }
- #if ENABLE_LOD
- // ----------------------------------------------------------------------------
- // SHADER: Default Medium Quality
- // ----------------------------------------------------------------------------
- struct VSOutput_M
- {
- float4 Position : POSITION;
- float4 Color : COLOR0;
- float Fog : COLOR1;
- float2 RiverTexCoord : TEXCOORD0;
- float2 ShroudTexCoord : TEXCOORD1;
- float3 ReflectionTexCoord : TEXCOORD2;
- };
- // ----------------------------------------------------------------------------
- VSOutput_M VS_M( float3 Position : POSITION,
- float4 Color : COLOR0,
- float2 RiverTexCoord : TEXCOORD0,
- float2 NormalTexCoord : TEXCOORD1 )
- {
- VSOutput_M Out;
- // Position
- Out.Position = mul( float4(Position, 1), WorldViewProjection );
- // Color
- float4 color = Color;
- color.w *= Opacity.w;
- Out.Color = color;
- // Fog
- float3 worldPosition = mul( float4(Position, 1), World );
- Out.Fog = CalculateFog( Fog, worldPosition, GetEyePosition() );
- // RiverTexCoord
- Out.RiverTexCoord = NormalTexCoord;
- // ShroudTexCoord
- Out.ShroudTexCoord = CalculateShroudTexCoord( Shroud, worldPosition );
- // Compute view direction in world space
- float3 worldEyeDir = normalize( GetEyePosition() - worldPosition );
- // Compute env map reflection direction
- float3 worldNormal = float3( 0, 0, 1 ); // Rivers always face up
- Out.ReflectionTexCoord = -reflect( worldEyeDir, worldNormal );
- return Out;
- }
- // ----------------------------------------------------------------------------
- float4 PS_M( VSOutput_M In ) : COLOR
- {
- // Sample the base texture
- float4 color = tex2D( SAMPLER(RiverTexture), In.RiverTexCoord );
- // Apply vertex color
- color *= In.Color;
- // Apply the reflection map
- float3 reflectionColor = texCUBE( SAMPLER(EnvironmentTexture), In.ReflectionTexCoord );
- color.xyz *= reflectionColor;
- // Apply fog
- color.xyz *= In.Fog;
- // Apply shroud
- float3 shroud = tex2D( SAMPLER(ShroudTexture), In.ShroudTexCoord ).xyz;
- color.xyz *= shroud;
-
- return color;
- }
- // ----------------------------------------------------------------------------
- // TECHNIQUE: High Quality
- // ----------------------------------------------------------------------------
- technique _Default
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_M();
- PixelShader = compile PS_2_0 PS_M();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = true;
- AlphaTestEnable = false;
- ColorWriteEnable = 7;
- SrcBlend = SrcAlpha;
- DestBlend = One;
- }
- }
- // ----------------------------------------------------------------------------
- // TECHNIQUE: Low Quality
- // ----------------------------------------------------------------------------
- technique _Default_L
- {
- // Do nothing!
- }
- #endif
|