Ejemplo n.º 1
0
        /// <summary>
        /// Constructor for LightShader, which renders both directional lights
        /// and point lights.
        /// </summary>
        /// <param name="profile"></param>
        /// <param name="content"></param>

        public DepthMapShader(RenderProfile profile, ContentManager content)
            : base(profile, content)
        {
            halfPixel.X = 0.5f / (float)(backBufferWidth * bufferScaling);
            halfPixel.Y = 0.5f / (float)(backBufferHeight * bufferScaling);

            // Depth map target
            depthRT = profile.AddRenderTarget(shadowMapSize * mapsPerRow, shadowMapSize * mapsPerCol,
                                              SurfaceFormat.Single, DepthFormat.Depth24);

            outputTargets = new RenderTarget2D[] { depthRT };

            // Set depth map cache textures
            depthMapCache = new Texture2D[2] {
                new Texture2D(graphicsDevice, shadowMapSize, shadowMapSize),
                new Texture2D(graphicsDevice, shadowMapSize, shadowMapSize)
            };

            lightCamera = new Camera();
            lightCamera.farPlaneDistance = 5000f;
            lightCamera.Initialize(shadowMapSize, shadowMapSize);

            lightViewProj   = new Matrix[numCascades];
            lightProjection = new Matrix[numCascades];

            // Load depth mapping shader effects
            depthEffect        = LoadEffect("depth");
            terrainDepthEffect = LoadEffect("terrainDepth");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Load the GBuffer content
        /// </summary>

        public SmallGBufferShader(RenderProfile profile, ContentManager content)
            : base(profile, content)
        {
            // Normal render targets
            normalRT = profile.AddRenderTarget(
                (int)(backBufferWidth * bufferScaling),
                (int)(backBufferHeight * bufferScaling),
                SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 4);

            depthRT = profile.AddRenderTarget(
                (int)(backBufferWidth * bufferScaling),
                (int)(backBufferHeight * bufferScaling),
                SurfaceFormat.Rg32, DepthFormat.None, 4);

            // Set new half-pixel values to reflect new sizes
            halfPixel.X = 0.5f / (float)(backBufferWidth * bufferScaling);
            halfPixel.Y = 0.5f / (float)(backBufferHeight * bufferScaling);

            bindingTargets    = new RenderTargetBinding[2];
            bindingTargets[0] = normalRT;
            bindingTargets[1] = depthRT;

            outputTargets    = new RenderTarget2D[2];
            outputTargets[0] = normalRT;
            outputTargets[1] = depthRT;

            // Load the shader effects
            gBufferEffect        = content.Load <Effect>("renderGBuffer");
            terrainGBufferEffect = content.Load <Effect>("terrainGBuffer");
            clearBufferEffect    = content.Load <Effect>("clearGBuffer");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Load the GBuffer content
        /// </summary>

        public GBufferShader(RenderProfile profile, ContentManager content)
            : base(profile, content)
        {
            // Diffuse/albedo render target
            diffuseRT = profile.AddRenderTarget(
                (int)(backBufferWidth * bufferScaling),
                (int)(backBufferHeight * bufferScaling),
                SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 4);

            // Specular render target
            specularRT = profile.AddRenderTarget(
                (int)(backBufferWidth * bufferScaling),
                (int)(backBufferHeight * bufferScaling),
                SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 4);

            outputTargets    = new RenderTarget2D[4];
            outputTargets[0] = normalRT;
            outputTargets[1] = depthRT;
            outputTargets[2] = diffuseRT;
            //outputTargets[3] = specularRT;

            bindingTargets    = new RenderTargetBinding[3];
            bindingTargets[0] = outputTargets[0];
            bindingTargets[1] = outputTargets[1];
            bindingTargets[2] = outputTargets[2];
            //bindingTargets[3] = outputTargets[3];
        }
        /// <summary>
        /// Constructor for LightShader, which renders both directional lights
        /// and point lights.
        /// </summary>
        /// <param name="profile"></param>
        /// <param name="content"></param>

        public LightShader(RenderProfile profile, ContentManager content)
            : base(profile, content)
        {
            // Lighting render target
            lightRT = profile.AddRenderTarget(
                (int)(backBufferWidth * bufferScaling),
                (int)(backBufferHeight * bufferScaling),
                SurfaceFormat.HdrBlendable, DepthFormat.None);

            halfPixel.X = 0.5f / (float)(backBufferWidth * bufferScaling);
            halfPixel.Y = 0.5f / (float)(backBufferHeight * bufferScaling);

            outputTargets = new RenderTarget2D[] { lightRT };

            // Configure camera for directional light
            lightCamera = new Camera();
            lightCamera.farPlaneDistance = 1000f;
            lightCamera.Initialize(shadowMapSize, shadowMapSize);

            lightViewProj = new Matrix[numCascades];

            // Load the shader effects
            directionalLightEffect = content.Load <Effect>("directionalLight");
            pointLightEffect       = content.Load <Effect>("pointLight");

            // Set constant parameters
            directionalLightEffect.Parameters["halfPixel"].SetValue(halfPixel);
            pointLightEffect.Parameters["halfPixel"].SetValue(halfPixel);

            // Load the point light model
            sphereModel = content.Load <XnaModel>("sphere");
        }
        public ForwardShader(RenderProfile profile, ContentManager content)
            : base(profile, content)
        {
            hasSceneInput = true;

            // Diffuse render target
            forwardLightingRT = profile.AddRenderTarget(
                (int)(backBufferWidth * bufferScaling),
                (int)(backBufferHeight * bufferScaling),
                SurfaceFormat.Color, DepthFormat.Depth24, 4);

            // Set new half-pixel values to reflect new sizes
            halfPixel.X = 0.5f / (float)(backBufferWidth * bufferScaling);
            halfPixel.Y = 0.5f / (float)(backBufferHeight * bufferScaling);

            outputTargets = new RenderTarget2D[]
            {
                forwardLightingRT
            };

            // Load the shader effects
            forwardRenderEffect        = LoadEffect("forwardRender");
            terrainForwardRenderEffect = LoadEffect("terrainForwardRender");

            renderEffects = new Effect[2] {
                forwardRenderEffect, terrainForwardRenderEffect
            };
        }
Ejemplo n.º 6
0
        public CopyShader(RenderProfile profile, ContentManager content)
            : base(profile, content)
        {
            hasSceneInput = true;

            copyRT = profile.AddRenderTarget(backBufferWidth,
                                             backBufferHeight, SurfaceFormat.Rgba1010102, DepthFormat.Depth24);

            gBufferEffect = content.Load <Effect>("renderGBuffer");
        }
Ejemplo n.º 7
0
        public DepthOfFieldShader(RenderProfile profile, ContentManager content)
            : base(profile, content)
        {
            // Light and combined effect targets
            dofRT = profile.AddRenderTarget(backBufferWidth,
                                            backBufferHeight, SurfaceFormat.Rgba1010102, DepthFormat.None);
            blurFactorRT = profile.AddRenderTarget(backBufferWidth,
                                                   backBufferHeight, SurfaceFormat.Rgba1010102, DepthFormat.None);

            outputTargets = new RenderTarget2D[] {
                dofRT, blurFactorRT
            };

            // Load the shader effects
            blurEffect = content.Load <Effect>("blur");
        }
        /// <summary>
        /// Base renderer where custom RenderTasks derive from, with their
        /// own set of Scenes and render targets for inputs and outputs.
        /// </summary>

        public BaseShader(RenderProfile profile, ContentManager content)
        {
            hasSceneInput = true;
            this.content  = content;

            graphicsDevice = profile.graphicsDevice;

            renderStopWatch = new Stopwatch();
            renderInputs    = new Dictionary <string, RenderInput>();

            // Setup rendering components
            quadRenderer  = new QuadRenderComponent(graphicsDevice);
            sceneRenderer = new SceneRenderer(graphicsDevice, content);
            sceneCuller   = new SceneCuller();

            LoadContent();
        }
        public BlurShader(RenderProfile profile, ContentManager content)
            : base(profile, content)
        {
            float blurStep = 1.5f;

            finalRT = new RenderTarget2D[2];

            // Light and combined effect targets
            finalRT[0] = profile.AddRenderTarget(backBufferWidth,
                                                 backBufferHeight, SurfaceFormat.Color, DepthFormat.None);
            finalRT[1] = profile.AddRenderTarget(backBufferWidth,
                                                 backBufferHeight, SurfaceFormat.Color, DepthFormat.None);

            // Load the shader effects
            blurEffect = content.Load <Effect>("blur");

            blur = new GaussianBlur(backBufferWidth, backBufferHeight, blurStep, blurEffect);
            blurEffect.Parameters["halfPixel"].SetValue(halfPixel);
        }
Ejemplo n.º 10
0
        public FXAAShader(RenderProfile profile, ContentManager content)
            : base(profile, content)
        {
            // Light and combined effect targets
            finalRT = profile.AddRenderTarget(
                (int)(backBufferWidth * bufferScaling),
                (int)(backBufferHeight * bufferScaling), SurfaceFormat.Color, DepthFormat.None);

            // Set new half-pixel values to reflect new sizes
            halfPixel.X = 0.5f / (float)(backBufferWidth * bufferScaling);
            halfPixel.Y = 0.5f / (float)(backBufferHeight * bufferScaling);

            outputTargets = new RenderTarget2D[]
            {
                finalRT
            };

            // Load the shader effects
            fxaaEffect = content.Load <Effect>("fxaa");
        }
Ejemplo n.º 11
0
        public CompositeShader(RenderProfile profile, ContentManager content)
            : base(profile, content)
        {
            // Light and combined effect targets
            finalRT = profile.AddRenderTarget(
                (int)(backBufferWidth * bufferScaling),
                (int)(backBufferHeight * bufferScaling),
                SurfaceFormat.Color, DepthFormat.None);

            halfPixel.X = 0.5f / (float)(backBufferWidth * bufferScaling);
            halfPixel.Y = 0.5f / (float)(backBufferHeight * bufferScaling);

            randomNumber = new Random();

            outputTargets    = new RenderTarget2D[1];
            outputTargets[0] = finalRT;

            // Load the shader effects
            finalComboEffect = content.Load <Effect>("combination");
        }
        public BloomShader(RenderProfile profile, ContentManager content)
            : base(profile, content)
        {
            finalRT = new RenderTarget2D[3];

            // Light and combined effect targets
            finalRT[0] = profile.AddRenderTarget(backBufferWidth,
                                                 backBufferHeight, SurfaceFormat.Rgba1010102, DepthFormat.None);

            finalRT[1] = profile.AddRenderTarget(backBufferWidth / 4,
                                                 backBufferHeight / 4, SurfaceFormat.Rgba1010102, DepthFormat.None);
            finalRT[2] = profile.AddRenderTarget(backBufferWidth / 4,
                                                 backBufferHeight / 4, SurfaceFormat.Rgba1010102, DepthFormat.None);

            // Load the shader effects
            blurEffect = LoadEffect("blur");
            blur       = new GaussianBlur(backBufferWidth, backBufferHeight, 0.5f, blurEffect);

            // Set shader parameters
            threshold      = blurEffect.Parameters["threshold"];
            bloomIntensity = blurEffect.Parameters["bloomFactor"];
            saturation     = blurEffect.Parameters["saturation"];
            contrast       = blurEffect.Parameters["contrast"];

            // Blur parameters
            sampleWeights = blurEffect.Parameters["sampleWeights"];
            sampleOffsets = blurEffect.Parameters["sampleOffsets"];

            // Texture parameters
            diffuseMap     = blurEffect.Parameters["diffuseMap"];
            blurMap        = blurEffect.Parameters["blurMap"];
            halfPixelParam = blurEffect.Parameters["halfPixel"];

            threshold.SetValue(0.75f);
            bloomIntensity.SetValue(1f);
            halfPixelParam.SetValue(halfPixel);

            saturation.SetValue(1.25f);
            contrast.SetValue(1.05f);
        }
        public DiffuseShader(RenderProfile profile, ContentManager content)
            : base(profile, content)
        {
            hasSceneInput = true;

            // Diffuse render target
            diffuseRT = profile.AddRenderTarget(
                (int)(backBufferWidth * bufferScaling),
                (int)(backBufferHeight * bufferScaling),
                SurfaceFormat.Rgba1010102, DepthFormat.Depth24);

            // Set new half-pixel values to reflect new sizes
            halfPixel.X = 0.5f / (float)(backBufferWidth * bufferScaling);
            halfPixel.Y = 0.5f / (float)(backBufferHeight * bufferScaling);

            outputTargets = new RenderTarget2D[]
            {
                diffuseRT
            };

            // Load the shader effects
            gBufferEffect        = content.Load <Effect>("renderGBuffer");
            terrainGBufferEffect = content.Load <Effect>("terrainGBuffer");
        }
        public SSAOShader(RenderProfile profile, ContentManager content)
            : base(profile, content)
        {
            // Light and combined effect targets
            finalRT = new RenderTarget2D[2];

            finalRT[0] = profile.AddRenderTarget(backBufferWidth / 1,
                                                 backBufferHeight / 1, SurfaceFormat.Alpha8, DepthFormat.None);

            finalRT[1] = profile.AddRenderTarget(backBufferWidth / 1,
                                                 backBufferHeight / 1, SurfaceFormat.Alpha8, DepthFormat.None);

            outputTargets = new RenderTarget2D[]
            {
                finalRT[0], finalRT[1]
            };

            randomMap = content.Load <Texture2D>("random");

            // Load the shader effects
            ssaoEffect = content.Load <Effect>("ssao");
            ssaoEffect.Parameters["halfPixel"].SetValue(halfPixel);

            blurEffect = content.Load <Effect>("blur");
            blurEffect.Parameters["halfPixel"].SetValue(halfPixel);

            ssaoEffect.Parameters["g_radius"].SetValue(radius);
            ssaoEffect.Parameters["g_intensity"].SetValue(intensity);
            ssaoEffect.Parameters["g_scale"].SetValue(scale);
            ssaoEffect.Parameters["g_bias"].SetValue(bias);

            //ssaoEffect.Parameters["RandomMap"].SetValue(randomMap);

            // Initialize blur
            blur = new GaussianBlur(backBufferWidth, backBufferHeight, 2f, blurEffect);
        }
Ejemplo n.º 15
0
 protected ShadowMapper(RenderProfile profile, ResourceContentManager content)
     : base(profile, content)
 {
 }