public void DrawWallShadows(List <Vector2[]> walls, LightData pointLight) { GD.SetRenderTarget(ShadowTarg); var geom = ShadowGeometry.GenerateWallShadows(walls, pointLight); DrawShadows(geom, (pointLight.LightType == LightType.OUTDOORS)?2:0, pointLight); }
public void DrawObjShadows(List <Rectangle> objects, LightData pointLight) { GD.SetRenderTarget(ObjShadowTarg); Tuple <GradVertex[], int[]> geom; if (pointLight.LightType == LightType.ROOM) { geom = ShadowGeometry.GenerateObjShadows(objects.Where(x => x.Intersects(pointLight.LightBounds)).ToList(), pointLight); } else { geom = ShadowGeometry.GenerateObjShadows(objects, pointLight); } DrawShadows(geom, 1, pointLight); }
public void DrawWallShadows(List <Vector2[]> walls, LightData pointLight) { if (pointLight.LightType == LightType.OUTDOORS && WallComp != null) { CreateOutsideIfMissing(); LightEffect.Parameters["shadowMap"].SetValue(OutsideShadowTarg); if (OutShadowFloor == pointLight.Level) { return; } OutShadowFloor = pointLight.Level; GD.SetRenderTarget(OutsideShadowTarg); var rect = new Rectangle(DrawRect.X * 2, DrawRect.Y * 2, DrawRect.Width * 2, DrawRect.Height * 2); GD.ScissorRectangle = rect; GD.Clear(Color.Black); var effect = this.GradEffect; effect.Parameters["Projection"].SetValue(Projection); var mat = GetSunlightMat(pointLight); GD.BlendState = MaxBlendRed; WallComp.DrawLMap(GD, pointLight, Projection, mat); Blueprint.Terrain.DrawLMap(GD, pointLight, Projection, mat); Blueprint.RoofComp.DrawLMap(GD, pointLight, Projection, mat); effect.CurrentTechnique = effect.Techniques[0]; EffectPassCollection passes = effect.Techniques[0].Passes; passes[2].Apply(); if (WorldConfig.Current.UltraLighting) { Draw3DObjShadows(pointLight, false); } } else { GD.SetRenderTarget(ShadowTarg); var geom = ShadowGeometry.GenerateWallShadows(walls, pointLight); GD.BlendState = AddBlendRed; DrawShadows(geom, (pointLight.LightType == LightType.OUTDOORS) ? 2 : 0, pointLight); } }
public void DrawObjShadows(List <Rectangle> objects, LightData pointLight) { GD.SetRenderTarget(ObjShadowTarg); if (WorldConfig.Current.UltraLighting) { Draw3DObjShadows(pointLight, true); } else { Tuple <GradVertex[], int[]> geom; if (pointLight.LightType == LightType.ROOM) { geom = ShadowGeometry.GenerateObjShadows(objects.Where(x => x.Intersects(pointLight.LightBounds)).ToList(), pointLight); } else { geom = ShadowGeometry.GenerateObjShadows(objects, pointLight); } GD.BlendState = MaxBlendGreen; DrawShadows(geom, 1, pointLight); } }
public void DrawWallShadows(List <Vector2[]> walls, LightData pointLight) { if (pointLight.LightType == LightType.OUTDOORS && WallComp != null) { CreateOutsideIfMissing(); LightEffect.shadowMap = OutsideShadowTarg; if (OutShadowFloor == pointLight.Level) { return; } OutShadowFloor = pointLight.Level; GD.SetRenderTarget(OutsideShadowTarg); var rect = new Rectangle(DrawRect.X * 2, DrawRect.Y * 2, DrawRect.Width * 2, DrawRect.Height * 2); GD.ScissorRectangle = rect; GD.Clear(Color.Black); var effect = this.GradEffect; effect.Projection = Projection; var mat = GetSunlightMat(pointLight); GD.BlendState = MaxBlendRed; WallComp.DrawLMap(GD, pointLight, Projection, mat); GD.BlendState = MaxBlendRed; Blueprint.Terrain.DrawLMap(GD, pointLight, Projection, mat); Blueprint.RoofComp.DrawLMap(GD, pointLight, Projection, mat); effect.CurrentTechnique = effect.Techniques[0]; EffectPassCollection passes = effect.Techniques[0].Passes; passes[2].Apply(); if (WorldConfig.Current.UltraLighting) { Draw3DObjShadows(pointLight, false); } //blit outside shadows onto post target (for blur) if (OutsideShadowTargPost != null) { var blend = GD.BlendState; var rast = GD.RasterizerState; var seffect = WorldContent.SpriteEffect; //seffect.blurAmount = 0.7f / Blueprint.Width); //seffect.blurAmount = 0.4f / Blueprint.Width); //seffect.heightMultiplier = pointLight.FalloffMultiplier); var blur = (0.2f / Blueprint.Width) * (float)Math.Pow(pointLight.FalloffMultiplier, 0.8f); var height = Math.Max(pointLight.FalloffMultiplier / 1.5f, 1); var harden = 0.03f * (float)Math.Sqrt(pointLight.FalloffMultiplier); //lower shadow target quality as blur size increases (to save on memory bandwidth) if (pointLight.FalloffMultiplier > 6) { ShadowTargQualityDivider = 4; } if (pointLight.FalloffMultiplier > 3) { ShadowTargQualityDivider = 2; } else { ShadowTargQualityDivider = 1; } seffect.blurAmount = new Vector2(blur, blur * 2 / 5f); seffect.heightMultiplier = new Vector2(height, height * 5 / 2f); seffect.hardenBias = new Vector2(harden, harden * 0.5f); seffect.noiseTexture = TextureGenerator.GetUniformNoise(GD); for (int i = 0; i < 4; i++) { seffect.SetTechnique((int)SpriteEffectTechniques.ShadowSeparableBlit1 + i); RenderTarget2D tex; if (i % 2 == 0) { GD.SetRenderTarget(OutsideShadowTargPost); tex = OutsideShadowTarg; } else { GD.SetRenderTarget(OutsideShadowTarg); tex = OutsideShadowTargPost; } ShadowTargBlit.Begin(blendState: (i == 1)? OpaqueBA : BlendState.Opaque, effect: seffect, samplerState: SamplerState.PointClamp); ShadowTargBlit.Draw(tex, new Rectangle(0, 0, tex.Width, tex.Height), Color.White); ShadowTargBlit.End(); } /* * ShadowTargBlit.Begin(blendState: BlendState.Opaque, effect: seffect); * seffect.CurrentTechnique = seffect.Techniques["ShadowBlurBlit"]; * seffect.blurAmount = 0.7f / Blueprint.Width); * seffect.heightMultiplier = pointLight.FalloffMultiplier); * seffect.noiseTexture"]?.SetValue(TextureGenerator.GetUniformNoise(GD)); * ShadowTargBlit.Draw(OutsideShadowTarg, new Rectangle(0, 0, OutsideShadowTarg.Width, OutsideShadowTarg.Height), Color.White); * ShadowTargBlit.End(); */ GD.SetRenderTarget(OutsideShadowTarg); GD.RasterizerState = rast; GD.BlendState = blend; } } else { GD.SetRenderTarget(ShadowTarg); var geom = ShadowGeometry.GenerateWallShadows(walls, pointLight); GD.BlendState = AddBlendRed; DrawShadows(geom, (pointLight.LightType == LightType.OUTDOORS) ? 2 : 0, pointLight); } }