| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779 |
- //////////////////////////////////////////////////////////////////////////////
- // ©2005 Electronic Arts Inc
- //
- // FX Shader for particles
- //////////////////////////////////////////////////////////////////////////////
- #include "Common.fxh"
- #include "Gamma.fxh"
- #include "CommonParticle.fxh"
- SAMPLER_2D_BEGIN(ParticleTexture,
- string UIWidget = "None";
- string SasBindAddress = "Particle.Draw.Texture";
- )
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Clamp;
- AddressV = Clamp;
- SAMPLER_2D_END
- // ----------------------------------------------------------------------------
- // Transformations
- // ----------------------------------------------------------------------------
- float4x4 Projection : Projection;
- float4x3 View : View;
-
- #if defined(_WW3D_)
- #if !defined(USE_INDIRECT_CONSTANT)
- float4x4 ViewProjection
- <
- string UIWidget = "None";
- string SasBindAddress = "Sas.Camera.WorldToProjection";
- >;
- #endif // #if !defined(USE_INDIRECT_CONSTANT)
- float4x4 GetViewProjection()
- {
- return ViewProjection;
- }
- #else
- float4x4 GetViewProjection()
- {
- return mul(View, Projection);
- }
- #endif
- // ----------------------------------------------------------------------------
- // Vertex shader
- // ----------------------------------------------------------------------------
-
- struct VSInput
- {
- float4 Position_Index : POSITION; // position (xyz), index (w)
- float2 Angle_Size : TEXCOORD0; // angle (x), size (y)
- float4 VertexColor : COLOR0; // color
- };
- struct VSOutput
- {
- float4 Position : POSITION;
- float4 DiffuseColor : COLOR0;
- float2 BaseTexCoord : TEXCOORD0;
- };
- VSOutput VS_Billboard(VSInput In)
- {
- VSOutput Out;
-
- // compute the z rotation matrix
- float zRotation = In.Angle_Size.x;
- float2x2 zRotationMatrix;
- zRotationMatrix[0][0] = cos(zRotation);
- zRotationMatrix[0][1] = -sin(zRotation);
- zRotationMatrix[1][1] = zRotationMatrix[0][0];
- zRotationMatrix[1][0] = -zRotationMatrix[0][1];
- // compute the vertex corners
- float Index = In.Position_Index.w;
- float2 vertexCorner = VertexCorners[Index];
- float2 relativeCornerPos = mul(vertexCorner, zRotationMatrix);
- float size = In.Angle_Size.y;
- float3 xVector = float3( View[0][0], View[1][0], View[2][0] );
- float3 zVector = float3( View[0][1], View[1][1], View[2][1] );
- float3 cornerPosition = In.Position_Index.xyz + size * (relativeCornerPos.x * xVector + relativeCornerPos.y * zVector);
-
- Out.Position = mul(float4(cornerPosition, 1), GetViewProjection());
- Out.DiffuseColor = In.VertexColor;
- Out.BaseTexCoord = GetVertexTexCoord(vertexCorner);
-
- return Out;
- }
- VSOutput VS_NoBillboard(VSInput In)
- {
- VSOutput Out;
-
- // compute the z rotation matrix
- float zRotation = In.Angle_Size.x;
- float2x2 zRotationMatrix;
- zRotationMatrix[0][0] = cos(zRotation);
- zRotationMatrix[0][1] = -sin(zRotation);
- zRotationMatrix[1][1] = zRotationMatrix[0][0];
- zRotationMatrix[1][0] = -zRotationMatrix[0][1];
- // compute the vertex corners
- float Index = In.Position_Index.w;
- float2 vertexCorner = VertexCorners[Index];
- float2 relativeCornerPos = mul(vertexCorner, zRotationMatrix);
- float size = In.Angle_Size.y;
- float3 cornerPosition = float3( In.Position_Index.xy + ( size * relativeCornerPos ), In.Position_Index.z );
-
- Out.Position = mul(float4(cornerPosition, 1), GetViewProjection());
- Out.DiffuseColor = In.VertexColor;
- Out.BaseTexCoord = GetVertexTexCoord(vertexCorner);
-
- return Out;
- }
- // ----------------------------------------------------------------------------
- // Pixel Shader
- // ----------------------------------------------------------------------------
- float4 PS(VSOutput In) : COLOR
- {
- float4 color = In.DiffuseColor;
-
- // Apply texture
- float4 baseTexture = tex2D(SAMPLER(ParticleTexture), In.BaseTexCoord);
- baseTexture.xyz = GammaToLinear(baseTexture.xyz);
- color *= baseTexture;
- return color;
- }
- float4 PS_M(VSOutput In) : COLOR
- {
- float4 color = In.DiffuseColor;
-
- // Apply texture
- color *= tex2D(SAMPLER(ParticleTexture), In.BaseTexCoord);
- return color;
- }
- //--------------------------------------------------------------------------
- // No billboard techniques
- //--------------------------------------------------------------------------
- technique AdditiveSpriteShader
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_NoBillboard();
- PixelShader = compile PS_2_0 PS();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
-
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
-
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- technique AdditiveAlphaTestSpriteShader
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_NoBillboard();
- PixelShader = compile PS_2_0 PS();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
-
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
-
- AlphaTestEnable = true;
- AlphaFunc = GreaterEqual;
- AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
- }
- }
- //--------------------------------------------------------------------------
- technique AlphaSpriteShader
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_NoBillboard();
- PixelShader = compile PS_2_0 PS();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
-
- AlphaBlendEnable = true;
- SrcBlend = SrcAlpha;
- DestBlend = InvSrcAlpha;
-
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- technique ATestSpriteShader
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_NoBillboard();
- PixelShader = compile PS_2_0 PS();
-
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
-
- AlphaBlendEnable = false;
-
- AlphaTestEnable = true;
- AlphaFunc = GreaterEqual;
- AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
- }
- }
- //--------------------------------------------------------------------------
- technique MultiplicativeSpriteShader
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_NoBillboard();
- PixelShader = compile PS_2_0 PS();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
-
- AlphaBlendEnable = true;
- SrcBlend = DestColor;
- DestBlend = Zero;
-
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- technique Additive2DShader
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_NoBillboard();
- PixelShader = compile PS_2_0 PS();
- ZEnable = false;
- ZWriteEnable = false;
- CullMode = None;
-
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
-
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- technique Alpha2DShader
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_NoBillboard();
- PixelShader = compile PS_2_0 PS();
- ZEnable = false;
- ZWriteEnable = false;
- CullMode = None;
-
- AlphaBlendEnable = true;
- SrcBlend = SrcAlpha;
- DestBlend = InvSrcAlpha;
-
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- // Billboard techniques
- //--------------------------------------------------------------------------
- technique AdditiveSpriteShaderBillboard
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_Billboard();
- PixelShader = compile PS_2_0 PS();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
-
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
-
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- technique AdditiveAlphaTestSpriteShaderBillboard
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_Billboard();
- PixelShader = compile PS_2_0 PS();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
-
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
-
- AlphaTestEnable = true;
- AlphaFunc = GreaterEqual;
- AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
- }
- }
- //--------------------------------------------------------------------------
- technique AlphaSpriteShaderBillboard
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_Billboard();
- PixelShader = compile PS_2_0 PS();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
-
- AlphaBlendEnable = true;
- SrcBlend = SrcAlpha;
- DestBlend = InvSrcAlpha;
-
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- technique ATestSpriteShaderBillboard
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_Billboard();
- PixelShader = compile PS_2_0 PS();
-
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
-
- AlphaBlendEnable = false;
-
- AlphaTestEnable = true;
- AlphaFunc = GreaterEqual;
- AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
- }
- }
- //--------------------------------------------------------------------------
- technique MultiplicativeSpriteShaderBillboard
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_Billboard();
- PixelShader = compile PS_2_0 PS();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
-
- AlphaBlendEnable = true;
- SrcBlend = DestColor;
- DestBlend = Zero;
-
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- technique Additive2DShaderBillboard
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_Billboard();
- PixelShader = compile PS_2_0 PS();
- ZEnable = false;
- ZWriteEnable = false;
- CullMode = None;
-
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
-
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- technique Alpha2DShaderBillboard
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_Billboard();
- PixelShader = compile PS_2_0 PS();
- ZEnable = false;
- ZWriteEnable = false;
- CullMode = None;
-
- AlphaBlendEnable = true;
- SrcBlend = SrcAlpha;
- DestBlend = InvSrcAlpha;
-
- AlphaTestEnable = false;
- }
- }
- //
- // Medium LOD versions
- //
- //--------------------------------------------------------------------------
- // No billboard techniques
- //--------------------------------------------------------------------------
- technique AdditiveSpriteShader_M
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_NoBillboard();
- PixelShader = compile PS_2_0 PS_M();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- technique AdditiveAlphaTestSpriteShader_M
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_NoBillboard();
- PixelShader = compile PS_2_0 PS_M();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
- AlphaTestEnable = true;
- AlphaFunc = GreaterEqual;
- AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
- }
- }
- //--------------------------------------------------------------------------
- technique AlphaSpriteShader_M
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_NoBillboard();
- PixelShader = compile PS_2_0 PS_M();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = true;
- SrcBlend = SrcAlpha;
- DestBlend = InvSrcAlpha;
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- technique ATestSpriteShader_M
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_NoBillboard();
- PixelShader = compile PS_2_0 PS_M();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = false;
- AlphaTestEnable = true;
- AlphaFunc = GreaterEqual;
- AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
- }
- }
- //--------------------------------------------------------------------------
- technique MultiplicativeSpriteShader_M
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_NoBillboard();
- PixelShader = compile PS_2_0 PS_M();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = true;
- SrcBlend = DestColor;
- DestBlend = Zero;
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- technique Additive2DShader_M
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_NoBillboard();
- PixelShader = compile PS_2_0 PS_M();
- ZEnable = false;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- technique Alpha2DShader_M
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_NoBillboard();
- PixelShader = compile PS_2_0 PS_M();
- ZEnable = false;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = true;
- SrcBlend = SrcAlpha;
- DestBlend = InvSrcAlpha;
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- // Billboard techniques
- //--------------------------------------------------------------------------
- technique AdditiveSpriteShaderBillboard_M
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_Billboard();
- PixelShader = compile PS_2_0 PS_M();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- technique AdditiveAlphaTestSpriteShaderBillboard_M
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_Billboard();
- PixelShader = compile PS_2_0 PS_M();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
- AlphaTestEnable = true;
- AlphaFunc = GreaterEqual;
- AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
- }
- }
- //--------------------------------------------------------------------------
- technique AlphaSpriteShaderBillboard_M
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_Billboard();
- PixelShader = compile PS_2_0 PS_M();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = true;
- SrcBlend = SrcAlpha;
- DestBlend = InvSrcAlpha;
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- technique ATestSpriteShaderBillboard_M
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_Billboard();
- PixelShader = compile PS_2_0 PS_M();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = false;
- AlphaTestEnable = true;
- AlphaFunc = GreaterEqual;
- AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
- }
- }
- //--------------------------------------------------------------------------
- technique MultiplicativeSpriteShaderBillboard_M
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_Billboard();
- PixelShader = compile PS_2_0 PS_M();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = true;
- SrcBlend = DestColor;
- DestBlend = Zero;
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- technique Additive2DShaderBillboard_M
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_Billboard();
- PixelShader = compile PS_2_0 PS_M();
- ZEnable = false;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
- AlphaTestEnable = false;
- }
- }
- //--------------------------------------------------------------------------
- technique Alpha2DShaderBillboard_M
- {
- pass P0
- {
- VertexShader = compile VS_2_0 VS_Billboard();
- PixelShader = compile PS_2_0 PS_M();
- ZEnable = false;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = true;
- SrcBlend = SrcAlpha;
- DestBlend = InvSrcAlpha;
- AlphaTestEnable = false;
- }
- }
|