| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674 |
- //////////////////////////////////////////////////////////////////////////////
- // 2008 Electronic Arts Inc
- //
- // GPU vertex particle FX Shader with 2 pass distortion
- //////////////////////////////////////////////////////////////////////////////
- #define SUPPORT_FOG 1
- #include "Common.fxh"
- #include "Gamma.fxh"
- #include "CommonParticle.fxh"
- //
- // draw params
- //
- SAMPLER_2D_BEGIN( ParticleTextureSampler,
- string UIWidget = "None";
- string SasBindAddress = "Particle.Draw.Texture";
- )
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Clamp;
- AddressV = Clamp;
- SAMPLER_2D_END
- // $Note(WSK) - We shouldn't need to use a different sampler, and it actually doesn't work on ps3
- // We should be able to do the same for pc and xenon but since they are close to final,
- // we want to be safe and make this change for ps3 only
- #if defined(EA_PLATFORM_PS3)
- static const sampler2D NextFrameTextureSamplerSampler = ParticleTextureSamplerSampler;
- #else // #if defined(EA_PLATFORM_PS3)
- SAMPLER_2D_BEGIN( NextFrameTextureSampler,
- string UIWidget = "None";
- string SasBindAddress = "Particle.Draw.Texture";
- )
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Clamp;
- AddressV = Clamp;
- SAMPLER_2D_END
- #endif // #if defined(EA_PLATFORM_PS3)
- SAMPLER_2D_BEGIN( DetailTextureSampler,
- string UIWidget = "None";
- string SasBindAddress = "Particle.Draw.DetailTexture";
- )
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Wrap;
- AddressV = Wrap;
- SAMPLER_2D_END
- // Used to see where the particle volume intersects an object.
- SAMPLER_2D_BEGIN( DepthTexture,
- string SasBindAddress = "WW3D.DepthTexture";
- )
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Point;
- AddressU = Clamp;
- AddressV = Clamp;
- SAMPLER_2D_END
- float4 ParticleMiscValues
- <
- string UIWidget = "None";
- string SasBindAddress = "Particle.Draw.MiscValues";
- > = float4(1.0,1.0,1.0,1.0);
-
- //--------------------------------- GENERAL STUFF --------------------------------------
- bool ShouldDrawParticleSoft
- <
- string UIWidget = "None";
- string SasBindAddress = "Particle.Draw.ShouldDrawParticleSoft";
- > = false;
- // 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;
- // Transformations
- float4x4 WorldView : WorldView;
- float4x4 Projection: Projection;
- float4x4 WorldViewProjection : WorldViewProjection;
- float4x3 View : View;
- float4x4 ProjectionI : ProjectionInverse;
- #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_)
- // Time (ie. material is animated)
- float Time : Time;
- // ----------------------------------------------------------------------------
- // SHADER: HIGH ~ ULTRAHIGH
- // ----------------------------------------------------------------------------
- struct ParticleVSOutput_H
- {
- float4 Position : POSITION;
- float2 ParticleTexCoord : TEXCOORD0;
- float4 Color : COLOR0;
- float3 Fog : TEXCOORD1; // This is just a scalar, but PS1.1 can't replicate-swizzle, so replicate scalar into a vector in vertex shader
- float Depth : TEXCOORD2; // For _CreateShadowMap technique
- float3 NextFrameTexCoord : TEXCOORD3; // for interpolating between two frames
- float4 NDCPosition : TEXCOORD4;
- float2 ZPositions : TEXCOORD5; // x is the particle z position, y is the ViewEyeDirection z component.
- float4 DisplaceTexCoord : TEXCOORD6;
- };
- // Making this value smaller will increase the size of the transparent edge where
- // the particle intersects the background.
- #define PARTICLE_VOLUME_SCALE 5
- // For indexing the shader array based on what type of blend is needed for the particle draw type.
- #define SOFTBLEND_ADDITIVE 0
- #define SOFTBLEND_ALPHA 1
- #define SOFTBLEND_DISABLED 2
- // ----------------------------------------------------------------------------
- ParticleVSOutput_H ParticleVertexShader_H(
- float4 StartPositionLifeInFrames : POSITION,
- float4 StartVelocityCreationFrame : TEXCOORD0,
- float2 SeedAndIndex : TEXCOORD1,
- uniform int fogMode)
- {
- ParticleVSOutput_H Out;
- // decode vertex data
- float3 StartPosition = StartPositionLifeInFrames.xyz;
- float LifeInFrames = StartPositionLifeInFrames.w;
- float3 StartVelocity = StartVelocityCreationFrame.xyz;
- float CreationFrame = StartVelocityCreationFrame.w;
- float Seed = SeedAndIndex.x;
- float Index = SeedAndIndex.y;
- // particle system works with frames, so first convert time to frame
- // rather than converting everything else to time
- float age = (Time * CLIENT_FRAMES_PER_SECOND - CreationFrame);
-
- // first eliminate dead particles
- if (age > LifeInFrames)
- Index = 0;
- float relativeAge = age / LifeInFrames;
-
- float3 particlePosition;
- float size;
- float2x2 zRotationMatrix;
-
- Particle_ComputePhysics(particlePosition, size, zRotationMatrix,
- age, StartPosition, StartVelocity, Seed);
- // Calculate vertex position
- float2 vertexCorner = VertexCorners[Index];
- float2 relativeCornerPos = mul(vertexCorner, zRotationMatrix);
- 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 = particlePosition + size * (relativeCornerPos.x * xVector + relativeCornerPos.y * zVector);
-
- // Convert the particle position into view space so that we can get the distance
- // between the particle and the background.
- float particleSize = size / PARTICLE_VOLUME_SCALE;
- float4 particlePosView = mul(float4(cornerPosition, 1), WorldView);
- Out.ZPositions.x = particlePosView.z / particleSize;
-
- // Finish projecting the position.
- float4 ndcPos = mul(particlePosView, Projection);
- Out.Position = ndcPos;
- Out.NDCPosition = ndcPos;
- Out.Depth = Out.Position.z / Out.Position.w;
- // Convert the position into a view vector to the far plane.
- float4 screenFarPlanePosition = float4(ndcPos.xy, 1, 1);
- float4 viewFarPlanePosition4 = mul(screenFarPlanePosition, ProjectionI);
- float3 viewFarPlanePosition = viewFarPlanePosition4.xyz / viewFarPlanePosition4.w;
-
- // We don't really want a vector to the far plane. We want the vector with a z length of 1,
- // so that we know how much in x-y we need to step per z-depth that we get from the depth texture.
- Out.ZPositions.y = (viewFarPlanePosition.z / viewFarPlanePosition.z) / particleSize;
-
- if (fogMode != FogMode_Disabled)
- {
- // Fog depends on world position, but world matrix should be identity.
- Out.Fog = CalculateFog(Fog, cornerPosition, GetEyePosition()).xxx;
- }
- else
- {
- Out.Fog = 0;
- }
- Particle_ComputeVideoTexture(age, Seed, vertexCorner, GetVertexTexCoord(vertexCorner), Out.ParticleTexCoord, Out.NextFrameTexCoord);
-
- // compute color
- Out.Color = Particle_ComputeColor(relativeAge, Seed, true);
-
- // Build Displace Texture Rotation Matrix And Convert Degrees to Radians -----
- float DisplaceScalar = ParticleMiscValues.x;
- float DisplaceSpeed = ParticleMiscValues.y * Time;
- float DisplaceDivergenceAngle = ParticleMiscValues.z;
- // float DisplaceScalar = .1;
- // float DisplaceSpeed = .07 * Time;
- // float DisplaceDivergenceAngle = 45;
-
- float cosAngle, sinAngle;
- cosAngle = 0;
- sinAngle = 0;
- float2x2 uvCoordRotate = { 1.0f, 0.0f, 1.0f, 0.0f };
-
- sincos (DisplaceDivergenceAngle * .017453, sinAngle, cosAngle);
-
- uvCoordRotate[0][0] = cosAngle;
- uvCoordRotate[0][1] = -sinAngle;
- uvCoordRotate[1][1] = uvCoordRotate[0][0];
- uvCoordRotate[1][0] = -uvCoordRotate[0][1];
-
- // Rotate and Animate Displace Divergence Texture Coords --------------------
- float2 texCoord = GetVertexTexCoord(vertexCorner);
- float2 DisplaceTexCoords = texCoord * DisplaceScalar + Seed;
- float2 DisplaceTexCoordsDiverge = mul(DisplaceTexCoords, uvCoordRotate);
- DisplaceTexCoordsDiverge.x += DisplaceSpeed;
- float2 DisplaceTexCoordsDivergeInv = mul(DisplaceTexCoords, transpose(uvCoordRotate));
- DisplaceTexCoordsDivergeInv.x += DisplaceSpeed;
-
- Out.DisplaceTexCoord = float4(DisplaceTexCoordsDiverge, DisplaceTexCoordsDivergeInv);
- return Out;
- }
- // ----------------------------------------------------------------------------
- float4 SoftParticlePixelShader(ParticleVSOutput_H In, uniform int fogMode, uniform int blendMode) COLORTARGET
- {
- float3 ndcPosition = In.NDCPosition.xyz / In.NDCPosition.w;
- //Grab the detail texture and displace primary texture coords according to normal
- float4 DetailColor = tex2D( SAMPLER(DetailTextureSampler), In.DisplaceTexCoord.xy) * 2 -1;
- DetailColor += tex2D( SAMPLER(DetailTextureSampler), In.DisplaceTexCoord.zw) * 2 - 1;
-
- DetailColor *= ParticleMiscValues.w;
-
- // Convert the position into texture space then grab the depth value from the
- // depth texture. Then, move along that vector by the depth to find the pixel position.
- float2 depthTexCoord = ndcPosition.xy * float2(0.5, -0.5) + 0.5;
- float backgroundDepth = tex2D(SAMPLER(DepthTexture), depthTexCoord).x;
- float backgroundPosView = backgroundDepth * In.ZPositions.y;
- // The closer the particle is to the background, the more transparent it is.
- float linearBlend = saturate(In.ZPositions.x - backgroundPosView);
- // do interpolation between two frames (for particles with video textures)
- float4 TextureColor = tex2D( SAMPLER(ParticleTextureSampler), In.ParticleTexCoord + DetailColor);
- float4 NextFrameColor = tex2D( SAMPLER(NextFrameTextureSampler), In.NextFrameTexCoord.xy + DetailColor);
- float4 Color = lerp(TextureColor, NextFrameColor, In.NextFrameTexCoord.z) * In.Color;
- Color.xyz = GammaToLinear(Color.xyz);
- // Modify the color (or alpha) of a the particle depending on how it's being drawn
- // so the particle has a soft edge to it.
- if (blendMode == SOFTBLEND_ALPHA)
- {
- Color.w *= linearBlend;
- }
- else if (blendMode == SOFTBLEND_ADDITIVE)
- {
- Color.xyz *= linearBlend;
- }
-
- // Apply fog
- float3 fogStrength = saturate(In.Fog) ;
- if (fogMode == FogMode_Opaque)
- {
- // apply fog
- Color.xyz = lerp(Fog.Color, Color.xyz, fogStrength);
- }
- else if (fogMode == FogMode_Additive)
- {
- // Fog used with additive blending just needs to reduce the additive influence, not blend towards the fog color
- Color.xyz *= fogStrength;
- }
- return Color;
- }
- // ----------------------------------------------------------------------------
- // SHADER: XENON
- // ----------------------------------------------------------------------------
- float4 ParticlePixelShader_Xenon(ParticleVSOutput_H In ) : COLOR
- {
- return SoftParticlePixelShader( In,
- Fog.IsEnabled ? ((Draw.ShaderType == ShaderType_Additive || Draw.ShaderType == ShaderType_AdditiveAlphaTest || Draw.ShaderType == ShaderType_Multiply) ? FogMode_Additive : FogMode_Opaque) : FogMode_Disabled,
- !ShouldDrawParticleSoft ? SOFTBLEND_DISABLED : ((Draw.ShaderType == ShaderType_Alpha) ? SOFTBLEND_ALPHA : SOFTBLEND_ADDITIVE));
- }
- // ----------------------------------------------------------------------------
- // TECHNIQUE: HIGH ~ ULTRAHIGH (And XENON)
- // ----------------------------------------------------------------------------
- DEFINE_ARRAY_MULTIPLIER( PS_Multiplier_FogMode = 1 );
- #define PS_FogMode_H(drawType) \
- compile PS_3_0 SoftParticlePixelShader(FogMode_Disabled, drawType), \
- compile PS_3_0 SoftParticlePixelShader(FogMode_Opaque, drawType), \
- compile PS_3_0 SoftParticlePixelShader(FogMode_Additive, drawType)
- DEFINE_ARRAY_MULTIPLIER( PS_Multiplier_ShaderType = PS_Multiplier_FogMode * 3 );
- #define PS_ShaderType_H \
- PS_FogMode_H(SOFTBLEND_ADDITIVE), \
- PS_FogMode_H(SOFTBLEND_ALPHA), \
- PS_FogMode_H(SOFTBLEND_DISABLED)
-
- DEFINE_ARRAY_MULTIPLIER( PS_Multiplier_Final_H = PS_Multiplier_ShaderType * 3 );
- #if SUPPORTS_SHADER_ARRAYS
- pixelshader PS_Array_H[PS_Multiplier_Final_H] =
- {
- PS_ShaderType_H
- };
- #endif
- technique Default
- {
- pass P0
- <
- USE_EXPRESSION_EVALUATOR("Particle")
- >
- {
- VertexShader = compile VS_3_0 ParticleVertexShader_H(FogMode_Opaque);
- PixelShader = ARRAY_EXPRESSION_PS( PS_Array_H, (!ShouldDrawParticleSoft ? SOFTBLEND_DISABLED : ((Draw.ShaderType == ShaderType_Alpha) ? SOFTBLEND_ALPHA : SOFTBLEND_ADDITIVE)) * PS_Multiplier_ShaderType
- + (Fog.IsEnabled ? ((Draw.ShaderType == ShaderType_Additive || Draw.ShaderType == ShaderType_AdditiveAlphaTest || Draw.ShaderType == ShaderType_Multiply) ? FogMode_Additive : FogMode_Opaque) : FogMode_Disabled),
- compile PS_VERSION ParticlePixelShader_Xenon()
- );
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
-
- SETUP_ALPHA_BLEND_AND_TEST(Draw.ShaderType);
- }
- }
- // ----------------------------------------------------------------------------
- // SHADER: MEDIUM
- // ----------------------------------------------------------------------------
- struct ParticleVSOutput_M
- {
- float4 Position : POSITION;
- float2 ParticleTexCoord : TEXCOORD0;
- float4 Color : COLOR0;
- float3 Fog : TEXCOORD1; // This is just a scalar, but PS1.1 can't replicate-swizzle, so replicate scalar into a vector in vertex shader
- float Depth : TEXCOORD2; // For _CreateShadowMap technique
- float3 NextFrameTexCoord : TEXCOORD3; // for interpolating between two frames
- };
- // ----------------------------------------------------------------------------
- ParticleVSOutput_M ParticleVertexShader_M(float4 StartPositionLifeInFrames : POSITION,
- float4 StartVelocityCreationFrame : TEXCOORD0, float2 SeedAndIndex : TEXCOORD1,
- uniform int fogMode)
- {
- ParticleVSOutput_M Out;
- // decode vertex data
- float3 StartPosition = StartPositionLifeInFrames.xyz;
- float LifeInFrames = StartPositionLifeInFrames.w;
- float3 StartVelocity = StartVelocityCreationFrame.xyz;
- float CreationFrame = StartVelocityCreationFrame.w;
- float Seed = SeedAndIndex.x;
- float Index = SeedAndIndex.y;
- // particle system works with frames, so first convert time to frame
- // rather than converting everything else to time
- float age = (Time * CLIENT_FRAMES_PER_SECOND - CreationFrame);
-
- // first eliminate dead particles
- if (age > LifeInFrames)
- Index = 0;
- float relativeAge = age / LifeInFrames;
-
- float3 particlePosition;
- float size;
- float2x2 zRotationMatrix;
-
- Particle_ComputePhysics(particlePosition, size, zRotationMatrix,
- age, StartPosition, StartVelocity, Seed);
- // Calculate vertex position
- float2 vertexCorner = VertexCorners[Index];
- float2 relativeCornerPos = mul(vertexCorner, zRotationMatrix);
- 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 = particlePosition + size * (relativeCornerPos.x * xVector + relativeCornerPos.y * zVector);
-
- Out.Position = mul(float4(cornerPosition, 1), WorldViewProjection);
- Out.Depth = Out.Position.z / Out.Position.w;
- if (fogMode != FogMode_Disabled)
- {
- // Fog depends on world position, but world matrix should be identity.
- Out.Fog = CalculateFog(Fog, cornerPosition, GetEyePosition()).xxx;
- }
- else
- {
- Out.Fog = 0;
- }
- Particle_ComputeVideoTexture(age, Seed, vertexCorner, GetVertexTexCoord(vertexCorner), Out.ParticleTexCoord, Out.NextFrameTexCoord);
-
- // compute color
- Out.Color = Particle_ComputeColor(relativeAge, Seed, true);
- return Out;
- }
- // ----------------------------------------------------------------------------
- float4 ParticlePixelShader(ParticleVSOutput_M In, uniform int fogMode) : COLOR
- {
- float4 TextureColor = tex2D( SAMPLER(ParticleTextureSampler), In.ParticleTexCoord);
- float4 NextFrameColor = tex2D( SAMPLER(NextFrameTextureSampler), In.NextFrameTexCoord.xy);
- // do interpolation between two frames (for particles with video textures)
- float4 Color = lerp(TextureColor, NextFrameColor, In.NextFrameTexCoord.z) * In.Color;
- // Apply fog
- float3 fogStrength = saturate(In.Fog) ;
- if (fogMode == FogMode_Opaque)
- {
- // apply fog
- Color.xyz = lerp(Fog.Color, Color.xyz, fogStrength);
- }
- else if (fogMode == FogMode_Additive)
- {
- // Fog used with additive blending just needs to reduce the additive influence, not blend towards the fog color
- Color.xyz *= fogStrength;
- }
- return Color;
- }
- // Having this ensures that xenon doesn't load techniques that it doesn't use.
- // This has to be below the medium functions because that is used for the shadowmap.
- #if ENABLE_LOD
- // ----------------------------------------------------------------------------
- // TECHNIQUE: MEDIUM
- // ----------------------------------------------------------------------------
- #define PS_ShaderType_M \
- compile PS_2_0 ParticlePixelShader(FogMode_Disabled), \
- compile PS_2_0 ParticlePixelShader(FogMode_Opaque), \
- compile PS_2_0 ParticlePixelShader(FogMode_Additive)
- DEFINE_ARRAY_MULTIPLIER( PS_Multiplier_Final_M = 3 );
- #if SUPPORTS_SHADER_ARRAYS
- pixelshader PS_Array_M[PS_Multiplier_Final_M] =
- {
- PS_ShaderType_M
- };
- #endif
- technique Default_M
- {
- pass P0
- <
- USE_EXPRESSION_EVALUATOR("Particle")
- >
- {
- VertexShader = compile VS_2_0 ParticleVertexShader_M(FogMode_Opaque);
- PixelShader = ARRAY_EXPRESSION_PS( PS_Array_M,
- Fog.IsEnabled ? ((Draw.ShaderType == ShaderType_Additive || Draw.ShaderType == ShaderType_AdditiveAlphaTest || Draw.ShaderType == ShaderType_Multiply) ? FogMode_Additive : FogMode_Opaque) : FogMode_Disabled,
- compile PS_VERSION ParticlePixelShader_Xenon()
- );
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
-
- SETUP_ALPHA_BLEND_AND_TEST(Draw.ShaderType);
- }
- }
- // ----------------------------------------------------------------------------
- // SHADER: LowQuality
- // ----------------------------------------------------------------------------
- struct ParticleVSLowOutput
- {
- float4 Position : POSITION;
- float2 ParticleTexCoord : TEXCOORD0;
- float4 Color : COLOR0;
- };
- // ----------------------------------------------------------------------------
- ParticleVSLowOutput ParticleVertexShaderLow(float4 StartPositionLifeInFrames : POSITION,
- float4 StartVelocityCreationFrame : TEXCOORD0, float2 SeedAndIndex : TEXCOORD1)
- {
- ParticleVSLowOutput Out;
- // decode vertex data
- float3 StartPosition = StartPositionLifeInFrames.xyz;
- float LifeInFrames = StartPositionLifeInFrames.w;
- float3 StartVelocity = StartVelocityCreationFrame.xyz;
- float CreationFrame = StartVelocityCreationFrame.w;
- float Seed = SeedAndIndex.x;
- float Index = SeedAndIndex.y;
- // particle system works with frames, so first convert time to frame
- // rather than converting everything else to time
- float age = (Time * CLIENT_FRAMES_PER_SECOND - CreationFrame);
-
- // first eliminate dead particles
- if (age > LifeInFrames)
- Index = 0;
- float relativeAge = age / LifeInFrames;
- float3 particlePosition;
- float size;
- float2x2 zRotationMatrix;
-
- Particle_ComputePhysics_Simplified(particlePosition, size, zRotationMatrix,
- age, StartPosition, StartVelocity, Seed);
- // Calculate vertex position
- float2 vertexCorner = VertexCorners[Index];
- float2 relativeCornerPos = mul(vertexCorner, zRotationMatrix);
- 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 = particlePosition + size * (relativeCornerPos.x * xVector + relativeCornerPos.y * zVector);
- Out.Position = mul(float4(cornerPosition, 1), WorldViewProjection);
- // texture coordinate
- Particle_ComputeVideoTextureNoNextFrame(age, Seed, GetVertexTexCoord(vertexCorner), Out.ParticleTexCoord);
- // compute color
- Out.Color = Particle_ComputeColor(relativeAge, Seed, false);
-
- return Out;
- }
- // ----------------------------------------------------------------------------
- float4 ParticlePixelShaderLow(ParticleVSLowOutput In) : COLOR
- {
- float4 TextureColor = tex2D( SAMPLER(ParticleTextureSampler), In.ParticleTexCoord);
- float4 Color = TextureColor * In.Color;
- return Color;
- }
- // ----------------------------------------------------------------------------
- // TECHNIQUE: LowQuality
- // ----------------------------------------------------------------------------
- technique Default_L
- {
- pass P0
- <
- USE_EXPRESSION_EVALUATOR("Particle")
- >
- {
- VertexShader = compile VS_2_0 ParticleVertexShaderLow();
- PixelShader = compile PS_2_0 ParticlePixelShaderLow();
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = None;
-
- SETUP_ALPHA_BLEND_AND_TEST(Draw.ShaderType);
- }
- }
- #endif // #if ENABLE_LOD
- // ----------------------------------------------------------------------------
- // SHADER: CreateShadowMap
- // ----------------------------------------------------------------------------
- float4 CreateShadowMapPS(ParticleVSOutput_M In, uniform int shaderType) COLORTARGET
- {
- float4 textureColor = tex2D( SAMPLER(ParticleTextureSampler), In.ParticleTexCoord);
- float4 color = textureColor * In.Color;
- // Threshold where "alpha testing" or color equivalents set pixel to be opaque.
- // Needs to be much lower than common alpha test threshold as a single particle is usually quite transparent.
- const float opacityThreshold = 0.1;
-
- if (shaderType == ShaderType_Additive)
- {
- // The brighter the color the denser the particle. Clip dark areas.
- clip(dot(color, float3(1, 1, 1)) - 3 * opacityThreshold);
- }
- else if (shaderType == ShaderType_Multiply)
- {
- // The darker the color the denser the particle. Clip bright areas.
- clip(3 * opacityThreshold - dot(color, float3(1, 1, 1)));
- }
- else if (shaderType == ShaderType_AdditiveAlphaTest || shaderType == ShaderType_Alpha
- || shaderType == ShaderType_AlphaTest)
- {
- // Simulate alpha testing
- clip(color.a - opacityThreshold);
- }
- return In.Depth;
- }
- // ----------------------------------------------------------------------------
- float4 CreateShadowMapPS_Xenon( ParticleVSOutput_M In ) : COLOR
- {
- return CreateShadowMapPS( In, min(Draw.ShaderType, ShaderType_Multiply) );
- }
- // ----------------------------------------------------------------------------
- // TECHNIQUE: CreateShadowMap
- // ----------------------------------------------------------------------------
- #define PSCreateShadowMap_ShaderType \
- compile PS_2_0 CreateShadowMapPS(0), \
- compile PS_2_0 CreateShadowMapPS(ShaderType_Additive), \
- compile PS_2_0 CreateShadowMapPS(ShaderType_AdditiveAlphaTest), \
- compile PS_2_0 CreateShadowMapPS(ShaderType_Alpha), \
- compile PS_2_0 CreateShadowMapPS(ShaderType_AlphaTest), \
- compile PS_2_0 CreateShadowMapPS(ShaderType_Multiply)
- DEFINE_ARRAY_MULTIPLIER( PSCreateShadowMap_Multiplier_Final = 6 );
- #if SUPPORTS_SHADER_ARRAYS
- pixelshader PSCreateShadowMap_Array[PSCreateShadowMap_Multiplier_Final] =
- {
- PSCreateShadowMap_ShaderType
- };
- #endif
- // ----------------------------------------------------------------------------
- technique _CreateShadowMap
- {
- pass P0
- <
- USE_EXPRESSION_EVALUATOR("GPUParticle_CreateShadowMap")
- >
- {
- VertexShader = compile VS_2_0 ParticleVertexShader_M(FogMode_Disabled);
- PixelShader = ARRAY_EXPRESSION_PS( PSCreateShadowMap_Array,
- min(Draw.ShaderType, ShaderType_Multiply),
- compile PS_VERSION CreateShadowMapPS_Xenon()
- );
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = true;
- CullMode = None;
- AlphaBlendEnable = false;
- AlphaTestEnable = false; // Handled in pixel shader
- }
- }
|