6 using SiliconStudio.Core;
7 using SiliconStudio.Core.Mathematics;
8 using SiliconStudio.Paradox.Effects.Modules.Processors;
9 using SiliconStudio.Paradox.Engine;
10 using SiliconStudio.Paradox.EntityModel;
11 using SiliconStudio.Paradox.Graphics;
13 namespace SiliconStudio.
Paradox.Effects.Modules.Renderers
20 #region Private static members
45 #region Private members
51 private bool renderInSinglePass;
67 throw new Exception(
"Cubemaps not supported on profiles below 10.1.");
68 renderInSinglePass = singlePass && (GraphicsDevice.Features.Profile >= GraphicsProfile.Level_10_1);
73 #region Protected methods
77 var entitySystem = Services.GetServiceAs<
EntitySystem>();
79 if (cubemapSourceProcessor == null)
82 foreach (var source
in cubemapSourceProcessor.Cubemaps)
84 if (source.Value.IsDynamic)
86 if (renderInSinglePass)
87 RenderInSinglePass(context, source.Key, source.Value);
89 RenderInSixPasses(context, source.Key, source.Value);
96 #region Private methods
106 var cameraPos = entity.Transformation.Translation;
107 for (var i = 0; i < 6; ++i)
111 ComputeViewProjectionMatrices(cameraPos, TargetPositions[i], CameraUps[i], component, out worldToCamera, out projection);
114 GraphicsDevice.Parameters.Set(TransformationKeys.View, worldToCamera);
115 GraphicsDevice.Parameters.Set(TransformationKeys.Projection, projection);
116 GraphicsDevice.Parameters.Set(CameraKeys.NearClipPlane, component.NearPlane);
117 GraphicsDevice.Parameters.Set(CameraKeys.FarClipPlane, component.FarPlane);
118 GraphicsDevice.Parameters.Set(CameraKeys.FieldOfView, MathUtil.PiOverTwo);
119 GraphicsDevice.Parameters.Set(CameraKeys.Aspect, 1);
122 component.CreateSingleViewRenderTargets();
124 var renderTarget = component.RenderTargets[i];
125 GraphicsDevice.Clear(component.DepthStencil, DepthStencilClearOptions.DepthBuffer);
126 GraphicsDevice.Clear(renderTarget, Color.Black);
128 GraphicsDevice.SetRenderTargets(component.DepthStencil, renderTarget);
132 base.OnRendering(context);
135 GraphicsDevice.SetRenderTarget(GraphicsDevice.DepthStencilBuffer, GraphicsDevice.BackBuffer);
137 GraphicsDevice.Parameters.Remove(TransformationKeys.View);
138 GraphicsDevice.Parameters.Remove(TransformationKeys.Projection);
139 GraphicsDevice.Parameters.Remove(CameraKeys.NearClipPlane);
140 GraphicsDevice.Parameters.Remove(CameraKeys.FarClipPlane);
141 GraphicsDevice.Parameters.Remove(CameraKeys.FieldOfView);
142 GraphicsDevice.Parameters.Remove(CameraKeys.Aspect);
143 GraphicsDevice.Parameters.Remove(CameraKeys.FocusDistance);
154 var cameraPos = component.Entity.Transformation.Translation;
155 for (var i = 0; i < 6; ++i)
159 ComputeViewProjectionMatrices(cameraPos, TargetPositions[i], CameraUps[i], component, out worldToCamera, out projection);
160 cameraViewProjMatrices[i] = worldToCamera * projection;
164 GraphicsDevice.Parameters.Set(CameraCubeKeys.CameraViewProjectionMatrices, cameraViewProjMatrices);
165 GraphicsDevice.Parameters.Set(CameraCubeKeys.CameraWorldPosition, cameraPos);
168 component.CreateFullViewRenderTarget();
170 GraphicsDevice.Clear(component.DepthStencil, DepthStencilClearOptions.DepthBuffer);
171 GraphicsDevice.Clear(component.RenderTarget, Color.Black);
173 GraphicsDevice.SetRenderTargets(component.DepthStencil, component.RenderTarget);
175 base.OnRendering(context);
177 GraphicsDevice.SetRenderTarget(GraphicsDevice.DepthStencilBuffer, GraphicsDevice.BackBuffer);
179 GraphicsDevice.Parameters.Remove(CameraCubeKeys.CameraViewProjectionMatrices);
180 GraphicsDevice.Parameters.Remove(CameraCubeKeys.CameraWorldPosition);
189 viewMatrix = Matrix.LookAtRH(position, position + faceOffset, up);
190 Matrix.PerspectiveFovRH(MathUtil.PiOverTwo, 1, source.NearPlane, source.FarPlane, out projection);
RenderTarget RenderTarget
The render target of the cubemap.
Game entity. It usually aggregates multiple EntityComponent
Puts a cubemap at the containing entity location. This could be dynamic (runtime rendered) or static ...
Represents a three dimensional mathematical vector.
A service registry is a IServiceProvider that provides methods to register and unregister services...
Performs primitive-based rendering, creates resources, handles system-level variables, adjusts gamma ramp levels, and creates shaders. See The+GraphicsDevice+class to learn more about the class.
This Renderer recursively render another RenderPass.
Thread-local storage context used during rendering.
GraphicsDeviceFeatures Features
Gets the features supported by this graphics device.
RenderTarget[] RenderTargets
The render targets of the cubemap.
Manage a collection of entities.
Keeps tracks of the active cubemaps.
override void OnRendering(RenderContext context)
CubemapRenderer(IServiceRegistry services, RenderPipeline recursivePipeline, bool singlePass)
CubemapRenderer constructor.
GraphicsProfile
Identifies the set of supported devices for the demo based on device capabilities.
Defines an entry point for mesh instantiation and recursive rendering.
GraphicsProfile Profile
Features level of the current device.
Represents a 4x4 mathematical matrix.