Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ScriptMulticore.cs
Go to the documentation of this file.
1 using System;
2 using System.Linq;
3 using System.Threading.Tasks;
4 
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 
14 namespace ScriptTest
15 {
16  [ParadoxScript]
17  public class ScriptMulticore
18  {
19  [ParadoxScript]
20  public static async Task Run(EngineContext engineContext)
21  {
22 #if PARADOX_YEBIS
23  YebisPlugin yebisPlugin;
24  if (engineContext.DataContext.RenderPassPlugins.TryGetValueCast("YebisPlugin", out yebisPlugin))
25  {
26  yebisPlugin.Glare.Enable = false;
27  yebisPlugin.DepthOfField.Enable = false;
28  yebisPlugin.ToneMap.AutoExposure.Enable = false;
29  yebisPlugin.ToneMap.Exposure = 1.0f;
30  yebisPlugin.ToneMap.Gamma = 2.2f;
31  }
32 #endif
33 
34  EffectOld effect = engineContext.RenderContext.Effects.First(x => x.Name == "Multicore");
35  //Effect effect = engineContext.RenderContext.BuildEffect("Multicore")
36  // .Using(new BasicShaderPlugin("ShaderBase") { RenderPassPlugin = renderingSetup.MainDepthReadOnlyPlugin })
37  // .Using(new BasicShaderPlugin("TransformationWVP") { RenderPassPlugin = renderingSetup.MainDepthReadOnlyPlugin })
38  // .Using(new BasicShaderPlugin(new ShaderMixinSource()
39  // {
40  // "NormalVSStream",
41  // "PositionVSStream",
42  // new ShaderComposition("albedoDiffuse", new ShaderClassSource("ComputeColorStream")),
43  // new ShaderComposition("albedoSpecular", new ShaderClassSource("ComputeColor")), // TODO: Default values!
44  // "BRDFDiffuseLambert",
45  // "BRDFSpecularBlinnPhong",
46  // }) { RenderPassPlugin = renderingSetup.MainDepthReadOnlyPlugin })
47  // .Using(new BasicShaderPlugin("AlbedoFlatShading") { RenderPassPlugin = renderingSetup.MainDepthReadOnlyPlugin })
48  // .Using(new LightingShaderPlugin { RenderPassPlugin = renderingSetup.LightingPlugin })
49  // //.Using(new BasicShaderPlugin("LightDirectionalShading") { RenderPassPlugin = renderingSetup.MainDepthReadOnlyPlugin })
50  // ;
51 
52  //effect.Permutations.Set(LightingPermutation.Key, new LightingPermutation { Lights = new Light[] { new DirectionalLight { LightColor = new Color3(1.0f), LightDirection = new R32G32B32_Float(-1.0f, -1.0f, 1.0f) } } });
53 
54  var rand = new Random();
55  var cubeMeshData = Enumerable.Range(0, 10).Select(x => MeshDataHelper.CreateBox(10, 10, 10, new Color((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), 1.0f))).ToArray();
56 
57  var effectMeshGroup = new RenderPassListEnumerator();
58  engineContext.RenderContext.RenderPassEnumerators.Add(effectMeshGroup);
59 
60  int objectSqrtCount = 31;
61  int meshCount = objectSqrtCount * objectSqrtCount * objectSqrtCount;
62 
63  for (int j = 0; j < meshCount; ++j)
64  {
65  var effectMesh = new EffectMesh(effect, cubeMeshData[(j / 25) % 10]);
66  effectMesh.KeepAliveBy(engineContext.SimpleComponentRegistry);
67  effectMeshGroup.AddMesh(effectMesh);
68 
69  var w2 = Matrix.Scaling(1.0f)
70  * Matrix.Translation(new Vector3(
71  (j % objectSqrtCount - objectSqrtCount / 2) * 30.0f - 30.0f,
72  (((j / objectSqrtCount) % objectSqrtCount) - objectSqrtCount / 2) * 30.0f - 30.0f,
73  (j / (objectSqrtCount * objectSqrtCount) - objectSqrtCount / 2) * 30.0f - 30.0f));
74 
75  effectMesh.Parameters.Set(TransformationKeys.World, w2);
76  }
77  }
78  }
79 }
static async Task Run(EngineContext engineContext)
SiliconStudio.Core.Mathematics.Color Color
Definition: ColorPicker.cs:14
SiliconStudio.Core.Mathematics.Vector3 Vector3