/// Casts a ray and checks if it intersects any object. We can then /// compute the color of the point corresponding to the closest /// intersected object. private Color Raycast(Ray ray) { Object3D collidedObj = ray.ClosestIntersectedObject(Scene.Objects); // If the ray previously encountered an object, compute the pixel's // color. if (collidedObj != null) { V3 collisionPoint = ray.CollisionPoint(); V2 collisionUV = collidedObj.UV(collisionPoint); float shadowCoeff = Occultation(collidedObj, collisionPoint); return shadowCoeff * Scene.IlluModel.Compute( Scene.Lights, collidedObj, collisionPoint, collisionUV ); } return null; }
/// Casts a ray and checks if it intersects any object. We can then /// compute the color of the point corresponding to the closest /// intersected object. private Color Raycast(Ray ray) { Object3D collidedObj = ray.ClosestIntersectedObject(Scene.Objects); // If the ray previously encountered an object, compute the pixel's // color. if (collidedObj != null) { V3 collisionPoint = ray.CollisionPoint(); V2 collisionUV = collidedObj.UV(collisionPoint); float shadowCoeff = Occultation(collidedObj, collisionPoint); return(shadowCoeff * Scene.IlluModel.Compute( Scene.Lights, collidedObj, collisionPoint, collisionUV )); } return(null); }
/// Casts a ray and checks if it intersects any object. We can then /// compute the color of the point corresponding to the closest /// intersected object. If the intersected object is transparent or /// reflective, new rays are cast from the collision point. private Color Raytrace(Ray ray, int depth) { if (depth <= 0) { return(null); } Object3D collidedObj = ray.ClosestIntersectedObject(Scene.Objects); // If the ray previously encountered an object, compute the pixel's // color. if (collidedObj != null) { V3 collisionPoint = ray.CollisionPoint(); V2 collisionUV = collidedObj.UV(collisionPoint); float shadowCoeff = Occultation(collidedObj, collisionPoint); Color directComponent = Scene.IlluModel.Compute( Scene.Lights, collidedObj, collisionPoint, collisionUV ); // reflected light component Color reflectionColor = ReflectionColor( -ray.Direction, collisionPoint, collisionUV, collidedObj, depth ); // refracted light component Color refractionColor = RefractionColor( ray.Direction, collisionPoint, collisionUV, collidedObj, depth ); return(shadowCoeff * ( directComponent + reflectionColor + refractionColor )); } return(null); }
/// Casts a ray and checks if it intersects any object. We can then /// compute the color of the point corresponding to the closest /// intersected object. If the intersected object is transparent or /// reflective, new rays are cast from the collision point. private Color Raytrace(Ray ray, int depth) { if (depth <= 0) { return null; } Object3D collidedObj = ray.ClosestIntersectedObject(Scene.Objects); // If the ray previously encountered an object, compute the pixel's // color. if (collidedObj != null) { V3 collisionPoint = ray.CollisionPoint(); V2 collisionUV = collidedObj.UV(collisionPoint); float shadowCoeff = Occultation(collidedObj, collisionPoint); Color directComponent = Scene.IlluModel.Compute( Scene.Lights, collidedObj, collisionPoint, collisionUV ); // reflected light component Color reflectionColor = ReflectionColor( -ray.Direction, collisionPoint, collisionUV, collidedObj, depth ); // refracted light component Color refractionColor = RefractionColor( ray.Direction, collisionPoint, collisionUV, collidedObj, depth ); return shadowCoeff * ( directComponent + reflectionColor + refractionColor ); } return null; }