2 using System.Diagnostics;
4 using System.Threading.Tasks;
6 using SiliconStudio.Paradox.DataModel;
7 using SiliconStudio.Paradox.Effects.Modules;
9 using Paradox.Effects.Yebis;
11 using SiliconStudio.Paradox.Engine;
12 using SiliconStudio.Paradox.EntityModel;
13 using SiliconStudio.Paradox.Games;
14 using SiliconStudio.Paradox;
15 using SiliconStudio.Paradox.Effects;
16 using SiliconStudio.Core.Extensions;
17 using SiliconStudio.Paradox.Graphics;
18 using SiliconStudio.Paradox.Graphics.Data;
19 using SiliconStudio.Paradox.Games.IO;
20 using SiliconStudio.Paradox.Games.MicroThreading;
21 using SiliconStudio.Paradox.Games.Mathematics;
22 using Paradox.Framework.Shaders;
36 public EffectMesh
Mesh;
52 renderingSetup.RegisterLighting(engineContext);
56 if (engineContext.DataContext.RenderPassPlugins.TryGetValueCast(
"YebisPlugin", out yebisPlugin))
58 yebisPlugin.Glare.Enable =
false;
59 yebisPlugin.DepthOfField.Enable =
false;
60 yebisPlugin.ToneMap.AutoExposure.Enable =
false;
61 yebisPlugin.ToneMap.Exposure = 1.0f;
62 yebisPlugin.ToneMap.Gamma = 2.2f;
65 var lightPrepassPlugin = (
LightingPrepassPlugin)engineContext.DataContext.RenderPassPlugins.TryGetValue(
"LightingPrepassPlugin");
66 var gbufferPlugin = (
GBufferPlugin)engineContext.DataContext.RenderPassPlugins.TryGetValue(
"GBufferPlugin");
68 EffectOld effect = engineContext.RenderContext.BuildEffect(
"SimpleCube")
69 .Using(
new BasicShaderPlugin(
"ShaderBase") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
70 .Using(
new BasicShaderPlugin(
"TransformationWVP") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
71 .Using(
new BasicShaderPlugin(
"AlbedoSpecularBase") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
72 .Using(
new BasicShaderPlugin(
"AlbedoDiffuseBase") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
73 .Using(
new BasicShaderPlugin(
"NormalVSGBuffer") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
74 .Using(
new BasicShaderPlugin(
"SpecularPowerPerMesh") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
75 .Using(
new BasicShaderPlugin(
"PositionVSGBuffer") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
76 .Using(
new BasicShaderPlugin(
"BRDFDiffuseLambert") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
77 .Using(
new BasicShaderPlugin(
"BRDFSpecularBlinnPhong") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
78 .Using(
new BasicShaderPlugin(
new ShaderMixinSource() {
79 new ShaderComposition(
"albedoDiffuse",
new ShaderClassSource(
"ComputeColorStream"))}) {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
80 .Using(
new BasicShaderPlugin(
new ShaderMixinSource() {
81 new ShaderComposition(
"albedoSpecular",
new ShaderClassSource(
"ComputeColorSynthetic"))}) {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
84 .Using(
new BasicShaderPlugin(
"LightDirectionalShading") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
87 EffectOld effect2 = engineContext.RenderContext.BuildEffect(
"SimpleSkinning")
88 .Using(
new BasicShaderPlugin(
"ShaderBase") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
89 .Using(
new BasicShaderPlugin(
"TransformationWVP") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
90 .Using(
new BasicShaderPlugin(
"TransformationSkinning") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
91 .Using(
new BasicShaderPlugin(
"AlbedoSpecularBase") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
92 .Using(
new BasicShaderPlugin(
"AlbedoDiffuseBase") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
93 .Using(
new BasicShaderPlugin(
"NormalVSGBuffer") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
94 .Using(
new BasicShaderPlugin(
"SpecularPowerPerMesh") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
95 .Using(
new BasicShaderPlugin(
"PositionVSGBuffer") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
96 .Using(
new BasicShaderPlugin(
"BRDFDiffuseLambert") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
97 .Using(
new BasicShaderPlugin(
"BRDFSpecularBlinnPhong") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
98 .Using(
new BasicShaderPlugin(
new ShaderMixinSource() {
99 new ShaderClassSource(
"AlbedoDiffuseBase"),
100 new ShaderComposition(
"albedoDiffuse",
new ShaderClassSource(
"ComputeColorTexture",
TexturingKeys.DiffuseTexture.Name,
"TEXCOORD")),
101 new ShaderComposition(
"albedoSpecular",
new ShaderClassSource(
"ComputeColor")),
105 .Using(
new BasicShaderPlugin(
"LightDirectionalShading") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
112 var entityCube =
new Entity(
"Cube");
114 meshComponent.SubMeshes.Add(
new EffectMeshData { EffectData =
new EffectData(
"SimpleCube"), MeshData = MeshDataHelper.CreateBox(100.0f, 100.0f, 100.0f, Color.Gray) });
115 entityCube.Set(ModelComponent.Key, meshComponent);
117 engineContext.AssetManager.Url.Set(entityCube,
"/global_data/cube.hotei#/root");
118 engineContext.AssetManager.Save(entityCube);
120 var entitySphere =
new Entity(
"Cube");
122 meshComponent.SubMeshes.Add(
new EffectMeshData { EffectData =
new EffectData(
"SimpleCube"), MeshData = MeshDataHelper.CreateSphere(100.0f, 30, 30, Color.Gray) });
123 entitySphere.Set(ModelComponent.Key, meshComponent);
125 engineContext.AssetManager.Url.Set(entitySphere,
"/global_data/sphere.hotei#/root");
126 engineContext.AssetManager.Save(entitySphere);
130 public static async
Task Run(EngineContext engineContext)
133 renderingSetup.Initialize(engineContext);
134 renderingSetup.RegisterLighting(engineContext);
138 if (engineContext.DataContext.RenderPassPlugins.TryGetValueCast(
"YebisPlugin", out yebisPlugin))
140 yebisPlugin.Glare.Enable =
true;
141 yebisPlugin.ToneMap.Exposure = 1.0f;
142 yebisPlugin.ToneMap.Gamma = 2.2f;
146 var lightPrepassPlugin = (
LightingPrepassPlugin)engineContext.DataContext.RenderPassPlugins.TryGetValue(
"LightingPrepassPlugin");
147 var gbufferPlugin = (
GBufferPlugin)engineContext.DataContext.RenderPassPlugins.TryGetValue(
"GBufferPlugin");
149 EffectOld effect = engineContext.RenderContext.BuildEffect(
"SimpleCube")
150 .Using(
new BasicShaderPlugin(
"ShaderBase") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
151 .Using(
new BasicShaderPlugin(
"TransformationWVP") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
152 .Using(
new BasicShaderPlugin(
"AlbedoSpecularBase") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
153 .Using(
new BasicShaderPlugin(
"AlbedoDiffuseBase") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
154 .Using(
new BasicShaderPlugin(
"NormalVSGBuffer") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
155 .Using(
new BasicShaderPlugin(
"SpecularPowerPerMesh") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
156 .Using(
new BasicShaderPlugin(
"PositionVSGBuffer") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
157 .Using(
new BasicShaderPlugin(
"BRDFDiffuseLambert") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
158 .Using(
new BasicShaderPlugin(
"BRDFSpecularBlinnPhong") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
159 .Using(
new BasicShaderPlugin(
new ShaderMixinSource() {
160 new ShaderComposition(
"albedoDiffuse",
new ShaderClassSource(
"ComputeColorStream"))}) {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
161 .Using(
new BasicShaderPlugin(
new ShaderMixinSource() {
162 new ShaderComposition(
"albedoSpecular",
new ShaderClassSource(
"ComputeColorSynthetic"))}) {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
166 .Using(
new BasicShaderPlugin(
"LightDirectionalShading") {
RenderPassPlugin = renderingSetup.MainTargetPlugin })
172 var r =
new Random(0);
175 VirtualFileSystem.MountFileSystem(
"/global_data",
"..\\..\\deps\\data\\");
176 VirtualFileSystem.MountFileSystem(
"/global_data2",
"..\\..\\data\\");
179 if (engineContext.DataContext.RenderPassPlugins.TryGetValueCast(
"SkyBoxPlugin", out skyBoxPlugin))
181 var skyBoxTexture = (
Texture2D)await engineContext.AssetManager.LoadAsync<
Texture>(
"/global_data/gdc_demo/bg/GDC2012_map_sky.dds");
182 skyBoxPlugin.Texture = skyBoxTexture;
185 var effectMeshGroup =
new RenderPassListEnumerator();
186 engineContext.RenderContext.RenderPassEnumerators.Add(effectMeshGroup);
188 var groundMesh =
new EffectMesh(effect, MeshDataHelper.CreateBox(10000, 10000, 1,
Color.White));
189 groundMesh.KeepAliveBy(engineContext.SimpleComponentRegistry);
190 effectMeshGroup.AddMesh(groundMesh);
191 groundMesh.Parameters.Set(TransformationKeys.World, Matrix.Translation(
new Vector3(0, 0, 0)));
194 for (
int i = 0; i < 1024; ++i)
197 Color3 color = (Color3)
Color.White;
201 case 0: color = (Color3)
Color.DarkOrange;
break;
202 case 1: color = (Color3)Color.DarkGoldenrod;
break;
203 case 2: color = (Color3)
Color.DarkSalmon;
break;
204 case 3: color = (Color3)Color.DarkRed;
break;
206 var effectMesh =
new EffectMesh(lightPrepassPlugin.Lights);
207 effectMesh.Parameters.Set(LightKeys.LightRadius, (float)r.NextDouble() * 200 + 200.0f);
208 effectMesh.Parameters.Set(LightKeys.LightColor, color);
209 effectMesh.KeepAliveBy(engineContext.SimpleComponentRegistry);
211 effectMeshGroup.AddMesh(effectMesh);
214 EffectOld effectLight = lightPrepassPlugin.Lights;
216 var lightInfo =
new LightInfo[effectLight != null ? effectLight.Meshes.Count : 0];
217 for (
int i = 0; i < lightInfo.Length; ++i)
219 lightInfo[i].Radius = (float)r.NextDouble() * 7000.0f + 500.0f;
220 lightInfo[i].Phase = (float)(r.NextDouble() * Math.PI * 2.0);
221 lightInfo[i].Z = (float)r.NextDouble() * 3000.0f; ;
242 var clock =
new Stopwatch();
249 var spheres =
new Sphere[sizeY,sizeX];
251 Random random =
new Random(0);
254 var meshData = MeshDataHelper.CreateSphere(
size, 30, 30, Color.Gray);
256 for (
int iy = 0; iy < sizeY; iy++)
258 for (
int ix = 0; ix < sizeX; ix++)
260 var sphere =
new Sphere();
262 sphere.Mesh =
new EffectMesh(effect, meshData);
263 sphere.Phase = (float)random.NextDouble();
264 sphere.Speed = (float)random.NextDouble();
266 spheres[iy, ix] = sphere;
267 effectMeshGroup.AddMesh(sphere.Mesh);
274 await Scheduler.Current.NextFrame();
277 for (
int iy = 0; iy < sizeY; iy++)
279 for (
int ix = 0; ix < sizeX; ix++)
281 var iFactor = (float)(iy * sizeY + ix) / (sizeX * sizeY);
283 var sphere = spheres[iy, ix];
284 var sphereMesh = sphere.Mesh;
285 var specularColor = Color.SmoothStep(Color.GreenYellow, Color.Gray, iFactor);
288 sphereMesh.Parameters.Set(
289 TransformationKeys.World,
292 (ix - sizeX / 2) * (size * 1.2f) * 2.0f,
293 (iy - sizeY / 2) * (size * 1.2f) * 2.0f,
294 (
float)(2000 * (0.5 + 0.5 * Math.Sin(clock.ElapsedMilliseconds / 1000.0f * sphere.Speed * 0.5f + Math.PI * sphere.Phase))))));
295 sphereMesh.Parameters.Set(MaterialKeys.SpecularPower, iFactor * 0.9f);
296 sphereMesh.Parameters.Set(MaterialKeys.SpecularColor, specularColor);
300 time = clock.ElapsedMilliseconds / 1000.0f;
302 if (lightInfo.Length > 0)
305 foreach (var mesh
in effectLight.Meshes)
307 mesh.Parameters.Set(LightKeys.LightPosition,
new Vector3(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))));
static async Task Run(EngineContext engineContext)
Game entity. It usually aggregates multiple EntityComponent
Plugin used to render to a GBuffer from a MainPlugin.
static async Task GenerateTestPrefabs(EngineContext engineContext)
Shader effect used with GBufferPlugin
static readonly RenderingSetup Singleton
Shader used with LightingPrepassPlugin.
SiliconStudio.Core.Mathematics.Color Color
A Texture 2D frontend to SharpDX.Direct3D11.Texture2D.
Add a Model to an Entity, that will be used during rendering.
SiliconStudio.Core.Mathematics.Vector3 Vector3
static async Task GenerateSimpleCubeEffect(EngineContext engineContext)
_In_ size_t _In_ size_t size
Deffered lighting plugin.
Base class for texture resources.