objects

package
v0.0.0-...-405cb25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

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

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 And

func And(a, b Interface) Interface

And returns the intersection (boolean AND) of two objects.

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

func Bounded(orig Interface) Interface

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 Box

func Box(m Material, width, height, depth float64, center Vec) Interface

Box returns an (axis-aligned) box with given size and center.

func BoxWithBounds

func BoxWithBounds(m Material, min, max Vec) Interface

func Cylinder

func Cylinder(m Material, diam, height float64, center Vec) Interface

func CylinderDir

func CylinderDir(m Material, dir int, diam, height float64, center Vec) Interface

func CylinderWithCaps

func CylinderWithCaps(m Material, diam, height float64, center Vec) Interface

func Difference

func Difference(a, b Interface) Interface

func Disk

func Disk(m Material, diam float64, center Vec) Interface

func Hollow

func Hollow(orig Interface) Interface

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

func IsoSurface(mat Material, dx, dy, dz float64, f func(u, v float64) float64) Interface

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

func Mesh(m Material, vertices []Vec, faceIdx [][3]int) Interface

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

func MeshWithUV(m Material, vertices []Vec, faceIdx [][3]int, UV []Vec2) Interface

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

func Not(object Interface) Interface

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 Or

func Or(a, b Interface) Interface

func Parametric

func Parametric(m Material, numU, numV int, f func(u, v float64) Vec) Interface

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

func Rectangle(m Material, width, depth float64, center Vec) Interface

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 Remap

func Remap(orig Interface, remap func(Vec) Vec) Interface

func Restrict

func Restrict(a, b Interface) Interface

func Sphere

func Sphere(m Material, diam float64, center Vec) Interface

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 Translated(orig Interface, delta Vec) Interface

func Tree

func Tree(objects ...Interface) Interface

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)

func WithMaterial

func WithMaterial(m Material, obj Interface) Interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL