Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ScriptSingleSphere.cs
Go to the documentation of this file.
1 using System;
2 using System.Diagnostics;
3 using System.Linq;
4 using System.Threading.Tasks;
5 
6 using SiliconStudio.Paradox.DataModel;
7 using SiliconStudio.Paradox.Effects.Modules;
8 #if PARADOX_YEBIS
9 using Paradox.Effects.Yebis;
10 #endif
11 using SiliconStudio.Paradox.Games;
12 using SiliconStudio.Paradox;
13 using SiliconStudio.Paradox.Effects;
14 using SiliconStudio.Core.Extensions;
15 using SiliconStudio.Paradox.Graphics;
16 using SiliconStudio.Paradox.Graphics.Data;
17 using SiliconStudio.Paradox.Games.IO;
18 using SiliconStudio.Paradox.Games.MicroThreading;
19 using SiliconStudio.Paradox.Games.Mathematics;
20 using Paradox.Framework.Shaders;
21 
22 namespace ScriptTest
23 {
24  [ParadoxScript]
25  public class ScriptSingleSphere
26  {
27  public void Dispose()
28  {
29  //depthTextureHolder.Release();
30  }
31 
32  class Sphere
33  {
34  public EffectMesh Mesh;
35  public float Phase;
36  public float Speed;
37  }
38 
39  struct LightInfo
40  {
41  public float Radius;
42  public float Phase;
43  public float Z;
44  }
45 
46  [ParadoxScript]
47  public static async Task Run(EngineContext engineContext)
48  {
49  var renderingSetup = RenderingSetup.Singleton;
50  renderingSetup.Initialize(engineContext);
51  renderingSetup.RegisterLighting(engineContext);
52 
53 
54 #if PARADOX_YEBIS
55  YebisPlugin yebisPlugin;
56  if (engineContext.DataContext.RenderPassPlugins.TryGetValueCast("YebisPlugin", out yebisPlugin))
57  {
58  yebisPlugin.Glare.Enable = true;
59  yebisPlugin.ToneMap.Exposure = 1.0f;
60  yebisPlugin.ToneMap.Gamma = 2.2f;
61  }
62 #endif
63 
64  EffectOld effect = engineContext.RenderContext.BuildEffect("SimpleCube")
65  .Using(new BasicShaderPlugin("ShaderBase") { RenderPassPlugin = renderingSetup.MainTargetPlugin })
66  .Using(new BasicShaderPlugin("TransformationWVP") { RenderPassPlugin = renderingSetup.MainTargetPlugin })
67  .Using(new BasicShaderPlugin("AlbedoSpecularBase") { RenderPassPlugin = renderingSetup.MainTargetPlugin })
68  .Using(new BasicShaderPlugin("AlbedoDiffuseBase") { RenderPassPlugin = renderingSetup.MainTargetPlugin })
69  .Using(new BasicShaderPlugin("NormalVSGBuffer") { RenderPassPlugin = renderingSetup.MainTargetPlugin })
70  .Using(new BasicShaderPlugin("SpecularPowerPerMesh") { RenderPassPlugin = renderingSetup.MainTargetPlugin })
71  .Using(new BasicShaderPlugin("PositionVSGBuffer") { RenderPassPlugin = renderingSetup.MainTargetPlugin })
72  .Using(new BasicShaderPlugin("BRDFDiffuseLambert") { RenderPassPlugin = renderingSetup.MainTargetPlugin })
73  .Using(new BasicShaderPlugin("BRDFSpecularBlinnPhong") { RenderPassPlugin = renderingSetup.MainTargetPlugin })
74  .Using(new BasicShaderPlugin(new ShaderMixinSource() {
75  new ShaderComposition("albedoDiffuse", new ShaderClassSource("ComputeColorStream"))}) { RenderPassPlugin = renderingSetup.MainTargetPlugin })
76  .Using(new BasicShaderPlugin(new ShaderMixinSource() {
77  new ShaderComposition("albedoSpecular", new ShaderClassSource("ComputeColorSynthetic"))}) { RenderPassPlugin = renderingSetup.MainTargetPlugin })
78  .Using(new GBufferShaderPlugin { RenderPassPlugin = (GBufferPlugin)engineContext.DataContext.RenderPassPlugins.TryGetValue("GBufferPlugin") })
79  .Using(new LightingShaderPlugin() { RenderPassPlugin = (LightingPlugin)engineContext.DataContext.RenderPassPlugins.TryGetValue("LightingPlugin") })
80  .Using(new BasicShaderPlugin("LightDirectionalShading") { RenderPassPlugin = renderingSetup.MainTargetPlugin })
81  ;
82 
83  var shadowMap1 = new ShadowMap(new DirectionalLight() { LightColor = new Color3(1.0f, 1.0f, 1.0f), LightDirection = new Vector3(1.0f, 1.0f, 1.0f) });
84  effect.Permutations.Set(ShadowMapPermutationArray.Key, new ShadowMapPermutationArray { ShadowMaps = { shadowMap1 } });
85 
86  var r = new Random(0);
87 
88 
89  VirtualFileSystem.MountFileSystem("/global_data", "..\\..\\deps\\data\\");
90  VirtualFileSystem.MountFileSystem("/global_data2", "..\\..\\data\\");
91 
92  SkyBoxPlugin skyBoxPlugin;
93  if (engineContext.DataContext.RenderPassPlugins.TryGetValueCast("SkyBoxPlugin", out skyBoxPlugin))
94  {
95  var skyBoxTexture = (Texture2D)await engineContext.AssetManager.LoadAsync<Texture>("/global_data/gdc_demo/bg/GDC2012_map_sky.dds");
96  skyBoxPlugin.Texture = skyBoxTexture;
97  }
98 
99  var effectMeshGroup = new RenderPassListEnumerator();
100  engineContext.RenderContext.RenderPassEnumerators.Add(effectMeshGroup);
101 
102  var groundMesh = new EffectMesh(effect, MeshDataHelper.CreateBox(10000, 10000, 1, Color.White));
103  groundMesh.KeepAliveBy(engineContext.SimpleComponentRegistry);
104  effectMeshGroup.AddMesh(groundMesh);
105  groundMesh.Parameters.Set(TransformationKeys.World, Matrix.Translation(new Vector3(0, 0, 0)));
106 
107  var meshData = MeshDataHelper.CreateSphere(200, 30, 30, Color.Gray);
108  var sphereMesh = new EffectMesh(effect, meshData);
109  sphereMesh.Parameters.Set(TransformationKeys.World,Matrix.Translation(new Vector3(0, 0, 50)));
110  sphereMesh.Parameters.Set(MaterialKeys.SpecularPower, 0f);
111  sphereMesh.Parameters.Set(MaterialKeys.SpecularColor, Color.White);
112  effectMeshGroup.AddMesh(sphereMesh);
113 
114  //while (true)
115  //{
116  // await Scheduler.Current.WaitFrame();
117 
118 
119  // for (int iy = 0; iy < sizeY; iy++)
120  // {
121  // for (int ix = 0; ix < sizeX; ix++)
122  // {
123  // var iFactor = (float)(iy * sizeY + ix) / (sizeX * sizeY);
124 
125  // var sphere = spheres[iy, ix];
126  // var sphereMesh = sphere.Mesh;
127  // var specularColor = R8G8B8A8.SmoothStep(R8G8B8A8.GreenYellow, R8G8B8A8.Gray, iFactor);
128 
129  // // Matrix.RotationX((float)Math.PI/2.0f) * M
130  // sphereMesh.Parameters.Set(
131  // TransformationKeys.World,
132  // Matrix.Translation(
133  // new R32G32B32_Float(
134  // (ix - sizeX / 2) * (size * 1.2f) * 2.0f,
135  // (iy - sizeY / 2) * (size * 1.2f) * 2.0f,
136  // (float)(2000 * (0.5 + 0.5 * Math.Sin(clock.ElapsedMilliseconds / 1000.0f * sphere.Speed * 0.5f + Math.PI * sphere.Phase))))));
137  // sphereMesh.Parameters.Set(MaterialKeys.SpecularPower, iFactor * 0.9f);
138  // sphereMesh.Parameters.Set(MaterialKeys.SpecularColor, specularColor);
139  // }
140  // }
141 
142  // time = clock.ElapsedMilliseconds / 1000.0f;
143 
144  // if (lightInfo.Length > 0)
145  // {
146  // int index = 0;
147  // foreach (var mesh in effectLight.Meshes)
148  // {
149  // mesh.Parameters.Set(LightKeys.LightPosition, new R32G32B32_Float(lightInfo[index].Radius * (float)Math.Cos(-time * 0.17f + lightInfo[index].Phase), lightInfo[index].Radius * (float)Math.Sin(-time * 0.05f + lightInfo[index].Phase), lightInfo[index].Z * (0.5f + 0.5f * (float)Math.Sin(-time * 0.1f + lightInfo[index].Phase * 2.0f))));
150  // index++;
151  // }
152  // }
153  //}
154  }
155  }
156 }
static async Task Run(EngineContext engineContext)
Plugin used to render to a GBuffer from a MainPlugin.
Represents a ShadowMap.
Definition: ShadowMap.cs:11
Shader effect used with GBufferPlugin
static readonly RenderingSetup Singleton
SiliconStudio.Core.Mathematics.Color Color
Definition: ColorPicker.cs:14
A Texture 2D frontend to SharpDX.Direct3D11.Texture2D.
Definition: Texture2D.cs:37
SiliconStudio.Core.Mathematics.Vector3 Vector3
Base class for texture resources.
Definition: Texture.cs:38