public Ray Reflect(Vector3 normal, Vector3 point, SpectralColor colorFilter) { return(new Ray( point, Vector3.Reflect(Direction, normal), ColorFilter.ApplyFilter(colorFilter) )); }
public MaterialObject( Vector3 origin, Quaternion rotation, List <Triangle> triangles, SpectralColor color ) : base(origin, rotation, triangles) { Color = color; }
public LightSource( Vector3 origin, Quaternion rotation, List <Triangle> triangles, float totalFlux, SpectralColor spectralColor ) : base(origin, rotation, triangles) { TotalFlux = totalFlux; Spectral = spectralColor.Normalize(); }
public void AccumulatePixel(uint x, uint y, SpectralColor luminance) { lock (this) { var pixel = Pixels[x, y]; var hits = HitsCount[x, y] + 1; var newValues = pixel.Values.Zip(luminance.Values, (o, n) => o + (n - o) / (float)hits).ToArray(); Pixels[x, y] = new SpectralColor(newValues); HitsCount[x, y] = hits; } }
public Ray CastRay(Vector2 pixel) { return(new Ray( Origin, Vector3.Normalize( Vector3.Transform( new Vector3(pixel.X * ViewAngle.X, pixel.Y * ViewAngle.Y, ViewAngle.Z), Direction ) ), SpectralColor.One() )); }
public Image(uint w, uint h) { var pixels = new SpectralColor[w, h]; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { pixels[i, j] = SpectralColor.Zero(); } } Pixels = pixels; HitsCount = new uint[w, h]; }
static void Main(string[] args) { var camera = new Camera(new Vector3(0f, 0f, -1f), Quaternion.Identity, new Vector3(1f, 1f, 1f)); var lights = new LightSource( new Vector3(1f, 1f, -1f), Quaternion.Identity, new List <Triangle>() { new Triangle(new Vector3(-0.5f, 0.5f, 0f), new Vector3(0.5f, 0.5f, 0f), new Vector3(-0.5f, -0.5f, 0f)), new Triangle(new Vector3(0.5f, 0.5f, 0f), new Vector3(0.5f, -0.5f, 0f), new Vector3(-0.5f, -0.5f, 0f)) }, 100f, new SpectralColor(new float[40].Select((f, i) => (float)i * 10).ToArray()).Normalize()); var objects = new MaterialObject( new Vector3(0f, 0f, 0f), Quaternion.CreateFromYawPitchRoll(0.5f, 0.5f, 0f), new List <Triangle>() { new Triangle(new Vector3(0, 0, 0), new Vector3(0, 1, 0), new Vector3(1, 0, 0)), new Triangle(new Vector3(1, 1, 0), new Vector3(0, 1, 0), new Vector3(1, 0, 0)), // new Triangle(new Vector3(0, 0, 0), new Vector3(0, 0, 1), new Vector3(1, 0, 0)), // new Triangle(new Vector3(1, 1, 0), new Vector3(0, 0, 1), new Vector3(1, 0, 0)) }, SpectralColor.One() ); var scene = new Scene(new List <MaterialObject>() { objects }, new List <LightSource>() { lights }); var renderer = new Renderer(scene, camera); var image = renderer.Render(1366, 768, 4); var imgStr = HDRPrinter.StringifyImage(image); File.WriteAllText("C:\\img.txt", imgStr); }
public SpectralColor ApplyFilter(SpectralColor colorFilter) { return(new(Values.Zip(colorFilter.Values, (c, f) => c * f).ToArray())); }
public SpectralColor AddLuminance(SpectralColor lumi) { return(new(Values.Zip(lumi.Values, (l, r) => l + r).ToArray())); }
public Ray(Vector3 origin, Vector3 direction, SpectralColor color) { Origin = origin; Direction = direction; ColorFilter = color; }