public ViewPlane(int width, int height, Camera camera) { this.pixelWidth = width; this.pixelHeight = height; this.camera = camera; this.worldHeight = 2 * Math.Tan(Func.DegreeToRadian(camera.GetFOVY())/2); this.worldWidth = worldHeight * (double)PixelWidth / (double)PixelHeight; CalculateUpperLeft(); }
void Start() { int width = 800; int height = 600; Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false); RayTracing.Scene scene = new RayTracing.Scene(); scene.AddSphere(new RayTracing.Sphere() { Position = new Vector3(0, 0, -10), Radius = 2 }); RayTracing.Camera camera = new RayTracing.Camera(2, 1, Vector3.zero, new RayTracing.Screen(width, height)); camera.TakePhoto(scene); Color[] texColors = camera.CameraTexture; tex.SetPixels(texColors); tex.Apply(); material.mainTexture = tex; }
public static Ray RayThruPixels(Camera cam, int i, int j) { double alpha = Math.Tan(DegreeToRadian(cam.GetFOVX()) / 2) * (j - (Screen.width / 2)) / (Screen.width / 2); double beta = Math.Tan(DegreeToRadian(cam.GetFOVY()) / 2) * ((Screen.height / 2) - i) / (Screen.height / 2); Vector position = cam.GetLookFrom(); Vector temp = (cam.GetVectorU() * alpha + cam.GetVectorV() * beta - cam.GetVectorW() ); Vector direction = temp / temp.Distance(); return new Ray(position, direction); }