示例#1
0
        private void FinalPass(DeviceContext context)
        {
            context.Rasterizer.SetViewport(Viewport);
            context.VertexShader.Set(FinalPassVS);
            context.PixelShader.Set(FinalPassPS);

            var srv = SceneColourSRV;

            context.PixelShader.SetShaderResources(0, srv, LumBlendResult.SRV, EnableBloom ? Bloom.SRV : null);

            if (CS_FULL_PIXEL_REDUCTION)
            {
                FinalPSVars.Vars.invPixelCount = new Vector4(1.0f / (Width * Height));
            }
            else
            {
                FinalPSVars.Vars.invPixelCount = new Vector4(1.0f / (81 * 81));
            }
            FinalPSVars.Update(context);
            FinalPSVars.SetPSCBuffer(context, 0);

            context.PixelShader.SetSamplers(0, SampleStatePoint, SampleStateLinear);

            context.InputAssembler.InputLayout = FinalPassLayout;
            FinalPassQuad.Draw(context);

            context.VertexShader.Set(null);
            context.PixelShader.Set(null);
            context.PixelShader.SetShaderResources(0, null, null, null);
            context.PixelShader.SetSamplers(0, null, null);
        }
示例#2
0
        public void RenderLights(DeviceContext context, Camera camera, Shadowmap globalShadows, ShaderGlobalLights globalLights)
        {
            //first full-screen directional light pass, for sun/moon
            //discard pixels where scene depth is 0, since nothing was rendered there
            //blend mode: overwrite

            var ps = (MSAASampleCount > 1) ? DirLightMSPS : DirLightPS;

            context.VertexShader.Set(DirLightVS);
            context.PixelShader.Set(ps);

            LightVSVars.Vars.ViewProj  = Matrix.Identity;
            LightVSVars.Vars.CameraPos = Vector4.Zero;
            LightVSVars.Vars.LightType = 0;
            LightVSVars.Vars.IsLOD     = 0;
            LightVSVars.Vars.Pad0      = 0;
            LightVSVars.Vars.Pad1      = 0;
            LightVSVars.Update(context);
            LightVSVars.SetVSCBuffer(context, 0);

            LightPSVars.Vars.GlobalLights       = globalLights.Params;
            LightPSVars.Vars.ViewProjInv        = Matrix.Transpose(camera.ViewProjInvMatrix);
            LightPSVars.Vars.CameraPos          = Vector4.Zero;
            LightPSVars.Vars.EnableShadows      = (globalShadows != null) ? 1u : 0u;
            LightPSVars.Vars.RenderMode         = 0;
            LightPSVars.Vars.RenderModeIndex    = 1;
            LightPSVars.Vars.RenderSamplerCoord = 0;
            LightPSVars.Vars.LightType          = 0;
            LightPSVars.Vars.IsLOD       = 0;
            LightPSVars.Vars.SampleCount = (uint)MSAASampleCount;
            LightPSVars.Vars.SampleMult  = 1.0f / MSAASampleCount;
            LightPSVars.Update(context);
            LightPSVars.SetPSCBuffer(context, 0);

            context.PixelShader.SetShaderResources(0, GBuffers.DepthSRV);
            context.PixelShader.SetShaderResources(2, GBuffers.SRVs);

            if (globalShadows != null)
            {
                globalShadows.SetFinalRenderResources(context);
            }

            context.InputAssembler.InputLayout = LightQuadLayout;
            LightQuad.Draw(context);


            context.VertexShader.Set(null);
            context.PixelShader.Set(null);
            context.PixelShader.SetShaderResources(0, null, null, null);
            context.PixelShader.SetSamplers(0, null, null);
        }
示例#3
0
        public void RenderMoon(DeviceContext context, Camera camera, Weather weather, ShaderGlobalLights lights, RenderableTexture moontex)
        {
            context.VertexShader.Set(moonvs);
            context.PixelShader.Set(moonps);


            Quaternion ori  = Quaternion.Invert(Quaternion.LookAtRH(Vector3.Zero, lights.CurrentMoonDir, lights.MoonAxis));
            Matrix     omat = ori.ToMatrix();


            VSSunMoonVars.Vars.ViewProj = Matrix.Transpose(camera.ViewProjMatrix);
            VSSunMoonVars.Vars.ViewInv  = Matrix.Transpose(omat);// camera.ViewInvMatrix);
            VSSunMoonVars.Vars.CamRel   = new Vector4(lights.CurrentMoonDir, 0);
            VSSunMoonVars.Vars.Size     = new Vector2(weather.CurrentValues.skyMoonDiscSize * 0.008f);
            VSSunMoonVars.Vars.Offset   = Vector2.Zero;
            VSSunMoonVars.Update(context);
            VSSunMoonVars.SetVSCBuffer(context, 0);

            PSSunMoonVars.Vars.Colour = new Vector4(weather.CurrentValues.skyMoonCol * weather.CurrentValues.skyMoonIten, weather.CurrentValues.skyMoonIten);
            PSSunMoonVars.Update(context);
            PSSunMoonVars.SetPSCBuffer(context, 0);

            context.PixelShader.SetSampler(0, texsampler);
            moontex.SetPSResource(context, 0);

            context.InputAssembler.InputLayout = moonlayout;
            moonquad.Draw(context);
        }