turn point lights into classes and give them a shadow map
parent
ee909ba94e
commit
d5d0a38ff1
|
@ -74,32 +74,6 @@ namespace Kav
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DeferredPBREffect(DeferredPBREffect cloneSource) : base(cloneSource)
|
|
||||||
{
|
|
||||||
GPosition = cloneSource.GPosition;
|
|
||||||
GAlbedo = cloneSource.GAlbedo;
|
|
||||||
GNormal = cloneSource.GNormal;
|
|
||||||
GMetallicRoughness = cloneSource.GMetallicRoughness;
|
|
||||||
|
|
||||||
EyePosition = cloneSource.EyePosition;
|
|
||||||
|
|
||||||
PointLights = new PointLightCollection(
|
|
||||||
Parameters["LightPositions"],
|
|
||||||
Parameters["PositionLightColors"],
|
|
||||||
MaxPointLights
|
|
||||||
);
|
|
||||||
|
|
||||||
for (int i = 0; i < MaxPointLights; i++)
|
|
||||||
{
|
|
||||||
PointLights[i] = cloneSource.PointLights[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Effect Clone()
|
|
||||||
{
|
|
||||||
return new DeferredPBREffect(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnApply()
|
protected override void OnApply()
|
||||||
{
|
{
|
||||||
gPositionParam.SetValue(GPosition);
|
gPositionParam.SetValue(GPosition);
|
||||||
|
|
|
@ -197,45 +197,6 @@ namespace Kav
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PBREffect(PBREffect cloneSource) : base(cloneSource)
|
|
||||||
{
|
|
||||||
CacheEffectParameters();
|
|
||||||
|
|
||||||
World = cloneSource.World;
|
|
||||||
View = cloneSource.View;
|
|
||||||
Projection = cloneSource.Projection;
|
|
||||||
|
|
||||||
PointLights = new PointLightCollection(
|
|
||||||
Parameters["LightPositions"],
|
|
||||||
Parameters["PositionLightColors"],
|
|
||||||
MaxPointLights
|
|
||||||
);
|
|
||||||
|
|
||||||
for (int i = 0; i < MaxPointLights; i++)
|
|
||||||
{
|
|
||||||
PointLights[i] = cloneSource.PointLights[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
AlbedoTexture = cloneSource.AlbedoTexture;
|
|
||||||
NormalTexture = cloneSource.NormalTexture;
|
|
||||||
EmissionTexture = cloneSource.EmissionTexture;
|
|
||||||
OcclusionTexture = cloneSource.OcclusionTexture;
|
|
||||||
MetallicRoughnessTexture = cloneSource.MetallicRoughnessTexture;
|
|
||||||
EnvDiffuseTexture = cloneSource.EnvDiffuseTexture;
|
|
||||||
BRDFLutTexture = cloneSource.BRDFLutTexture;
|
|
||||||
EnvSpecularTexture = cloneSource.EnvSpecularTexture;
|
|
||||||
|
|
||||||
Albedo = cloneSource.Albedo;
|
|
||||||
Metallic = cloneSource.Metallic;
|
|
||||||
Roughness = cloneSource.Roughness;
|
|
||||||
AO = cloneSource.AO;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Effect Clone()
|
|
||||||
{
|
|
||||||
return new PBREffect(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnApply()
|
protected override void OnApply()
|
||||||
{
|
{
|
||||||
if ((dirtyFlags & EffectDirtyFlags.World) != 0)
|
if ((dirtyFlags & EffectDirtyFlags.World) != 0)
|
||||||
|
|
|
@ -23,20 +23,6 @@ namespace Kav
|
||||||
|
|
||||||
public PointLight this[int i]
|
public PointLight this[int i]
|
||||||
{
|
{
|
||||||
get
|
|
||||||
{
|
|
||||||
var color = colors[i] / intensities[i];
|
|
||||||
return new PointLight(
|
|
||||||
positions[i],
|
|
||||||
new Color(
|
|
||||||
color.X,
|
|
||||||
color.Y,
|
|
||||||
color.Z,
|
|
||||||
1f
|
|
||||||
),
|
|
||||||
intensities[i]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
positions[i] = value.Position;
|
positions[i] = value.Position;
|
||||||
|
|
|
@ -1,24 +1,55 @@
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Kav
|
namespace Kav
|
||||||
{
|
{
|
||||||
public struct PointLight
|
public sealed class PointLight : IDisposable
|
||||||
{
|
{
|
||||||
public static double ATTENUATION_EPSILON = 0.1;
|
|
||||||
|
|
||||||
public Vector3 Position { get; }
|
public Vector3 Position { get; }
|
||||||
public Color Color { get; }
|
public Color Color { get; }
|
||||||
public float Radius { get; }
|
public float Radius { get; }
|
||||||
|
|
||||||
public BoundingSphere BoundingSphere { get; }
|
public BoundingSphere BoundingSphere { get; }
|
||||||
|
|
||||||
public PointLight(Vector3 position, Color color, float radius)
|
public RenderTargetCube ShadowMap { get; }
|
||||||
{
|
|
||||||
|
public PointLight(
|
||||||
|
GraphicsDevice graphicsDevice,
|
||||||
|
Vector3 position,
|
||||||
|
Color color,
|
||||||
|
float radius,
|
||||||
|
int shadowMapSize
|
||||||
|
) {
|
||||||
Position = position;
|
Position = position;
|
||||||
Color = color;
|
Color = color;
|
||||||
Radius = radius;
|
Radius = radius;
|
||||||
|
|
||||||
BoundingSphere = new BoundingSphere(position, Radius);
|
BoundingSphere = new BoundingSphere(position, Radius);
|
||||||
|
|
||||||
|
ShadowMap = new RenderTargetCube(
|
||||||
|
graphicsDevice,
|
||||||
|
shadowMapSize,
|
||||||
|
false,
|
||||||
|
SurfaceFormat.Single,
|
||||||
|
DepthFormat.Depth24,
|
||||||
|
0,
|
||||||
|
RenderTargetUsage.PreserveContents
|
||||||
|
);
|
||||||
|
|
||||||
|
var currentRTs = graphicsDevice.GetRenderTargets();
|
||||||
|
foreach (CubeMapFace face in Enum.GetValues(typeof(CubeMapFace)))
|
||||||
|
{
|
||||||
|
graphicsDevice.SetRenderTarget(ShadowMap, face);
|
||||||
|
graphicsDevice.Clear(Color.White);
|
||||||
|
}
|
||||||
|
|
||||||
|
graphicsDevice.SetRenderTargets(currentRTs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
ShadowMap.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -755,7 +755,6 @@ namespace Kav
|
||||||
|
|
||||||
public void RenderPointShadowMapIndexed<T>(
|
public void RenderPointShadowMapIndexed<T>(
|
||||||
RenderTargetCube pointShadowCubeMap,
|
RenderTargetCube pointShadowCubeMap,
|
||||||
PerspectiveCamera camera,
|
|
||||||
IEnumerable<(T, Matrix)> modelTransforms,
|
IEnumerable<(T, Matrix)> modelTransforms,
|
||||||
PointLight pointLight
|
PointLight pointLight
|
||||||
) where T : ICullable, IIndexDrawable {
|
) where T : ICullable, IIndexDrawable {
|
||||||
|
|
Loading…
Reference in New Issue