Documentation ¶
Overview ¶
Package objects provides concrete implementations of the tracer.Object interface.
In addition to the basic tracer.Object interface, the implementations in this package provide accelerated ray-object intersection and constructive solid geometry (CSG) operations. Both are hidden to the ray tracing algorithm. I.e., package tracer does not need to know about this.
Index ¶
- type BoundingBox
- func (b BoundingBox) Center() Vec
- func (b BoundingBox) CenterBack() Vec
- func (b BoundingBox) CenterBottom() Vec
- func (b BoundingBox) CenterFront() Vec
- func (b BoundingBox) CenterTop() Vec
- func (b BoundingBox) Dx() float64
- func (b BoundingBox) Dy() float64
- func (b BoundingBox) Dz() float64
- func (b BoundingBox) Size() Vec
- type Interface
- func And(a, b Interface) Interface
- func Backdrop(m Material) Interface
- func Bounded(orig Interface) Interface
- func Box(m Material, width, height, depth float64, center Vec) Interface
- func BoxWithBounds(m Material, min, max Vec) Interface
- func Cylinder(m Material, diam, height float64, center Vec) Interface
- func CylinderDir(m Material, dir int, diam, height float64, center Vec) Interface
- func CylinderWithCaps(m Material, diam, height float64, center Vec) Interface
- func Difference(a, b Interface) Interface
- func Disk(m Material, diam float64, center Vec) Interface
- func Hollow(orig Interface) Interface
- func IsoSurface(mat Material, dx, dy, dz float64, f func(u, v float64) float64) Interface
- func Mesh(m Material, vertices []Vec, faceIdx [][3]int) Interface
- func MeshWithUV(m Material, vertices []Vec, faceIdx [][3]int, UV []Vec2) Interface
- func Not(object Interface) Interface
- func ObjFile(m map[string]Material, file string, transf ...*geom.AffineTransform) Interface
- func Or(a, b Interface) Interface
- func Parametric(m Material, numU, numV int, f func(u, v float64) Vec) Interface
- func PlyFile(m Material, file string, transf ...*geom.AffineTransform) Interface
- func Quadrilateral(m Material, a, b, c, d Vec) Interface
- func Rectangle(m Material, width, depth float64, center Vec) Interface
- func RectangleWithVertices(m Material, o, a, b Vec) Interface
- func Remap(orig Interface, remap func(Vec) Vec) Interface
- func Restrict(a, b Interface) Interface
- func Sphere(m Material, diam float64, center Vec) Interface
- func Transformed(object Interface, t *geom.AffineTransform) Interface
- func Translated(orig Interface, delta Vec) Interface
- func Tree(objects ...Interface) Interface
- func Triangle(m Material, a, b, c Vec) Interface
- func WithMaterial(m Material, obj Interface) Interface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BoundingBox ¶
type BoundingBox struct {
Min, Max Vec
}
BoundingBox is an Axis Aligned box, used to accelerate intersection tests with groups of objects. See https://en.wikipedia.org/wiki/Minimum_bounding_box#Axis-aligned_minimum_bounding_box.
func (BoundingBox) Center ¶
func (b BoundingBox) Center() Vec
func (BoundingBox) CenterBack ¶
func (b BoundingBox) CenterBack() Vec
func (BoundingBox) CenterBottom ¶
func (b BoundingBox) CenterBottom() Vec
func (BoundingBox) CenterFront ¶
func (b BoundingBox) CenterFront() Vec
func (BoundingBox) CenterTop ¶
func (b BoundingBox) CenterTop() Vec
func (BoundingBox) Dx ¶
func (b BoundingBox) Dx() float64
func (BoundingBox) Dy ¶
func (b BoundingBox) Dy() float64
func (BoundingBox) Dz ¶
func (b BoundingBox) Dz() float64
func (BoundingBox) Size ¶
func (b BoundingBox) Size() Vec
type Interface ¶
type Interface interface { Object // Bounds returns an axis-aligned bounding box completely enclosing the object. // This allows for accelerated ray-object intersection using a bounding volume hierarchy (BVH). Bounds() BoundingBox // Inside returns true if a point lies inside the Object's surface. // This allows for objects to be composed via constructive solid geometry (CSG). // // For hollow objects (pure surfaces that are empty on the inside), // Inside always returns false. Inside(point Vec) bool }
Interface satisfied by all tracer.Object implementations in this package. In addition to tracer.Object, this interface adds Bounds and Inside, which are used for efficient intersection tests and to construct solid geometry (CSG), respectively.
func Backdrop ¶
func Backdrop(m Material) Interface
Backdrop returns a "fake backdrop", a gigantic sphere near infinity, on which a background like a sky can be textured.
Usually, a Flat material should be applied, (since no light can reach the infinitely far away backdrop). A flat material also makes the backdrop an indirect light source. E.g.: a backdrop with a Flat solid color is the canonical ambient light.
The local coordinates are the ray direction.
func Bounded ¶
Bounded returns the original object, wrapped with an Intersect method that first checks for intersection with the object's bounding box.
This may speed up performace if the original Intersect is sufficiently expensive.
func BoxWithBounds ¶
func BoxWithBounds(m Material, min, max Vec) Interface
func CylinderDir ¶
func CylinderWithCaps ¶
func Difference ¶
func Hollow ¶
Hollow returns the object with a modified Inside method that always returns false. This causes the object to become hollow inside (only its surface remains).
This has a visible effect only when parts of an object are cut away (e.g. with And(Not(...))), so that the inside is revealed.
func IsoSurface ¶
IsoSurface constructs a surface defined by the height function:
y = dz * f(u, v)
where (u, v) are varied in the interval (0, 1), and f is expected to return a value in (0,1).
The surface is meshless. A numerical method is used to find ray-object intersection. This works best when the object is not viewed under a grazing angle, and when the surface gradient is small compared to 1 (i.e. has low "frequency").
A texture can be used as height map, yielding "relief mapping" (See https://en.wikipedia.org/wiki/Relief_mapping_(computer_graphics) ).
TODO: provide a way to tune the intersection so that it works with high frequencies.
func Mesh ¶
Mesh returns a smooth triangle mesh with given vertices. The faces are defined by a list vertex indices.
Normal vectors are calculated per vertex as the average over the faces sharing that vertex. The normals are also smoothly interpolated over inside each face.
TODO: allow to (partially) turn smoothing off.
func MeshWithUV ¶
MeshWithUV is like Mesh, but also attaches a (u,v) coordiante to each vertex. This allows the mesh to be textured.
len(UV) must be equal to len(vertices) (exactly one UV coordinate per vertex).
func Not ¶
Not returns the "inverse" of an object: The insideness and normal vectors are reversed with respect to the original.
This is useful for boolean operations, E.g.:
object1.And(Not(object2))
removes from object1 all points that are inside object2.
func ObjFile ¶
func ObjFile(m map[string]Material, file string, transf ...*geom.AffineTransform) Interface
func Parametric ¶
Parametric constructs a mesh approximating the parametric surface defined by
x,y,z = f(u,v)
where u, v are varied from 0 to 1 (inclusive) in numU, numV steps respectively.
TODO: automatically make normals seamless.
func PlyFile ¶
func PlyFile(m Material, file string, transf ...*geom.AffineTransform) Interface
PlyFile reads a mesh from a file in Standord PLY format. Optional affine transformations are applied to the vertices (left-to-right). TODO: .gz
func Quadrilateral ¶
func Quadrilateral(m Material, a, b, c, d Vec) Interface
Quadrilateral constructs a general quadrilateral with given vertices ordered as shown below. The vertices' UV coordinates are shown in parentheses.
d *-------------* c (0,1)| | (1,1) | | a *-------------* b (0,0) (0,1)
TODO: currently, a quadrilateral is composed of two triagles which each do their own UV mapping. While this mapping is continuous (seamless), it does not map straight lines to straight lines: there is a "kink" when crossing from one triangle to another.
func Rectangle ¶
Rectangle constructs a rectangle in the XZ (horizontal) plane with given width (along X), depth (along Z) and center.
func RectangleWithVertices ¶
func RectangleWithVertices(m Material, o, a, b Vec) Interface
RectangleFromVertices constructs a rectangle with vertices o, a, b, and an automatically determined fourth vertex a+b-o. The vertices are ordered as shown below. The vertices' UV coordinates are shown in parentheses.
b *-------------* a+b-o (automatic) (0,1)| | (1,1) | | o *-------------* a (0,0) (0,1)
It is OK for the sides not to be perpendicular. In that case a parallelogram is retrurned.
func Transformed ¶
func Transformed(object Interface, t *geom.AffineTransform) Interface
Transformed returns a transformed instance of the original object. The transform may be a rotation and/or scale (equal in all directions), but not an anistropic scale or shear, etc.
Multiple transformed instances of the same object may be made, they efficiently share underlying state.
If the original object is already a transformed instance, then the resulting chain of transforms is optimized into a single, equivalent transform. Thus, one may call
Transformed(Transformed(...))
without negative performance implications.
func Translated ¶
func Tree ¶
Tree returns a Bounding Volume Hierarchy containing the given objects, which as an efficient Intersect method.
func Triangle ¶
func Triangle(m Material, a, b, c Vec) Interface
Triangle constructs a triangle with vertices a, b, c. The orientation of the normal vector is determined by the right-hand rule. The respective vertices get UV coordinates
(0,0), (1,0), (0,1)