6 using System.Runtime.InteropServices;
7 using System.Threading.Tasks;
9 using SiliconStudio.Paradox;
10 using SiliconStudio.Paradox.Effects;
11 using SiliconStudio.Paradox.Effects.Modules;
12 using SiliconStudio.Paradox.Engine;
13 using SiliconStudio.Paradox.EntityModel;
14 using SiliconStudio.Core.Extensions;
15 using SiliconStudio.Paradox.Graphics;
16 using SiliconStudio.Paradox.Graphics.Data;
17 using SiliconStudio.Paradox.Games.Mathematics;
20 using ScriptShader.Effects;
43 internal static readonly
ParameterKey<Buffer> VerticesEmitterKey = ParticleUpdaterBulletKeys.VerticesEmitter;
56 [StructLayout(LayoutKind.Explicit, Size = 36, Pack = 4)]
88 public static void Run(EngineContext engineContext)
91 if (!engineContext.DataContext.RenderPassPlugins.TryGetValueCast(
"ParticlePlugin", out particlePlugin))
111 var emitterPositions =
new[]
113 new Vector3(-2047.287f, -613.5108f, -400.0f),
114 new Vector3(-1881.002f, -564.9566f, -400.0f),
115 new Vector3(-1627.844f, -449.1949f, -400.0f),
116 new Vector3(-1391.335f, -423.1865f, -400.0f),
117 new Vector3(-1314.865f, -482.0599f, -400.0f),
118 new Vector3(-1019.54f, -932.4803f, -400.0f),
119 new Vector3(-957.3735f, -988.7004f, -400.0f),
120 new Vector3(-759.9126f, -1168.646f, -400.0f),
121 new Vector3(-529.1716f, -1083.003f, -400.0f),
122 new Vector3(-198.7756f, -1029.24f, -400.0f),
123 new Vector3(309.9702f, -832.7861f, -400.0f),
124 new Vector3(876.9819f, -667.9489f, -400.0f),
125 new Vector3(1908.686f, -1085.583f, -400.0f),
126 new Vector3(2308.45f, -995.1572f, -400.0f),
127 new Vector3(2864.581f, -906.4545f, -400.0f),
128 new Vector3(3770.119f, -832.0695f, -400.0f),
129 new Vector3(4561.941f, -728.9376f, -400.0f),
130 new Vector3(5429.49f, -722.3638f, -400.0f),
131 new Vector3(6447.015f, -310.0454f, -400.0f),
132 new Vector3(6420.864f, 532.3475f, -400.0f),
133 new Vector3(6157.83f, 658.0294f, -400.0f),
134 new Vector3(4732.579f, 955.4061f, -400.0f),
135 new Vector3(1630.28f, 1551.338f, -400.0f),
136 new Vector3(931.7393f, 1274.533f, -400.0f),
137 new Vector3(1586.493f, 1505.558f, -400.0f),
138 new Vector3(906.572f, 1268.478f, -400.0f),
139 new Vector3(390.1973f, 1314.976f, -400.0f),
140 new Vector3(-30.39231f, 1553.894f, -400.0f),
141 new Vector3(-356.4023f, 1605.162f, -400.0f),
142 new Vector3(-1055.699f, 971.7286f, -400.0f),
143 new Vector3(-1218.041f, 727.1427f, -400.0f),
144 new Vector3(-1377.148f, 606.9602f, -400.0f),
145 new Vector3(-1676.512f, 640.7913f, -400.0f),
146 new Vector3(-2089.593f, 833.8343f, -400.0f),
147 new Vector3(-2290.1f, 992.6068f, -400.0f),
148 new Vector3(-2196.059f, 764.4152f, -400.0f),
149 new Vector3(-1448.233f, 391.5037f, -400.0f),
150 new Vector3(-1337.535f, 223.827f, -400.0f),
151 new Vector3(-1287.335f, -125.6966f, -400.0f),
152 new Vector3(-4226.484f, -1213.027f, -400.0f),
153 new Vector3(-4593.09f, -1091.131f, -400.0f),
154 new Vector3(-4803.661f, -958.4816f, -400.0f),
155 new Vector3(-5262.959f, -1025.99f, -400.0f),
156 new Vector3(-5519.119f, -881.3628f, -400.0f),
157 new Vector3(-5543.972f, -547.7667f, -400.0f),
158 new Vector3(-5775.069f, -294.6195f, -400.0f),
159 new Vector3(-6333.859f, -423.4442f, -400.0f),
160 new Vector3(-6977.528f, 840.5598f, -400.0f),
161 new Vector3(-6847.938f, 1640.414f, -400.0f),
162 new Vector3(-7259.18f, 1724.889f, -400.0f),
163 new Vector3(-7693.181f, 1660.773f, -400.0f),
164 new Vector3(-8300.401f, 1609.711f, -400.0f),
165 new Vector3(-8704.221f, 1241.705f, -400.0f),
166 new Vector3(-9049.8f, 905.2922f, -400.0f),
167 new Vector3(-8739.72f, 105.7951f, -400.0f),
168 new Vector3(-8515.267f, -371.7517f, -400.0f),
169 new Vector3(-8110.098f, -316.8557f, -400.0f),
170 new Vector3(-7915.391f, -304.8632f, -400.0f),
171 new Vector3(-7191.82f, -353.2674f, -400.0f),
172 new Vector3(-6270.604f, -2246.958f, -400.0f),
173 new Vector3(-6655.961f, -2615.954f, -400.0f),
174 new Vector3(-7056.6f, -2839.48f, -400.0f),
175 new Vector3(-7632.455f, -3047.234f, -400.0f),
176 new Vector3(-8325.431f, -2937.415f, -400.0f),
177 new Vector3(-8273.172f, -3403.743f, -400.0f),
178 new Vector3(-8179.38f, -3616.764f, -400.0f),
179 new Vector3(-7814.024f, -4484.587f, -400.0f),
180 new Vector3(-6525.229f, -4816.507f, -400.0f),
181 new Vector3(-5648.252f, -4344.051f, -400.0f),
182 new Vector3(-6140.713f, -3957.125f, -400.0f),
183 new Vector3(-7001.114f, -3650.077f, -400.0f),
187 var random =
new Random(1);
190 for (
int i = 0; i < emitters.Length; i++)
193 var verticalScatter = (float)(2.0 + 3.0 * random.NextDouble());
194 var horizontalScatter = (float)(3.0 + 6.0 * random.NextDouble());
201 Position = emitterPositions[i],
202 Scatter =
new Vector3(horizontalScatter, horizontalScatter, verticalScatter),
203 Velocity =
new Vector3(0, 0.0f, 0.5f + 4.0f * (
float)random.NextDouble()),
204 MaxTime = 1000.0f + 4000.0f * (
float)random.NextDouble(),
205 InitialSize = 50.0f + 30.0f * (
float)random.NextDouble(),
206 DeltaSize = 30.0f + 20.0f * (
float)random.NextDouble(),
210 emitter.OnUpdateData();
212 emitters[i] = emitter;
215 var smokeVolTexture = (
Texture2D)engineContext.AssetManager.Load<
Texture>(
"/global_data/gdc_demo/fx/smokevol.dds");
216 var smokeGradTexture = (
Texture2D)engineContext.AssetManager.
Load<
Texture>(
"/global_data/gdc_demo/fx/smokegrad.dds");
217 particlePlugin.Parameters.Set(SmokeTexture, smokeVolTexture);
218 particlePlugin.Parameters.Set(SmokeColor, smokeGradTexture);
220 var particleEmitterRootEntity =
new Entity(
"ParticleEmitters");
222 engineContext.EntityManager.AddEntity(particleEmitterRootEntity);
224 for (
int index = 0; index < emitters.Length; index++)
226 var emitter = emitters[index];
227 var entity =
new Entity(
string.Format(
"ParticleEmitter-{0}", index));
228 entity.Set(TransformationComponent.Key,
new TransformationComponent(
new TransformationTRS { Translation = emitter.Description.Position }));
229 entity.Set(ParticleEmitterComponent.Key, emitter);
231 particleEmitterRootEntity.Transformation.Children.Add(entity.Transformation);
Key of an effect parameter.
Game entity. It usually aggregates multiple EntityComponent
SiliconStudio.Paradox.Games.Mathematics.Half4 Half4
All-in-One Buffer class linked SharpDX.Direct3D11.Buffer.
static Texture Load(GraphicsDevice device, Stream stream, TextureFlags textureFlags=TextureFlags.ShaderResource, GraphicsResourceUsage usage=GraphicsResourceUsage.Immutable)
Loads a texture from a stream.
SiliconStudio.Paradox.Games.Mathematics.Half Half
A Texture 2D frontend to SharpDX.Direct3D11.Texture2D.
SiliconStudio.Paradox.Graphics.Buffer Buffer
SiliconStudio.Core.Mathematics.Vector3 Vector3
static void Run(EngineContext engineContext)
Base class for texture resources.