Browse Source

tweak point light rendering

mesh_sprite_draw
cosmonaut 5 months ago
parent
commit
ee909ba94e
4 changed files with 8 additions and 19 deletions
  1. +1
    -2
      Effects/PointLightCollection.cs
  2. +4
    -6
      Lights/PointLight.cs
  3. BIN
      Models/UnitSphere.glb
  4. +3
    -11
      Renderer.cs

+ 1
- 2
Effects/PointLightCollection.cs View File

@ -40,8 +40,7 @@ namespace Kav
set
{
positions[i] = value.Position;
colors[i] = value.Color.ToVector3() * value.Intensity;
intensities[i] = value.Intensity;
colors[i] = value.Color.ToVector3() * value.Radius;
lightPositionsParam.SetValue(positions);
lightColorsParam.SetValue(colors);
}


+ 4
- 6
Lights/PointLight.cs View File

@ -8,19 +8,17 @@ namespace Kav
public Vector3 Position { get; }
public Color Color { get; }
public float Intensity { get; }
public float Radius { get; }
public float EffectiveRadius { get; }
public BoundingSphere BoundingSphere { get; }
public PointLight(Vector3 position, Color color, float intensity = 1f)
public PointLight(Vector3 position, Color color, float radius)
{
Position = position;
Color = color;
Intensity = intensity;
Radius = radius;
EffectiveRadius = (float) System.Math.Sqrt(Intensity);
BoundingSphere = new BoundingSphere(position, EffectiveRadius);
BoundingSphere = new BoundingSphere(position, Radius);
}
}
}

BIN
Models/UnitSphere.glb View File


+ 3
- 11
Renderer.cs View File

@ -467,15 +467,7 @@ namespace Kav
PointLight pointLight
) {
GraphicsDevice.SetRenderTarget(renderTarget);
if (Vector3.Distance(camera.Position, pointLight.Position) < pointLight.EffectiveRadius)
{
GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;
}
else
{
GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
}
GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;
GraphicsDevice.DepthStencilState = DepthStencilState.None;
GraphicsDevice.BlendState = BlendState.Additive;
@ -489,12 +481,12 @@ namespace Kav
DeferredPointLightEffect.PointLightPosition = pointLight.Position;
DeferredPointLightEffect.PointLightColor =
pointLight.Color.ToVector3() * pointLight.Intensity;
pointLight.Color.ToVector3() * pointLight.Radius;
DeferredPointLightEffect.FarPlane = 25f; // FIXME: magic value
DeferredPointLightEffect.World =
Matrix.CreateScale(pointLight.EffectiveRadius) *
Matrix.CreateScale(pointLight.Radius) *
Matrix.CreateTranslation(pointLight.Position);
DeferredPointLightEffect.View = camera.View;
DeferredPointLightEffect.Projection = camera.Projection;


Loading…
Cancel
Save