Ejemplo n.º 1
0
        public DistantLightsShader(Device device)
        {
            byte[] vsbytes = File.ReadAllBytes("Shaders\\DistantLightsVS.cso");
            byte[] psbytes = File.ReadAllBytes("Shaders\\DistantLightsPS.cso");

            lightsvs = new VertexShader(device, vsbytes);
            lightsps = new PixelShader(device, psbytes);

            layout = new InputLayout(device, vsbytes, new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0),
            });


            texsampler = new SamplerState(device, new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Clamp,
                AddressV           = TextureAddressMode.Clamp,
                AddressW           = TextureAddressMode.Clamp,
                BorderColor        = Color.Transparent,
                ComparisonFunction = Comparison.Always,
                Filter             = Filter.MinMagMipLinear,
                MaximumAnisotropy  = 1,
                MaximumLod         = float.MaxValue,
                MinimumLod         = 0,
                MipLodBias         = 0,
            });


            quad = new UnitQuad(device);

            VSSceneVars = new GpuVarsBuffer <DistantLightsShaderVSSceneVars>(device);
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
        public SkydomeShader(Device device)
        {
            byte[] skyvsbytes  = File.ReadAllBytes("Shaders\\SkydomeVS.cso");
            byte[] skypsbytes  = File.ReadAllBytes("Shaders\\SkydomePS.cso");
            byte[] sunvsbytes  = File.ReadAllBytes("Shaders\\SkySunVS.cso");
            byte[] sunpsbytes  = File.ReadAllBytes("Shaders\\SkySunPS.cso");
            byte[] moonvsbytes = File.ReadAllBytes("Shaders\\SkyMoonVS.cso");
            byte[] moonpsbytes = File.ReadAllBytes("Shaders\\SkyMoonPS.cso");

            skyvs  = new VertexShader(device, skyvsbytes);
            skyps  = new PixelShader(device, skypsbytes);
            sunvs  = new VertexShader(device, sunvsbytes);
            sunps  = new PixelShader(device, sunpsbytes);
            moonvs = new VertexShader(device, moonvsbytes);
            moonps = new PixelShader(device, moonpsbytes);

            SkyLocalVars = new GpuVarsBuffer <SkydomeShaderSkySystemLocals>(device);
            VSSceneVars  = new GpuVarsBuffer <SkydomeShaderVSSceneVars>(device);
            VSEntityVars = new GpuVarsBuffer <SkydomeShaderVSEntityVars>(device);
            VSModelVars  = new GpuVarsBuffer <SkydomeShaderVSModelVars>(device);
            PSSceneVars  = new GpuVarsBuffer <SkydomeShaderPSSceneVars>(device);

            VSSunMoonVars = new GpuVarsBuffer <SkydomeShaderVSSunMoonVars>(device);
            PSSunMoonVars = new GpuVarsBuffer <SkydomeShaderPSSunMoonVars>(device);

            sundisc   = new UnitDisc(device, 30, true);
            sunlayout = new InputLayout(device, sunvsbytes, sundisc.GetLayout());
            skylayout = new InputLayout(device, skyvsbytes, VertexTypeGTAV.GetLayout(VertexType.PTT));

            moonquad   = new UnitQuad(device, true);
            moonlayout = new InputLayout(device, moonvsbytes, moonquad.GetLayout());

            texsampler = new SamplerState(device, new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                BorderColor        = Color.Black,
                ComparisonFunction = Comparison.Always,
                Filter             = Filter.MinMagMipLinear,
                MaximumAnisotropy  = 1,
                MaximumLod         = float.MaxValue,
                MinimumLod         = 0,
                MipLodBias         = 0,
            });
        }
Ejemplo n.º 4
0
        public void Dispose()
        {
            DisposeBuffers();

            if (BlendState != null)
            {
                BlendState.Dispose();
                BlendState = null;
            }
            if (SampleStateLinear != null)
            {
                SampleStateLinear.Dispose();
                SampleStateLinear = null;
            }
            if (SampleStatePoint != null)
            {
                SampleStatePoint.Dispose();
                SampleStatePoint = null;
            }
            if (LightVSVars != null)
            {
                LightVSVars.Dispose();
                LightVSVars = null;
            }
            if (LightPSVars != null)
            {
                LightPSVars.Dispose();
                LightPSVars = null;
            }
            if (LightInstVars != null)
            {
                LightInstVars.Dispose();
                LightInstVars = null;
            }
            if (LightQuadLayout != null)
            {
                LightQuadLayout.Dispose();
                LightQuadLayout = null;
            }
            if (LightQuad != null)
            {
                LightQuad.Dispose();
                LightQuad = null;
            }
            if (LightCone != null)
            {
                LightCone.Dispose();
                LightCone = null;
            }
            if (LightSphere != null)
            {
                LightSphere.Dispose();
                LightSphere = null;
            }
            if (LightCapsule != null)
            {
                LightCapsule.Dispose();
                LightCapsule = null;
            }
            if (DirLightPS != null)
            {
                DirLightPS.Dispose();
                DirLightPS = null;
            }
            if (DirLightMSPS != null)
            {
                DirLightMSPS.Dispose();
                DirLightMSPS = null;
            }
            if (DirLightVS != null)
            {
                DirLightVS.Dispose();
                DirLightVS = null;
            }
            if (LodLightPS != null)
            {
                LodLightPS.Dispose();
                LodLightPS = null;
            }
            if (LodLightMSPS != null)
            {
                LodLightMSPS.Dispose();
                LodLightMSPS = null;
            }
            if (LodLightVS != null)
            {
                LodLightVS.Dispose();
                LodLightVS = null;
            }
            if (LightPS != null)
            {
                LightPS.Dispose();
                LightPS = null;
            }
            if (LightMSPS != null)
            {
                LightMSPS.Dispose();
                LightMSPS = null;
            }
            if (LightVS != null)
            {
                LightVS.Dispose();
                LightVS = null;
            }
            if (SSAAPSVars != null)
            {
                SSAAPSVars.Dispose();
                SSAAPSVars = null;
            }
            if (SSAAPS != null)
            {
                SSAAPS.Dispose();
                SSAAPS = null;
            }
            if (FinalVS != null)
            {
                FinalVS.Dispose();
                FinalVS = null;
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public void Dispose()
        {
            DisposeBuffers();

            if (BlendState != null)
            {
                BlendState.Dispose();
                BlendState = null;
            }
            if (SampleStateLinear != null)
            {
                SampleStateLinear.Dispose();
                SampleStateLinear = null;
            }
            if (SampleStatePoint != null)
            {
                SampleStatePoint.Dispose();
                SampleStatePoint = null;
            }
            if (FinalPSVars != null)
            {
                FinalPSVars.Dispose();
                FinalPSVars = null;
            }
            if (FilterVCSVars != null)
            {
                FilterVCSVars.Dispose();
                FilterVCSVars = null;
            }
            if (FilterBPHCSVars != null)
            {
                FilterBPHCSVars.Dispose();
                FilterBPHCSVars = null;
            }
            if (LumBlendCSVars != null)
            {
                LumBlendCSVars.Dispose();
                LumBlendCSVars = null;
            }
            if (ReduceCSVars != null)
            {
                ReduceCSVars.Dispose();
                ReduceCSVars = null;
            }
            if (FinalPassLayout != null)
            {
                FinalPassLayout.Dispose();
                FinalPassLayout = null;
            }
            if (FinalPassQuad != null)
            {
                FinalPassQuad.Dispose();
                FinalPassQuad = null;
            }
            if (FinalPassPS != null)
            {
                FinalPassPS.Dispose();
                FinalPassPS = null;
            }
            if (FinalPassVS != null)
            {
                FinalPassVS.Dispose();
                FinalPassVS = null;
            }
            if (CopyPixelsPS != null)
            {
                CopyPixelsPS.Dispose();
                CopyPixelsPS = null;
            }
            if (BloomFilterVCS != null)
            {
                BloomFilterVCS.Dispose();
                BloomFilterVCS = null;
            }
            if (BloomFilterBPHCS != null)
            {
                BloomFilterBPHCS.Dispose();
                BloomFilterBPHCS = null;
            }
            if (LumBlendCS != null)
            {
                LumBlendCS.Dispose();
                LumBlendCS = null;
            }
            if (ReduceTo0DCS != null)
            {
                ReduceTo0DCS.Dispose();
                ReduceTo0DCS = null;
            }
            if (ReduceTo1DCS != null)
            {
                ReduceTo1DCS.Dispose();
                ReduceTo1DCS = null;
            }
        }