internal static FloatColour Min(FloatColour value1, FloatColour value2) { FloatColour output; output.R = Math.Min(value1.R, value2.R); output.G = Math.Min(value1.G, value2.G); output.B = Math.Min(value1.B, value2.B); return output; }
internal static FloatColour Min(FloatColour value1, FloatColour value2) { FloatColour output; output.R = Math.Min(value1.R, value2.R); output.G = Math.Min(value1.G, value2.G); output.B = Math.Min(value1.B, value2.B); return(output); }
public static FloatColour operator *(FloatColour value, float multiplier) { FloatColour output = value; output.R *= multiplier; output.G *= multiplier; output.B *= multiplier; return(output); }
public FloatColour TraceRay(Primitive pIgnorePrimitive, Ray tRay, int nDepth) { // check whether we have reached maximum recursion depth if (nDepth > 6) { //return new Colour(0, 0, 0); return(new FloatColour(1)); } // declare intersection variables float fClosestIntersectionDistance = float.MaxValue; Primitive closestIntersectedPrimitive = null; // loop through all objects in scene foreach (Primitive primitive in m_pScene.Primitives) { // test for intersection float fDistance; if (primitive.Intersect(tRay, out fDistance)) { // check that we are closer than the last intersection if (fDistance < fClosestIntersectionDistance) { // set closest intersection fClosestIntersectionDistance = fDistance; closestIntersectedPrimitive = primitive; } } } // if nothing was intersected, set to background colour FloatColour tColour = new FloatColour(Color.CornflowerBlue); if (closestIntersectedPrimitive != null) // test for intersection { tColour = closestIntersectedPrimitive.Shade(this, tRay, fClosestIntersectionDistance, nDepth + 1); } tColour = FloatColour.Min(tColour, new FloatColour(1)); // return colour return(tColour); }
public bool ProcessFrame() { // loop through all pixels for (int y = 0; y < _height; y++) { for (int x = 0; x < _width; x++) { // set direction of ray Ray tPrimaryRay = _camera.GetUnprojectedRay(x, y); // trace ray (this is recursive) FloatColour tColour = TraceRay(null, tPrimaryRay, 0); // set colour of pixels in bitmap m_pImage[x, y] = tColour; } } return(true); }
public FloatColour TraceRay(Primitive pIgnorePrimitive, Ray tRay, int nDepth) { // check whether we have reached maximum recursion depth if (nDepth > 6) { //return new Colour(0, 0, 0); return new FloatColour(1); } // declare intersection variables float fClosestIntersectionDistance = float.MaxValue; Primitive closestIntersectedPrimitive = null; // loop through all objects in scene foreach (Primitive primitive in m_pScene.Primitives) { // test for intersection float fDistance; if (primitive.Intersect(tRay, out fDistance)) { // check that we are closer than the last intersection if (fDistance < fClosestIntersectionDistance) { // set closest intersection fClosestIntersectionDistance = fDistance; closestIntersectedPrimitive = primitive; } } } // if nothing was intersected, set to background colour FloatColour tColour = new FloatColour(Color.CornflowerBlue); if (closestIntersectedPrimitive != null) // test for intersection { tColour = closestIntersectedPrimitive.Shade(this, tRay, fClosestIntersectionDistance, nDepth + 1); } tColour = FloatColour.Min(tColour, new FloatColour(1)); // return colour return tColour; }