GPUParticleOceanDisplacement.fx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //////////////////////////////////////////////////////////////////////////////
  2. // ©2005 Electronic Arts Inc
  3. //
  4. // GPU vertex particle FX Shader
  5. //////////////////////////////////////////////////////////////////////////////
  6. #include "Common.fxh"
  7. #include "CommonParticle.fxh"
  8. int _SasGlobal : SasGlobal
  9. <
  10. string UIWidget = "None";
  11. int3 SasVersion = int3(1, 0, 0);
  12. string RenderBin = "OceanDisplacement";
  13. > = 0;
  14. SAMPLER_2D_BEGIN( NormalTexture,
  15. string UIWidget = "None";
  16. string SasBindAddress = "Particle.Draw.Texture";
  17. )
  18. MinFilter = Linear;
  19. MagFilter = Linear;
  20. MipFilter = Linear;
  21. AddressU = Wrap;
  22. AddressV = Wrap;
  23. SAMPLER_2D_END
  24. float4 ParticleMiscValues
  25. <
  26. string UIWidget = "None";
  27. string SasBindAddress = "Particle.Draw.MiscValues";
  28. > = float4(1.0,1.0,1.0,1.0);
  29. //--------------------------------- GENERAL STUFF --------------------------------------
  30. // Transformations
  31. float4x4 WorldViewProjection : WorldViewProjection;
  32. // Time (ie. material is animated)
  33. float Time : Time;
  34. // ----------------------------------------------------------------------------
  35. // SHADER: Default
  36. // ----------------------------------------------------------------------------
  37. struct ParticleVSOutput
  38. {
  39. float4 Position : POSITION;
  40. float2 ParticleTexCoord : TEXCOORD0;
  41. float4 Color : TEXCOORD1; // Not in color register to have increased range from -1 to 1
  42. };
  43. // ----------------------------------------------------------------------------
  44. ParticleVSOutput ParticleVertexShader(
  45. float4 StartPositionLifeInFrames : POSITION,
  46. float4 StartVelocityCreationFrame : TEXCOORD0,
  47. float2 SeedAndIndex : TEXCOORD1)
  48. {
  49. ParticleVSOutput Out;
  50. // decode vertex data
  51. float3 StartPosition = StartPositionLifeInFrames.xyz;
  52. float LifeInFrames = StartPositionLifeInFrames.w;
  53. float3 StartVelocity = StartVelocityCreationFrame.xyz;
  54. float CreationFrame = StartVelocityCreationFrame.w;
  55. float Seed = SeedAndIndex.x;
  56. float Index = SeedAndIndex.y;
  57. // particle system works with frames, so first convert time to frame
  58. // rather than converting everything else to time
  59. float age = (Time * CLIENT_FRAMES_PER_SECOND - CreationFrame);
  60. // first eliminate dead particles
  61. if (age > LifeInFrames)
  62. {
  63. Index = 0;
  64. }
  65. float relativeAge = age / LifeInFrames;
  66. // Calculate the z rotation, before position and other values
  67. float dummy1;
  68. float3 dummy3;
  69. float2x2 zRotationMatrix;
  70. Particle_ComputePhysics(dummy3, dummy1, zRotationMatrix,
  71. age, StartPosition, StartVelocity, Seed);
  72. // Rotatate StartVelocity by z rotation
  73. StartVelocity.xy = mul(StartVelocity.xy, zRotationMatrix);
  74. // Now calculate position based on rotated velocity
  75. float3 particlePosition;
  76. float size;
  77. float2x2 dummy2x2;
  78. float aspectRatio = ParticleMiscValues.x;
  79. Particle_ComputePhysics(particlePosition, size, dummy2x2,
  80. age, StartPosition, StartVelocity, Seed);
  81. // Calculate vertex position
  82. float2 vertexCorner = VertexCorners[Index];
  83. float2 velocityDir = normalize(StartVelocity.xy); // TODO: Take current velocity, not start velocity into account
  84. float2 xVector = float2(-velocityDir.y, velocityDir.x); // orthogonal to velocityDir
  85. float2 yVector = velocityDir;
  86. float2 cornerPosition = particlePosition + size * (vertexCorner.x * xVector * aspectRatio + vertexCorner.y * yVector);
  87. Out.Position = mul(float4(cornerPosition, 0, 1), WorldViewProjection);
  88. // Texture coordinate
  89. float randomIndex = GetRandomFloatValue(float2(0.0f, 1.0f), Seed, 7) * Draw.VideoTex_NumPerRow_LastFrame_SingleRow_isRand.y;
  90. randomIndex -= frac(randomIndex);
  91. float currentTexFrame = age * Draw.SpeedMultiplier + randomIndex;
  92. float2 texCoord = GetVertexTexCoord(vertexCorner);
  93. Out.ParticleTexCoord = Particle_ComputeVideoTextureDefault(currentTexFrame, texCoord);
  94. // compute color
  95. float4 color = Particle_ComputeColor(relativeAge, Seed, true);
  96. Out.Color = color;
  97. return Out;
  98. }
  99. // ----------------------------------------------------------------------------
  100. float4 ParticlePixelShader(ParticleVSOutput In) : COLOR
  101. {
  102. float2 texCoord0 = In.ParticleTexCoord;
  103. float4 displacementSample = tex2D( SAMPLER( NormalTexture ), texCoord0);
  104. float amplitude = In.Color.w;
  105. #if defined(EA_PLATFORM_XENON) // scale range on xenon
  106. return float4(amplitude * 0.5, amplitude * 0.5, amplitude, 0) * displacementSample * 0.6; // want less static waves for now
  107. #else
  108. return float4(amplitude, amplitude, amplitude, 0) * displacementSample;
  109. #endif
  110. }
  111. // ----------------------------------------------------------------------------
  112. // TECHNIQUE: Default (Medium and up)
  113. // ----------------------------------------------------------------------------
  114. technique Default_M
  115. {
  116. pass P0
  117. {
  118. VertexShader = compile VS_3_0 ParticleVertexShader();
  119. PixelShader = compile PS_3_0 ParticlePixelShader();
  120. ZEnable = false;
  121. ZWriteEnable = false;
  122. CullMode = None;
  123. AlphaBlendEnable = true;
  124. SrcBlend = One;
  125. DestBlend = One;
  126. AlphaTestEnable = false;
  127. }
  128. }
  129. // ----------------------------------------------------------------------------
  130. // TECHNIQUE: LowQuality
  131. // ----------------------------------------------------------------------------
  132. technique Default_L
  133. {
  134. // Disabled
  135. }