public IDepthStencil CreateDepthStencil(string debugName, int width, int height, Format resourceFormat = Format.R32G8X24_Typeless, Format dsvFormat = Format.D32_Float_S8X24_UInt, Format srvDepthFormat = Format.R32_Float_X8X24_Typeless, Format srvStencilFormat = Format.X32_Typeless_G8X24_UInt, int samplesCount = 1, int samplesQuality = 0) { MyRenderProxy.Assert(width > 0); MyRenderProxy.Assert(height > 0); MyDepthStencil tex = m_objectsPool.Allocate(); tex.Init(debugName, width, height, resourceFormat, dsvFormat, srvDepthFormat, srvStencilFormat, samplesCount, samplesQuality); if (m_isDeviceInit) { try { tex.OnDeviceInit(); } catch (System.Exception ex) { IDepthStencil t = tex; DisposeTex(ref t); throw; } } return(tex); }
internal static void Run(IDepthStencil dst, IDepthStencil src) { RC.PixelShader.Set(m_ps); RC.SetRtv(dst, MyDepthStencilAccess.ReadWrite); RC.PixelShader.SetSrv(0, src.SrvDepth); DrawFullscreenQuad(); }
internal void Resize(int width, int height, int samplesNum, int samplesQuality) { Release(); m_samplesCount = samplesNum; m_samplesQuality = samplesQuality; MyDepthStencilManager dsManager = MyManagers.DepthStencils; m_depthStencil = dsManager.CreateDepthStencil("MyGBuffer.DepthStencil", width, height, samplesCount: samplesNum, samplesQuality: samplesQuality); if (MyRender11.MultisamplingEnabled) { m_resolvedDepthStencil = dsManager.CreateDepthStencil("MyGBuffer.ResolvedDepth", width, height); } MyRwTextureManager rwManager = MyManagers.RwTextures; m_gbuffer0 = rwManager.CreateRtv("MyGBuffer.GBuffer0", width, height, Format.R8G8B8A8_UNorm_SRgb, samplesNum, samplesQuality); m_gbuffer1 = rwManager.CreateRtv("MyGBuffer.GBuffer1", width, height, Format.R10G10B10A2_UNorm, samplesNum, samplesQuality); m_gbuffer2 = rwManager.CreateRtv("MyGBuffer.GBuffer2", width, height, Format.R8G8B8A8_UNorm, samplesNum, samplesQuality); m_lbuffer = rwManager.CreateRtv("MyGBuffer.LBuffer", width, height, LBufferFormat, samplesNum, samplesQuality); }
public void MarkOneCascade(int numCascade, IDepthStencil depthStencil, Matrix worldToProjection, ICascadeShadowMapSlice slice) { MyRenderContext RC = MyRender11.RC; RC.SetVertexBuffer(0, m_vertexBuffer); RC.SetIndexBuffer(m_indexBuffer); RC.SetInputLayout(m_inputLayout); RC.SetViewport(0, 0, MyRender11.ResolutionI.X, MyRender11.ResolutionI.Y); RC.SetDepthStencilState(MyDepthStencilStateManager.MarkIfInsideCascadeOld[numCascade], 0xf - numCascade); RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState); RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList); MyMapping mapping = MyMapping.MapDiscard(m_markerConstantBuffer); Matrix shadowToProjection = slice.MatrixShadowToWorldAt0Space * worldToProjection; shadowToProjection = Matrix.Transpose(shadowToProjection); mapping.WriteAndPosition(ref shadowToProjection); mapping.Unmap(); RC.VertexShader.SetConstantBuffer(6, m_markerConstantBuffer); RC.VertexShader.Set(m_vsMarker); RC.PixelShader.SetSrv(0, depthStencil.SrvDepth); //RC.PixelShader.SetSrv(1, depthStencil.SrvStencil); RC.PixelShader.Set(m_psMarker); RC.SetRtv(depthStencil, MyDepthStencilAccess.DepthReadOnly); RC.DrawIndexed(36, 0, 0); }
void InternalSetRtvs(IDepthStencil ds, MyDepthStencilAccess access, params IRtvBindable[] rtvs) { // Init DepthStencilView DepthStencilView dsv = null; if (ds == null) { dsv = null; } else { IDepthStencilInternal dsInternal = (IDepthStencilInternal)ds; switch (access) { case MyDepthStencilAccess.ReadWrite: dsv = dsInternal.Dsv; break; case MyDepthStencilAccess.DepthReadOnly: dsv = dsInternal.Dsv_roDepth; break; case MyDepthStencilAccess.StencilReadOnly: dsv = dsInternal.Dsv_roStencil; break; case MyDepthStencilAccess.ReadOnly: dsv = dsInternal.Dsv_ro; break; } } InternalSetRtvs(dsv, rtvs); }
internal void ClearDsv(IDepthStencil ds, DepthStencilClearFlags clearFlags, float depth, byte stencil) { IDepthStencilInternal dsInternal = (IDepthStencilInternal)ds; m_deviceContext.ClearDepthStencilView(dsInternal.Dsv, clearFlags, depth, stencil); CheckErrors(); }
public void Enable(IDepthStencil depthStencil) { video.currentRenderTargets[0] = this; video.disableActiveTexture(this); video.disableInactiveRenderTargets(this); renderTargetCom.Enable(((DepthStencil)depthStencil).com); }
public void Enable(IDepthStencil depthStencil) { video.currentRenderTargets[0] = this; video.disableActiveTexture(this); video.disableInactiveRenderTargets(this); renderTargetCom.Enable(((DepthStencil)depthStencil).com); }
public Device(ID3D11Device device, ID3D11RenderTargetView renderTarget, ID3D11DepthStencilView depthStencilView, ID3DCompiler compiler) { _device = device ?? throw new ArgumentNullException(nameof(device)); _renderTarget = renderTarget ?? throw new ArgumentNullException(nameof(renderTarget)); _depthStencilView = depthStencilView ?? throw new ArgumentNullException(nameof(depthStencilView)); ImmediateContext = new DeviceContext(device.Context, false); BackBuffer = new RenderTarget(renderTarget); DepthStencil = new DepthStencil(depthStencilView); TEMPORARYCompiler = compiler; }
public void Enable(IDepthStencil depthStencil) { video.disableActiveTextures(this); GL.BindFramebuffer(GL.FRAMEBUFFER, frameBuffer); GL.FramebufferTexture2D(GL.FRAMEBUFFER, GL.COLOR_ATTACHMENT0, GL.TEXTURE_2D, Texture, 0); ((DepthStencil)depthStencil).enable(); #if DEBUG Video.checkForError(); #endif }
/// <summary>Render depth and normals of windows to the specified target</summary> /// <returns>True if windows to be rendered found</returns> /// <param name="squaredDistanceMin">Squared distance internal minor</param> internal static bool RenderWindowsDepthOnly(IDepthStencil depthStencil, IRtvBindable gbuffer1, float squaredDistanceMin, float squaredDistanceMax) { int offset = 0; int windowsCount = 0; int windowsCountMax = WindowCountSafe; for (int it = 0; it < windowsCountMax; it++) { // Interval is [min, max) MyBillboard billboard = m_sortedBuffer[m_sorteWindowIndices[it]]; if (billboard.DistanceSquared >= squaredDistanceMax) { break; } if (billboard.DistanceSquared < squaredDistanceMin) { offset++; } else { windowsCount++; } } if (windowsCount == 0) { return(false); } TransferDataBillboards(offset, windowsCount, ref m_arrayDataWindows); RC.SetRtv(depthStencil, MyDepthStencilAccess.ReadWrite, gbuffer1); BindResourcesCommon(); RC.SetBlendState(null); RC.VertexShader.Set(m_vsDepthOnly); RC.PixelShader.Set(m_psDepthOnly); if (!MyStereoRender.Enable) { RC.DrawIndexed(m_windowCount * 6, 0, 0); } else { MyStereoRender.DrawIndexedBillboards(RC, m_windowCount * 6, 0, 0); } MyStatsUpdater.Passes.DrawBillboards++; RC.SetRasterizerState(null); return(true); }
void DisposeTexture(MyBorrowedDepthStencilTexture depthStencil) { IDepthStencil customTexture = depthStencil.DepthStencilTexture; MyManagers.DepthStencils.DisposeTex(ref customTexture); MyBorrowedTextureKey key = depthStencil.Key; m_dictionaryDepthStencilTextures[key].Remove(depthStencil); m_objectPoolDepthStencil.Deallocate(depthStencil); }
public void Enable(IDepthStencil depthStencil) { video.disableActiveTextures(this); GL.BindFramebuffer(GL.FRAMEBUFFER, frameBuffer); GL.FramebufferTexture2D(GL.FRAMEBUFFER, GL.COLOR_ATTACHMENT0, GL.TEXTURE_2D, Texture, 0); ((DepthStencil)depthStencil).enable(); #if DEBUG Video.checkForError(); #endif }
public void EnableRenderTarget(IDepthStencil depthStencil) { if (depthStencil != null) { com.EnableRenderTarget(((DepthStencil)depthStencil).com); } else { com.EnableRenderTarget(null); } }
public void MarkAllCascades(IDepthStencil depthStencil, Matrix worldToProjection, ICascadeShadowMap csm) { MyRenderContext RC = MyRender11.RC; RC.ClearDsv(depthStencil, DepthStencilClearFlags.Stencil, 0, 0); for (int i = 0; i < csm.SlicesCount; i++) { MarkOneCascade(i, depthStencil, worldToProjection, csm.GetSlice(i)); } }
public void EnableRenderTarget(IDepthStencil depthStencil) { #if iOS ((GLKView)application.View).BindDrawable(); #else GL.BindFramebuffer(GL.FRAMEBUFFER, 0); #endif uint surface = ((DepthStencil)depthStencil).depthBuffer; GL.BindRenderbuffer(GL.RENDERBUFFER, surface); GL.FramebufferRenderbuffer(GL.FRAMEBUFFER, GL.DEPTH_ATTACHMENT, GL.RENDERBUFFER, surface); }
public void DrawCoverage(IRtvTexture outTex, IDepthStencil depthStencil) { MyRenderContext RC = MyRender11.RC; RC.SetBlendState(null); RC.SetRtv(outTex); RC.PixelShader.Set(m_psDrawCoverage); RC.PixelShader.SetSrv(1, depthStencil.SrvStencil); MyScreenPass.DrawFullscreenQuad(); RC.ResetTargets(); }
public RenderToBackbufferPass(IDevice device, ID3DCompiler compiler) { _backBuffer = device.BackBuffer; _depthStencil = device.DepthStencil; _indexBuffer = device.CreateIndexBuffer(new int[] { 0, 3, 1, 3, 2, 1 }); _vertexBuffer = device.CreateVertexBuffer(CreateCube()); using var pixelShaderBlob = new Blob(compiler.CompileShaderFromFile(@"F:\Git\GameDev\resources\shaders\BackBufferPixelShader.hlsl", "main", "ps_5_0")); _pixelShader = device.CreatePixelShader(pixelShaderBlob); using var vertexShaderBlob = new Blob(compiler.CompileShaderFromFile(@"F:\Git\GameDev\resources\shaders\BackBufferVertexShader.hlsl", "main", "vs_5_0")); _vertexShader = device.CreateVertexShader(vertexShaderBlob); _inputLayout = device.CreateInputLayout(new VertexLayout(2).Append("POSITION", VertexLayoutTypes.Position2D).Append("TEXCOORD", VertexLayoutTypes.Position2D), vertexShaderBlob); _sampler = device.CreateSampler(); }
/// <summary>Render depth and normals of windows to the specified target</summary> /// <returns>True if glass to be rendered found</returns> /// <param name="squaredDistanceMin">Squared distance internal minor</param> internal static bool RenderGlassDepthOnly(IDepthStencil depthStencil, IRtvBindable gbuffer1, float squaredDistanceMin, float squaredDistanceMax) { int offset = 0; int windowsCount = 0; for (int it = 0; it < m_squaredDistances.Count; it++) { // Interval is [min, max) double squaredDistance = m_squaredDistances[it].Item2; if (squaredDistance >= squaredDistanceMax) { break; } if (squaredDistance < squaredDistanceMin) { offset++; } else { windowsCount++; } } if (windowsCount == 0) { return(false); } var pass = MyStaticGlassPass.Instance; pass.ViewProjection = MyRender11.Environment.Matrices.ViewProjectionAt0; pass.Viewport = new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y); pass.BeginDepthOnly(); RC.SetRtv(depthStencil, MyDepthStencilAccess.ReadWrite, gbuffer1); for (int it = offset; it < windowsCount; it++) { var renderable = m_squaredDistances[it].Item1; pass.RecordCommandsDepthOnly(renderable.RenderProxy); } pass.End(); return(true); }
internal void DisposeTex(ref IDepthStencil tex) { if (tex == null) { return; } MyDepthStencil texture = (MyDepthStencil)tex; if (m_isDeviceInit) { texture.OnDeviceEnd(); } m_objectsPool.Deallocate(texture); }
internal static void RunWithPixelStencilTest(IRtvBindable dst, ISrvBindable src, IBlendState bs = null, bool inverseTest = false, IDepthStencil depthStencil = null) { RC.SetDepthStencilState(null); RC.SetBlendState(bs); RC.SetRasterizerState(null); RC.SetRtv(dst); RC.PixelShader.SetSrv(0, src); RC.PixelShader.SetSrv(1, depthStencil == null ? MyGBuffer.Main.DepthStencil.SrvStencil : depthStencil.SrvStencil); if (!inverseTest) RC.PixelShader.Set(m_stencilTestPixelShader); else RC.PixelShader.Set(m_stencilInverseTestPixelShader); DrawFullscreenQuad(); RC.SetBlendState(null); }
public void Draw(IRtvTexture outTex, IDepthStencil stencil, ICascadeShadowMap csm, ref MyShadowsSettings settings) { MyRenderContext RC = MyRender11.RC; RC.SetBlendState(null); RC.SetRtv(outTex); RC.PixelShader.Set(m_ps); RC.PixelShader.SetSrv(0, stencil.SrvDepth); RC.PixelShader.SetSrv(1, stencil.SrvStencil); RC.PixelShader.SetSrv(2, csm.DepthArrayTexture); RC.PixelShader.SetSrv(3, MyGBuffer.Main.GBuffer1); RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.PixelShader.SetConstantBuffer(1, GetShadowConstants(csm, ref settings)); RC.PixelShader.SetSampler(6, MySamplerStateManager.Shadowmap); MyScreenPass.DrawFullscreenQuad(); RC.ResetTargets(); }
internal static void Resize(int width, int height, int samplesNum, int samplesQuality) { MyDepthStencilManager dsManager = MyManagers.DepthStencils; dsManager.DisposeTex(ref m_resolvedDepth); m_resolvedDepth = dsManager.CreateDepthStencil("MyScreenDependants.ResolvedDepth", width, height); MyRwTextureManager texManager = MyManagers.RwTextures; texManager.DisposeTex(ref m_ambientOcclusionHelper); m_ambientOcclusionHelper = texManager.CreateRtv("MyScreenDependants.AmbientOcclusionHelper", width, height, Format.R8_UNorm, 1, 0); texManager.DisposeTex(ref m_ambientOcclusion); m_ambientOcclusion = texManager.CreateRtv("MyScreenDependants.AmbientOcclusion", width, height, Format.R8_UNorm, 1, 0); TilesX = (width + MyLightRendering.TILE_SIZE - 1) / MyLightRendering.TILE_SIZE; TilesY = ((height + MyLightRendering.TILE_SIZE - 1) / MyLightRendering.TILE_SIZE); TilesNum = TilesX * TilesY; if (m_tileIndices != null) m_tileIndices.Release(); m_tileIndices = new MyRWStructuredBuffer(TilesNum + TilesNum * MyRender11Constants.MAX_POINT_LIGHTS, sizeof(uint), MyRWStructuredBuffer.UavType.Default, true, "MyScreenDependants::tileIndices"); }
public void Draw(IRtvTexture outTex, IDepthStencil stencil, ICascadeShadowMap csm, ref MyShadowsSettings settings) { MyRenderContext RC = MyRender11.RC; RC.SetBlendState(null); RC.SetRtv(outTex); RC.PixelShader.Set(m_ps); RC.PixelShader.SetSrv(0, stencil.SrvDepth); RC.PixelShader.SetSrv(1, stencil.SrvStencil); RC.PixelShader.SetSrv(2, csm.DepthArrayTexture); RC.PixelShader.SetSrv(3, MyGBuffer.Main.GBuffer1); RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.PixelShader.SetConstantBuffer(1, GetShadowConstants(csm, ref settings)); RC.PixelShader.SetSampler(6, MySamplerStateManager.Shadowmap); MyScreenPass.DrawFullscreenQuad(); RC.ResetTargets(); }
internal void Resize(int width, int height, int samplesNum, int samplesQuality) { Release(); m_samplesCount = samplesNum; m_samplesQuality = samplesQuality; MyDepthStencilManager dsManager = MyManagers.DepthStencils; m_depthStencil = dsManager.CreateDepthStencil("MyGBuffer.DepthStencil", width, height, samplesCount: samplesNum, samplesQuality: samplesQuality); MyRwTextureManager rwManager = MyManagers.RwTextures; m_gbuffer0 = rwManager.CreateRtv("MyGBuffer.GBuffer0", width, height, Format.R8G8B8A8_UNorm_SRgb, samplesNum, samplesQuality); m_gbuffer1 = rwManager.CreateRtv("MyGBuffer.GBuffer1", width, height, Format.R10G10B10A2_UNorm, samplesNum, samplesQuality); m_gbuffer2 = rwManager.CreateRtv("MyGBuffer.GBuffer2", width, height, Format.R8G8B8A8_UNorm, samplesNum, samplesQuality); m_lbuffer = rwManager.CreateRtv("MyGBuffer.LBuffer", width, height, LBufferFormat, samplesNum, samplesQuality); }
internal static void RunWithPixelStencilTest(IRtvBindable dst, ISrvBindable src, IBlendState bs = null, bool inverseTest = false, IDepthStencil depthStencil = null) { RC.SetDepthStencilState(null); RC.SetBlendState(bs); RC.SetRasterizerState(null); RC.SetRtv(dst); RC.PixelShader.SetSrv(0, src); RC.PixelShader.SetSrv(1, depthStencil == null ? MyGBuffer.Main.DepthStencil.SrvStencil : depthStencil.SrvStencil); if (!inverseTest) { RC.PixelShader.Set(m_stencilTestPixelShader); } else { RC.PixelShader.Set(m_stencilInverseTestPixelShader); } DrawFullscreenQuad(); RC.SetBlendState(null); }
internal static void RunWithStencil(IRtvBindable destinationResource, ISrvBindable sourceResource, IBlendState blendState, IDepthStencilState depthStencilState = null, int stencilMask = 0x0, IDepthStencil depthStencil = null) { RC.SetBlendState(blendState); RC.SetRasterizerState(null); if (depthStencilState == null) { RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil); RC.SetRtv(null, MyDepthStencilAccess.ReadOnly, destinationResource); } else { RC.SetDepthStencilState(depthStencilState, stencilMask); RC.SetRtv(depthStencil ?? MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, destinationResource); } RC.PixelShader.SetSrv(0, sourceResource); RC.PixelShader.Set(m_copyPixelShader); DrawFullscreenQuad(); RC.SetBlendState(null); }
public static IDepthStencil New(VideoTypes videoType, IDisposableResource parent, int width, int height, DepthStencilFormats format) { IDepthStencil api = null; #if WIN32 if (videoType == VideoTypes.D3D9) { api = new D3D9.DepthStencil(parent, width, height, format); } #endif #if WIN32 || WINRT || WP8 if (videoType == VideoTypes.D3D11) { api = new D3D11.DepthStencil(parent, width, height, format); } #endif #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl if (videoType == VideoTypes.OpenGL) { api = new OpenGL.DepthStencil(parent, width, height, format); } #endif #if VITA if (videoType == VideoTypes.Vita) { api = new Vita.DepthStencil(parent, width, height, format); } #endif if (api == null) { Debug.ThrowError("DepthStencilAPI", "Unsuported InputType: " + videoType); } return(api); }
/// <summary>Render depth and normals of windows to the specified target</summary> /// <returns>True if glass to be rendered found</returns> /// <param name="squaredDistanceMin">Squared distance internal minor</param> internal static bool RenderGlassDepthOnly(IDepthStencil depthStencil, IRtvBindable gbuffer1, float squaredDistanceMin, float squaredDistanceMax) { int offset = 0; int windowsCount = 0; for (int it = 0; it < m_squaredDistances.Count; it++) { // Interval is [min, max) double squaredDistance = m_squaredDistances[it].Item2; if (squaredDistance >= squaredDistanceMax) break; if (squaredDistance < squaredDistanceMin) offset++; else windowsCount++; } if (windowsCount == 0) return false; var pass = MyStaticGlassPass.Instance; pass.ViewProjection = MyRender11.Environment.Matrices.ViewProjectionAt0; pass.Viewport = new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y); pass.BeginDepthOnly(); RC.SetRtv(depthStencil, MyDepthStencilAccess.ReadWrite, gbuffer1); for (int it = offset; it < windowsCount; it++) { var renderable = m_squaredDistances[it].Item1; pass.RecordCommandsDepthOnly(renderable.RenderProxy); } pass.End(); return true; }
internal static void Resize(int width, int height, int samplesNum, int samplesQuality) { MyDepthStencilManager dsManager = MyManagers.DepthStencils; dsManager.DisposeTex(ref m_resolvedDepth); m_resolvedDepth = dsManager.CreateDepthStencil("MyScreenDependants.ResolvedDepth", width, height); MyRwTextureManager texManager = MyManagers.RwTextures; texManager.DisposeTex(ref m_ambientOcclusionHelper); m_ambientOcclusionHelper = texManager.CreateRtv("MyScreenDependants.AmbientOcclusionHelper", width, height, Format.R8_UNorm, 1, 0); texManager.DisposeTex(ref m_ambientOcclusion); m_ambientOcclusion = texManager.CreateRtv("MyScreenDependants.AmbientOcclusion", width, height, Format.R8_UNorm, 1, 0); TilesX = (width + MyLightRendering.TILE_SIZE - 1) / MyLightRendering.TILE_SIZE; TilesY = ((height + MyLightRendering.TILE_SIZE - 1) / MyLightRendering.TILE_SIZE); TilesNum = TilesX * TilesY; if (m_tileIndices != null) { m_tileIndices.Release(); } m_tileIndices = new MyRWStructuredBuffer(TilesNum + TilesNum * MyRender11Constants.MAX_POINT_LIGHTS, sizeof(uint), MyRWStructuredBuffer.UavType.Default, true, "MyScreenDependants::tileIndices"); }
internal static void Run(IRtvBindable target, ICustomTexture fxaaTarget, IDepthStencil depthStencilCopy) { if (!HasHighlights) return; ProfilerShort.Begin("MyHighlight.Run"); MyGpuProfiler.IC_BeginBlock("MyHighlight.Run"); // set resolved depth/ stencil // render all with proper depth-stencil state // blur // blend to main target testing with stencil again MyHighlightPass.Instance.ViewProjection = MyRender11.Environment.Matrices.ViewProjectionAt0; MyHighlightPass.Instance.Viewport = new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y); MyHighlightPass.Instance.PerFrame(); MyHighlightPass.Instance.Begin(); RC.VertexShader.SetSrvs(0, null, null, null, null, null, null); RC.GeometryShader.SetSrvs(0, null, null, null, null, null, null); RC.PixelShader.SetSrvs(0, null, null, null, null, null, null); RC.ComputeShader.SetSrvs(0, null, null, null, null, null, null); int samples = MyRender11.RenderSettings.AntialiasingMode.SamplesCount(); IBorrowedRtvTexture rgba8_1 = MyManagers.RwTexturesPool.BorrowRtv("MyHighlight.Rgba8_1", Format.R8G8B8A8_UNorm_SRgb, samples); RC.ClearRtv(rgba8_1, new SharpDX.Color4(0, 0, 0, 0)); RC.SetRtv(depthStencilCopy, MyDepthStencilAccess.DepthReadOnly, rgba8_1); float maxThickness = 0f; foreach (var pair in m_highlights) { MyActor actor = MyIDTracker<MyActor>.FindByID(pair.Key); MyRenderableComponent renderableComponent; if (actor == null || (renderableComponent = actor.GetRenderable()) == null) { // If an actor has been removed without removing outlines, just remove the outlines too m_keysToRemove.Add(pair.Key); continue; } var renderLod = renderableComponent.Lods[renderableComponent.CurrentLod]; var model = renderableComponent.GetModel(); LodMeshId currentModelId; if (!MyMeshes.TryGetLodMesh(model, renderableComponent.CurrentLod, out currentModelId)) { Debug.Fail("Mesh for outlining not found!"); continue; } foreach (MyHighlightDesc descriptor in pair.Value) { if (!renderableComponent.IsRenderedStandAlone) { MyGroupLeafComponent leafComponent = actor.GetGroupLeaf(); MyGroupRootComponent groupComponent = leafComponent.RootGroup; if (groupComponent != null) RecordMeshPartCommands(model, actor, groupComponent, groupComponent.m_proxy, descriptor, ref maxThickness); continue; } if (descriptor.SectionIndex == -1) { RecordMeshPartCommands(model, currentModelId, renderableComponent, renderLod, descriptor, ref maxThickness); } else { RecordMeshSectionCommands(model, currentModelId, renderableComponent, renderLod, descriptor, ref maxThickness); } } } MyHighlightPass.Instance.End(); RC.SetBlendState(null); foreach (var outlineKey in m_keysToRemove) m_highlights.Remove(outlineKey); m_keysToRemove.SetSize(0); ISrvBindable initialSourceView = rgba8_1; IRtvBindable renderTargetview = rgba8_1; if (maxThickness > 0) { IBorrowedRtvTexture rgba8_2 = MyManagers.RwTexturesPool.BorrowRtv("MyHighlight.Rgba8_2", Format.R8G8B8A8_UNorm_SRgb); MyBlur.Run(renderTargetview, rgba8_2, initialSourceView, (int)Math.Round(maxThickness), MyBlur.MyBlurDensityFunctionType.Exponential, 0.25f, MyDepthStencilStateManager.IgnoreDepthStencil); rgba8_2.Release(); } MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); BlendHighlight(target, rgba8_1, fxaaTarget, depthStencilCopy); }
private static void BlendHighlight(IRtvBindable target, ISrvBindable outlined, ICustomTexture fxaaTarget, IDepthStencil depthStencilCopy) { MyGpuProfiler.IC_BeginBlock("Highlight Blending"); ProfilerShort.Begin("Highlight Blending"); if (fxaaTarget != null) { MyBlendTargets.RunWithStencil( fxaaTarget.SRgb, outlined, MyBlendStateManager.BlendAdditive, MyDepthStencilStateManager.TestHighlightOuterStencil, HIGHLIGHT_STENCIL_MASK, depthStencilCopy); MyBlendTargets.RunWithStencil( fxaaTarget.SRgb, outlined, MyBlendStateManager.BlendTransparent, MyDepthStencilStateManager.TestHighlightInnerStencil, HIGHLIGHT_STENCIL_MASK, depthStencilCopy); } else { if (MyRender11.MultisamplingEnabled) { MyBlendTargets.RunWithPixelStencilTest(target, outlined, MyBlendStateManager.BlendAdditive, false, depthStencilCopy); MyBlendTargets.RunWithPixelStencilTest(target, outlined, MyBlendStateManager.BlendTransparent, true, depthStencilCopy); } else { MyBlendTargets.RunWithStencil(target, outlined, MyBlendStateManager.BlendAdditive, MyDepthStencilStateManager.TestHighlightOuterStencil, HIGHLIGHT_STENCIL_MASK, depthStencilCopy); MyBlendTargets.RunWithStencil(target, outlined, MyBlendStateManager.BlendTransparent, MyDepthStencilStateManager.TestHighlightInnerStencil, HIGHLIGHT_STENCIL_MASK, depthStencilCopy); } } ProfilerShort.End(); MyGpuProfiler.IC_EndBlock(); }
public void DrawCoverage(IRtvTexture outTex, IDepthStencil depthStencil) { MyRenderContext RC = MyRender11.RC; RC.SetBlendState(null); RC.SetRtv(outTex); RC.PixelShader.Set(m_psDrawCoverage); RC.PixelShader.SetSrv(1, depthStencil.SrvStencil); MyScreenPass.DrawFullscreenQuad(); RC.ResetTargets(); }
internal static void RunWithStencil(IRtvBindable destinationResource, ISrvBindable sourceResource, IBlendState blendState, IDepthStencilState depthStencilState = null, int stencilMask = 0x0, IDepthStencil depthStencil = null) { RC.SetBlendState(blendState); RC.SetRasterizerState(null); if (depthStencilState == null) { RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil); RC.SetRtv(null, MyDepthStencilAccess.ReadOnly, destinationResource); } else { RC.SetDepthStencilState(depthStencilState, stencilMask); RC.SetRtv(depthStencil ?? MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, destinationResource); } RC.PixelShader.SetSrv(0, sourceResource); RC.PixelShader.Set(m_copyPixelShader); DrawFullscreenQuad(); RC.SetBlendState(null); }
internal void DisposeTex(ref IDepthStencil tex) { if (tex == null) return; MyDepthStencil texture = (MyDepthStencil)tex; if (m_isDeviceInit) texture.OnDeviceEnd(); m_objectsPool.Deallocate(texture); }
public void DrawCoverage(IRtvTexture outTex, IDepthStencil depthStencil) { m_markCascades.DrawCoverage(outTex, depthStencil); }
public void MarkOneCascade(int numCascade, IDepthStencil depthStencil, Matrix worldToProjection, ICascadeShadowMapSlice slice) { MyRenderContext RC = MyRender11.RC; RC.SetVertexBuffer(0, m_vertexBuffer.Buffer, m_vertexBuffer.Stride); RC.SetIndexBuffer(m_indexBuffer.Buffer, m_indexBuffer.Format); RC.SetInputLayout(m_inputLayout); RC.SetViewport(0, 0, MyRender11.ResolutionI.X, MyRender11.ResolutionI.Y); RC.SetDepthStencilState(MyDepthStencilStateManager.MarkIfInsideCascadeOld[numCascade], 0xf - numCascade); RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState); RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList); MyMapping mapping = MyMapping.MapDiscard(m_markerConstantBuffer); Matrix shadowToProjection = slice.MatrixShadowToWorldAt0Space * worldToProjection; shadowToProjection = Matrix.Transpose(shadowToProjection); mapping.WriteAndPosition(ref shadowToProjection); mapping.Unmap(); RC.VertexShader.SetConstantBuffer(6, m_markerConstantBuffer); RC.VertexShader.Set(m_vsMarker); RC.PixelShader.SetSrv(0, depthStencil.SrvDepth); //RC.PixelShader.SetSrv(1, depthStencil.SrvStencil); RC.PixelShader.Set(m_psMarker); RC.SetRtv(depthStencil, MyDepthStencilAccess.DepthReadOnly); RC.DrawIndexed(36, 0, 0); }
public void MarkAllCascades(IDepthStencil depthStencil, Matrix worldToProjection, ICascadeShadowMap csm) { m_markCascades.MarkAllCascades(depthStencil, worldToProjection, csm); }
public void Enable(IDepthStencil depthStencil) { renderTargetCom.Enable(((DepthStencil)depthStencil).com); }
internal static unsafe void Draw(IRtvBindable renderTarget, IDepthStencil depth) { RC.SetScreenViewport(); RC.SetPrimitiveTopology(PrimitiveTopology.LineList); RC.SetInputLayout(m_inputLayout); RC.SetRasterizerState(MyRasterizerStateManager.LinesRasterizerState); RC.VertexShader.Set(m_vs); RC.PixelShader.Set(m_ps); RC.SetBlendState(MyBlendStateManager.BlendAlphaPremult); RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState); CheckBufferSize(m_vertices.Count); RC.SetVertexBuffer(0, m_VB.Buffer, m_VB.Stride); RC.SetRtv(depth, MyDepthStencilAccess.ReadOnly, renderTarget); RC.AllShaderStages.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.ProjectionConstants); if(m_batches.Count > 0) { var mapping = MyMapping.MapDiscard(m_VB.Buffer); mapping.WriteAndPosition(m_vertices.GetInternalArray(), 0, m_vertices.Count); mapping.Unmap(); Matrix prevMatrix = Matrix.Zero; foreach (var batch in m_batches) { Matrix matrix; if (batch.CustomViewProjection.HasValue) { matrix = batch.CustomViewProjection.Value; } else { matrix = MyRender11.Environment.Matrices.ViewProjectionAt0; } if (prevMatrix != matrix) { prevMatrix = matrix; var transpose = Matrix.Transpose(matrix); mapping = MyMapping.MapDiscard(MyCommon.ProjectionConstants); mapping.WriteAndPosition(ref transpose); mapping.Unmap(); } if(batch.IgnoreDepth) { RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil); } else { RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState); } RC.Draw(batch.VertexCount, batch.StartVertex); } } RC.SetDepthStencilState(null); RC.SetRasterizerState(null); m_vertices.Clear(); foreach(var batch in m_batches) { m_batchesPool.Deallocate(batch); } m_batches.Clear(); }
internal static unsafe void Draw(IRtvBindable renderTarget, IDepthStencil depth) { RC.SetScreenViewport(); RC.SetPrimitiveTopology(PrimitiveTopology.LineList); RC.SetInputLayout(m_inputLayout); RC.SetRasterizerState(MyRasterizerStateManager.LinesRasterizerState); RC.VertexShader.Set(m_vs); RC.PixelShader.Set(m_ps); RC.SetBlendState(MyBlendStateManager.BlendAlphaPremult); RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState); CheckBufferSize(m_vertices.Count); RC.SetVertexBuffer(0, m_VB.Buffer, m_VB.Stride); RC.SetRtv(depth, MyDepthStencilAccess.ReadOnly, renderTarget); RC.AllShaderStages.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.ProjectionConstants); if (m_batches.Count > 0) { var mapping = MyMapping.MapDiscard(m_VB.Buffer); mapping.WriteAndPosition(m_vertices.GetInternalArray(), 0, m_vertices.Count); mapping.Unmap(); Matrix prevMatrix = Matrix.Zero; foreach (var batch in m_batches) { Matrix matrix; if (batch.CustomViewProjection.HasValue) { matrix = batch.CustomViewProjection.Value; } else { matrix = MyRender11.Environment.Matrices.ViewProjectionAt0; } if (prevMatrix != matrix) { prevMatrix = matrix; var transpose = Matrix.Transpose(matrix); mapping = MyMapping.MapDiscard(MyCommon.ProjectionConstants); mapping.WriteAndPosition(ref transpose); mapping.Unmap(); } if (batch.IgnoreDepth) { RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil); } else { RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState); } RC.Draw(batch.VertexCount, batch.StartVertex); } } RC.SetDepthStencilState(null); RC.SetRasterizerState(null); m_vertices.Clear(); foreach (var batch in m_batches) { m_batchesPool.Deallocate(batch); } m_batches.Clear(); }
public void MarkAllCascades(IDepthStencil depthStencil, Matrix worldToProjection, ICascadeShadowMap csm) { MyRenderContext RC = MyRender11.RC; RC.ClearDsv(depthStencil, DepthStencilClearFlags.Stencil, 0, 0); for (int i = 0; i < csm.SlicesCount; i++) { MarkOneCascade(i, depthStencil, worldToProjection, csm.GetSlice(i)); } }
public void Build(IDevice device) { _backBuffer = device.BackBuffer; _depthStencil = device.DepthStencil; }
public void DrawCoverage(IRtvTexture outTex, IDepthStencil depthStencil) { m_markCascades.DrawCoverage(outTex, depthStencil); }
public void SetDepthStencil(IDepthStencil depthStencil) { }
public void ApplyPostprocess(MyPostprocessShadows.Type type, IRtvTexture outTex, IDepthStencil stencil, ICascadeShadowMap csm, ref MyShadowsSettings settings) { MyPostprocessShadows postprocess = null; switch (type) { case MyPostprocessShadows.Type.HARD: postprocess = m_postprocessHardShadows; break; case MyPostprocessShadows.Type.SIMPLE: postprocess = m_postprocessSimpleShadows; break; default: MyRenderProxy.Assert(false); break; } postprocess.Draw(outTex, stencil, csm, ref settings); }
public void MarkAllCascades(IDepthStencil depthStencil, Matrix worldToProjection, ICascadeShadowMap csm) { m_markCascades.MarkAllCascades(depthStencil, worldToProjection, csm); }
internal static unsafe void Render(MyRenderContext RC, IDepthStencil ds, IRtvBindable rtv) { bool debugDraw = MyRender11.Settings.DrawOcclusionQueriesDebug; if (m_vb == null || m_tempBuffer2.Length < m_queries.Count) { int allocCount = System.Math.Max(m_queries.Count * 3 / 2, 32); System.Diagnostics.Debug.Assert(allocCount < 256); if (m_vb == null) { m_vb = VRage.Render11.Common.MyManagers.Buffers.CreateVertexBuffer("MyOcclusionQueryRenderer.VB", allocCount, sizeof(MyVbConstantElement), usage: SharpDX.Direct3D11.ResourceUsage.Dynamic); } else { VRage.Render11.Common.MyManagers.Buffers.Resize(m_vb, allocCount); } m_tempBuffer = new MyVbConstantElement[allocCount]; m_tempBuffer2 = new MyOcclusionQuery[allocCount]; } VRage.Profiler.ProfilerShort.Begin("Gather"); int ctr = 0; float currentTime = MyCommon.TimerMs; foreach (var item in m_queries) { Vector3 cameraPos = item.Position - MyRender11.Environment.Matrices.CameraPosition; if (debugDraw) { item.LastResult = 0; } else { if (item.Running) { var result = item.Query.GetResult(false); if (result != -1) { var dist = cameraPos.Length(); var viewPos = new Vector3(item.Size, item.Size, dist); var projPos = Vector3.Transform(viewPos, MyRender11.Environment.Matrices.Projection); var pixels = new Vector2(projPos.X, projPos.Y) * MyRender11.ResolutionF / 2; var squared = System.Math.Abs(pixels.X * pixels.Y); item.LastResult = System.Math.Min(result / squared, 1.0f); item.NextQueryTime = currentTime + item.FreqMinMs + m_random.NextFloat() * item.FreqRndMs; item.Running = false; } else { continue; } } } if (!item.Visible || currentTime < item.NextQueryTime) { continue; } item.Running = true; var data = new MyVbConstantElement { Position = cameraPos, Size = item.Size }; m_tempBuffer2[ctr] = item.Query; m_tempBuffer[ctr] = data; ctr++; item.Visible = false; } if (ctr > 0) { VRage.Profiler.ProfilerShort.BeginNextBlock("Setup"); RC.SetInputLayout(m_inputLayout); RC.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip); RC.VertexShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState); RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState); RC.VertexShader.Set(m_vs); if (debugDraw) { RC.PixelShader.Set(m_ps); RC.SetRtv(ds, MyDepthStencilAccess.ReadOnly, rtv); } else { RC.SetRtv(ds, MyDepthStencilAccess.ReadOnly, null); RC.PixelShader.Set(null); } VRage.Profiler.ProfilerShort.BeginNextBlock("Map"); MyMapping mappingVb = MyMapping.MapDiscard(RC, m_vb); mappingVb.WriteAndPosition(m_tempBuffer, ctr); mappingVb.Unmap(); RC.SetVertexBuffer(0, m_vb); VRage.Profiler.ProfilerShort.BeginNextBlock("Render"); if (debugDraw) { for (int i = 0; i < ctr; i++) { RC.DrawInstanced(4, 1, 0, i); } } else { for (int i = 0; i < ctr; i++) { m_tempBuffer2[i].Begin(); RC.DrawInstanced(4, 1, 0, i); m_tempBuffer2[i].End(); } } } VRage.Profiler.ProfilerShort.End(); RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList); }
public void ApplyPostprocess(MyPostprocessShadows.Type type, IRtvTexture outTex, IDepthStencil stencil, ICascadeShadowMap csm, ref MyShadowsSettings settings) { MyPostprocessShadows postprocess = null; switch (type) { case MyPostprocessShadows.Type.HARD: postprocess = m_postprocessHardShadows; break; case MyPostprocessShadows.Type.SIMPLE: postprocess = m_postprocessSimpleShadows; break; default: MyRenderProxy.Assert(false); break; } postprocess.Draw(outTex, stencil, csm, ref settings); }
internal static void Draw(IRtvBindable renderTarget, IDepthStencil depth) { RC.SetScreenViewport(); RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList); RC.SetInputLayout(m_inputLayout); RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState); RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState); RC.VertexShader.Set(m_vs); RC.PixelShader.Set(m_ps); RC.SetRtv(depth, MyDepthStencilAccess.ReadOnly, renderTarget); RC.AllShaderStages.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.ProjectionConstants); RC.SetBlendState(MyBlendStateManager.BlendTransparent); SortTransparent(); var transpose = Matrix.Transpose(MyRender11.Environment.Matrices.ViewProjectionAt0); var mapping = MyMapping.MapDiscard(MyCommon.ProjectionConstants); mapping.WriteAndPosition(ref transpose); mapping.Unmap(); CheckBufferSize(m_vertexList.Count); RC.SetVertexBuffer(0, m_VB.Buffer, m_VB.Stride); if (m_vertexList.Count > 0) { mapping = MyMapping.MapDiscard(m_VB.Buffer); mapping.WriteAndPosition(m_vertexList.GetInternalArray(), 0, m_vertexList.Count); mapping.Unmap(); } RC.Draw(m_vertexList.Count, 0); if (m_debugMeshes.Count > 0) { var transposeViewProj = Matrix.Transpose(MyRender11.Environment.Matrices.ViewProjection); mapping = MyMapping.MapDiscard(MyCommon.ProjectionConstants); mapping.WriteAndPosition(ref transposeViewProj); mapping.Unmap(); } foreach (var mesh in m_debugMeshes.Values) { if (mesh.depth) RC.SetRtv(depth, MyDepthStencilAccess.ReadWrite, renderTarget); else RC.SetRtv(renderTarget); if (mesh.edges) { RC.SetRasterizerState(MyRasterizerStateManager.NocullWireframeRasterizerState); } else { RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState); } RC.SetVertexBuffer(0, mesh.vbuffer.Buffer, mesh.vbuffer.Stride); RC.Draw(mesh.vbuffer.Capacity, 0); } RC.SetBlendState(null); m_vertexList.Clear(); m_postSortVertexList.Clear(); m_triangleSortDistance.Clear(); m_sortedIndices.Clear(); }
public void EnableRenderTarget(IDepthStencil depthStencil) { com.EnableRenderTarget(((DepthStencil)depthStencil).com); }
public void EnableRenderTarget(IDepthStencil depthStencil) { if (depthStencil != null) com.EnableRenderTarget(((DepthStencil)depthStencil).com); else com.EnableRenderTarget(null); }