public PointLight(Point3D l) { _color = new RGBColor(1, 1, 1); _intensity = 0.5f; _location = new Point3D(l); _castsShadows = false; }
//Constructors public DirectionalLight() { _direction = (new Vect3D(-1, -1, -1)).Hat(); _intensity = 0.5f; _color = new RGBColor(1, 1, 1); _castsShadows = false; }
public PointLight(RGBColor c, float i, Point3D l) { _color = new RGBColor(c); _intensity = i; _location = new Point3D(l); _castsShadows = false; }
//Copy constructor public GlossySpecular(GlossySpecular clone) { _phongExponent = clone.PhongExponent; _specularReflectionCoefficient = clone.SpecularReflectionCoefficient; _colorSpecular = clone.ColorSpecular; samplerPointer = clone.Sampler; }
public DirectionalLight(Vect3D d) { _direction = d.Hat(); _intensity = 0.5f; _color = new RGBColor(1, 1, 1); _castsShadows = false; }
public DirectionalLight(RGBColor c, float i, Vect3D d) { _color = new RGBColor(c); _intensity = i; _direction = d.Hat(); _castsShadows = false; }
//public virtual bool castsShadows() { return _castsShadows; } //public virtual void setShadow(bool shad) { _castsShadows = shad; } //public RGBColor getColor() { return _color; } //public void setColor(RGBColor c) { _color = new RGBColor(c); } public static Light LoadLight(XmlElement lightRoot) { //Determine light type... Light toReturn; string light_type = lightRoot.GetAttribute("type"); //...and defer loading task to correct loader. if (light_type.Equals("point")) { toReturn = PointLight.LoadPointLight(lightRoot); } else if (light_type.Equals("directional")) { toReturn = DirectionalLight.LoadDirectionalLight(lightRoot); } else { toReturn = new PointLight(); Console.WriteLine("Unknown light type " + light_type + ", treating as point light"); } //Load attributes common to all lights string node_shadow = lightRoot.GetAttribute("shadow"); if (!node_shadow.Equals("")) { toReturn.CastsShadows = Convert.ToBoolean(node_shadow); } XmlNode node_color = lightRoot.SelectSingleNode("color"); if (node_color != null) { string str_color = ((XmlText)node_color.FirstChild).Data; RGBColor color = new RGBColor(System.Drawing.ColorTranslator.FromHtml(str_color)); //if (color.r != null) //{ toReturn.Color = color; //} } return toReturn; }
public void DisplayPixel(int row, int column, RGBColor pixel_color) { RGBColor disp_color = new RGBColor(pixel_color.Values * 255.0f); Vector3 cols = disp_color.clamp().Values; int x = column; int y = _viewPlane.VerticalResolution-1-row; //live_view.live_image.SetPixel((uint)column, (uint)(vp.vres-1-row), new SFML.Graphics.Color(r, g, b)); _renderImage[(y * 4 * _viewPlane.HorizontalResolution) + (x * 4)] = (byte)cols.X; _renderImage[(y * 4 * _viewPlane.HorizontalResolution) + (x * 4) + 1] = (byte)cols.Y; _renderImage[(y * 4 * _viewPlane.HorizontalResolution) + (x * 4) + 2] = (byte)cols.Z; _renderImage[(y * 4 * _viewPlane.HorizontalResolution) + (x * 4) + 3] = 255; }
/// <summary> /// Builds the world /// </summary> public void Build() { _backgroundColor = GlobalVars.COLOR_BLACK; if (GlobalVars.inFile != null) { // Attempt to open an input file XMLProcessor sceneLoader = new XMLProcessor(GlobalVars.inFile, this); // Load materials from XML file, if verbose output enabled provide debug info in console sceneLoader.LoadMaterials(); if (GlobalVars.verbose) { Console.WriteLine("Materials loaded:"); foreach (Material m in _materialList) { Console.WriteLine(m.ToString()); } } // Load objects for instancing from XML file, if verbose output enabled provide debug info in console sceneLoader.LoadObjects(); if (GlobalVars.verbose) { Console.WriteLine("Object definitions loaded:"); foreach (RenderableObject o in _objectList) { Console.WriteLine(o.ToString()); } } // Finally, load the scene from XML file, if verbose output enabled provide debug info in console sceneLoader.LoadWorld(); if (GlobalVars.verbose) { Console.WriteLine("Scene loaded!"); foreach (RenderableObject o in _renderList) { Console.WriteLine(o.ToString()); } } /* //Sphere mysphere = new Sphere(new Point3D(0, 0, 0), 1000); //mysphere.setMaterial(getMaterialById("myreflective")); //add_Object(mysphere); //((ThinLensCamera)camera).set_sampler(vp.vpSampler); UniformGrid mygrid = new UniformGrid(); //Plane groundplane = new Plane(new Point3D(0, -100, 0), new Normal(0, 1, 0)); //groundplane.setMaterial(new DebugCheckerboard()); //add_Object(groundplane); SphericalMapper sphere_map = new SphericalMapper(); RectangularMapper rect_map = new RectangularMapper(); Image my_image = new Image(); my_image.LoadFromFile("E:\\earth.jpg"); ImageTexture my_tex = new ImageTexture(); my_tex.MapType = rect_map; my_tex.Image = my_image; MatteShader mymatte = new MatteShader(); //mymatte.setCr(my_tex); mymatte.Texture = my_tex; //mymatte.setReflectivity(0.95f); //mymatte.setKa(0.9f); //PhongShader myshader = (PhongShader)getMaterialById("myphong"); //myshader.setCd(my_tex); //Sphere mysphere = new Sphere(new Point3D(0, 0, 0), 20); //mysphere.setMaterial(mymatte); //Instance myinstance = new Instance(mysphere); //myinstance.scale(new Vect3D(5, 5, 5)); //myinstance.rotate(new Vect3D(23.5f, 90, 0)); //mygrid.add_object(myinstance); //add_Object(myinstance); Image my_skybox = new Image(); my_skybox.LoadFromFile("E:\\skybox.jpg"); my_tex = new ImageTexture(); my_tex.MapType = sphere_map; my_tex.Image = my_skybox; MatteShader skymatte = new MatteShader(); skymatte.Texture = my_tex; skymatte.AmbientReflectionCoefficient = 1.0f; Sphere skybox = new Sphere(new Point3D(0, 10, 0),1000); skybox.Material = skymatte; //mygrid.add_object(skybox); AddObjectToScene(skybox); //mygrid.setup_cells(); //add_Object(mygrid); Mesh dragon = new Mesh(); dragon.loadFromFile("E:\\dragon.off", true); dragon.setup_cells(); dragon.Material = new PhongShader(); Instance myInstance = new Instance(dragon); myInstance.Scale(100, 100, 100); myInstance.Rotate(90, 40, 0); myInstance.Material = new PhongShader(); AddObjectToScene(myInstance); */ } //Custom build function if no input file specified else { ///--------------------------------------------------------------------------------------- ///Insert your build function here ///---------------------------------------------------------------------------------------- } }
public override void RenderScene(World w) { RGBColor L = new RGBColor(); Ray ray = new Ray(); ViewPlane vp = w.CurrentViewPlane; int depth = 0; Point2D sp = new Point2D(); Point2D pp = new Point2D(); Point2D dp = new Point2D(); Point2D lp = new Point2D(); //w.open_window(vp.hres, vp.vres); vp.PixelSize /= _zoom; for(int r = 0; r < vp.VerticalResolution-1; r++) { for(int c = 0; c < vp.HorizontalResolution-1; c++) { L = GlobalVars.COLOR_BLACK; for(int n = 0; n < vp.NumSamples; n++) { //Sample on unit square sp = vp.ViewPlaneSampler.SampleUnitSquare(); //Sample in screenspace pp.coords.X = vp.PixelSize * (c - vp.HorizontalResolution * 0.5f + sp.coords.X); pp.coords.Y = vp.PixelSize * (r - vp.VerticalResolution * 0.5f + sp.coords.Y); dp = depthSampler.SampleDisk(); lp.coords.X = dp.coords.X * radius; lp.coords.Y = dp.coords.Y * radius; ray.Origin = _eye + lp.coords.X * u + lp.coords.Y * v; ray.Direction = GetRayDirection(pp, lp); L += w.CurrentTracer.TraceRay(ray, depth); } L /= vp.NumSamples; L *= _exposureTime; w.DisplayPixel(r, c, L); w.PollEvents(); } } }
public GlossySpecular() { _phongExponent = 1.0f; _specularReflectionCoefficient = 1.0f; _colorSpecular = new RGBColor(1.0f, 1.0f, 1.0f); }
/* public override Vect3D getDirection(ShadeRec sr) { //Ambient light has no direction return new Vect3D(0, 0, 0); } */ public static AmbientLight LoadAmbient(XmlElement lightRoot) { AmbientLight toReturn = new AmbientLight(); XmlNode node_intensity = lightRoot.SelectSingleNode("intensity"); if (node_intensity != null) { string str_intensity = ((XmlText)node_intensity.FirstChild).Data; float intensity = Convert.ToSingle(str_intensity); toReturn.setIntensity(intensity); } XmlNode node_color = lightRoot.SelectSingleNode("color"); if (node_color != null) { string str_color = ((XmlText)node_color.FirstChild).Data; RGBColor color = new RGBColor(System.Drawing.ColorTranslator.FromHtml(str_color)); toReturn.Color = color; } return toReturn; }
public AmbientLight(RGBColor c, float i) { _color = new RGBColor(c); _intensity = i; }
//Default constructor public AmbientLight() { _intensity = 0.5f; _color = new RGBColor(1, 1, 1); }
/// <summary> /// Renders a single rectangular chunk of the scene /// </summary> /// <param name="worldRef">Reference to the world</param> /// <param name="xCoord1">Smallest x coordinate</param> /// <param name="xCoord2">Largest x coordinate</param> /// <param name="yCoord1">Smallest y coordinate</param> /// <param name="yCoord2">Largest y coordinate</param> /// <param name="threadNum">Thread number</param> public override void RenderSceneFragment(World worldRef, int xCoord1, int xCoord2, int yCoord1, int yCoord2, int threadNum) { RGBColor L = new RGBColor(); Ray ray = new Ray(); ViewPlane vp = worldRef.CurrentViewPlane; int depth = 0; Point2D samplePoint = new Point2D(); Point2D samplePointPixelSpace = new Point2D(); Point2D samplePointOnDisk = new Point2D(); Point2D samplePointOnLens = new Point2D(); Sampler screenSamplerClone = GlobalVars.VIEWPLANE_SAMPLER.Clone(); Sampler lensSamplerClone = depthSampler.Clone(); //vp.s /= zoom; //Vector2 tmp2 = new Vector2(vp.hres * 0.5f, vp.vres*0.5f); for (int r = yCoord1; r < yCoord2; r++) { for (int c = xCoord1; c < xCoord2; c++) { L = GlobalVars.COLOR_BLACK; for (int n = 0; n < vp.NumSamples; n++) { //Sample on unit square samplePoint = screenSamplerClone.SampleUnitSquare(); //Sample in screenspace //Vector2 tmp1 = new Vector2(c, r); //pp.coords = vp.s * (tmp1 - tmp2 * sp.coords); samplePointPixelSpace.coords.X = vp.PixelSize * (c - vp.HorizontalResolution * 0.5f + samplePoint.coords.X); samplePointPixelSpace.coords.Y = vp.PixelSize * (r - vp.VerticalResolution * 0.5f + samplePoint.coords.Y); samplePointOnDisk = lensSamplerClone.SampleDisk(); samplePointOnLens.coords.X = samplePointOnDisk.coords.X * radius; samplePointOnLens.coords.Y = samplePointOnDisk.coords.Y * radius; //lp.coords = dp.coords * radius; ray.Origin = _eye + samplePointOnLens.coords.X * u + samplePointOnLens.coords.Y * v; ray.Direction = GetRayDirection(samplePointPixelSpace, samplePointOnLens); L += worldRef.CurrentTracer.TraceRay(ray, depth); } L /= vp.NumSamples; L *= _exposureTime; worldRef.DisplayPixel(r, c, L); } } DequeueNextRenderFragment(); }
public override RGBColor F(ShadeRec sr, Vect3D incomingDirection, Vect3D reflectedDirection) { RGBColor L = new RGBColor(0.0f, 0.0f, 0.0f); float nDotWi = (sr.Normal * incomingDirection); //Dot product of normal and angle of incidence gives the angle of mirror reflection Vect3D r = new Vect3D(-incomingDirection + 2.0f * sr.Normal * nDotWi); //Vector describing direction of mirror reflection float rDotWo = (r * reflectedDirection); if (rDotWo > 0.0) { L = _specularReflectionCoefficient * (float)Math.Pow(rDotWo, _phongExponent) * _colorSpecular; } return L; }
//Copy constructor public RGBColor(RGBColor color) { _vals = color._vals; }