tweak point light rendering
parent
0060c22d72
commit
ee909ba94e
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
14
Renderer.cs
14
Renderer.cs
|
@ -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…
Reference in New Issue