File LightSource.cs
File List > Render > src > LightSource.cs
Go to the documentation of this file.
using System;
using System.Drawing;
using Qkmaxware.Geometry;
namespace Qkmaxware.Rendering {
public abstract class LightSource : SceneNode {
public Color Tint {get; set;} = Color.White;
public abstract double Intensity(Vec3 position, Vec3 normal);
public abstract Vec3 Direction (Vec3 position, Vec3 normal);
}
public class AmbientLight : LightSource {
public double SourceIntensity {get; set;} = 0.1;
public override double Intensity(Vec3 position, Vec3 normal) {
return SourceIntensity;
}
public override Vec3 Direction (Vec3 position, Vec3 normal) {
return -normal;
}
}
public class PointLight : LightSource {
public double SourceIntensity {get; set;} = 1;
public override double Intensity(Vec3 position, Vec3 normal) {
var distance = Vec3.Distance(this.Position, position);
var intensity = (1 / (distance * distance));
return SourceIntensity * Math.Max(intensity, 0);
}
public override Vec3 Direction (Vec3 position, Vec3 normal) {
return (position - this.Position).Normalized;
}
}
}