basic rendering structure
parent
7857679666
commit
f0f09115f5
18
Camera.cs
18
Camera.cs
|
@ -6,15 +6,16 @@ namespace Kav
|
|||
{
|
||||
public Matrix Transform { get; set; }
|
||||
public Matrix Projection { get; set; }
|
||||
public Matrix View {
|
||||
public Matrix View
|
||||
{
|
||||
get
|
||||
{
|
||||
return Matrix.CreateLookAt(Transform.Translation, Transform.Forward, Transform.Up);
|
||||
}
|
||||
}
|
||||
|
||||
public float FOV { get; set; } = 75f;
|
||||
public float AspectRatio { get; set; } = 1920 / 1080;
|
||||
public float FOV { get; set; } = MathHelper.PiOver4;
|
||||
public float AspectRatio { get; set; } = 1920f / 1080f;
|
||||
public float NearPlane { get; set; } = 0.1f;
|
||||
public float FarPlane { get; set; } = 200f;
|
||||
|
||||
|
@ -28,5 +29,16 @@ namespace Kav
|
|||
FarPlane
|
||||
);
|
||||
}
|
||||
|
||||
public Camera(Matrix transform)
|
||||
{
|
||||
Transform = transform;
|
||||
Projection = Matrix.CreatePerspectiveFieldOfView(
|
||||
FOV,
|
||||
AspectRatio,
|
||||
NearPlane,
|
||||
FarPlane
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@ namespace Kav
|
|||
{
|
||||
public interface PointLightEffect
|
||||
{
|
||||
PointLight[] PointLights { get; } // TODO: should be a collection class?
|
||||
PointLightCollection PointLights { get; } // TODO: should be a collection class?
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,19 +3,7 @@ using Microsoft.Xna.Framework.Graphics;
|
|||
|
||||
namespace Kav
|
||||
{
|
||||
public struct PBRLight
|
||||
{
|
||||
public Vector3 position;
|
||||
public Vector3 color;
|
||||
|
||||
public PBRLight(Vector3 position, Vector3 colour)
|
||||
{
|
||||
this.position = position;
|
||||
this.color = colour;
|
||||
}
|
||||
}
|
||||
|
||||
public class PBRLightCollection
|
||||
public class PointLightCollection
|
||||
{
|
||||
private readonly Vector3[] positions = new Vector3[4];
|
||||
private readonly Vector3[] colors = new Vector3[4];
|
||||
|
@ -23,26 +11,37 @@ namespace Kav
|
|||
readonly EffectParameter lightPositionsParam;
|
||||
readonly EffectParameter lightColorsParam;
|
||||
|
||||
public PBRLightCollection(EffectParameter lightPositionsParam, EffectParameter lightColorsParam)
|
||||
public PointLightCollection(EffectParameter lightPositionsParam, EffectParameter lightColorsParam)
|
||||
{
|
||||
this.lightPositionsParam = lightPositionsParam;
|
||||
this.lightColorsParam = lightColorsParam;
|
||||
}
|
||||
|
||||
public PBRLight this[int i]
|
||||
public PointLight this[int i]
|
||||
{
|
||||
get { return new PBRLight(positions[i], colors[i]); }
|
||||
get
|
||||
{
|
||||
return new PointLight(
|
||||
positions[i],
|
||||
new Color(
|
||||
colors[i].X,
|
||||
colors[i].Y,
|
||||
colors[i].Z,
|
||||
1f
|
||||
)
|
||||
);
|
||||
}
|
||||
set
|
||||
{
|
||||
positions[i] = value.position;
|
||||
colors[i] = value.color;
|
||||
positions[i] = value.Position;
|
||||
colors[i] = value.Color.ToVector3() * value.Intensity;
|
||||
lightPositionsParam.SetValue(positions);
|
||||
lightColorsParam.SetValue(colors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class PBREffect : Effect
|
||||
public class PBREffect : Effect, TransformEffect, PointLightEffect
|
||||
{
|
||||
EffectParameter worldParam;
|
||||
EffectParameter worldViewProjectionParam;
|
||||
|
@ -69,7 +68,7 @@ namespace Kav
|
|||
Matrix world = Matrix.Identity;
|
||||
Matrix view = Matrix.Identity;
|
||||
Matrix projection = Matrix.Identity;
|
||||
PBRLightCollection pbrLightCollection;
|
||||
PointLightCollection pointLightCollection;
|
||||
|
||||
Vector3 albedo;
|
||||
float metallic;
|
||||
|
@ -114,10 +113,10 @@ namespace Kav
|
|||
}
|
||||
}
|
||||
|
||||
public PBRLightCollection Lights
|
||||
public PointLightCollection PointLights
|
||||
{
|
||||
get { return pbrLightCollection; }
|
||||
internal set { pbrLightCollection = value; }
|
||||
get { return pointLightCollection; }
|
||||
internal set { pointLightCollection = value; }
|
||||
}
|
||||
|
||||
public Vector3 Albedo
|
||||
|
@ -227,7 +226,7 @@ namespace Kav
|
|||
{
|
||||
CacheEffectParameters();
|
||||
|
||||
pbrLightCollection = new PBRLightCollection(
|
||||
pointLightCollection = new PointLightCollection(
|
||||
Parameters["LightPositions"],
|
||||
Parameters["LightColors"]
|
||||
);
|
||||
|
@ -241,14 +240,14 @@ namespace Kav
|
|||
View = cloneSource.View;
|
||||
Projection = cloneSource.Projection;
|
||||
|
||||
Lights = new PBRLightCollection(
|
||||
PointLights = new PointLightCollection(
|
||||
Parameters["LightPositions"],
|
||||
Parameters["LightColors"]
|
||||
);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Lights[i] = cloneSource.Lights[i];
|
||||
PointLights[i] = cloneSource.PointLights[i];
|
||||
}
|
||||
|
||||
AlbedoTexture = cloneSource.AlbedoTexture;
|
||||
|
|
|
@ -5,11 +5,24 @@ namespace Kav
|
|||
public class Model
|
||||
{
|
||||
public Mesh[] Meshes { get; }
|
||||
public Matrix Transform { get; set; } // TODO: this should probably be a wrapper class
|
||||
|
||||
public Model(Mesh[] meshes, Matrix transform)
|
||||
public Model(Mesh[] meshes)
|
||||
{
|
||||
Meshes = meshes;
|
||||
}
|
||||
|
||||
public void ApplyTransform(Matrix transform)
|
||||
{
|
||||
foreach (var mesh in Meshes)
|
||||
{
|
||||
foreach (var meshPart in mesh.MeshParts)
|
||||
{
|
||||
if (meshPart.Effect is TransformEffect transformEffect)
|
||||
{
|
||||
transformEffect.World = transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@ namespace Kav
|
|||
public class PointLight
|
||||
{
|
||||
public Vector3 Position { get; set; }
|
||||
public Vector4 Color { get; set; }
|
||||
public Color Color { get; set; }
|
||||
public float Intensity { get; set; }
|
||||
|
||||
public PointLight(Vector3 position, Vector4 color, float intensity = 1f)
|
||||
public PointLight(Vector3 position, Color color, float intensity = 1f)
|
||||
{
|
||||
Position = position;
|
||||
Color = color;
|
||||
|
|
|
@ -26,7 +26,6 @@ namespace Kav
|
|||
|
||||
if (meshPart.Effect is TransformEffect transformEffect)
|
||||
{
|
||||
transformEffect.World = model.Transform;
|
||||
transformEffect.View = view;
|
||||
transformEffect.Projection = projection;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue