2 using System.Collections.Generic;
6 using SiliconStudio.Paradox.Engine.Xaml;
7 using SiliconStudio.Paradox.EntityModel;
8 using SiliconStudio.Paradox.Games;
9 using SiliconStudio.Core.IO;
10 using SiliconStudio.Core.Xaml;
11 using SiliconStudio.Paradox;
12 using SiliconStudio.Paradox.DataModel;
13 using SiliconStudio.Paradox.Effects;
14 using SiliconStudio.Paradox.Effects.Modules;
16 using SiliconStudio.Paradox.Effects.Yebis;
18 using SiliconStudio.Paradox.Engine;
19 using SiliconStudio.Paradox.Configuration;
20 using SiliconStudio.Core.Extensions;
21 using SiliconStudio.Paradox.Graphics;
22 using SiliconStudio.Core.Mathematics;
23 using SiliconStudio.Paradox.ObjectModel;
24 using ScriptShader.Effects;
33 private bool lightingRegistered;
36 private IRenderSystem renderSystem;
38 private IEffectSystemOld effectSystemOld;
39 private IEntitySystem entitySystem;
41 private RenderConfigContext RenderConfigContext {
get; set; }
50 renderSystem = registry.GetSafeServiceAs<IRenderSystem>();
52 this.effectSystemOld = registry.GetSafeServiceAs<IEffectSystemOld>();
53 entitySystem = registry.GetSafeServiceAs<IEntitySystem>();
55 var rootRenderPass = renderSystem.RootRenderPass;
56 var dataContext = RenderConfigContext = renderSystem.ConfigContext;
57 var graphicsDevice = graphicsDeviceService.GraphicsDevice;
59 if (effectFilename == null)
60 effectFilename = Path.Combine(
"/shaders/effects.xml");
62 var context =
new ParadoxXamlSchemaContext(dataContext);
63 var xamlObjectWriter =
new XamlObjectWriter(context);
65 using (var fileStream = VirtualFileSystem.OpenStream(effectFilename, VirtualFileMode.Open, VirtualFileAccess.Read))
66 XamlServices.Transform(
new XamlXmlReader(fileStream, context), xamlObjectWriter);
68 var effectConfig = (RenderConfig)xamlObjectWriter.Result;
70 foreach (var renderPass in effectConfig.Content.OfType<
RenderPass>())
72 dataContext.RenderPasses.Add(renderPass.Name, renderPass);
73 rootRenderPass.AddPass(renderPass);
76 foreach (var item
in effectConfig.Content)
81 dataContext.RenderPassPlugins.Add(plugin.Name, plugin);
84 var setter = item as Setter;
87 PropertyPath.SetNextValue(setter.Target, setter.Property, setter.Value);
91 MainPlugin = dataContext.RenderPassPlugins.Select(x => x.Value).OfType<MainPlugin>().First();
92 MainTargetPlugin = dataContext.RenderPassPlugins.Select(x => x.Value).OfType<RenderTargetsPlugin>().FirstOrDefault(x => x.Name ==
"MainTargetPlugin");
94 var mainBackBuffer = graphicsDevice.BackBuffer;
95 MainPlugin.RenderTarget = graphicsDevice.BackBuffer;
98 var depthStencilTexture = Texture2D.New(graphicsDevice, mainBackBuffer.Width, mainBackBuffer.Height, PixelFormat.D32_Float,
100 MainPlugin.DepthStencil = depthStencilTexture.ToDepthStencilBuffer(
false);
107 if (RenderConfigContext.RenderPassPlugins.TryGetValueCast(
"HeatShimmerPlugin", out heatShimmerPlugin))
109 throw new NotImplementedException();
116 var plugins = dataContext.RenderPassPlugins
117 .OrderBy(x => rootRenderPass.Passes.IndexOf(x.Value.RenderPass)).ToArray();
121 var currentTarget = mainBackBuffer;
122 for (
int i = plugins.Length - 1; i >= 0; --i)
124 var plugin = plugins[i];
127 if (targetPlugin != null)
129 if (targetPlugin.RenderTarget == null)
130 targetPlugin.RenderTarget = currentTarget;
132 currentTarget = targetPlugin.RenderTarget;
136 if (sourcePlugin != null)
138 if (sourcePlugin.RenderSource == null)
140 sourcePlugin.RenderSource = Texture2D.New(graphicsDevice, mainBackBuffer.Width, mainBackBuffer.Height, PixelFormat.R16G16B16A16_Float, TextureFlags.ShaderResource | TextureFlags.RenderTarget);
143 currentTarget = sourcePlugin.RenderSource.ToRenderTarget();
147 foreach (var plugin
in dataContext.RenderPassPlugins)
149 renderSystem.RenderPassPlugins.Add(plugin.Value);
152 foreach (var effectBuilder
in effectConfig.Content.OfType<EffectBuilder>())
154 foreach (var plugin
in effectBuilder.Plugins)
156 plugin.Services = registry;
158 this.effectSystemOld.Effects.Add(effectBuilder);
163 if (RenderConfigContext.RenderPassPlugins.TryGetValueCast(
"YebisPlugin", out yebisPlugin))
165 yebisPlugin.AntiAlias =
true;
167 yebisPlugin.ToneMap.Gamma = 2.2f;
168 yebisPlugin.ToneMap.Type = ToneMapType.SensiToMetric;
169 yebisPlugin.ToneMap.AutoExposure.Enable =
true;
170 yebisPlugin.ToneMap.AutoExposure.MiddleGray = 0.25f;
171 yebisPlugin.ToneMap.AutoExposure.AdaptationSensitivity = 0.5f;
172 yebisPlugin.ToneMap.AutoExposure.AdaptationScale = 0.8f;
173 yebisPlugin.ToneMap.AutoExposure.AdaptationSpeedLimit = 4.0f;
174 yebisPlugin.ToneMap.AutoExposure.DarkAdaptationSensitivity = 0.9f;
175 yebisPlugin.ToneMap.AutoExposure.DarkAdaptationScale = 0.6f;
176 yebisPlugin.ToneMap.AutoExposure.DarkAdaptationSpeedLimit = 4.0f;
177 yebisPlugin.ToneMap.AutoExposure.LightDarkExposureBorder = 1.0f;
179 yebisPlugin.Glare.Enable =
true;
183 yebisPlugin.Lens.Vignette.Enable =
true;
185 yebisPlugin.Lens.Distortion.Enable =
false;
186 yebisPlugin.Lens.Distortion.Power = 0.2f;
187 yebisPlugin.Lens.Distortion.EdgeSmoothness = 0.2f;
189 yebisPlugin.DepthOfField.Enable =
true;
190 yebisPlugin.DepthOfField.AutoFocus =
true;
191 yebisPlugin.DepthOfField.Aperture = 2.0f;
192 yebisPlugin.DepthOfField.ImageSensorHeight = 40.0f;
196 yebisPlugin.HeatShimmer.Enable =
false;
204 if (RenderConfigContext.RenderPassPlugins.TryGetValueCast(
"ParticlePlugin", out particlePlugin))
207 entitySystem.Processors.Add(particleSystem);
214 if (RenderConfigContext.RenderPassPlugins.TryGetValueCast(
"WireframePlugin", out wireframePlugin))
215 return wireframePlugin.RenderPass.Enabled = !wireframePlugin.RenderPass.Enabled;
222 if (lightingRegistered)
225 lightingRegistered =
true;
230 RenderConfigContext.RenderPassPlugins.TryGetValueCast(
"LightingPrepassPlugin", out lightingPrepassPlugin);
231 RenderConfigContext.RenderPassPlugins.TryGetValueCast(
"LightingPlugin", out lightingPlugin);
232 if (lightingPrepassPlugin != null || lightingPlugin != null)
235 RenderConfigContext.RenderPassPlugins.TryGetValueCast(
"EditorTargetPlugin", out editorTargetPlugin);
236 var lightProcessor =
new LightProcessor(lightingPlugin, editorTargetPlugin, lightingPrepassPlugin != null ? lightingPrepassPlugin.
Lights : null,
false);
237 entitySystem.Processors.Add(lightProcessor);
241 if (RenderConfigContext.RenderPasses.TryGetValue(
"LightShaftsPass", out lightShaftsPass))
Service providing method to access GraphicsDevice life-cycle.
DepthStencilBuffer DepthStencilReadOnly
void Initialize(IServiceRegistry registry, string effectFilename=null, string[] optionalFeatures=null)
SiliconStudio.Core.IServiceRegistry IServiceRegistry
Plugin used to render to a GBuffer from a MainPlugin.
static readonly RenderingSetup Singleton
Plugin used for the main rendering view.
Level10 render pass using a depth buffer and a render target.
RenderTargetsPlugin MainTargetPlugin
RenderPass is a hierarchy that defines how to collect and render meshes.
Deffered lighting plugin.