3 using System.Threading.Tasks;
4 using System.Xml.Serialization;
5 using SiliconStudio.Paradox;
6 using SiliconStudio.Paradox.Effects.Modules;
8 using SiliconStudio.Paradox.Effects;
9 using System.Diagnostics;
11 using SiliconStudio.Paradox.Games;
12 using SiliconStudio.Core.Extensions;
13 using SiliconStudio.Paradox.Games.MicroThreading;
14 using SiliconStudio.Paradox.Games.Mathematics;
15 using SiliconStudio.Paradox.Configuration;
37 [XmlAttribute(
"animatedLights")]
44 var r =
new Random(0);
46 var config = AppConfig.GetConfiguration<
Config>(
"LightScript2");
49 if (!engineContext.DataContext.RenderPassPlugins.TryGetValueCast(
"LightingPrepassPlugin", out lightingPrepassPlugin))
52 var effectMeshGroup =
new RenderPassListEnumerator();
53 engineContext.RenderContext.RenderPassEnumerators.Add(effectMeshGroup);
56 for (
int i = 0; i < 1024; ++i)
58 var effectMesh =
new EffectMesh(lightingPrepassPlugin.Lights);
60 Color3 color = (Color3)
Color.White;
63 case 0: color =
new Color3(0.7f, 0.0f, 0.0f);
break;
64 case 1: color =
new Color3(0.0f, 0.7f, 0.0f);
break;
65 case 2: color =
new Color3(0.0f, 0.0f, 0.7f);
break;
66 case 3: color =
new Color3(0.7f, 0.7f, 0.0f);
break;
67 case 4: color =
new Color3(0.7f, 0.0f, 0.7f);
break;
68 case 5: color =
new Color3(0.0f, 0.7f, 0.7f);
break;
69 case 6: color =
new Color3(0.7f, 0.7f, 0.7f);
break;
71 effectMesh.Parameters.Set(LightKeys.LightRadius, 60.0f);
72 effectMesh.Parameters.Set(LightKeys.LightColor, color);
73 effectMesh.Parameters.Set(LightKeys.LightIntensity, 1.0f);
74 effectMesh.KeepAliveBy(engineContext.SimpleComponentRegistry);
76 effectMeshGroup.AddMesh(effectMesh);
79 bool animatedLights = config.AnimatedLights;
81 EffectOld effectLight = null;
84 effectLight = engineContext.RenderContext.RenderPassPlugins.OfType<
LightingPrepassPlugin>().FirstOrDefault().Lights;
91 var lightInfo =
new LightInfo[effectLight != null ? effectLight.Meshes.Count : 0];
92 for (
int i = 0; i < lightInfo.Length; ++i)
94 lightInfo[i].Radius = (float)r.NextDouble() * 1000.0f + 500.0f;
95 lightInfo[i].Phase = (float)r.NextDouble() * 10.0f;
96 lightInfo[i].Z = (float)r.NextDouble() * 150.0f + 150.0f;
99 var st =
new Stopwatch();
100 var lastTickCount = 0;
102 var st2 =
new Stopwatch();
105 bool firstTime =
true;
108 await Scheduler.NextFrame();
112 if (lightInfo.Length > 0)
114 if (animatedLights || firstTime)
117 foreach (var mesh
in effectLight.Meshes)
119 mesh.Parameters.Set(LightKeys.LightPosition,
new Vector3(lightInfo[index].Radius * (
float)Math.Cos(time * 3.0f + lightInfo[index].Phase), lightInfo[index].Radius * (float)Math.Sin(time * 3.0f + lightInfo[index].Phase), lightInfo[index].Z));
SiliconStudio.Core.Mathematics.Color Color
static async Task MoveLights(EngineContext engineContext)
SiliconStudio.Core.Mathematics.Vector3 Vector3
Deffered lighting plugin.