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