コード例 #1
0
        public Vector2 RelativeZeroHLSL(ShadowCasterMap shadowMap)
        {
            Vector2 sizedRelativeZero      = this.RelativeZero * shadowMap.PrecisionRatio;
            float   shadowmapRelativeZeroX = sizedRelativeZero.X / shadowMap.Size.X;

            shadowmapRelativeZeroX -= (shadowmapRelativeZeroX % shadowMap.PixelSizeHLSL.X) * shadowMap.PrecisionRatio;
            float shadowmapRelativeZeroY = sizedRelativeZero.Y / shadowMap.Size.Y;

            shadowmapRelativeZeroY -= (shadowmapRelativeZeroY % shadowMap.PixelSizeHLSL.Y) * shadowMap.PrecisionRatio;
            return(new Vector2(shadowmapRelativeZeroX, shadowmapRelativeZeroY));
        }
コード例 #2
0
        private void ExecuteTechniqueDistortAndComputeDistance(ShadowCasterMap shadowCasterMap, LightSource light, RenderTarget2D destination, string techniqueName)
        {
            graphicsDevice.SetRenderTarget(destination);
            graphicsDevice.Clear(Color.White);

            this.lightsFX.ResolveShadowsEffect.Parameters["lightRelativeZero"].SetValue(light.RelativeZeroHLSL(shadowCasterMap));

            Vector2 shadowCasterMapPortion = (light.Size * shadowCasterMap.PrecisionRatio) / shadowCasterMap.Size;

            this.lightsFX.ResolveShadowsEffect.Parameters["shadowCasterMapPortion"].SetValue(shadowCasterMapPortion);

            this.lightsFX.ResolveShadowsEffect.Parameters["InputTexture"].SetValue(shadowCasterMap.Map);

            this.lightsFX.ResolveShadowsEffect.CurrentTechnique = this.lightsFX.ResolveShadowsEffect.Techniques[techniqueName];

            this.lightsFX.ResolveShadowsEffect.CurrentTechnique.Passes[0].Apply();
            ShadowMapResolver.QuadRender.Render(this.graphicsDevice, Vector2.One * -1, Vector2.One);

            graphicsDevice.SetRenderTarget(null);
        }
コード例 #3
0
 public void ResolveShadows(ShadowCasterMap shadowCasterMap, LightSource resultLight, PostEffect postEffect)
 {
     this.ResolveShadows(shadowCasterMap, resultLight, postEffect, 1f);
 }
コード例 #4
0
        public void ResolveShadows(ShadowCasterMap shadowCasterMap, LightSource resultLight, PostEffect postEffect, float distanceMod)
        {
            BlendState backupBlendState = graphicsDevice.BlendState;

            graphicsDevice.BlendState = BlendState.Opaque;

            this.ExecuteTechniqueDistortAndComputeDistance(shadowCasterMap, resultLight, shadowMapDistorted, "DistortAndComputeDistances");

            // Horizontal reduction
            this.ApplyHorizontalReduction(shadowMapDistorted, this.shadowMapDigested);

            this.distanceMod = distanceMod;

            switch (postEffect)
            {
            case PostEffect.LinearAttenuation:
            {
                this.ExecuteTechniqueDrawShadows(resultLight.PrintedLight, "DrawShadowsLinearAttenuation", this.shadowMapDigested);
            }
            break;

            case PostEffect.LinearAttenuation_BlurLow:
            {
                this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyLow");
                this.ExecuteTechniqueBlurV(processedShadowsRT, resultLight.PrintedLight, "BlurVerticallyLowLinearAttenuation");
            }
            break;

            case PostEffect.LinearAttenuation_BlurMid:
            {
                this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyMid");
                this.ExecuteTechniqueBlurV(processedShadowsRT, resultLight.PrintedLight, "BlurVerticallyMidLinearAttenuation");
            }
            break;

            case PostEffect.LinearAttenuation_BlurHigh:
            {
                this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyHigh");
                this.ExecuteTechniqueBlurV(processedShadowsRT, resultLight.PrintedLight, "BlurVerticallyHighLinearAttenuation");
            }
            break;

            case PostEffect.CurveAttenuation:
            {
                this.ExecuteTechniqueDrawShadows(resultLight.PrintedLight, "DrawShadowsCurveAttenuation", this.shadowMapDigested);
            }
            break;

            case PostEffect.CurveAttenuation_BlurLow:
            {
                this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyLow");
                this.ExecuteTechniqueBlurV(processedShadowsRT, resultLight.PrintedLight, "BlurVerticallyLowCurveAttenuation");
            }
            break;

            case PostEffect.CurveAttenuation_BlurMid:
            {
                this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyMid");
                this.ExecuteTechniqueBlurV(processedShadowsRT, resultLight.PrintedLight, "BlurVerticallyMidCurveAttenuation");
            }
            break;

            case PostEffect.CurveAttenuation_BlurHigh:
            {
                this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyHigh");
                this.ExecuteTechniqueBlurV(processedShadowsRT, resultLight.PrintedLight, "BlurVerticallyHighCurveAttenuation");
            }
            break;

            case PostEffect.Only_BlurLow:
            {
                this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyLow");
                this.ExecuteTechniqueBlurV(processedShadowsRT, resultLight.PrintedLight, "BlurVerticallyLowNoAttenuation");
            }
            break;

            case PostEffect.Only_BlurMid:
            {
                this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyMid");
                this.ExecuteTechniqueBlurV(processedShadowsRT, resultLight.PrintedLight, "BlurVerticallyMidNoAttenuation");
            }
            break;

            case PostEffect.Only_BlurHigh:
            {
                this.ExecuteTechniqueDrawShadows(shadowsRT, "DrawShadowsNoAttenuationPreBlur", this.shadowMapDigested);
                this.ExecuteTechniqueBlurH(shadowsRT, processedShadowsRT, "BlurHorizontallyHigh");
                this.ExecuteTechniqueBlurV(processedShadowsRT, resultLight.PrintedLight, "BlurVerticallyHighNoAttenuation");
            }
            break;

            default:     //NOFX
            {
                this.ExecuteTechniqueDrawShadows(resultLight.PrintedLight, "DrawShadowsNoAttenuation", this.shadowMapDigested);
            }
            break;
            }
            graphicsDevice.BlendState = backupBlendState;
        }
コード例 #5
0
 public void ResolveShadows(ShadowCasterMap shadowCasterMap, LightSource resultLight, PostEffect postEffect, float distanceMod, Vector2 newPosition)
 {
     resultLight.Position = newPosition;
     this.ResolveShadows(shadowCasterMap, resultLight, postEffect, distanceMod);
 }