예제 #1
0
        public void OnWindowResize(DXManager dxman)
        {
            DisposeBuffers();

            var device = dxman.device;



            int uw = Width = dxman.backbuffer.Description.Width * SSAASampleCount;
            int uh = Height = dxman.backbuffer.Description.Height * SSAASampleCount;

            Viewport          = new ViewportF();
            Viewport.Width    = (float)uw;
            Viewport.Height   = (float)uh;
            Viewport.MinDepth = 0.0f;
            Viewport.MaxDepth = 1.0f;
            Viewport.X        = 0.0f;
            Viewport.Y        = 0.0f;


            GBuffers             = new GpuMultiTexture(device, uw, uh, 4, Format.R8G8B8A8_UNorm, true, Format.D32_Float, MSAASampleCount);
            WindowSizeVramUsage += GBuffers.VramUsage;

            SceneColour          = new GpuTexture(device, uw, uh, Format.R32G32B32A32_Float, 1, 0, true, Format.D32_Float);
            WindowSizeVramUsage += SceneColour.VramUsage;
        }
예제 #2
0
        public void OnWindowResize(DXManager dxman)
        {
            DisposeBuffers();

            var device = dxman.device;


            int sc = dxman.multisamplecount;
            int sq = dxman.multisamplequality;

            Multisampled = (sc > 1);

            int uw = Width = dxman.backbuffer.Description.Width;
            int uh = Height = dxman.backbuffer.Description.Height;

            Viewport          = new ViewportF();
            Viewport.Width    = (float)uw;
            Viewport.Height   = (float)uh;
            Viewport.MinDepth = 0.0f;
            Viewport.MaxDepth = 1.0f;
            Viewport.X        = 0.0f;
            Viewport.Y        = 0.0f;


            Format f  = Format.R32G32B32A32_Float;
            Format df = Format.D32_Float;


            Primary              = new GpuTexture(device, uw, uh, f, sc, sq, true, df);
            WindowSizeVramUsage += Primary.VramUsage;


            int rc = (int)(Math.Ceiling(uw / 8.0f) * Math.Ceiling(uh / 8.0f));

            Reduction0           = new GpuBuffer <float>(device, 1, rc);
            Reduction1           = new GpuBuffer <float>(device, 1, rc);
            WindowSizeVramUsage += sizeof(float) * rc * 2;

            LumBlendResult       = new GpuBuffer <float>(device, 1, 1);
            WindowSizeVramUsage += sizeof(float); //because 4 bytes matter

            int tw = uw / 8;
            int th = uh / 8;

            rc = tw * th;
            f  = Format.R8G8B8A8_UNorm;

            Bloom0 = new GpuBuffer <Vector4>(device, 1, rc);
            Bloom1 = new GpuBuffer <Vector4>(device, 1, rc);
            WindowSizeVramUsage += /*sizeof(V4F)*/ 16 * rc * 2;

            Bloom = new GpuTexture(device, tw, th, f, 1, 0, false, df);
            WindowSizeVramUsage += Bloom.VramUsage;
        }
예제 #3
0
        public PostProcessor(DXManager dxman)
        {
            var device = dxman.device;

            byte[] bReduceTo1DCS     = File.ReadAllBytes("Shaders\\PPReduceTo1DCS.cso");
            byte[] bReduceTo0DCS     = File.ReadAllBytes("Shaders\\PPReduceTo0DCS.cso");
            byte[] bLumBlendCS       = File.ReadAllBytes("Shaders\\PPLumBlendCS.cso");
            byte[] bBloomFilterBPHCS = File.ReadAllBytes("Shaders\\PPBloomFilterBPHCS.cso");
            byte[] bBloomFilterVCS   = File.ReadAllBytes("Shaders\\PPBloomFilterVCS.cso");
            byte[] bCopyPixelsPS     = File.ReadAllBytes("Shaders\\PPCopyPixelsPS.cso");
            byte[] bFinalPassVS      = File.ReadAllBytes("Shaders\\PPFinalPassVS.cso");
            byte[] bFinalPassPS      = File.ReadAllBytes("Shaders\\PPFinalPassPS.cso");

            ReduceTo1DCS     = new ComputeShader(device, bReduceTo1DCS);
            ReduceTo0DCS     = new ComputeShader(device, bReduceTo0DCS);
            LumBlendCS       = new ComputeShader(device, bLumBlendCS);
            BloomFilterBPHCS = new ComputeShader(device, bBloomFilterBPHCS);
            BloomFilterVCS   = new ComputeShader(device, bBloomFilterVCS);
            CopyPixelsPS     = new PixelShader(device, bCopyPixelsPS);
            FinalPassVS      = new VertexShader(device, bFinalPassVS);
            FinalPassPS      = new PixelShader(device, bFinalPassPS);
            FinalPassQuad    = new UnitQuad(device, true);
            FinalPassLayout  = new InputLayout(device, bFinalPassVS, new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0),
            });


            ReduceCSVars    = new GpuVarsBuffer <PostProcessorReduceCSVars>(device);
            LumBlendCSVars  = new GpuVarsBuffer <PostProcessorLumBlendCSVars>(device);
            FilterBPHCSVars = new GpuVarsBuffer <PostProcessorFilterBPHCSVars>(device);
            FilterVCSVars   = new GpuVarsBuffer <PostProcessorFilterVCSVars>(device);
            FinalPSVars     = new GpuVarsBuffer <PostProcessorFinalPSVars>(device);

            TextureAddressMode a = TextureAddressMode.Clamp;
            Color4             b = new Color4(0.0f, 0.0f, 0.0f, 0.0f);
            Comparison         c = Comparison.Always;

            SampleStatePoint  = DXUtility.CreateSamplerState(device, a, b, c, Filter.MinMagMipPoint, 0, 1.0f, 1.0f, 0.0f);
            SampleStateLinear = DXUtility.CreateSamplerState(device, a, b, c, Filter.MinMagMipLinear, 0, 1.0f, 1.0f, 0.0f);

            BlendState = DXUtility.CreateBlendState(device, false, BlendOperation.Add, BlendOption.One, BlendOption.Zero, BlendOperation.Add, BlendOption.One, BlendOption.Zero, ColorWriteMaskFlags.All);

            GetSampleWeights(ref FilterVCSVars.Vars.avSampleWeights, 3.0f, 1.25f); //init sample weights
            FilterBPHCSVars.Vars.avSampleWeights = FilterVCSVars.Vars.avSampleWeights;
        }
예제 #4
0
        public void Render(DXManager dxman, float elapsed)
        {
            ElapsedTime = elapsed;

            var context = dxman.context;

            if (Multisampled)
            {
                int sr = 0;// D3D11CalcSubresource(0, 0, 1);
                context.ResolveSubresource(Primary.TextureMS, sr, Primary.Texture, sr, Format.R32G32B32A32_Float);
            }

            context.OutputMerger.SetRenderTargets((RenderTargetView)null);

            ProcessLuminance(context);
            ProcessBloom(context);

            dxman.SetDefaultRenderTarget(context);
            context.OutputMerger.SetBlendState(BlendState, null, 0xFFFFFFFF);
            FinalPass(context);
        }
예제 #5
0
        public void Render(DXManager dxman, float elapsed, DeferredScene defScene)
        {
            ElapsedTime = elapsed;
            DefScene    = defScene;
            UsePrimary  = ((defScene?.SSAASampleCount ?? 2) > 1) || (defScene?.SceneColour == null);

            var context = dxman.context;

            if (Multisampled && UsePrimary)
            {
                int sr = 0;// D3D11CalcSubresource(0, 0, 1);
                context.ResolveSubresource(Primary.TextureMS, sr, Primary.Texture, sr, Format.R32G32B32A32_Float);
            }

            context.OutputMerger.SetRenderTargets((RenderTargetView)null);

            ProcessLuminance(context);
            ProcessBloom(context);

            dxman.SetDefaultRenderTarget(context);
            context.OutputMerger.SetBlendState(BlendState, null, 0xFFFFFFFF);
            FinalPass(context);
        }
예제 #6
0
        public DeferredScene(DXManager dxman)
        {
            var device = dxman.device;

            byte[] bDirLightVS   = File.ReadAllBytes("Shaders\\DirLightVS.cso");
            byte[] bDirLightPS   = File.ReadAllBytes("Shaders\\DirLightPS.cso");
            byte[] bDirLightMSPS = File.ReadAllBytes("Shaders\\DirLightPS_MS.cso");
            byte[] bLodLightVS   = File.ReadAllBytes("Shaders\\LodLightsVS.cso");
            byte[] bLodLightPS   = File.ReadAllBytes("Shaders\\LodLightsPS.cso");
            byte[] bLodLightMSPS = File.ReadAllBytes("Shaders\\LodLightsPS_MS.cso");
            byte[] bLightVS      = File.ReadAllBytes("Shaders\\LightVS.cso");
            byte[] bLightPS      = File.ReadAllBytes("Shaders\\LightPS.cso");
            byte[] bLightMSPS    = File.ReadAllBytes("Shaders\\LightPS_MS.cso");
            byte[] bFinalVS      = File.ReadAllBytes("Shaders\\PPFinalPassVS.cso");
            byte[] bSSAAPS       = File.ReadAllBytes("Shaders\\PPSSAAPS.cso");

            DirLightVS = new VertexShader(device, bDirLightVS);
            DirLightPS = new PixelShader(device, bDirLightPS);
            LodLightVS = new VertexShader(device, bLodLightVS);
            LodLightPS = new PixelShader(device, bLodLightPS);
            LightVS    = new VertexShader(device, bLightVS);
            LightPS    = new PixelShader(device, bLightPS);

            try
            {
                //error could happen here if the device isn't supporting feature level 10.1
                DirLightMSPS = new PixelShader(device, bDirLightMSPS);
                LodLightMSPS = new PixelShader(device, bLodLightMSPS);
                LightMSPS    = new PixelShader(device, bLightMSPS);
            }
            catch
            {
                MSAASampleCount = 1; //can't do MSAA without at least 10.1 support
            }


            LightCone       = new UnitCone(device, bLodLightVS, 4, false);
            LightSphere     = new UnitSphere(device, bLodLightVS, 4, true);
            LightCapsule    = new UnitCapsule(device, bLodLightVS, 4, false);
            LightQuad       = new UnitQuad(device, true);
            LightQuadLayout = new InputLayout(device, bDirLightVS, new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0),
            });

            LightVSVars   = new GpuVarsBuffer <DeferredLightVSVars>(device);
            LightPSVars   = new GpuVarsBuffer <DeferredLightPSVars>(device);
            LightInstVars = new GpuVarsBuffer <DeferredLightInstVars>(device);


            FinalVS = new VertexShader(device, bFinalVS);
            SSAAPS  = new PixelShader(device, bSSAAPS);

            SSAAPSVars = new GpuVarsBuffer <DeferredSSAAPSVars>(device);

            TextureAddressMode a = TextureAddressMode.Clamp;
            Color4             b = new Color4(0.0f, 0.0f, 0.0f, 0.0f);
            Comparison         c = Comparison.Always;

            SampleStatePoint  = DXUtility.CreateSamplerState(device, a, b, c, Filter.MinMagMipPoint, 0, 1.0f, 1.0f, 0.0f);
            SampleStateLinear = DXUtility.CreateSamplerState(device, a, b, c, Filter.MinMagMipLinear, 0, 1.0f, 1.0f, 0.0f);

            BlendState = DXUtility.CreateBlendState(device, false, BlendOperation.Add, BlendOption.One, BlendOption.Zero, BlendOperation.Add, BlendOption.One, BlendOption.Zero, ColorWriteMaskFlags.All);
        }