Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ScriptCave.cs
Go to the documentation of this file.
1 using System;
2 using System.Linq;
3 using System.Threading;
4 using System.Threading.Tasks;
5 using System.Xml.Serialization;
6 using SiliconStudio.Paradox;
7 using SiliconStudio.Paradox.DataModel;
8 using SiliconStudio.Paradox.Effects;
9 using SiliconStudio.Paradox.Effects.Modules;
10 #if PARADOX_YEBIS
11 using Paradox.Effects.Yebis;
12 #endif
13 using SiliconStudio.Paradox.Engine;
14 using SiliconStudio.Paradox.EntityModel;
15 using SiliconStudio.Paradox.Extensions;
16 using SiliconStudio.Paradox.Games;
17 using SiliconStudio.Paradox.Configuration;
18 using SiliconStudio.Core.Extensions;
19 using SiliconStudio.Paradox.Graphics;
20 using SiliconStudio.Paradox.Graphics.Data;
21 using SiliconStudio.Paradox.Games.Mathematics;
22 using SiliconStudio.Paradox.Games.MicroThreading;
23 using SiliconStudio.Paradox.Input;
24 using SiliconStudio.Paradox.Prefabs;
25 
26 using ScriptTest2;
27 #if NET45
28 using TaskEx = System.Threading.Tasks.Task;
29 #endif
30 
31 namespace ScriptTest
32 {
33  [ParadoxScript]
34  public class ScriptCave
35  {
36  private const float CaveSceneTotalTime = 79.0f;
37  private const float FullExposureTime = CaveSceneTotalTime - 7.0f;
38  private const float LogoTimeBegin = FullExposureTime + 2.5f;
39  private const float LogoTimeFull = LogoTimeBegin + 0.8f;
40  private const float LogoTimeURL = LogoTimeFull + 3.5f;
41  private const float LogoTimeStartToEnd = LogoTimeURL + 0.8f;
42  private const float LogoTimeEnd = LogoTimeStartToEnd + 1f;
43  private const float CaveSceneEndBlack = LogoTimeEnd + 1.5f;
44  private const float CaveSceneRestart = CaveSceneEndBlack + 0.1f;
45 
46  [ParadoxScript]
47  public static async Task Run(EngineContext engineContext)
48  {
49  var renderingSetup = RenderingSetup.Singleton;
50  renderingSetup.RegisterLighting(engineContext);
51 
52  ParticlePlugin particlePlugin;
53  if (engineContext.DataContext.RenderPassPlugins.TryGetValueCast("ParticlePlugin", out particlePlugin))
54  {
55  ScriptParticleSmoke.Run(engineContext);
56  }
57 
58 
59  var yebisPlugin = engineContext.RenderContext.RenderPassPlugins.OfType<YebisPlugin>().FirstOrDefault();
60  if (yebisPlugin != null)
61  {
62  var yebisConfig = AppConfig.GetConfiguration<YebisConfig>("Yebis");
63 
64  // yebisPlugin.ToneMap.Type = ToneMapType.Linear;
65  yebisPlugin.ToneMap.Gamma = yebisConfig.Gamma;
66  yebisPlugin.ColorCorrection.Saturation = yebisConfig.Saturation;
67  yebisPlugin.ColorCorrection.Contrast = yebisConfig.Contrast;
68  yebisPlugin.ColorCorrection.Brightness = yebisConfig.Brightness;
69  yebisPlugin.ColorCorrection.ColorTemperature = yebisConfig.ColorTemperature;
70  yebisPlugin.Lens.Vignette.Enable = true;
71  yebisPlugin.Lens.Vignette.PowerOfCosine = 5.0f;
72  yebisPlugin.Lens.Distortion.Enable = true;
73  yebisPlugin.Lens.Distortion.EdgeRoundness = 0.1f;
74  yebisPlugin.Lens.Distortion.EdgeSmoothness = 1.0f;
75  }
76 
77  // Run the script to animate the intro fade-in/fade-out
78  engineContext.Scheduler.Add(async () => await AnimateIntroAndEndScene(engineContext));
79 
80  var cameraEntityRootPrefab = await engineContext.AssetManager.LoadAsync<Entity>("/global_data/gdc_demo/char/camera.hotei#");
81  var lightCamEntityRootPrefab = await engineContext.AssetManager.LoadAsync<Entity>("/global_data/gdc_demo/char/light_cam.hotei#");
82 
83  var lightCamEntityRoot = Prefab.Inherit(lightCamEntityRootPrefab);
84  var cameraEntityRoot = Prefab.Inherit(cameraEntityRootPrefab);
85 
86  engineContext.EntityManager.AddEntity(cameraEntityRoot);
87  engineContext.EntityManager.AddEntity(lightCamEntityRoot);
88  Scheduler.Current.Add(() => AnimScript.AnimateFBXModel(engineContext, cameraEntityRoot, CaveSceneTotalTime, CaveSceneRestart));
89  Scheduler.Current.Add(() => AnimScript.AnimateFBXModel(engineContext, lightCamEntityRoot, CaveSceneTotalTime, CaveSceneRestart));
90 
91  foreach(var light in ParameterContainerExtensions.CollectEntityTree(lightCamEntityRoot))
92  {
93  var lightComp = light.Get(LightComponent.Key);
94  if (lightComp != null)
95  {
96 
97  if (!lightComp.ShadowMap && lightComp.Type == LightType.Directional)
98  {
99  lightComp.Intensity *= 0.1f;
100  }
101  }
102  }
103 
104  var config = AppConfig.GetConfiguration<Script1.Config>("Script1");
105 
106  var shadowMap1 = new Entity();
107  var shadowMap2 = new Entity();
108  shadowMap1.Set(TransformationComponent.Key, TransformationTRS.CreateComponent());
109  shadowMap2.Set(TransformationComponent.Key, TransformationTRS.CreateComponent());
110  shadowMap1.Set(LightComponent.Key, new LightComponent { Type = LightType.Directional, Intensity = 0.9f, Color = new Color3(0.9f, 0.9f, 1.0f), LightDirection = new Vector3(-0.2f, -0.1f, -1.0f), ShadowMap = true, DecayStart = 40000.0f });
111  shadowMap2.Set(LightComponent.Key, new LightComponent { Type = LightType.Directional, Color = new Color3(1.0f, 1.0f, 1.0f), LightDirection = new Vector3(-0.5f, 0.1f, -1.0f), ShadowMap = true, DecayStart = 40000.0f });
112  shadowMap1.Set(LightShaftsComponent.Key, new LightShaftsComponent { Color = new Color3(1.0f, 1.0f, 1.0f), LightShaftsBoundingBoxes =
113  {
114  new EffectMeshData { MeshData = MeshDataHelper.CreateBox(1, 1, 1, Color.White, true), Parameters = new ParameterCollection { { TransformationKeys.World, Matrix.Scaling(3000, 3500, 3000) * Matrix.Translation(-2500, 0, 1500) } } }
115  } });
116  shadowMap2.Set(LightShaftsComponent.Key, new LightShaftsComponent { Color = new Color3(1.0f, 1.0f, 1.0f), LightShaftsBoundingBoxes =
117  {
118  new EffectMeshData { MeshData = MeshDataHelper.CreateBox(1, 1, 1, Color.White, true), Parameters = new ParameterCollection { { TransformationKeys.World, Matrix.Scaling(3500, 3500, 3000) * Matrix.Translation(-3000, 0, 1500) } } }
119  } });
120 
121  engineContext.EntityManager.AddEntity(shadowMap1);
122  engineContext.EntityManager.AddEntity(shadowMap2);
123 
124 
125  var dragon = await LoadDragon(engineContext);
126  await LoadCave(engineContext, dragon);
127 
128  var dragonHead = engineContext.EntityManager.Entities.FirstOrDefault(x => x.Name == "English DragonHead");
129  TransformationTRS headCameraTransfo = null;
130  if (dragonHead != null)
131  {
132  var headCamera = new Entity("Head camera");
133  headCamera.Set(CameraComponent.Key, new CameraComponent { AspectRatio = 16.0f / 9.0f, VerticalFieldOfView = (float)Math.PI * 0.3f, Target = dragonHead, AutoFocus = true, NearPlane = 10.0f });
134  headCamera.Set(TransformationComponent.Key, new TransformationComponent(new TransformationTRS { Translation = new Vector3(100.0f, -100.0f, 300.0f) }));
135  //engineContext.EntitySystem.Entities.Add(headCamera);
136  dragonHead.Transformation.Children.Add(headCamera.Transformation);
137  }
138 
139  engineContext.Scheduler.Add(() => AnimateLights(engineContext));
140 
141  // Performs several full GC after the scene has been loaded
142  for (int i = 0; i < 10; i++)
143  {
144  GC.Collect();
145  Thread.Sleep(1);
146  }
147 
148  while (true)
149  {
150  await engineContext.Scheduler.NextFrame();
151 
152  if (headCameraTransfo != null)
153  {
154  var time = (double)DateTime.UtcNow.Ticks / (double)TimeSpan.TicksPerSecond;
155  float rotationSpeed = 0.317f;
156  var position = new Vector2((float)Math.Cos(time * rotationSpeed), (float)Math.Sin(time * rotationSpeed)) * 330.0f * ((float)Math.Sin(time * 0.23f) * 0.4f + 0.9f);
157  headCameraTransfo.Translation = new Vector3(position.X, -150.0f + (float)Math.Cos(time * rotationSpeed) * 50.0f, position.Y);
158  }
159 
160  if (engineContext.InputManager.IsKeyPressed(Keys.F1))
161  {
162  bool isWireframeEnabled = renderingSetup.ToggleWireframe();
163  if (yebisPlugin != null)
164  {
165  yebisPlugin.DepthOfField.Enable = !isWireframeEnabled;
166  yebisPlugin.Lens.Vignette.Enable = !isWireframeEnabled;
167  yebisPlugin.Lens.Distortion.Enable = !isWireframeEnabled;
168  }
169  }
170 
171  if (engineContext.InputManager.IsKeyPressed(Keys.D1))
172  engineContext.CurrentTime = TimeSpan.FromSeconds(0);
173  if (engineContext.InputManager.IsKeyPressed(Keys.D2))
174  engineContext.CurrentTime = TimeSpan.FromSeconds(10);
175  if (engineContext.InputManager.IsKeyPressed(Keys.D3))
176  engineContext.CurrentTime = TimeSpan.FromSeconds(20);
177  if (engineContext.InputManager.IsKeyPressed(Keys.D4))
178  engineContext.CurrentTime = TimeSpan.FromSeconds(30);
179  if (engineContext.InputManager.IsKeyPressed(Keys.D5))
180  engineContext.CurrentTime = TimeSpan.FromSeconds(40);
181  if (engineContext.InputManager.IsKeyPressed(Keys.D6))
182  engineContext.CurrentTime = TimeSpan.FromSeconds(50);
183  if (engineContext.InputManager.IsKeyPressed(Keys.D7))
184  engineContext.CurrentTime = TimeSpan.FromSeconds(60);
185  if (engineContext.InputManager.IsKeyPressed(Keys.D8))
186  engineContext.CurrentTime = TimeSpan.FromSeconds(70);
187 
188  if (engineContext.InputManager.IsKeyPressed(Keys.T))
189  {
190  if (particlePlugin != null)
191  {
192  particlePlugin.EnableSorting = !particlePlugin.EnableSorting;
193  }
194  }
195 
196  }
197  }
198 
199  public static async Task AnimateIntroAndEndScene(EngineContext engineContext)
200  {
201  var yebisPlugin = engineContext.RenderContext.RenderPassPlugins.OfType<YebisPlugin>().FirstOrDefault();
202  var slideShowPlugin = engineContext.RenderContext.RenderPassPlugins.OfType<SlideShowPlugin>().FirstOrDefault();
203 
204  // Return immediately if there is no Yebis
205  if (yebisPlugin == null || slideShowPlugin == null)
206  {
207  return;
208  }
209 
210  var paradoxLogo = (Texture2D)await engineContext.AssetManager.LoadAsync<Texture>("/global_data/gdc_demo/bg/LogoParadox.dds");
211  var paradoxLogoURL = (Texture2D)await engineContext.AssetManager.LoadAsync<Texture>("/global_data/gdc_demo/bg/LogoParadoxURL.dds");
212 
213  slideShowPlugin.TextureFrom = paradoxLogo;
214  slideShowPlugin.TextureTo = paradoxLogoURL;
215  slideShowPlugin.RenderPass.Enabled = false;
216 
217  double lastTime = 0;
218  float lastExposure = 0.0f;
219 
220  yebisPlugin.ToneMap.AutoExposure.Enable = true;
221 
222  var savedToneMap = yebisPlugin.ToneMap;
223  var savedLens = yebisPlugin.Lens;
224  var savedColorCorrection = yebisPlugin.ColorCorrection;
225 
226  while (true)
227  {
228  await engineContext.Scheduler.NextFrame();
229 
230  var animationTime = (float)engineContext.CurrentTime.TotalSeconds % CaveSceneRestart;
231 
232  var deltaTime = (float)(animationTime - lastTime);
233 
234  // If scene restart
235  if (deltaTime < 0.0f)
236  {
237  yebisPlugin.ToneMap = savedToneMap;
238  yebisPlugin.Lens = savedLens;
239  yebisPlugin.ColorCorrection = savedColorCorrection;
240 
241  // Enable all
242  foreach (var pass in engineContext.RenderContext.RootRenderPass.Passes)
243  {
244  if (pass.Name == "WireframePass")
245  continue;
246  pass.Enabled = true;
247  }
248  // Disable SlideShow
249  slideShowPlugin.RenderPass.Enabled = false;
250  yebisPlugin.ToneMap.Exposure = 0.005f;
251  yebisPlugin.ToneMap.AutoExposure.Enable = true;
252  slideShowPlugin.TransitionFactor = 0.0f;
253  }
254 
255  // If we reset, reupload the particle buffer
256  if (animationTime < FullExposureTime)
257  {
258  yebisPlugin.ToneMap.AutoExposure.Enable = true;
259  }
260  else if (animationTime < LogoTimeBegin)
261  {
262  if (yebisPlugin.ToneMap.AutoExposure.Enable)
263  {
264  lastExposure = yebisPlugin.ToneMap.Exposure;
265  yebisPlugin.ToneMap.AutoExposure.Enable = false;
266  }
267 
268  yebisPlugin.ToneMap.Exposure = lastExposure + (60.0f - lastExposure) * (float)Math.Pow((animationTime - FullExposureTime) / (LogoTimeBegin - FullExposureTime), 2.0f);
269  }
270  else
271  {
272  if (!slideShowPlugin.RenderPass.Enabled)
273  {
274  // Enable only Yebis and SlideShow
275  foreach (var pass in engineContext.RenderContext.RootRenderPass.Passes)
276  {
277  pass.Enabled = false;
278  }
279  yebisPlugin.RenderPass.Enabled = true;
280  slideShowPlugin.RenderPass.Enabled = true;
281 
282  yebisPlugin.ToneMap.Type = ToneMapType.Linear;
283  yebisPlugin.Lens.Vignette.Enable = false;
284  yebisPlugin.ToneMap.Gamma = 1.0f;
285  yebisPlugin.ColorCorrection.ColorTemperature = 6500;
286  yebisPlugin.ColorCorrection.Saturation = 1.0f;
287  yebisPlugin.ColorCorrection.Contrast = 1.0f;
288  yebisPlugin.ColorCorrection.Brightness = 1.0f;
289  lastExposure = yebisPlugin.ToneMap.Exposure;
290  slideShowPlugin.TransitionFactor = 0.0f;
291  }
292 
293  if (animationTime < LogoTimeFull)
294  {
295  slideShowPlugin.ZoomFactor = 0.5f + (1.0f - 0.5f) * Quintic((animationTime - LogoTimeBegin) / (LogoTimeFull - LogoTimeBegin));
296  yebisPlugin.ToneMap.Exposure = lastExposure + (1.0f - lastExposure) * (float)Math.Pow((animationTime - LogoTimeBegin) / (LogoTimeFull - LogoTimeBegin), 0.1f);
297  }
298  else
299  {
300  slideShowPlugin.ZoomFactor = 1.0f;
301  if (animationTime < LogoTimeURL)
302  {
303  yebisPlugin.ToneMap.Exposure = 1.0f;
304  }
305  else if (animationTime < LogoTimeStartToEnd)
306  {
307  slideShowPlugin.TransitionFactor = Math.Min(1.0f, (animationTime - LogoTimeURL) / (LogoTimeStartToEnd - LogoTimeURL));
308  }
309  else if (animationTime < LogoTimeEnd)
310  {
311  slideShowPlugin.TransitionFactor = 1.0f;
312  }
313  else if (animationTime < CaveSceneEndBlack)
314  {
315  yebisPlugin.ToneMap.Exposure = Math.Max(0.0f, 1.0f - (animationTime - LogoTimeEnd) / (CaveSceneEndBlack - LogoTimeEnd));
316  }
317  else
318  {
319  yebisPlugin.ToneMap.Exposure = 0f;
320  }
321  }
322  }
323  //Console.WriteLine("Exposure: {0}", yebisPlugin.ToneMap.Exposure);
324 
325  lastTime = animationTime;
326  }
327  }
328 
329  public static async Task AnimateLights(EngineContext engineContext)
330  {
331  while (true)
332  {
333  await engineContext.Scheduler.NextFrame();
334 
335  if (engineContext.InputManager.IsKeyPressed(Keys.F3))
336  {
337  var lights = engineContext.EntityManager.Entities.Components(LightComponent.Key);
338  await engineContext.Scheduler.WhenAll(lights.Select((lightComponent, index) =>
339  engineContext.Scheduler.Add(() => AnimateLight(engineContext, index, lightComponent))).ToArray());
340  }
341  }
342  }
343 
344  private static float Quintic(float x)
345  {
346  return x * x * x * (x * (x * 6.0f - 15.0f) + 10.0f);
347  }
348 
349  public static async Task AnimateLight(EngineContext engineContext, int index, LightComponent lightComponent)
350  {
351  // Wait different time for each light
352  await TaskEx.Delay(index * 20);
353  var startIntensity = lightComponent.Intensity;
354 
355  // Turn light off
356  var startTime = DateTime.UtcNow;
357  while (true)
358  {
359  await engineContext.Scheduler.NextFrame();
360  var elapsedTime = (DateTime.UtcNow - startTime).Seconds * 0.2f;
361  if (elapsedTime > 1.0f)
362  break;
363  lightComponent.Intensity = startIntensity * (1.0f - elapsedTime);
364  }
365 
366  // Turn light on
367 
368  lightComponent.Intensity = startIntensity;
369  }
370 
371  //[ParadoxScript]
372  public static async Task<Entity> LoadDragon(EngineContext engineContext)
373  {
374  var renderingSetup = RenderingSetup.Singleton;
375  renderingSetup.RegisterLighting(engineContext);
376 
377  var characterEntity = await AnimScript.LoadFBXModel(engineContext, "/global_data/gdc_demo/char/dragon_camera.hotei#");
378  characterEntity.Name = "Dragon";
379  Scheduler.Current.Add(() => AnimScript.AnimateFBXModel(engineContext, characterEntity, CaveSceneTotalTime, CaveSceneRestart));
380 
381  // Setup predefined specular intensities/power for dragon
382  foreach (var entity in ParameterContainerExtensions.CollectEntityTree(characterEntity))
383  {
384  var meshComponent = entity.Get(ModelComponent.Key);
385  if (meshComponent == null)
386  continue;
387 
388  foreach (var effectMesh in meshComponent.InstantiatedSubMeshes)
389  {
390  effectMesh.Value.Parameters.Set(TessellationKeys.DesiredTriangleSize, 4.0f);
391 
392  switch (effectMesh.Key.EffectData.Part)
393  {
394  case "skin":
395  effectMesh.Value.Parameters.Set(MaterialKeys.SpecularPower, 0.4f);
396  effectMesh.Value.Parameters.Set(MaterialKeys.SpecularIntensity, 0.4f);
397  break;
398  case "mouth":
399  effectMesh.Value.Parameters.Set(MaterialKeys.SpecularPower, 0.3f);
400  effectMesh.Value.Parameters.Set(MaterialKeys.SpecularIntensity, 0.3f);
401  break;
402  case "skin2":
403  effectMesh.Value.Parameters.Set(MaterialKeys.SpecularPower, 0.5f);
404  effectMesh.Value.Parameters.Set(MaterialKeys.SpecularIntensity, 0.5f);
405  break;
406  case "wing":
407  effectMesh.Value.Parameters.Set(MaterialKeys.SpecularPower, 0.4f);
408  effectMesh.Value.Parameters.Set(MaterialKeys.SpecularIntensity, 0.5f);
409  break;
410  case "tooth":
411  effectMesh.Value.Parameters.Set(MaterialKeys.SpecularPower, 0.4f);
412  effectMesh.Value.Parameters.Set(MaterialKeys.SpecularIntensity, 0.7f);
413  break;
414  case "eye":
415  effectMesh.Value.Parameters.Set(MaterialKeys.SpecularPower, 0.7f);
416  effectMesh.Value.Parameters.Set(MaterialKeys.SpecularIntensity, 0.7f);
417  break;
418  default:
419  effectMesh.Value.Parameters.Set(MaterialKeys.SpecularPower, 0.3f);
420  effectMesh.Value.Parameters.Set(MaterialKeys.SpecularIntensity, 0.3f);
421  break;
422  }
423  }
424  }
425 
426  return characterEntity;
427  }
428 
429  // [ParadoxScript]
430  public static async Task LoadCave(EngineContext engineContext, Entity animationEntity)
431  {
432  // Setup "fake" directional light for outdoor so that normal maps stand out.
433  var outdoorLight = new DirectionalLight { LightDirection = new Vector3(-2.0f, -1.0f, -1.0f) };
434  //outdoor.Permutations.Set(LightingPermutation.Key, new LightingPermutation { Lights = { outdoorLight } });
435  //outdoor.Permutations.Set(LightingPermutation.Key, new LightingPermutation { Lights = { outdoorLight } });
436 
437  var effectMagma = engineContext.RenderContext.Effects.First(x => x.Name == "Magma");
438 
439  effectMagma.Parameters.AddSources(engineContext.DataContext.RenderPassPlugins.TryGetValue("NoisePlugin").Parameters);
440 
441  //var assetManager = new AssetManager(new ContentSerializerContextGenerator(engineContext.VirtualFileSystem, engineContext.PackageManager, ParameterContainerExtensions.DefaultSceneSerializer));
442  var caveEntityPrefab1 = await engineContext.AssetManager.LoadAsync<Entity>("/global_data/gdc_demo/bg/bg1.hotei#");
443  var caveEntityPrefab2 = await engineContext.AssetManager.LoadAsync<Entity>("/global_data/gdc_demo/bg/bg2.hotei#");
444 
445  var caveEntity1 = Prefab.Clone(caveEntityPrefab1);
446  var caveEntity2 = Prefab.Clone(caveEntityPrefab2);
447 
448  SkyBoxPlugin skyBoxPlugin;
449  if (engineContext.DataContext.RenderPassPlugins.TryGetValueCast("SkyBoxPlugin", out skyBoxPlugin))
450  {
451  var skyBoxTexture = (Texture2D)await engineContext.AssetManager.LoadAsync<Texture>("/global_data/gdc_demo/bg/GDC2012_map_sky.dds");
452  skyBoxPlugin.Texture = skyBoxTexture;
453  }
454 
455  var magmaTexturePaths = new[]
456  {
457  "/global_data/gdc_demo/bg/GDC2012_map_maguma_04.dds",
458  "/global_data/gdc_demo/bg/GDC2012_map_maguma_05.dds",
459  "/global_data/gdc_demo/bg/GDC2012_map_maguma_06.dds",
460 
461  "/global_data/gdc_demo/bg/GDC2012_map_maguma_00.dds",
462  "/global_data/gdc_demo/bg/GDC2012_map_maguma_01.dds",
463  "/global_data/gdc_demo/bg/GDC2012_map_maguma_02.dds",
464  "/global_data/gdc_demo/bg/GDC2012_map_maguma_03.dds",
465  "/global_data/gdc_demo/bg/GDC2012_map_maguma_noise_00.dds",
466  "/global_data/gdc_demo/bg/GDC2012_map_maguma_noise_01.dds",
467  "/global_data/gdc_demo/bg/GDC2012_map_maguma_normals.dds",
468  };
469  var magmaTextures = new Texture2D[magmaTexturePaths.Length];
470  for (int i = 0; i < magmaTextures.Length; i++)
471  {
472  magmaTextures[i] = (Texture2D)await engineContext.AssetManager.LoadAsync<Texture>(magmaTexturePaths[i]);
473  }
474 
475  var lightVectors = new[]
476  {
477  new Vector3(-1.0f, 0.3f, -1.0f),
478  new Vector3(1.0f, 0.0f, -1.0f),
479  new Vector3(1.0f, 0.0f, -1.0f),
480  };
481 
482 
483  var random = new Random(0);
484  int planeIndex = 0;
485  foreach (var entity in ParameterContainerExtensions.CollectEntityTree(caveEntity1))
486  {
487  var meshComponent = entity.Get(ModelComponent.Key);
488  if (meshComponent == null)
489  continue;
490 
491  // Setup textures for magma
492  if (entity.Name.StartsWith("maguma_"))
493  {
494  meshComponent.MeshParameters.Set(LightKeys.LightDirection, lightVectors[planeIndex]);
495  meshComponent.MeshParameters.Set(ParameterKeys.IndexedKey(TexturingKeys.Texture0, 1), magmaTextures[planeIndex]);
496  planeIndex++;
497  for (int i = 3; i < magmaTextures.Length; i++)
498  meshComponent.MeshParameters.Set(ParameterKeys.IndexedKey(TexturingKeys.Texture0, i - 1), magmaTextures[i]);
499 
500 
501  foreach (var effectMesh in meshComponent.SubMeshes)
502  {
503  effectMesh.EffectData.Name = "Magma";
504  }
505 
506  // Attach a bullet particle emitter to the magma
507  var emitter = new BulletParticleEmitterComponent()
508  {
509  //Count = 4096,
510  Count = 16384,
511  Description = new BulletEmitterDescription()
512  {
513  Target = new Vector3(-3016.261f, -70.52288f, 800.8788f),
514  BulletSize = 4.0f,
515  //MaxTimeTarget = 1000.0f + 5000.0f * (float)random.NextDouble(),
516  VelocityUp = new Vector3(0, 0, 200),
517  MaxTimeUp = 5000.0f,
518  MaxTimeTarget = 20000.0f,
519  VelocityTarget = 200.0f,
520  Opacity = 1.0f,
521  //DistanceDragonRepulse = 1200.0f,
522  //DecayDragonRepulse = 70.0f,
523  DistanceDragonRepulse = 600.0f,
524  DecayDragonRepulse = 70.0f,
525  VelocityRepulse = 200.0f,
526  },
527  RootAnimation = animationEntity,
528  };
529  emitter.OnAddToSystem(engineContext.EntityManager, engineContext.RenderContext);
530  emitter.OnUpdateData();
531  entity.Set(ParticleEmitterComponent.Key, emitter);
532  }
533 
534  foreach (var effectMesh in meshComponent.SubMeshes)
535  {
536  effectMesh.Parameters.Set(ParameterKeys.IndexedKey(TexturingKeys.DiffuseTexture, 3), (Texture2D)await engineContext.AssetManager.LoadAsync<Texture>("/global_data/gdc_demo/bg/GDC2012_map_dis_ao.dds"));
537  }
538  }
539 
540  await engineContext.EntityManager.AddEntityAsync(caveEntity1);
541  await engineContext.EntityManager.AddEntityAsync(caveEntity2);
542 
543  foreach (var entity in ParameterContainerExtensions.CollectEntityTree(caveEntity1).Concat(ParameterContainerExtensions.CollectEntityTree(caveEntity2)))
544  {
545  var meshComponent = entity.Get(ModelComponent.Key);
546  if (meshComponent == null)
547  continue;
548 
549  foreach (var effectMesh in meshComponent.InstantiatedSubMeshes)
550  {
551  effectMesh.Value.Parameters.Set(MaterialKeys.SpecularIntensity, 2.0f);
552  effectMesh.Value.Parameters.Set(MaterialKeys.SpecularPower, 0.1f);
553  }
554  }
555  }
556  }
557 
558  public class YebisConfig
559  {
560  public YebisConfig()
561  {
562  Gamma = 2.2f;
563  Saturation = 0.7f;
564  Contrast = 1.06f;
565  Brightness = 1.2f;
566  ColorTemperature = 5500.0f;
567  }
568 
569  //yebisPlugin.ToneMap.Gamma = 2.2f;
570  //yebisPlugin.ColorCorrection.Saturation = 0.7f;
571  //yebisPlugin.ColorCorrection.Contrast = 1.06f;
572  //yebisPlugin.ColorCorrection.Brightness = 1.2f;
573  //yebisPlugin.ColorCorrection.ColorTemperature = 5500;
574 
575  [XmlAttribute("gamma")]
576  public float Gamma { get; set; }
577 
578  [XmlAttribute("saturation")]
579  public float Saturation { get; set; }
580 
581  [XmlAttribute("contrast")]
582  public float Contrast { get; set; }
583 
584  [XmlAttribute("brightness")]
585  public float Brightness { get; set; }
586 
587  [XmlAttribute("temperature")]
588  public float ColorTemperature { get; set; }
589  }
590 }
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
Add a light to an Entity, that will be used during rendering.
Game entity. It usually aggregates multiple EntityComponent
Definition: Entity.cs:28
Keys
Enumeration for keys.
Definition: Keys.cs:8
static async Task AnimateFBXModel(EngineContext engineContext, Entity characterEntity, float endAnimTime=0.0f, float loopTime=0.0f)
Definition: AnimScript.cs:69
static async Task AnimateLight(EngineContext engineContext, int index, LightComponent lightComponent)
Definition: ScriptCave.cs:349
Defines Position, Rotation and Scale of its Entity.
System.Threading.Tasks.Task Task
Represents a ShadowMap.
Definition: ShadowMap.cs:11
static async Task Run(EngineContext engineContext)
Definition: ScriptCave.cs:47
static readonly RenderingSetup Singleton
static async Task< Entity > LoadDragon(EngineContext engineContext)
Definition: ScriptCave.cs:372
Describes the camera projection and view.
SiliconStudio.Core.Mathematics.Color Color
Definition: ColorPicker.cs:14
static async Task LoadCave(EngineContext engineContext, Entity animationEntity)
Definition: ScriptCave.cs:430
A Texture 2D frontend to SharpDX.Direct3D11.Texture2D.
Definition: Texture2D.cs:37
static readonly ParameterKey< Texture > Texture0
Definition: Texturing.cs:21
SiliconStudio.Core.Mathematics.Vector3 Vector3
static async Task AnimateLights(EngineContext engineContext)
Definition: ScriptCave.cs:329
static async Task AnimateIntroAndEndScene(EngineContext engineContext)
Definition: ScriptCave.cs:199
A container to handle a hierarchical collection of effect variables.
Base class for texture resources.
Definition: Texture.cs:38