示例#1
0
文件: Ray.cs 项目: Stoorx/RayTracer
 public Ray Reflect(Vector3 normal, Vector3 point, SpectralColor colorFilter)
 {
     return(new Ray(
                point,
                Vector3.Reflect(Direction, normal),
                ColorFilter.ApplyFilter(colorFilter)
                ));
 }
示例#2
0
 public MaterialObject(
     Vector3 origin,
     Quaternion rotation,
     List <Triangle> triangles,
     SpectralColor color
     ) : base(origin, rotation, triangles)
 {
     Color = color;
 }
示例#3
0
 public LightSource(
     Vector3 origin,
     Quaternion rotation,
     List <Triangle> triangles,
     float totalFlux,
     SpectralColor spectralColor
     ) : base(origin, rotation, triangles)
 {
     TotalFlux = totalFlux;
     Spectral  = spectralColor.Normalize();
 }
示例#4
0
文件: Image.cs 项目: Stoorx/RayTracer
 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;
     }
 }
示例#5
0
 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()
                ));
 }
示例#6
0
文件: Image.cs 项目: Stoorx/RayTracer
        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];
        }
示例#7
0
        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);
        }
示例#8
0
 public SpectralColor ApplyFilter(SpectralColor colorFilter)
 {
     return(new(Values.Zip(colorFilter.Values, (c, f) => c * f).ToArray()));
 }
示例#9
0
 public SpectralColor AddLuminance(SpectralColor lumi)
 {
     return(new(Values.Zip(lumi.Values, (l, r) => l + r).ToArray()));
 }
示例#10
0
文件: Ray.cs 项目: Stoorx/RayTracer
 public Ray(Vector3 origin, Vector3 direction, SpectralColor color)
 {
     Origin      = origin;
     Direction   = direction;
     ColorFilter = color;
 }