6 using SiliconStudio.Core;
7 using SiliconStudio.Core.Mathematics;
8 using SiliconStudio.Paradox.Effects.Modules.Processors;
9 using SiliconStudio.Paradox.EntityModel;
10 using SiliconStudio.Paradox.Graphics;
12 namespace SiliconStudio.
Paradox.Effects.Modules.Renderers
19 #region Public static members
25 #region Private members
27 private string specularEffectName;
29 private bool clearTarget;
31 private bool externRenderTarget;
49 #region Public properties
58 return IBLRenderTarget == null ? null : IBLRenderTarget.Texture;
76 if (depthBuffer == null)
77 throw new ArgumentNullException(
"depthBuffer");
79 specularEffectName = effectName ??
"CubemapIBLSpecular";
81 readOnlyDepthBuffer = depthBuffer;
83 if (renderTarget != null)
85 if (renderTarget.Width != readOnlyDepthBuffer.Description.Width
86 || renderTarget.Height != readOnlyDepthBuffer.Description.Height)
87 throw new Exception(
"Size of readOnlyDepthBuffer and renderTarget do not match.");
88 IBLRenderTarget = renderTarget;
89 externRenderTarget =
true;
92 clearTarget = clearRenderTarget;
97 #region Public methods
105 if (IBLRenderTarget == null)
106 IBLRenderTarget = Texture2D.New(
GraphicsDevice, readOnlyDepthBuffer.Description.Width, readOnlyDepthBuffer.Description.Height, PixelFormat.R16G16B16A16_Float, TextureFlags.ShaderResource | TextureFlags.RenderTarget).ToRenderTarget();
108 cubemapMesh = GeometricPrimitive.Cube.New(GraphicsDevice);
112 RenderTargets =
new[]
117 ColorSourceBlend = Blend.SourceAlpha,
118 ColorDestinationBlend = Blend.One,
119 ColorBlendFunction = BlendFunction.Add,
120 AlphaSourceBlend = Blend.One,
121 AlphaDestinationBlend = Blend.One,
122 AlphaBlendFunction = BlendFunction.Add,
127 IBLBlendState = BlendState.New(GraphicsDevice, blendStateDescr);
132 StencilEnable =
false,
133 DepthBufferFunction = CompareFunction.GreaterEqual,
137 IBLEffect = EffectSystem.LoadEffect(specularEffectName);
140 parameters.Set(RenderTargetKeys.DepthStencilSource, readOnlyDepthBuffer.Texture);
150 Utilities.Dispose(ref IBLEffect);
151 Utilities.Dispose(ref IBLDepthStencilState);
152 Utilities.Dispose(ref IBLBlendState);
153 Utilities.Dispose(ref cubemapMesh);
154 if (!externRenderTarget)
155 Utilities.Dispose(ref IBLRenderTarget);
160 #region Private methods
164 var entitySystem = Services.GetServiceAs<
EntitySystem>();
166 if (cubemapSourceProcessor == null)
171 GraphicsDevice.Clear(IBLRenderTarget,
new Color4(0, 0, 0, 0));
174 if (cubemapSourceProcessor.Cubemaps.Count <= 0)
178 GraphicsDevice.SetRenderTarget(readOnlyDepthBuffer, IBLRenderTarget);
181 GraphicsDevice.SetDepthStencilState(IBLDepthStencilState);
184 GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.CullFront);
187 GraphicsDevice.SetBlendState(IBLBlendState);
189 foreach (var cubemap
in cubemapSourceProcessor.Cubemaps)
193 parameters.Set(TransformationKeys.World, ComputeTransformationMatrix(cubemap.Value.InfluenceRadius, cubemap.Key.Transformation.Translation));
194 parameters.Set(CubemapIBLBaseKeys.CubemapRadius, cubemap.Value.InfluenceRadius);
195 parameters.Set(CubemapIBLBaseKeys.Cubemap, cubemap.Value.Texture);
196 parameters.Set(CubemapIBLBaseKeys.CubemapPosition, cubemap.Key.Transformation.Translation);
199 IBLEffect.Apply(parameters, context.CurrentPass.Parameters);
205 IBLEffect.UnbindResources();
208 GraphicsDevice.SetDepthStencilState(GraphicsDevice.DepthStencilStates.None);
209 GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.CullBack);
210 GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.Default);
LightingIBLRenderer(IServiceRegistry services, string effectName, DepthStencilBuffer depthBuffer, RenderTarget renderTarget=null, bool clearRenderTarget=true)
This renderer will compute the cubemap influence on the scene. It supposes a deferred shading/renderi...
Key of an effect parameter.
A renderable texture view.
override void Unload()
Unloads this instance. This method is called when a RenderPass is de-attached (directly or indirectly...
Contains depth-stencil state for the device.
Computes cubemaps contribution of the ambient specular.
Performs render pipeline transformations attached to a specific RenderPass.
A geometric primitive. Use Cube, Cylinder, GeoSphere, Plane, Sphere, Teapot, Torus. See Draw+vertices to learn how to use it.
Represents a three dimensional mathematical vector.
A service registry is a IServiceProvider that provides methods to register and unregister services...
static void Translation(ref Vector3 value, out Matrix result)
Creates a translation matrix using the specified offsets.
Represents a color in the form of rgba.
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.
override void Load()
Loads this instance. This method is called when a RenderPass is attached (directly or indirectly) to ...
Thread-local storage context used during rendering.
override void OnRendering(RenderContext context)
Manage a collection of entities.
Keeps tracks of the active cubemaps.
ColorWriteChannels
Identify which components of each pixel of a render target are writable during blending.
Describes a depth stencil state.
Describes the blend state for a render target.
_In_ size_t _In_ size_t size
A container to handle a hierarchical collection of effect variables.
Base class for texture resources.
Represents a 4x4 mathematical matrix.