/// <inheritdoc/> public override void Initialize() { base.Initialize(); graphicsDeviceService = Services.GetServiceAs<IGraphicsDeviceService>(); var graphicsDevice = graphicsDeviceService.GraphicsDevice; Parameters.AddSources(MainPlugin.ViewParameters); if (OfflineCompilation) return; // Create texture used for normal packing var texture2D = Texture.New2D(GraphicsDevice, 1024, 1024, 1, PixelFormat.A8_UNorm); texture2D.Name = "Renorm"; // Load normal packing data var texDataStream = VirtualFileSystem.OpenStream("/assets/effects/gbuffer/renorm.bin", VirtualFileMode.Open, VirtualFileAccess.Read); var texFileLength = texDataStream.Length; var texData = new byte[texFileLength]; texDataStream.Read(texData, 0, (int)texFileLength); texture2D.SetData(graphicsDevice, texData); texDataStream.Dispose(); // Force custom depth stencil state on main pass var mainDepthStencilState = MainTargetPlugin.Parameters.TryGet(EffectPlugin.DepthStencilStateKey) ?? graphicsDevice.DepthStencilStates.Default; MainTargetPlugin.Parameters.Set(EffectPlugin.DepthStencilStateKey, mainDepthStencilState); // Use depth stencil value from MainPlugin var defaultDescription = mainDepthStencilState.Description; ClearDepth = MainTargetPlugin.ClearDepth; // Use Default ZTest for GBuffer var depthStencilStateZStandard = DepthStencilState.New(GraphicsDevice, defaultDescription); depthStencilStateZStandard.Name = "ZStandard"; Parameters.Set(EffectPlugin.DepthStencilStateKey, depthStencilStateZStandard); Parameters.Set(GBufferKeys.NormalPack, texture2D); Parameters.Set(TexturingKeys.PointSampler, graphicsDevice.SamplerStates.PointWrap); // MainPlugin is going to use the readonly depth stencil buffer if (DepthStencilBuffer.IsReadOnlySupported(GraphicsDevice)) { MainTargetPlugin.UseDepthStencilReadOnly = true; MainTargetPlugin.Parameters.Set(RenderTargetKeys.DepthStencilSource, DepthStencil.Texture); MainTargetPlugin.DepthStencilReadOnly = DepthStencil.Texture.ToDepthStencilBuffer(true); } else { RenderPass.EndPass += (context) => { //context.GraphicsDevice.Copy(DepthStencil //DepthStencil.SynchronizeReadonly(context.GraphicsDevice) }; } defaultDescription = mainDepthStencilState.Description; defaultDescription.DepthBufferWriteEnable = false; DepthStencilStateZReadOnly = DepthStencilState.New(GraphicsDevice,defaultDescription); DepthStencilStateZReadOnly.Name = "ZReadOnly"; // Create normal texture (that LightPlugin will use) var gbufferTexture = Texture.New2D(GraphicsDevice, graphicsDevice.BackBuffer.Width, graphicsDevice.BackBuffer.Height, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget); gbufferTexture.Name = "GBufferTexture"; Parameters.Set(GBufferBaseKeys.GBufferTexture, gbufferTexture); RenderTarget = gbufferTexture.ToRenderTarget(); // Set parameters for MainPlugin MainTargetPlugin.Parameters.Set(GBufferBaseKeys.GBufferTexture, gbufferTexture); }
public DefaultModalElementRenderer(IServiceRegistry services) : base(services) { noStencilNoDepth = DepthStencilState.New(GraphicsDevice, new DepthStencilStateDescription(false, false)); }
protected override void LoadContent() { base.LoadContent(); // create effect and geometric primitives Batch = new UIBatch(GraphicsDevice); // create depth stencil states var depthStencilDescription = new DepthStencilStateDescription(true, true) { StencilEnable = true, FrontFace = new DepthStencilStencilOpDescription { StencilDepthBufferFail = StencilOperation.Keep, StencilFail = StencilOperation.Keep, StencilPass = StencilOperation.Keep, StencilFunction = CompareFunction.Equal }, BackFace = new DepthStencilStencilOpDescription { StencilDepthBufferFail = StencilOperation.Keep, StencilFail = StencilOperation.Keep, StencilPass = StencilOperation.Keep, StencilFunction = CompareFunction.Equal }, }; KeepStencilValueState = DepthStencilState.New(GraphicsDevice, depthStencilDescription); depthStencilDescription.FrontFace.StencilPass = StencilOperation.Increment; depthStencilDescription.BackFace.StencilPass = StencilOperation.Increment; IncreaseStencilValueState = DepthStencilState.New(GraphicsDevice, depthStencilDescription); depthStencilDescription.FrontFace.StencilPass = StencilOperation.Decrement; depthStencilDescription.BackFace.StencilPass = StencilOperation.Decrement; DecreaseStencilValueState = DepthStencilState.New(GraphicsDevice, depthStencilDescription); // set the default design of the UI elements. var designsTexture = TextureExtensions.FromFileData(GraphicsDevice, DefaultDesigns.Designs); Button.PressedImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Default button pressed design", designsTexture) { Borders = 8 * Vector4.One, Region = new RectangleF(71, 3, 32, 32)}); Button.NotPressedImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Default button not pressed design", designsTexture) { Borders = 8 * Vector4.One, Region = new RectangleF(3, 3, 32, 32) }); Button.MouseOverImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Default button overred design", designsTexture) { Borders = 8 * Vector4.One, Region = new RectangleF(37, 3, 32, 32) }); EditText.ActiveImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Default edit active design", designsTexture) { Borders = 12 * Vector4.One, Region = new RectangleF(105, 3, 32, 32) }); EditText.InactiveImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Default edit inactive design", designsTexture) { Borders = 12 * Vector4.One, Region = new RectangleF(139, 3, 32, 32) }); EditText.MouseOverImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Default edit overred design", designsTexture) { Borders = 12 * Vector4.One, Region = new RectangleF(173, 3, 32, 32) }); ToggleButton.CheckedImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Default toggle button checked design", designsTexture) { Borders = 8 * Vector4.One, Region = new RectangleF(71, 3, 32, 32) }); ToggleButton.UncheckedImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Default toggle button unchecked design", designsTexture) { Borders = 8 * Vector4.One, Region = new RectangleF(3, 3, 32, 32) }); ToggleButton.IndeterminateImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Default toggle button indeterminate design", designsTexture) { Borders = 8 * Vector4.One, Region = new RectangleF(37, 3, 32, 32) }); Slider.TrackBackgroundImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Default slider track background design", designsTexture) { Borders = 14 * Vector4.One, Region = new RectangleF(207, 3, 32, 32) }); Slider.TrackForegroundImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Default slider track foreground design", designsTexture) { Borders = 0 * Vector4.One, Region = new RectangleF(3, 37, 32, 32) }); Slider.ThumbImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Default slider thumb design", designsTexture) { Borders = 4 * Vector4.One, Region = new RectangleF(37, 37, 16, 32) }); Slider.MouseOverThumbImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Default slider thumb overred design", designsTexture) { Borders = 4 * Vector4.One, Region = new RectangleF(71, 37, 16, 32) }); Slider.TickImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Default slider track foreground design", designsTexture) { Region = new RectangleF(245, 3, 3, 6) }); Slider.TickOffsetPropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(13f); Slider.TrackStartingOffsetsrPropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new Vector2(3)); }
public override void Load() { base.Load(); if (OfflineCompilation) return; // Declare post render pass PostPass = new RenderPass("PostPass").KeepAliveBy(ActiveObjects); RenderPass.AddPass(PostPass); var depthStencilTexture = Texture.New2D(GraphicsDevice, AtlasSize, AtlasSize, PixelFormat.D32_Float, TextureFlags.DepthStencil | TextureFlags.ShaderResource).KeepAliveBy(ActiveObjects); var depthStencilBuffer = depthStencilTexture.ToDepthStencilBuffer(false); ShadowMapDepth = depthStencilBuffer; //MainTargetPlugin.Parameters.Set(ShadowMapKeys.Texture0, ShadowMapDepth); // Setup clear of this target var renderTargetPlugin = new RenderTargetsPlugin { Services = Services, EnableClearDepth = true, EnableSetTargets = false, RenderPass = RenderPass, RenderTarget = null, DepthStencil = depthStencilBuffer, }; renderTargetPlugin.Apply(); // Use Default ZTest for GBuffer depthStencilStateZStandard = DepthStencilState.New(GraphicsDevice, new DepthStencilStateDescription().Default()).KeepAliveBy(ActiveObjects); depthStencilStateZStandard.Name = "ZStandard"; Parameters.Set(EffectPlugin.DepthStencilStateKey, depthStencilStateZStandard); casterRasterizerState = RasterizerState.New(GraphicsDevice, new RasterizerStateDescription(CullMode.Back)).KeepAliveBy(ActiveObjects); // Variance Shadow Mapping // Create the blur temporary texture var shadowMapTextureDesc = ShadowMapDepth.Description; var shadowMapBlurH = Texture.New2D(GraphicsDevice, shadowMapTextureDesc.Width, shadowMapTextureDesc.Height, PixelFormat.R32G32_Float, TextureFlags.ShaderResource | TextureFlags.RenderTarget).KeepAliveBy(ActiveObjects); var shadowMapBlurV = Texture.New2D(GraphicsDevice, shadowMapTextureDesc.Width, shadowMapTextureDesc.Height, PixelFormat.R32G32_Float, TextureFlags.ShaderResource | TextureFlags.RenderTarget).KeepAliveBy(ActiveObjects); Texture2D textureSourceH = ShadowMapDepth.Texture; Texture2D textureSourceV = shadowMapBlurH; RenderTarget renderTargetH = shadowMapBlurH.ToRenderTarget(); RenderTarget renderTargetV = shadowMapBlurV.ToRenderTarget(); var blurQuadMesh = new EffectMesh[2]; for (int j = 0; j < BlurCount; j++) { for (int i = 0; i < 2; ++i) { blurQuadMesh[i] = new EffectMesh(j > 0 ? blurEffects[1] : blurEffects[i]).KeepAliveBy(ActiveObjects); blurQuadMesh[i].Parameters.Set(PostEffectBlurKeys.Coefficients, new[] { 0.2270270270f, 0.3162162162f, 0.3162162162f, 0.0702702703f, 0.0702702703f }); var unit = i == 0 ? Vector2.UnitX : Vector2.UnitY; blurQuadMesh[i].Parameters.Set(PostEffectBlurKeys.Offsets, new[] { Vector2.Zero, unit * -1.3846153846f, unit * +1.3846153846f, unit * -3.2307692308f, unit * +3.2307692308f }); PostPass.AddPass(blurQuadMesh[i].EffectPass); RenderSystem.GlobalMeshes.AddMesh(blurQuadMesh[i]); } blurQuadMesh[0].Parameters.Set(TexturingKeys.Texture0, textureSourceH); blurQuadMesh[1].Parameters.Set(TexturingKeys.Texture0, textureSourceV); blurQuadMesh[0].Parameters.Set(RenderTargetKeys.RenderTarget, renderTargetH); blurQuadMesh[1].Parameters.Set(RenderTargetKeys.RenderTarget, renderTargetV); textureSourceH = shadowMapBlurV; textureSourceV = shadowMapBlurH; } ShadowMapVsm = shadowMapBlurV; // Final texture for VSM is result of blur //MainTargetPlugin.Parameters.Set(ShadowMapKeys.Texture0, shadowMapBlurV); }
/// <summary> /// Sets the depth-stencil state of the output-merger stage. /// </summary> /// <param name="depthStencilState"><dd> <p>Pointer to a depth-stencil state interface (see <strong><see cref="SharpDX.Direct3D11.DepthStencilState"/></strong>) to bind to the device. Set this to <strong><c>null</c></strong> to use the default state listed in <strong><see cref="SharpDX.Direct3D11.DepthStencilStateDescription"/></strong>.</p> </dd></param> /// <param name="stencilReference"><dd> <p>Reference value to perform against when doing a depth-stencil test. See remarks.</p> </dd></param> /// <remarks> /// <p>To create a depth-stencil state interface, call <strong><see cref="SharpDX.Direct3D11.Device.CreateDepthStencilState"/></strong>.</p><p> The method will hold a reference to the interfaces passed in. This differs from the device state behavior in Direct3D 10. </p> /// </remarks> public void SetDepthStencilState(DepthStencilState depthStencilState, int stencilReference = 0) { throw new NotImplementedException(); }
/// <summary> /// Begins a image batch rendering using the specified blend state, sampler, depth stencil, rasterizer state objects, and the view-projection transformation matrix. /// Passing null for any of the state objects selects the default default state objects (BlendState.AlphaBlend, DepthStencilState.None, RasterizerState.CullCounterClockwise, SamplerState.LinearClamp). /// </summary> /// <param name="blendState">Blending options.</param> /// <param name="samplerState">Texture sampling options.</param> /// <param name="depthStencilState">Depth and stencil options.</param> /// <param name="rasterizerState">Rasterization options.</param> /// <param name="viewProjection">The view projection matrix used for this series of draw calls</param> /// <param name="stencilValue">The value of the stencil buffer to take as reference</param> public void Begin(ref Matrix viewProjection, BlendState blendState, SamplerState samplerState, RasterizerState rasterizerState, DepthStencilState depthStencilState, int stencilValue) { separateAlphaEffectBinded = false; viewProjectionMatrix = viewProjection; Begin(null, null, SpriteSortMode.BackToFront, blendState, samplerState, depthStencilState, rasterizerState, stencilValue); }
/// <summary> /// Begins a image batch rendering using the specified blend state, depth stencil and a view-projection transformation matrix. /// Passing null for any of the state objects selects the default default state objects (BlendState.AlphaBlend, DepthStencilState.None). /// </summary> /// <param name="blendState">Blending options.</param> /// <param name="depthStencilState">Depth and stencil options.</param> /// <param name="viewProjection">The view projection matrix used for this series of draw calls</param> /// <param name="stencilValue">The value of the stencil buffer to take as reference</param> public void Begin(ref Matrix viewProjection, BlendState blendState, DepthStencilState depthStencilState, int stencilValue) { Begin(ref viewProjection, blendState, null, null, depthStencilState, stencilValue); }
/// <summary> /// Begins a 3D sprite batch rendering using the specified sorting mode and blend state, sampler, depth stencil, rasterizer state objects, plus a custom effect and a view-projection matrix. /// Passing null for any of the state objects selects the default default state objects (BlendState.AlphaBlend, DepthStencilState.Default, RasterizerState.CullCounterClockwise, SamplerState.LinearClamp). /// Passing a null effect selects the default SpriteBatch Class shader. /// </summary> /// <param name="sortMode">The sprite drawing order to use for the batch session</param> /// <param name="effect">The effect to use for the batch session</param> /// <param name="blendState">The blending state to use for the batch session</param> /// <param name="samplerState">The sampling state to use for the batch session</param> /// <param name="depthStencilState">The depth stencil state to use for the batch session</param> /// <param name="rasterizerState">The rasterizer state to use for the batch session</param> /// <param name="stencilValue">The value of the stencil buffer to take as reference for the batch session</param> /// <param name="viewProjection">The view-projection matrix to use for the batch session</param> public void Begin(Matrix viewProjection, SpriteSortMode sortMode = SpriteSortMode.Deferred, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect = null, EffectParameterCollectionGroup parameterCollectionGroup = null, int stencilValue = 0) { CheckEndHasBeenCalled("begin"); transformationMatrix = viewProjection; Begin(effect, parameterCollectionGroup, sortMode, blendState, samplerState, depthStencilState, rasterizerState, stencilValue); }
/// <summary> /// Sets the depth-stencil state of the output-merger stage. /// </summary> /// <param name="depthStencilState"><dd> <p>Pointer to a depth-stencil state interface (see <strong><see cref="SharpDX.Direct3D11.DepthStencilState"/></strong>) to bind to the device. Set this to <strong><c>null</c></strong> to use the default state listed in <strong><see cref="SharpDX.Direct3D11.DepthStencilStateDescription"/></strong>.</p> </dd></param> /// <param name="stencilReference"><dd> <p>Reference value to perform against when doing a depth-stencil test. See remarks.</p> </dd></param> /// <remarks> /// <p>To create a depth-stencil state interface, call <strong><see cref="SharpDX.Direct3D11.Device.CreateDepthStencilState"/></strong>.</p><p> The method will hold a reference to the interfaces passed in. This differs from the device state behavior in Direct3D 10. </p> /// </remarks> public void SetDepthStencilState(DepthStencilState depthStencilState, int stencilReference = 0) { throw new NotImplementedException(); }
/// <summary> /// Sets the depth-stencil state of the output-merger stage. See <see cref="Render+states"/> to learn how to use it. /// </summary> /// <param name="depthStencilState">a depth-stencil state</param> /// <param name="stencilReference">Reference value to perform against when doing a depth-stencil test.</param> public void SetDepthStencilState(DepthStencilState depthStencilState, int stencilReference = 0) { currentState.DepthStencilState = depthStencilState; currentState.StencilReference = stencilReference; SetDepthStencilStateImpl(depthStencilState, stencilReference); }