2 using System.Collections.Generic;
4 using System.Threading.Tasks;
5 using SiliconStudio.Paradox;
6 using SiliconStudio.Paradox.DataModel;
7 using SiliconStudio.Paradox.Effects;
8 using SiliconStudio.Paradox.Effects.Modules;
9 using SiliconStudio.Paradox.Games;
10 using SiliconStudio.Core.Extensions;
11 using SiliconStudio.Paradox.Games.Mathematics;
12 using SiliconStudio.Paradox.Games.MicroThreading;
13 using SiliconStudio.Paradox.Input;
14 using SiliconStudio.Shaders;
26 public static async
Task Run(EngineContext engineContext)
33 shadowMapPlugin.RenderContext = engineContext.RenderContext;
35 var shadowMap1 =
new ShadowMap(
new DirectionalLight()) { Level = CascadeShadowMapLevel.X1, ShadowMapSize = 1024, ShadowDistance = 2000.0f }
37 var shadowMap2 =
new ShadowMap(
new DirectionalLight()) { Level = CascadeShadowMapLevel.X2, ShadowMapSize = 1024, ShadowDistance = 2000.0f }
40 shadowMapPlugin.AddShadowMap(shadowMap1);
41 shadowMapPlugin.AddShadowMap(shadowMap2);
43 shadowMap1.DirectionalLight.LightDirection =
new Vector3(-1.0f, -1.0f, -1.0f);
44 shadowMap1.DirectionalLight.LightColor =
new Color3(1.0f, 0.5f, 0.5f);
45 shadowMap2.DirectionalLight.LightDirection =
new Vector3(-1.0f, 1.0f, -1.0f);
46 shadowMap2.DirectionalLight.LightColor =
new Color3(0.5f, 0.5f, 1.0f);
48 engineContext.RenderContext.Register(shadowMapPlugin);
50 EffectOld effect = engineContext.RenderContext.BuildEffect(
"Permutation")
51 .Using(
new BasicShaderPlugin(
"ShaderBase") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
52 .Using(
new BasicShaderPlugin(
"TransformationWVP") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
53 .Using(
new BasicShaderPlugin(
new ShaderMixinSource()
57 new ShaderComposition(
"albedoDiffuse",
new ShaderClassSource(
"ComputeColorStream")),
58 new ShaderComposition(
"albedoSpecular",
new ShaderClassSource(
"ComputeColor")),
60 "BRDFSpecularBlinnPhong",
66 var sphereMeshData = MeshDataHelper.CreateSphere(10.0f, 20, 20, Color.White);
68 var effectMeshGroup =
new RenderPassListEnumerator();
69 engineContext.RenderContext.RenderPassEnumerators.Add(effectMeshGroup);
71 int objectSqrtCount = 1;
72 int meshCount = objectSqrtCount * objectSqrtCount * objectSqrtCount;
78 effect.Permutations.Set(ShadowMapPermutationArray.Key, shadowMapPermutation1);
80 var groups2 =
new[] { shadowMapPermutation1, shadowMapPermutation2, shadowMapPermutation3 };
83 var effectMeshes =
new List<EffectMesh>();
84 for (
int j = 0; j < meshCount; ++j)
86 var effectMesh =
new EffectMesh(effect, sphereMeshData);
87 effectMesh.KeepAliveBy(engineContext.SimpleComponentRegistry);
89 effect.Permutations.Set(ShadowMapPermutationArray.Key, groups2[2]);
91 var w2 = Matrix.Scaling(1.0f)
92 * Matrix.Translation(
new Vector3(
93 (j % objectSqrtCount - objectSqrtCount / 2) * 30.0f - 30.0f,
94 (((j / objectSqrtCount) % objectSqrtCount) - objectSqrtCount / 2) * 30.0f - 30.0f,
95 (j / (objectSqrtCount * objectSqrtCount)) * 30.0f + 30.0f));
97 effectMesh.Parameters.Set(TransformationKeys.World, w2);
98 effectMeshes.Add(effectMesh);
101 var groundMesh =
new EffectMesh(effect, MeshDataHelper.CreateBox(1000, 1000, 1,
Color.White));
102 groundMesh.KeepAliveBy(engineContext.SimpleComponentRegistry);
103 effectMeshGroup.AddMesh(groundMesh);
104 groundMesh.Parameters.Set(TransformationKeys.World, Matrix.Translation(0.0f, 0.0f, 0.0f));
106 var groups =
new[] {
new int[] { 0, 1 },
new int[] { 0 },
new int[] { 1 } };
109 await TaskEx.Delay(1000);
110 foreach (var effectMesh
in effectMeshes)
111 effectMeshGroup.AddMesh(effectMesh);
115 await engineContext.Scheduler.NextFrame();
117 if (engineContext.InputManager.IsKeyPressed(
Keys.F8))
120 effect.Permutations.Set(LightingPermutation.Key, permutation);
122 if (engineContext.InputManager.IsKeyPressed(
Keys.F9))
124 effect.Permutations.Set(ShadowMapPermutationArray.Key, groups2[(groupIndex2++) % groups2.Length]);
System.Threading.Tasks.Task Task
static readonly RenderingSetup Singleton
SiliconStudio.Core.Mathematics.Color Color
Plugin used for the main rendering view.
static async Task Run(EngineContext engineContext)
SiliconStudio.Core.Mathematics.Vector3 Vector3
RenderPass is a hierarchy that defines how to collect and render meshes.