Beispiel #1
0
        internal static void Run(MyBindableResource dst, MyGBuffer gbuffer, MyBindableResource resolvedDepth)
        {
            RC.Context.ClearRenderTargetView((dst as IRenderTargetBindable).RTV, new SharpDX.Color4(1, 1, 1, 1));

            var paramsCB = MyCommon.GetObjectCB(16 * (2 + NUM_SAMPLES * 2));

            var mapping = MyMapping.MapDiscard(paramsCB);

            mapping.stream.Write(Params.MinRadius);
            mapping.stream.Write(Params.MaxRadius);
            mapping.stream.Write(Params.RadiusGrow);
            mapping.stream.Write(Params.Falloff);
            mapping.stream.Write(Params.RadiusBias);
            mapping.stream.Write(Params.Contrast);
            mapping.stream.Write(Params.Normalization);
            mapping.stream.Write(0);
            FillRandomVectors(mapping.stream);
            mapping.Unmap();

            RC.SetCB(0, MyCommon.FrameConstants);
            RC.SetCB(1, paramsCB);

            RC.SetPS(m_ps);
            RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, dst);

            RC.BindGBufferForRead(0, gbuffer);
            RC.BindSRV(5, resolvedDepth);

            DrawFullscreenQuad();
        }
Beispiel #2
0
 internal static void Run(MyBindableResource dst, MyBindableResource src)
 {
     RC.SetPS(m_ps);
     RC.BindDepthRT(dst, DepthStencilAccess.ReadWrite, null);
     RC.BindSRV(0, src);
     DrawFullscreenQuad();
 }
Beispiel #3
0
        internal static void SSGrass(MyBindableResource destination,
                                     MyBindableResource depth, MyBindableResource source, MyBindableResource gbuffer2)
        {
            var context = MyRender.Context;

            var cbuffer = MyCommon.GetObjectBuffer(16);
            var mapping = MyMapping.MapDiscard(cbuffer.Buffer);

            mapping.stream.Write(MyRender.Settings.GrassPostprocessCloseDistance);
            mapping.Unmap();

            context.PixelShader.SetConstantBuffer(1, cbuffer.Buffer);

            context.OutputMerger.BlendState = null;
            context.Rasterizer.SetViewport(0, 0, MyRender.ViewportResolution.X, MyRender.ViewportResolution.Y);

            context.VertexShader.Set(FullscreenShader.VertexShader);
            context.PixelShader.Set(SSGrassShader.PixelShader);

            //var array = new ShaderResourceView[] { depth, resource, MyRender.MainGbuffer.Gbuffers[2].ShaderView };
            //context.OutputMerger.SetTargets(null as DepthStencilView, target);
            //context.PixelShader.SetShaderResources(0, array);

            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, destination);
            RC.BindSRV(0, depth, source, gbuffer2);

            context.Draw(3, 0);
        }
Beispiel #4
0
        internal static void Run(MyBindableResource dst, MyGBuffer gbuffer, MyBindableResource resolvedDepth)
        {
            RC.DeviceContext.ClearRenderTargetView((dst as IRenderTargetBindable).RTV, new SharpDX.Color4(1, 1, 1, 1));

            var paramsCB = MyCommon.GetObjectCB(16 * (2 + NUM_SAMPLES * 2));

            var mapping = MyMapping.MapDiscard(paramsCB);

            mapping.WriteAndPosition(ref Params);
            FillRandomVectors(mapping);
            mapping.Unmap();

            if (!MyStereoRender.Enable)
            {
                RC.SetCB(0, MyCommon.FrameConstants);
            }
            else
            {
                MyStereoRender.BindRawCB_FrameConstants(RC);
            }
            RC.SetCB(1, paramsCB);

            RC.SetPS(m_ps);
            RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, dst);

            RC.BindGBufferForRead(0, gbuffer);
            RC.BindSRV(5, resolvedDepth);

            DrawFullscreenQuad();
        }
Beispiel #5
0
        internal static void Run(MyBindableResource dst, MyBindableResource src, MyBindableResource avgLum, MyBindableResource bloom, bool enableTonemapping = true)
        {
            //Debug.Assert(src.GetSize() == dst.GetSize());

            var mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(16));

            mapping.stream.Write(MyRender11.Settings.MiddleGrey);
            mapping.stream.Write(MyRender11.Settings.LuminanceExposure);
            mapping.stream.Write(MyRender11.Settings.BloomExposure);
            mapping.stream.Write(MyRender11.Settings.BloomMult);
            mapping.Unmap();

            RC.CSSetCB(0, MyCommon.FrameConstants);
            RC.CSSetCB(1, MyCommon.GetObjectCB(16));

            RC.BindUAV(0, dst);
            RC.BindSRV(0, src, avgLum, bloom);

            RC.Context.ComputeShader.SetSampler(0, MyRender11.m_defaultSamplerState);

            if (enableTonemapping)
            {
                RC.SetCS(m_cs);
            }
            else
            {
                RC.SetCS(m_csSkip);
            }

            var size = dst.GetSize();

            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);
            RC.SetCS(null);
        }
Beispiel #6
0
 internal static void ResolveOIT(MyUnorderedAccessTexture accumTarget, MyUnorderedAccessTexture coverageTarget)
 {
     RC.SetBS(MyRender11.BlendInvTransparent);
     RC.SetPS(m_psResolve);
     RC.BindDepthRT(null, DepthStencilAccess.ReadOnly, MyGBuffer.Main.Get(MyGbufferSlot.LBuffer));
     RC.BindSRV(0, accumTarget);
     RC.BindSRV(1, coverageTarget);
     MyScreenPass.DrawFullscreenQuad(null);
 }
Beispiel #7
0
        internal static MyBindableResource Run(MyBindableResource src, MyBindableResource avgLum)
        {
            RC.CSSetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);

            RC.BindUAV(0, MyRender11.HalfScreenUavHDR);
            RC.BindSRVs(0, src, avgLum);

            RC.SetCS(m_bloomShader);

            var size = MyRender11.HalfScreenUavHDR.GetSize();

            VRageMath.Vector2I threadGroups = new VRageMath.Vector2I((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads);
            RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);

            RC.SetCS(m_downscaleShader);

            size         = MyRender11.QuarterScreenUavHDR.GetSize();
            threadGroups = new VRageMath.Vector2I((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads);
            RC.BindUAV(0, MyRender11.QuarterScreenUavHDR);
            RC.BindSRV(0, MyRender11.HalfScreenUavHDR);
            RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);

            size         = MyRender11.EighthScreenUavHDR.GetSize();
            threadGroups = new VRageMath.Vector2I((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads);
            RC.BindUAV(0, MyRender11.EighthScreenUavHDR);
            RC.BindSRV(0, MyRender11.QuarterScreenUavHDR);
            RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);

            RC.SetCS(m_blurV);
            RC.BindUAV(0, MyRender11.EighthScreenUavHDRHelper);
            RC.BindSRV(0, MyRender11.EighthScreenUavHDR);
            RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);

            RC.SetCS(m_blurH);
            RC.BindUAV(0, MyRender11.EighthScreenUavHDR);
            RC.BindSRV(0, MyRender11.EighthScreenUavHDRHelper);

            int nPasses = 1;

            if (MyStereoRender.Enable)
            {
                threadGroups.X /= 2;
                nPasses         = 2;
            }
            for (int nPass = 0; nPass < nPasses; nPass++)
            {
                MyStereoRegion region = MyStereoRegion.FULLSCREEN;
                if (MyStereoRender.Enable)
                {
                    region = nPass == 0 ? MyStereoRegion.LEFT : MyStereoRegion.RIGHT;
                }
                RC.CSSetCB(1, GetCB_blurH(region, size));
                RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);
            }

            return(MyRender11.EighthScreenUavHDR);
        }
        static void RenderDirectionalEnvironmentLight()
        {
            PixelShaderId directionalPixelShader;

            if (!MyRenderProxy.Settings.EnableShadows)
            {
                if (DirectionalEnvironmentLight_NoShadow == PixelShaderId.NULL)
                {
                    DirectionalEnvironmentLight_NoShadow = MyShaders.CreatePs("light_dir.hlsl", new[] { new ShaderMacro("NO_SHADOWS", null) });
                }

                directionalPixelShader = DirectionalEnvironmentLight_NoShadow;
            }
            else
            {
                directionalPixelShader = DirectionalEnvironmentLight_Pixel;
            }
            MySunlightConstantsLayout constants;

            constants.Direction = MyEnvironment.DirectionalLightDir;
            constants.Color     = MyEnvironment.DirectionalLightIntensity;

            var mapping = MyMapping.MapDiscard(m_sunlightConstants);

            mapping.WriteAndPosition(ref constants);
            mapping.Unmap();

            //context.VertexShader.Set(MyCommon.FullscreenShader.VertexShader);
            RC.SetPS(directionalPixelShader);
            RC.SetCB(1, m_sunlightConstants);
            RC.SetCB(4, MyRender11.DynamicShadows.ShadowCascades.CascadeConstantBuffer);
            RC.DeviceContext.PixelShader.SetSamplers(0, MyRender11.StandardSamplers);
            RC.DeviceContext.PixelShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MyRender11.m_shadowmapSamplerState);

            RC.DeviceContext.PixelShader.SetShaderResource(MyCommon.SKYBOX_SLOT, MyTextures.GetView(MyTextures.GetTexture(MyEnvironment.DaySkybox, MyTextureEnum.CUBEMAP, true)));

            RC.DeviceContext.PixelShader.SetShaderResource(MyCommon.SKYBOX_IBL_SLOT,
                                                           MyRender11.IsIntelBrokenCubemapsWorkaround ? MyTextures.GetView(MyTextures.IntelFallbackCubeTexId) : MyEnvironmentProbe.Instance.cubemapPrefiltered.ShaderView);
            RC.DeviceContext.PixelShader.SetShaderResource(MyCommon.SKYBOX2_SLOT, MyTextures.GetView(MyTextures.GetTexture(MyEnvironment.NightSkybox, MyTextureEnum.CUBEMAP, true)));
            RC.DeviceContext.PixelShader.SetShaderResource(MyCommon.SKYBOX2_IBL_SLOT, MyTextures.GetView(MyTextures.GetTexture(MyEnvironment.NightSkyboxPrefiltered, MyTextureEnum.CUBEMAP, true)));

            RC.DeviceContext.PixelShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, MyRender11.DynamicShadows.ShadowCascades.CascadeShadowmapArray.ShaderView);
            RC.DeviceContext.PixelShader.SetShaderResource(MyCommon.SHADOW_SLOT, MyRender11.PostProcessedShadows.ShaderView);

            RC.DeviceContext.PixelShader.SetShaderResource(MyCommon.AMBIENT_BRDF_LUT_SLOT,
                                                           MyCommon.GetAmbientBrdfLut());

            RC.BindSRV(MyCommon.AO_SLOT, MyScreenDependants.m_ambientOcclusion);

            MyScreenPass.RunFullscreenPixelFreq(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer));
            if (MyRender11.MultisamplingEnabled)
            {
                RC.SetPS(DirectionalEnvironmentLight_Sample);
                MyScreenPass.RunFullscreenSampleFreq(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer));
            }
        }
        internal static void DrawParticles(MyBindableResource particleRenderTarget, int quadStartX, int quadStartY, int quadSize)
        {
            RC.DeviceContext.PixelShader.Set(m_blitTextureShader);
            RC.BindSRV(0, particleRenderTarget);
            RC.SetBS(MyRender11.BlendAlphaPremult);

            DrawQuad(quadStartX, quadStartY, quadSize, quadSize * MyRender11.ViewportResolution.Y / MyRender11.ViewportResolution.X);
            RC.SetBS(null);
            RC.DeviceContext.PixelShader.SetShaderResource(0, null);
        }
Beispiel #10
0
        internal static void Run(MyBindableResource dst, MyBindableResource src, BlendState bs = null)
        {
            RC.SetBS(bs);
            RC.SetRS(null);
            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, dst);
            RC.BindSRV(0, src);
            RC.SetPS(m_copyPixelShader);

            DrawFullscreenQuad();
            RC.SetBS(null);
        }
        internal static void RunWithStencil(MyBindableResource dst, MyBindableResource src, BlendState bs = null)
        {
            RC.SetDS(MyDepthStencilState.TestOutlineMeshStencil, 0x40);
            RC.SetBS(bs);
            RC.SetRS(null);
            RC.BindDepthRT(MyGBuffer.Main.DepthStencil, DepthStencilAccess.ReadOnly, dst);
            RC.BindSRV(0, src);
            RC.SetPS(m_ps);

            DrawFullscreenQuad();
            RC.SetBS(null);
        }
Beispiel #12
0
        internal static void RunWithStencil(MyBindableResource destinationResource, MyBindableResource sourceResource, BlendState blendState, DepthStencilState depthStencilState, int stencilMask)
        {
            RC.SetDS(depthStencilState, stencilMask);
            RC.SetBS(blendState);
            RC.SetRS(null);
            RC.BindDepthRT(MyGBuffer.Main.DepthStencil, DepthStencilAccess.ReadOnly, destinationResource);
            RC.BindSRV(0, sourceResource);
            RC.SetPS(m_copyPixelShader);

            DrawFullscreenQuad();
            RC.SetBS(null);
        }
        internal static void Run(MyBindableResource dst, MyBindableResource src, MyBindableResource stencil)
        {
            RC.BindUAV(0, dst);
            RC.BindSRV(0, src, stencil);

            RC.SetCS(m_cs);

            var size = dst.GetSize();

            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);
            RC.SetCS(null);
        }
        internal static void Run(MyBindableResource dst, MyBindableResource src)
        {
            //RC.SetBS(MyRender.BlendStateAdditive);
            RC.SetBS(MyRender11.BlendAlphaPremult);
            RC.SetRS(null);
            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, dst);
            RC.BindSRV(0, src);
            RC.SetPS(m_ps);

            DrawFullscreenQuad();
            RC.SetBS(null);
        }
        internal static void RunWithPixelStencilTest(MyBindableResource dst, MyBindableResource src, BlendState bs = null)
        {
            RC.SetDS(null);
            RC.SetBS(bs);
            RC.SetRS(null);
            RC.BindDepthRT(null, DepthStencilAccess.ReadOnly, dst);
            RC.BindSRV(0, src);
            RC.BindSRV(1, MyGBuffer.Main.DepthStencil.Stencil);
            RC.SetPS(m_psPixelStencil);

            DrawFullscreenQuad();
            RC.SetBS(null);
        }
Beispiel #16
0
        static void RenderPointlightsTiled()
        {
            RC.BindSRV(MyCommon.TILE_LIGHT_INDICES_SLOT, MyScreenDependants.m_tileIndices);
            RC.BindRawSRV(MyCommon.POINTLIGHT_SLOT, m_pointlightCullHwBuffer.Srv);
            RC.BindSRV(MyCommon.AO_SLOT, MyScreenDependants.m_ambientOcclusion);

            RC.SetPS(PointlightsTiled_Pixel);
            MyScreenPass.RunFullscreenPixelFreq(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer));
            if (MyRender11.MultisamplingEnabled)
            {
                RC.SetPS(PointlightsTiled_Sample);
                MyScreenPass.RunFullscreenSampleFreq(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer));
            }
        }
Beispiel #17
0
        internal static void Run(MyBindableResource destination, MyBindableResource source)
        {
            var context = MyRender11.DeviceContext;

            context.OutputMerger.BlendState = null;

            RC.SetIL(null);
            context.PixelShader.Set(m_ps);

            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, destination);
            RC.BindSRV(0, source);

            MyScreenPass.DrawFullscreenQuad(new MyViewport(destination.GetSize().X, destination.GetSize().Y));
        }
Beispiel #18
0
        internal static MyBindableResource Run(MyBindableResource src, MyBindableResource avgLum)
        {
            var buffer  = MyCommon.GetObjectCB(16);
            var mapping = MyMapping.MapDiscard(buffer);

            mapping.WriteAndPosition(ref MyRender11.Settings.MiddleGrey);
            mapping.WriteAndPosition(ref MyRender11.Settings.LuminanceExposure);
            mapping.WriteAndPosition(ref MyRender11.Settings.BloomExposure);
            mapping.WriteAndPosition(ref MyRender11.Settings.BloomMult);
            mapping.Unmap();

            RC.CSSetCB(0, MyCommon.FrameConstants);
            RC.CSSetCB(1, MyCommon.GetObjectCB(16));

            RC.BindUAV(0, MyRender11.HalfScreenUavHDR);
            RC.BindSRVs(0, src, avgLum);

            RC.SetCS(m_bloomShader);

            var size = MyRender11.HalfScreenUavHDR.GetSize();

            RC.DeviceContext.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.SetCS(m_downscaleShader);

            size = MyRender11.QuarterScreenUavHDR.GetSize();
            RC.BindUAV(0, MyRender11.QuarterScreenUavHDR);
            RC.BindSRV(0, MyRender11.HalfScreenUavHDR);
            RC.DeviceContext.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            size = MyRender11.EighthScreenUavHDR.GetSize();
            RC.BindUAV(0, MyRender11.EighthScreenUavHDR);
            RC.BindSRV(0, MyRender11.QuarterScreenUavHDR);
            RC.DeviceContext.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.SetCS(m_blurH);
            RC.BindUAV(0, MyRender11.EighthScreenUavHDRHelper);
            RC.BindSRV(0, MyRender11.EighthScreenUavHDR);
            RC.DeviceContext.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.SetCS(m_blurV);
            RC.BindUAV(0, MyRender11.EighthScreenUavHDR);
            RC.BindSRV(0, MyRender11.EighthScreenUavHDRHelper);
            RC.DeviceContext.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            return(MyRender11.EighthScreenUavHDR);
        }
Beispiel #19
0
        internal static MyBindableResource Run(MyBindableResource src, MyBindableResource avgLum)
        {
            var mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(16));

            mapping.stream.Write(MyRender11.Settings.MiddleGrey);
            mapping.stream.Write(MyRender11.Settings.LuminanceExposure);
            mapping.stream.Write(MyRender11.Settings.BloomExposure);
            mapping.stream.Write(MyRender11.Settings.BloomMult);
            mapping.Unmap();

            RC.CSSetCB(0, MyCommon.FrameConstants);
            RC.CSSetCB(1, MyCommon.GetObjectCB(16));

            RC.BindUAV(0, MyRender11.m_div2);
            RC.BindSRV(0, src, avgLum);

            RC.SetCS(m_bloomShader);

            var size = MyRender11.m_div2.GetSize();

            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.SetCS(m_downscaleShader);

            size = MyRender11.m_div4.GetSize();
            RC.BindUAV(0, MyRender11.m_div4);
            RC.BindSRV(0, MyRender11.m_div2);
            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            size = MyRender11.m_div8.GetSize();
            RC.BindUAV(0, MyRender11.m_div8);
            RC.BindSRV(0, MyRender11.m_div4);
            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.SetCS(m_blurH);
            RC.BindUAV(0, MyRender11.m_div8_1);
            RC.BindSRV(0, MyRender11.m_div8);
            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.SetCS(m_blurV);
            RC.BindUAV(0, MyRender11.m_div8);
            RC.BindSRV(0, MyRender11.m_div8_1);
            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            return(MyRender11.m_div8);
        }
        static void RenderDirectionalEnvironmentLight()
        {
            MySunlightConstantsLayout constants;

            constants.Direction = MyEnvironment.DirectionalLightDir;
            constants.Color     = MyEnvironment.DirectionalLightIntensity;

            var mapping = MyMapping.MapDiscard(m_sunlightConstants);

            mapping.stream.Write(constants);
            mapping.Unmap();

            //context.VertexShader.Set(MyCommon.FullscreenShader.VertexShader);
            RC.SetPS(DirectionalEnvironmentLight_Pixel);
            RC.SetCB(1, m_sunlightConstants);
            RC.SetCB(4, MyShadows.m_csmConstants);
            RC.Context.PixelShader.SetSamplers(0, MyRender11.StandardSamplers);
            RC.Context.PixelShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MyRender11.m_shadowmapSamplerState);
            RC.Context.PixelShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, MyShadows.m_cascadeShadowmapArray.ShaderView);

            var z = Vector4.Transform(new Vector4(0.5f, 0.5f, -MyEnvironment.FarClipping, 1), MyEnvironment.Projection);


            RC.Context.PixelShader.SetShaderResource(MyCommon.SKYBOX_SLOT, MyTextures.GetView(MyTextures.GetTexture(MyEnvironment.DaySkybox, MyTextureEnum.CUBEMAP, true)));
            //RC.Context.PixelShader.SetShaderResource(MyCommon.SKYBOX_IBL_SLOT, MyTextures.GetView(MyTextures.GetTexture(MyEnvironment.DaySkyboxPrefiltered, MyTextureEnum.CUBEMAP, true)));

            RC.Context.PixelShader.SetShaderResource(MyCommon.SKYBOX_IBL_SLOT,
                                                     MyRender11.IsIntelBrokenCubemapsWorkaround ? MyTextures.GetView(MyTextures.IntelFallbackCubeTexId) : MyGeometryRenderer.m_envProbe.cubemapPrefiltered.ShaderView);
            RC.Context.PixelShader.SetShaderResource(MyCommon.SKYBOX2_SLOT, MyTextures.GetView(MyTextures.GetTexture(MyEnvironment.NightSkybox, MyTextureEnum.CUBEMAP, true)));
            RC.Context.PixelShader.SetShaderResource(MyCommon.SKYBOX2_IBL_SLOT, MyTextures.GetView(MyTextures.GetTexture(MyEnvironment.NightSkyboxPrefiltered, MyTextureEnum.CUBEMAP, true)));

            RC.Context.PixelShader.SetShaderResource(MyCommon.SHADOW_SLOT, MyRender11.m_shadowsHelper.ShaderView);

            RC.Context.PixelShader.SetShaderResource(MyCommon.AMBIENT_BRDF_LUT_SLOT,
                                                     MyCommon.GetAmbientBrdfLut());

            RC.BindSRV(MyCommon.AO_SLOT, MyScreenDependants.m_ambientOcclusion);

            MyScreenPass.RunFullscreenPixelFreq(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer));
            if (MyRender11.MultisamplingEnabled)
            {
                RC.SetPS(DirectionalEnvironmentLight_Sample);
                MyScreenPass.RunFullscreenSampleFreq(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer));
            }
        }
Beispiel #21
0
        internal static void Run(MyBindableResource destination, MyBindableResource source)
        {
            var context = MyRender11.Context;

            context.OutputMerger.BlendState = null;
            //context.Rasterizer.SetViewport(0, 0, MyRender.ViewportResolution.X, MyRender.ViewportResolution.Y);

            context.InputAssembler.InputLayout = null;
            context.PixelShader.Set(m_copyPs);

            //context.OutputMerger.SetTargets(null as DepthStencilView, target);
            //context.PixelShader.SetShaderResource(0, resource);

            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, destination);
            RC.BindSRV(0, source);

            MyScreenPass.DrawFullscreenQuad(new MyViewport(destination.GetSize().X, destination.GetSize().Y));
        }
Beispiel #22
0
        internal static void Copy(MyBindableResource destination, MyBindableResource source)
        {
            var context = MyRender.Context;

            context.OutputMerger.BlendState = null;
            context.Rasterizer.SetViewport(0, 0, MyRender.ViewportResolution.X, MyRender.ViewportResolution.Y);

            context.InputAssembler.InputLayout = null;
            context.VertexShader.Set(FullscreenShader.VertexShader);
            context.PixelShader.Set(CopyShader.PixelShader);

            //context.OutputMerger.SetTargets(null as DepthStencilView, target);
            //context.PixelShader.SetShaderResource(0, resource);

            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, destination);
            RC.BindSRV(0, source);

            context.Draw(3, 0);
        }
Beispiel #23
0
        private static void Render(SharpDX.Direct3D11.ShaderResourceView textureArraySRV, MyBindableResource depthRead)
        {
            RC.SetVS(m_vs);
            if (MyRender11.DebugOverrides.OIT)
            {
                RC.SetPS(m_psOIT);
            }
            else
            {
                RC.SetPS(m_ps);
            }

            RC.SetVB(0, null, 0);
            RC.SetIB(m_ib.Buffer, SharpDX.DXGI.Format.R32_UInt);
            RC.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;

            RC.SetCB(1, m_activeListConstantBuffer);

            RC.BindSRV(0, depthRead);
            RC.DeviceContext.PixelShader.SetShaderResources(1, textureArraySRV);

            RC.VSBindRawSRV(0, m_particleBuffer);
            RC.VSBindRawSRV(1, m_aliveIndexBuffer);
            RC.VSBindRawSRV(2, m_emitterStructuredBuffer);
            RC.DeviceContext.VertexShader.SetShaderResource(MyCommon.SKYBOX_IBL_SLOT,
                                                            MyRender11.IsIntelBrokenCubemapsWorkaround ? Resources.MyTextures.GetView(Resources.MyTextures.IntelFallbackCubeTexId) : MyEnvironmentProbe.Instance.cubemapPrefiltered.SRV);
            RC.DeviceContext.VertexShader.SetShaderResource(MyCommon.SKYBOX2_IBL_SLOT,
                                                            Resources.MyTextures.GetView(Resources.MyTextures.GetTexture(MyRender11.Environment.NightSkyboxPrefiltered, Resources.MyTextureEnum.CUBEMAP, true)));

            // bind render target?
            if (!MyStereoRender.Enable)
            {
                RC.DeviceContext.DrawIndexedInstancedIndirect(m_indirectDrawArgsBuffer.Buffer, 0);
            }
            else
            {
                MyStereoRender.DrawIndexedInstancedIndirectGPUParticles(RC, m_indirectDrawArgsBuffer.Buffer, 0);
            }

            MyRender11.ProcessDebugOutput();
            RC.DeviceContext.PixelShader.SetShaderResource(MyCommon.SKYBOX_IBL_SLOT, null);
            RC.DeviceContext.PixelShader.SetShaderResource(MyCommon.SKYBOX2_IBL_SLOT, null);
        }
Beispiel #24
0
        // Per-frame simulation step
        private static void Simulate(MyBindableResource depthRead)
        {
            RC.BindUAV(0, m_particleBuffer);
            RC.BindUAV(1, m_deadListBuffer);
            RC.BindUAV(2, m_aliveIndexBuffer, 0);
            RC.BindUAV(3, m_indirectDrawArgsBuffer);

            RC.BindSRV(0, depthRead);
            RC.CSBindRawSRV(1, m_emitterStructuredBuffer);

            RC.SetCS(m_csSimulate);

            RC.DeviceContext.Dispatch(align(MyGPUEmitters.MAX_PARTICLES, 256) / 256, 1, 1);

            RC.DeviceContext.ComputeShader.SetUnorderedAccessView(0, null, -1);
            RC.DeviceContext.ComputeShader.SetUnorderedAccessView(1, null, -1);
            RC.DeviceContext.ComputeShader.SetUnorderedAccessView(2, null, -1);
            RC.DeviceContext.ComputeShader.SetUnorderedAccessView(3, null, -1);
        }
Beispiel #25
0
        internal static void RunWithPixelStencilTest(MyBindableResource dst, MyBindableResource src, BlendState bs = null, bool inverseTest = false)
        {
            RC.SetDS(null);
            RC.SetBS(bs);
            RC.SetRS(null);
            RC.BindDepthRT(null, DepthStencilAccess.ReadOnly, dst);
            RC.BindSRV(0, src);
            RC.BindSRV(1, MyGBuffer.Main.DepthStencil.Stencil);
            if (!inverseTest)
            {
                RC.SetPS(m_stencilTestPixelShader);
            }
            else
            {
                RC.SetPS(m_stencilInverseTestPixelShader);
            }

            DrawFullscreenQuad();
            RC.SetBS(null);
        }
Beispiel #26
0
        internal static void Run(MyBindableResource dst1, MyBindableResource dst2, MyBindableResource lightBuffer, MyGBuffer gbuffer)
        {
            if (!Settings.BlurEnabled || Settings.BlurAmount < 0.01f)
            {
                return;
            }

            RC.DeviceContext.ClearRenderTargetView((dst1 as IRenderTargetBindable).RTV, new SharpDX.Color4(0, 0, 0, 0));
            RC.DeviceContext.ClearRenderTargetView((dst2 as IRenderTargetBindable).RTV, new SharpDX.Color4(0, 0, 0, 0));

            float zero    = 0f;
            var   mapping = MyMapping.MapDiscard(m_cb);

            mapping.WriteAndPosition(ref Settings.BlurAmount);
            mapping.WriteAndPosition(ref Settings.BlurDistance);
            mapping.WriteAndPosition(ref Settings.BlurTransitionRatio);
            mapping.WriteAndPosition(ref zero);
            mapping.Unmap();

            RC.SetCB(0, MyCommon.FrameConstants);
            RC.SetCB(1, m_cb);


            RC.SetPS(m_psH);
            RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, dst1);
            RC.BindGBufferForRead(0, gbuffer);
            RC.BindSRV(5, lightBuffer);
            DrawFullscreenQuad();


            RC.SetPS(m_psV);
            RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, dst2);
            RC.BindSRV(5, dst1);

            DrawFullscreenQuad();

//          MyBlendTargets.Run(lightBuffer, MyScreenDependants.m_planetBlur2, MyRender11.BlendPlanetBlur);
//          MyBlendTargets.Run(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer), MyScreenDependants.m_planetBlur2, MyRender11.BlendPlanetBlur);
        }
        internal unsafe static void Render(MyBindableResource dst, MyBindableResource depth, MyBindableResource depthRead)
        {
            if (!MyRender11.DebugOverrides.BillboardsDynamic)
            {
                OnFrameStart();
            }

            m_stats.Clear();
            MyRender11.GetRenderProfiler().StartProfilingBlock("Gather");
            Gather();
            MyRender11.GetRenderProfiler().EndProfilingBlock();

            MyRender11.GetRenderProfiler().StartProfilingBlock("Draw");
            TransferData();

            RC.SetupScreenViewport();
            RC.BindDepthRT(depth, DepthStencilAccess.ReadOnly, dst);
            RC.SetBS(MyRender11.BlendAlphaPremult);
            RC.SetRS(MyRender11.m_nocullRasterizerState);
            RC.BindRawSRV(104, m_SB);
            RC.BindSRV(1, depthRead);
            RC.SetCB(2, MyCommon.GetObjectCB(sizeof(Matrix) * MaxCustomProjections));
            RC.SetDS(MyDepthStencilState.DefaultDepthState);

            RC.SetCB(4, MyRender11.DynamicShadows.ShadowCascades.CascadeConstantBuffer);
            RC.DeviceContext.VertexShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, SamplerStates.m_shadowmap);
            RC.DeviceContext.VertexShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, MyRender11.DynamicShadows.ShadowCascades.CascadeShadowmapArray.SRV);
            RC.DeviceContext.VertexShader.SetSamplers(0, SamplerStates.StandardSamplers);

            RC.DeviceContext.VertexShader.SetShaderResource(MyCommon.SKYBOX_IBL_SLOT,
                                                            MyRender11.IsIntelBrokenCubemapsWorkaround ? MyTextures.GetView(MyTextures.IntelFallbackCubeTexId) : MyEnvironmentProbe.Instance.cubemapPrefiltered.SRV);
            RC.DeviceContext.VertexShader.SetShaderResource(MyCommon.SKYBOX2_IBL_SLOT,
                                                            MyTextures.GetView(MyTextures.GetTexture(MyEnvironment.NightSkyboxPrefiltered, MyTextureEnum.CUBEMAP, true)));

            RC.SetVB(0, m_VB.Buffer, m_VB.Stride);
            RC.SetIB(m_IB.Buffer, m_IB.Format);

            RC.SetIL(m_inputLayout);

            for (int i = 0; i < m_batches.Count; i++)
            {
                // first part of batches contain sorted billboards and they read depth
                // second part of batches contain unsorted billboards and they ignore depth
                // switch here:
                if (m_batches[i].Offset == m_sortedBillboardsNum)
                {
                    //RC.BindDepthRT(null, DepthStencilAccess.ReadOnly, dst);
                }

                if (m_batches[i].Lit)
                {
                    RC.SetVS(m_vsLit);

                    if (m_batches[i].AlphaCutout)
                    {
                        RC.SetPS(m_psAlphaCutoutAndLit);
                    }
                    else
                    {
                        RC.SetPS(m_psLit);
                    }
                }
                else
                if (m_batches[i].AlphaCutout)
                {
                    RC.SetVS(m_vs);
                    RC.SetPS(m_psAlphaCutout);
                }
                else
                {
                    RC.SetVS(m_vs);
                    RC.SetPS(m_ps);
                }

                RC.BindRawSRV(0, m_batches[i].Texture);
                RC.DeviceContext.DrawIndexed(m_batches[i].Num * 6, m_batches[i].Offset * 6, 0);
                ++RC.Stats.BillboardDrawIndexed;
            }
            m_stats.Billboards += m_sorted + m_unsorted;

            RC.SetRS(null);
            RC.SetBS(null);
            m_batches.Clear();
            MyRender11.GatherStats(m_stats);
            MyRender11.GetRenderProfiler().EndProfilingBlock();
        }
Beispiel #28
0
        internal static MyBindableResource Run(MyBindableResource uav0, MyBindableResource uav1, MyBindableResource src,
                                               MyBindableResource prevLum, MyBindableResource localAvgLum)
        {
            var size      = src.GetSize();
            var texelsNum = size.X * size.Y;
            var mapping   = MyMapping.MapDiscard(MyCommon.GetObjectCB(16));

            mapping.stream.Write((uint)size.X);
            mapping.stream.Write((uint)size.Y);
            mapping.stream.Write(texelsNum);
            mapping.stream.Write(MyRender11.Postprocess.EnableEyeAdaptation ? -1.0f : MyRender11.Postprocess.ConstantLuminance);

            mapping.Unmap();

            RC.CSSetCB(0, MyCommon.FrameConstants);
            RC.CSSetCB(1, MyCommon.GetObjectCB(16));

            RC.BindUAV(0, uav0);
            RC.BindSRV(0, src);
            RC.SetCS(m_initialShader);

            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.SetCS(m_sumShader);
            int i = 0;

            while (true)
            {
                size.X = (size.X + m_numthreads - 1) / m_numthreads;
                size.Y = (size.Y + m_numthreads - 1) / m_numthreads;

                if (size.X <= 8 && size.Y <= 8)
                {
                    break;
                }

                //mapping = MyMapping.MapDiscard(MyCommon.GetObjectBuffer(16).Buffer);
                //mapping.stream.Write(new Vector2I(size.X, size.Y));
                //mapping.Unmap();

                RC.BindUAV(0, (i % 2 == 0) ? uav1 : uav0);
                RC.BindSRV(0, (i % 2 == 0) ? uav0 : uav1);

                RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

                //might not be exactly correct if we skip this
                var dirty = (i % 2 == 0) ? uav0 : uav1;
                RC.Context.ClearUnorderedAccessView((dirty as IUnorderedAccessBindable).UAV, new SharpDX.Int4(0, 0, 0, 0));

                i++;
            }

            RC.SetCS(m_finalShader);

            //mapping = MyMapping.MapDiscard(MyCommon.GetObjectBuffer(16).Buffer);
            //mapping.stream.Write(new Vector2I(size.X, size.Y));
            //mapping.stream.Write(texelsNum);
            //mapping.Unmap();

            RC.BindUAV(0, (i % 2 == 0) ? uav1 : uav0);
            RC.BindSRV(0, (i % 2 == 0) ? uav0 : uav1, prevLum);

            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.SetCS(null);

            var output = (i % 2 == 0) ? uav1 : uav0;

            RC.Context.CopySubresourceRegion(output.m_resource, 0, new ResourceRegion(0, 0, 0, 1, 1, 1), prevLum.m_resource, 0);

            return(output);
        }
Beispiel #29
0
        internal static MyBindableResource Run(MyBindableResource uav0, MyBindableResource uav1, MyBindableResource src,
                                               MyBindableResource prevLum)
        {
            Vector3I size             = src.GetSize();
            int      texelsNum        = size.X * size.Y;
            uint     sizeX            = (uint)size.X;
            uint     sizeY            = (uint)size.Y;
            float    adaptationFactor = MyRender11.Postprocess.EnableEyeAdaptation ? -1.0f : MyRender11.Postprocess.ConstantLuminance;
            var      buffer           = MyCommon.GetObjectCB(16);
            var      mapping          = MyMapping.MapDiscard(buffer);

            mapping.WriteAndPosition(ref sizeX);
            mapping.WriteAndPosition(ref sizeY);
            mapping.WriteAndPosition(ref texelsNum);
            mapping.WriteAndPosition(ref adaptationFactor);
            mapping.Unmap();

            RC.CSSetCB(0, MyCommon.FrameConstants);
            RC.CSSetCB(1, MyCommon.GetObjectCB(16));

            RC.SetCS(m_initialShader);

            MyBindableResource output = uav0;
            MyBindableResource input  = src;

            RC.BindUAV(0, output);
            RC.BindSRV(0, input);

            int threadGroupCountX = ComputeGroupCount(size.X);
            int threadGroupCountY = ComputeGroupCount(size.Y);

            RC.DeviceContext.Dispatch(threadGroupCountX, threadGroupCountY, 1);

            RC.SetCS(m_sumShader);

            int i = 0;

            while (true)
            {
                size.X = threadGroupCountX;
                size.Y = threadGroupCountY;

                if (size.X <= NUM_THREADS && size.Y <= NUM_THREADS)
                {
                    break;
                }

                output = (i % 2 == 0) ? uav1 : uav0;
                input  = (i % 2 == 0) ? uav0 : uav1;
                RC.BindUAV(0, output);
                RC.BindSRV(0, input);

                threadGroupCountX = ComputeGroupCount(size.X);
                threadGroupCountY = ComputeGroupCount(size.Y);
                RC.DeviceContext.Dispatch(threadGroupCountX, threadGroupCountY, 1);

                i++;
            }

            RC.SetCS(m_finalShader);

            output = (i % 2 == 0) ? uav1 : uav0;
            input  = (i % 2 == 0) ? uav0 : uav1;
            RC.BindUAV(0, output);
            RC.BindSRVs(0, input, prevLum);

            threadGroupCountX = ComputeGroupCount(size.X);
            threadGroupCountY = ComputeGroupCount(size.Y);
            RC.DeviceContext.Dispatch(threadGroupCountX, threadGroupCountY, 1);

            RC.SetCS(null);

            // Backup the result for later process
            RC.DeviceContext.CopySubresourceRegion(output.m_resource, 0, new ResourceRegion(0, 0, 0, 1, 1, 1), prevLum.m_resource, 0);

            return(output);
        }
        internal unsafe static void Render(MyBindableResource dst, MyBindableResource depth, MyBindableResource depthRead)
        {
            MyRender11.GetRenderProfiler().StartProfilingBlock("Gather");
            Gather();
            MyRender11.GetRenderProfiler().EndProfilingBlock();


            MyRender11.GetRenderProfiler().StartProfilingBlock("Draw");
            TransferData();

            RC.SetupScreenViewport();
            RC.BindDepthRT(depth, DepthStencilAccess.ReadOnly, dst);
            RC.SetBS(MyRender11.BlendAlphaPremult);
            RC.SetRS(MyRender11.m_nocullRasterizerState);
            RC.BindRawSRV(104, m_SB.Srv);
            RC.BindSRV(1, depthRead);
            RC.SetCB(2, MyCommon.GetObjectCB(sizeof(Matrix) * MaxCustomProjections));
            RC.SetDS(MyDepthStencilState.DefaultDepthState);

            RC.SetCB(4, MyShadows.m_csmConstants);
            RC.Context.VertexShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MyRender11.m_shadowmapSamplerState);
            RC.Context.VertexShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, MyShadows.m_cascadeShadowmapArray.ShaderView);
            RC.Context.VertexShader.SetSamplers(0, MyRender11.StandardSamplers);


            RC.Context.VertexShader.SetShaderResource(MyCommon.SKYBOX_IBL_SLOT, MyTextures.GetView(MyTextures.GetTexture(MyEnvironment.DaySkyboxPrefiltered, MyTextureEnum.CUBEMAP, true)));
            RC.Context.PixelShader.SetShaderResource(MyCommon.SKYBOX2_IBL_SLOT, MyTextures.GetView(MyTextures.GetTexture(MyEnvironment.NightSkyboxPrefiltered, MyTextureEnum.CUBEMAP, true)));

            RC.SetVB(0, m_VB.Buffer, m_VB.Stride);
            RC.SetIB(m_IB.Buffer, m_IB.Format);

            RC.SetIL(m_inputLayout);

            for (int i = 0; i < m_batches.Count; i++)
            {
                // first part of batches contain sorted billboards and they read depth
                // second part of batches contain unsorted billboards and they ignore depth
                // switch here:
                if (m_batches[i].Offset == m_sortedBillboardsNum)
                {
                    //RC.BindDepthRT(null, DepthStencilAccess.ReadOnly, dst);
                }

                if (m_batches[i].Lit)
                {
                    RC.SetVS(m_vsLit);
                    RC.SetPS(m_psLit);
                }
                else
                {
                    RC.SetVS(m_vs);
                    RC.SetPS(m_ps);
                }

                RC.BindRawSRV(0, m_batches[i].Texture);
                RC.Context.DrawIndexed(m_batches[i].Num * 6, m_batches[i].Offset * 6, 0);
            }

            RC.SetRS(null);
            m_batches.Clear();
            MyRender11.GetRenderProfiler().EndProfilingBlock();
        }