tweak point light rendering

mesh_sprite_draw
cosmonaut 2020-12-09 16:28:40 -08:00
parent 0060c22d72
commit ee909ba94e
4 changed files with 8 additions and 19 deletions

View File

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

View File

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

Binary file not shown.

View File

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