tracer

package
v0.0.0-...-c293384 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2020 License: GPL-3.0 Imports: 32 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HDRToImage

func HDRToImage(filename string) image.Image

HDRToImage return an hdr image as an image.Image interface

func Render

func Render(w *World)

Render runs the render

func RenderLive

func RenderLive(w *World)

RenderLive renders using OpenGL to the screen

func RenderToFile

func RenderToFile(w *World, output string)

RenderToFile renders to a file

func Schlick

func Schlick(s *IntersectionState) float64

Schlick returns the reflectance - the fraction of light that is reflected [0,1]

Types

type AreaLight

type AreaLight struct {
	Shaper
	// contains filtered or unexported fields
}

AreaLight shines in all directions and is a shape

func NewAreaLight

func NewAreaLight(s Shaper, i Color, v bool) *AreaLight

NewAreaLight returns a new area light

func (*AreaLight) Intensity

func (al *AreaLight) Intensity() Color

Intensity implements the Light interface

func (*AreaLight) IsVisible

func (al *AreaLight) IsVisible() bool

IsVisible returns true if the light shape should be visible.

func (*AreaLight) Position

func (al *AreaLight) Position() Point

Position implements the Light interface

func (*AreaLight) RandomPosition

func (al *AreaLight) RandomPosition(rng *rand.Rand) Point

RandomPosition implements the Light interface

func (*AreaLight) SetIntensity

func (al *AreaLight) SetIntensity(c Color)

SetIntensity sets the intensity of the light

func (*AreaLight) Shape

func (al *AreaLight) Shape() Shaper

Shape returns the Shaper object of this light

type AreaSpotLight

type AreaSpotLight struct {
	Shaper
	// contains filtered or unexported fields
}

AreaSpotLight shines in a direction and is a shape

func NewAreaSpotLight

func NewAreaSpotLight(s Shaper, i Color, v bool, angle float64, to Point) *AreaSpotLight

NewAreaSpotLight returns a new area light

func (*AreaSpotLight) Angle

func (al *AreaSpotLight) Angle() float64

Angle returns the angle of the spot light

func (*AreaSpotLight) Direction

func (al *AreaSpotLight) Direction() Vector

Direction returns the direction of the spotlight

func (*AreaSpotLight) Intensity

func (al *AreaSpotLight) Intensity() Color

Intensity implements the Light interface

func (*AreaSpotLight) IsVisible

func (al *AreaSpotLight) IsVisible() bool

IsVisible returns true if the light shape should be visible.

func (*AreaSpotLight) Position

func (al *AreaSpotLight) Position() Point

Position implements the Light interface

func (*AreaSpotLight) RandomPosition

func (al *AreaSpotLight) RandomPosition(rng *rand.Rand) Point

RandomPosition implements the Light interface

func (*AreaSpotLight) SetIntensity

func (al *AreaSpotLight) SetIntensity(c Color)

SetIntensity sets the intensity of the light

func (*AreaSpotLight) Shape

func (al *AreaSpotLight) Shape() Shaper

Shape returns the Shaper object of this light

type BlendedPattern

type BlendedPattern struct {
	// contains filtered or unexported fields
}

BlendedPattern blends the output of two patterns

func NewBlendedPattern

func NewBlendedPattern(p1, p2 Patterner) *BlendedPattern

NewBlendedPattern returns a new blended patterner

func (*BlendedPattern) ColorAtObject

func (bp *BlendedPattern) ColorAtObject(o Shaper, p Point) Color

ColorAtObject returns the color for the given pattern on the given object

func (*BlendedPattern) SetTransform

func (bp *BlendedPattern) SetTransform(m Matrix)

SetTransform sets the transform

func (*BlendedPattern) Transform

func (bp *BlendedPattern) Transform() Matrix

Transform returns the pattern transform

func (*BlendedPattern) TransformInverse

func (bp *BlendedPattern) TransformInverse() Matrix

TransformInverse returns the inverse of the pattern transform

type Bound

type Bound struct {
	Min, Max Point
	// contains filtered or unexported fields
}

Bound describes the bounding box for a shape

func NewBound

func NewBound(min, max Point) Bound

NewBound returns a new bounding box

func (Bound) Center

func (b Bound) Center() Point

Center returns the center of the boundng box

func (Bound) Equal

func (b Bound) Equal(b2 Bound) bool

Equal returns true if the b == b2

type CSG

type CSG struct {
	Shape
	// contains filtered or unexported fields
}

CSG implements Constructive Solid Geometry shape Two shapes combined together via union, intersection or difference

func NewCSG

func NewCSG(s1, s2 Shaper, op Operation) *CSG

NewCSG returns a new CSG

func (*CSG) Equal

func (csg *CSG) Equal(csg2 *CSG) bool

Equal returns true if the CSGs are equal

func (*CSG) FilterIntersections

func (csg *CSG) FilterIntersections(xs Intersections) Intersections

FilterIntersections takes a list of intersections of two shapes and returns only those valid for the current CSG

func (*CSG) Includes

func (csg *CSG) Includes(s2 Shaper) bool

Includes implements includes logic

func (*CSG) IntersectWith

func (csg *CSG) IntersectWith(r Ray, xs Intersections) Intersections

IntersectWith returns the 't' values of Ray r intersecting with the CSG in sorted order

func (*CSG) IntersectionAllowed

func (csg *CSG) IntersectionAllowed(op Operation, lhit, inl, inr bool) bool

IntersectionAllowed returns true if this is a valid intersection

func (*CSG) NormalAt

func (csg *CSG) NormalAt(p Point, xs *Intersection) Vector

NormalAt is unused here

func (*CSG) PrecomputeValues

func (csg *CSG) PrecomputeValues()

PrecomputeValues precomputes some values for render speedup

type Camera

type Camera struct {
	Hsize, Vsize float64 // canvas size

	Transform             Matrix // view transformation matrix from the above function
	TransformInverse      Matrix // pre-cache the inverse as it's called for each pixel
	HalfWidth, HalfHeight float64
	PixelSize             float64
	// contains filtered or unexported fields
}

Camera defines the camera looking at the world

func NewCamera

func NewCamera(hsize, vsize, fov float64) *Camera

NewCamera returns

func (*Camera) RayForPixel

func (c *Camera) RayForPixel(x, y float64) Ray

RayForPixel returns a ray that starts at the camera and passes through x,y on the canvas

func (*Camera) SetFoV

func (c *Camera) SetFoV(fov float64)

SetFoV sets the field of view and recalculates the pixel size

func (*Camera) SetTransform

func (c *Camera) SetTransform(t Matrix)

SetTransform sets the transform on the camera

type Canvas

type Canvas struct {
	Width, Height int
	// contains filtered or unexported fields
}

Canvas is the canvas for drawing on

func NewCanvas

func NewCanvas(w, h int) *Canvas

NewCanvas returns a pointer to a new canvas

func (*Canvas) Colors

func (c *Canvas) Colors() []float32

Colors returns the array of vertex colors

func (*Canvas) ExportToPNG

func (c *Canvas) ExportToPNG(w io.Writer) error

ExportToPNG exports the canvas to a png file

func (*Canvas) Get

func (c *Canvas) Get(x, y int) (Color, error)

Get returns the color at the given coordinates

func (*Canvas) Points

func (c *Canvas) Points() []float32

Points returns the array of vertex points

func (*Canvas) Set

func (c *Canvas) Set(x, y int, clr Color) error

Set sets the color of a pixel

func (*Canvas) SetFloat

func (c *Canvas) SetFloat(x, y float64, clr Color) error

SetFloat sets the color of a pixel

type CheckerPattern

type CheckerPattern struct {
	// contains filtered or unexported fields
}

CheckerPattern implements a checker pattern

func NewCheckerPattern

func NewCheckerPattern(c1, c2 Color) *CheckerPattern

NewCheckerPattern returns a new checker pattern with the given colors

func (*CheckerPattern) ColorAtObject

func (cp *CheckerPattern) ColorAtObject(o Shaper, p Point) Color

ColorAtObject returns the color for the given pattern on the given object

func (*CheckerPattern) SetTransform

func (bp *CheckerPattern) SetTransform(m Matrix)

SetTransform sets the transform

func (*CheckerPattern) Transform

func (bp *CheckerPattern) Transform() Matrix

Transform returns the pattern transform

func (*CheckerPattern) TransformInverse

func (bp *CheckerPattern) TransformInverse() Matrix

TransformInverse returns the inverse of the pattern transform

type Color

type Color struct {
	R, G, B float64
}

Color represents a color with values between 0-1

func Black

func Black() Color

Black returns the color black

func ColorAtPoint

func ColorAtPoint(m *Material, o Shaper, p Point, l Light, eye, normal Vector, inShadow float64, rng *rand.Rand) Color

ColorAtPoint returns the clamped color at the given point

func ColorName

func ColorName(c color.Color) Color

ColorName returns a Color object given a color.Color interface

func NewColor

func NewColor(r, g, b float64) Color

NewColor returns a new color

func White

func White() Color

White returns the color white

func (Color) Add

func (c Color) Add(c2 Color) Color

Add adds to colors together

func (Color) Blend

func (c Color) Blend(c2 Color) Color

Blend blends two colors together by multiplying the rgb components by each other This is the Hadamard product (or Shur product)

func (Color) Clamp

func (c Color) Clamp() Color

Clamp returns the color with values <0 set to 0 and values >1 set to 1

func (Color) Equal

func (c Color) Equal(c2 Color) bool

Equal compares two colors to within Epsilon

func (Color) GreyScale

func (c Color) GreyScale() float64

GreyScale returns the GreyScale value of this color from https://stackoverflow.com/questions/17615963/standard-rgb-to-grayscale-conversion

func (Color) RGBA

func (c Color) RGBA() (r, g, b, a uint32)

RGBA implements the color.Color interface

func (Color) Scale

func (c Color) Scale(s float64) Color

Scale scales a color by a scalar

func (Color) Sub

func (c Color) Sub(c2 Color) Color

Sub subtracs one color from the other

type Colors

type Colors []Color

Colors is a list of Color

func (Colors) Average

func (cl Colors) Average() Color

Average returns the average of all the colors in the list

type Cone

type Cone struct {

	// used to truncate the cone, min and max values on the y axis (-y, y)
	Minimum, Maximum float64
	Closed           bool // if true, cone is capped on both ends
	Shape
}

Cone implements a double-napped cone

func NewClosedCone

func NewClosedCone(min, max float64) *Cone

NewClosedCone returns a new closed cone capped at min and max (y axis values, exclusive)

func NewCone

func NewCone(min, max float64) *Cone

NewCone returns a new cone capped at min and max (y axis values, exclusive)

func NewDefaultCone

func NewDefaultCone() *Cone

NewDefaultCone returns a new default cone

func (*Cone) Equal

func (c *Cone) Equal(c2 *Cone) bool

Equal returns true if the cones are equal

func (*Cone) Includes

func (c *Cone) Includes(s Shaper) bool

Includes implements includes logic

func (*Cone) IntersectWith

func (c *Cone) IntersectWith(r Ray, t Intersections) Intersections

IntersectWith returns the 't' values of Ray r intersecting with the cone in sorted order

func (*Cone) PrecomputeValues

func (c *Cone) PrecomputeValues()

PrecomputeValues precomputes some values for render speedup

type Cube

type Cube struct {
	Shape
}

Cube implements an AABB cube

func NewUnitCube

func NewUnitCube() *Cube

NewUnitCube returns a 1x1x1 cube

func (*Cube) Equal

func (c *Cube) Equal(c2 *Cube) bool

Equal returns true if the cubes are equal

func (*Cube) Includes

func (c *Cube) Includes(s Shaper) bool

Includes implements includes logic

func (*Cube) IntersectWith

func (c *Cube) IntersectWith(r Ray, t Intersections) Intersections

IntersectWith returns the 't' values of Ray r intersecting with the Cube in sorted order

func (*Cube) PrecomputeValues

func (c *Cube) PrecomputeValues()

PrecomputeValues precomputes some values for render speedup

type CubeMap

type CubeMap struct {
	// contains filtered or unexported fields
}

CubeMap implements a cube map

func NewCubeMap

func NewCubeMap(left, front, right, back, up, down UVPatterner) *CubeMap

NewCubeMap returns a new cube map

func NewCubeMapSame

func NewCubeMapSame(p UVPatterner) *CubeMap

NewCubeMapSame returns a new cube map that applies the same UVPattern to all faces

func (*CubeMap) Map

func (cm *CubeMap) Map(p Point) (float64, float64)

Map implements the Mapper interface

type CubeMapPattern

type CubeMapPattern struct {
	// contains filtered or unexported fields
}

CubeMapPattern ...

func NewCubeMapPattern

func NewCubeMapPattern(left, front, right, back, up, down UVPatterner) *CubeMapPattern

NewCubeMapPattern maps a texture onto a cube

func NewCubeMapPatternSame

func NewCubeMapPatternSame(p UVPatterner) *CubeMapPattern

NewCubeMapPatternSame maps a texture onto a cube

func (*CubeMapPattern) ColorAtObject

func (cm *CubeMapPattern) ColorAtObject(o Shaper, p Point) Color

ColorAtObject returns the color for the given pattern on the given object

func (*CubeMapPattern) SetTransform

func (bp *CubeMapPattern) SetTransform(m Matrix)

SetTransform sets the transform

func (*CubeMapPattern) Transform

func (bp *CubeMapPattern) Transform() Matrix

Transform returns the pattern transform

func (*CubeMapPattern) TransformInverse

func (bp *CubeMapPattern) TransformInverse() Matrix

TransformInverse returns the inverse of the pattern transform

type Cylinder

type Cylinder struct {
	Radius float64

	// used to truncate the cylinder, min and max values on the y axis (-y, y)
	Minimum, Maximum float64
	Closed           bool // if true, cylinder is capped on both ends
	Shape
}

Cylinder implements a cylinder of radius 1

func NewClosedCylinder

func NewClosedCylinder(min, max float64) *Cylinder

NewClosedCylinder returns a new closed cylinder capped at min and max (y axis values, exclusive)

func NewCylinder

func NewCylinder(min, max float64) *Cylinder

NewCylinder returns a new cylinder capped at min and max (y axis values, exclusive)

func NewDefaultCylinder

func NewDefaultCylinder() *Cylinder

NewDefaultCylinder returns a new cylinder

func (*Cylinder) Equal

func (c *Cylinder) Equal(c2 *Cylinder) bool

Equal returns true if the cylinders are equal

func (*Cylinder) Includes

func (c *Cylinder) Includes(s Shaper) bool

Includes implements includes logic

func (*Cylinder) IntersectWith

func (c *Cylinder) IntersectWith(r Ray, t Intersections) Intersections

IntersectWith returns the 't' values of Ray r intersecting with the Cylinder in sorted order

func (*Cylinder) PrecomputeValues

func (c *Cylinder) PrecomputeValues()

PrecomputeValues precomputes some values for render speedup

type CylinderMap

type CylinderMap struct{}

CylinderMap implements a cylinder map

func NewCylinderMap

func NewCylinderMap() *CylinderMap

NewCylinderMap returns a new plane map

func (*CylinderMap) Map

func (cm *CylinderMap) Map(p Point) (float64, float64)

Map implements the Mapper interface TODO: Does not handle cap ends.

type GradientPattern

type GradientPattern struct {
	// contains filtered or unexported fields
}

GradientPattern implements a gradient pattern

func NewGradientPattern

func NewGradientPattern(c1, c2 Color) *GradientPattern

NewGradientPattern returns a new gradient pattern with the given colors

func (*GradientPattern) ColorAtObject

func (gp *GradientPattern) ColorAtObject(o Shaper, p Point) Color

ColorAtObject returns the color for the given pattern on the given object

func (*GradientPattern) SetTransform

func (bp *GradientPattern) SetTransform(m Matrix)

SetTransform sets the transform

func (*GradientPattern) Transform

func (bp *GradientPattern) Transform() Matrix

Transform returns the pattern transform

func (*GradientPattern) TransformInverse

func (bp *GradientPattern) TransformInverse() Matrix

TransformInverse returns the inverse of the pattern transform

type Group

type Group struct {
	Shape
	// contains filtered or unexported fields
}

Group is a collection of other groups/objects

func NewGroup

func NewGroup() *Group

NewGroup returns a new, empty group

func ParseGLTF

func ParseGLTF(f string) (*Group, error)

ParseGLTF paes a .gltf file and returns the result as a group

func ParseOBJ

func ParseOBJ(f string) (*Group, error)

ParseOBJ parses an OBJ file and returns the result as a group

func (*Group) AddMember

func (g *Group) AddMember(m Shaper)

AddMember adds a new member to this group

func (*Group) AddMembers

func (g *Group) AddMembers(m ...Shaper)

AddMembers adds a new member to this group

func (*Group) Equal

func (g *Group) Equal(g2 *Group) bool

Equal returns true if the groups are equal

func (*Group) HasMembers

func (g *Group) HasMembers() bool

HasMembers returns true if this is a group that has members

func (*Group) Includes

func (g *Group) Includes(s Shaper) bool

Includes implements includes logic

func (*Group) IntersectWith

func (g *Group) IntersectWith(r Ray, t Intersections) Intersections

IntersectWith returns the 't' values of Ray r intersecting with the group

func (*Group) IntersectWithBoundingBox

func (g *Group) IntersectWithBoundingBox(r Ray, b Bound) bool

IntersectWithBoundingBox returns true if the ray intersects with the bounding box min and max define the bounding box

func (*Group) Members

func (g *Group) Members() []Shaper

Members returns all the direct members of this group

func (*Group) NormalAt

func (g *Group) NormalAt(p Point, xs *Intersection) Vector

NormalAt returns the normal vector at the given point on the surface of the group

func (*Group) NumShapes

func (g *Group) NumShapes() int

NumShapes returns the number of shapes contained in this object

func (*Group) PrecomputeValues

func (g *Group) PrecomputeValues()

PrecomputeValues precomputes some values for render speedup

func (*Group) SetWorldConfig

func (g *Group) SetWorldConfig(wc *WorldConfig)

SetWorldConfig attachs the world config to this object

type ImageHeightmapPerturber

type ImageHeightmapPerturber struct {
	// contains filtered or unexported fields
}

ImageHeightmapPerturber perturbes based on a height image

func NewImageHeightmapPerturber

func NewImageHeightmapPerturber(filename string, mapper Mapper) (*ImageHeightmapPerturber, error)

NewImageHeightmapPerturber returns a perturber that uses an image to simulate bumps

func (*ImageHeightmapPerturber) Perturb

func (ip *ImageHeightmapPerturber) Perturb(normal Vector, p Point) Vector

Perturb implements the Perturber interface

func (*ImageHeightmapPerturber) SetTransform

func (bp *ImageHeightmapPerturber) SetTransform(m Matrix)

SetTransform sets the transform

func (*ImageHeightmapPerturber) Transform

func (bp *ImageHeightmapPerturber) Transform() Matrix

Transform returns the pattern transform

func (*ImageHeightmapPerturber) TransformInverse

func (bp *ImageHeightmapPerturber) TransformInverse() Matrix

TransformInverse returns the inverse of the perturber transform

func (*ImageHeightmapPerturber) UVColorAt

func (ip *ImageHeightmapPerturber) UVColorAt(u, v float64) Color

UVColorAt returns the color at the 2D coordinate (u, v)

type Intersection

type Intersection struct {
	// contains filtered or unexported fields
}

Intersection encapsulates an intersection t value an an object

func NewIntersection

func NewIntersection(o Shaper, t float64) *Intersection

NewIntersection returns an intersection object

func NewIntersectionUV

func NewIntersectionUV(o Shaper, t, u, v float64) *Intersection

NewIntersectionUV returns an intersection object with UV filled in

func (*Intersection) Equal

func (i *Intersection) Equal(i2 *Intersection) bool

Equal returns true if the intersections are the same

func (*Intersection) Object

func (i *Intersection) Object() Shaper

Object returns the object of the intersection

func (*Intersection) T

func (i *Intersection) T() float64

T returns the t value for the intersection

type IntersectionState

type IntersectionState struct {
	T                     float64 // How far away from Ray origin did this occur?
	Object                Shaper  // The object we intersected
	Point                 Point   // the point of intersection
	EyeV                  Vector  // eye vector
	NormalV               Vector  // normal vector
	Inside                bool    // did the hit occure inside or outside the shape?
	OverPoint, UnderPoint Point   // offset to properly render shadows and refraction due to floating point errors
	ReflectV              Vector  // reflection vector
	N1, N2                float64 // RefractiveIndex of (n1) leaving material and (n2) entering material
	U, V                  float64 // u,v values for where the intersection occured
}

IntersectionState holds precomputed values for an intersection

func PrepareComputations

func PrepareComputations(hit *Intersection, r Ray, xs Intersections) *IntersectionState

PrepareComputations prepopulates the IntersectionState structure

type Intersections

type Intersections []*Intersection

Intersections is a collection of Intersections

func NewIntersections

func NewIntersections(i ...*Intersection) Intersections

NewIntersections aggregates the given intersections into a sorted list

func (Intersections) Hit

func (i Intersections) Hit() (*Intersection, error)

Hit returns the visible intersection (lowest non-negative value)

type Light

type Light interface {
	Intensity() Color
	SetIntensity(Color)
	IsVisible() bool

	// Center position on the light
	Position() Point
	// Random postion on the light
	RandomPosition(*rand.Rand) Point
	Shape() Shaper
}

Light is the interface all the lights use

type Lights

type Lights []Light

Lights is a collection of Light

type Mapper

type Mapper interface {
	// Map maps a 3D point to a 2D coordinate
	Map(Point) (float64, float64)
}

Mapper is a texture map interface

type Material

type Material struct {
	Color                                                                            Color
	Pattern                                                                          Patterner
	Ambient, Diffuse, Specular, Shininess, Reflective, Transparency, RefractiveIndex float64

	// This material emits light
	Emissive Color

	// Some objects should not cast shadows (e.g. water in a pond)
	ShadowCaster bool

	// Some materials have textures associated with them, this is an image file read in and stored as a canvas
	Texture *Canvas
	// contains filtered or unexported fields
}

Material is a material to apply to shapes

func NewDefaultGlassMaterial

func NewDefaultGlassMaterial() *Material

NewDefaultGlassMaterial returns a default glass material

func NewDefaultMaterial

func NewDefaultMaterial() *Material

NewDefaultMaterial returns a default material

func NewMaterial

func NewMaterial(clr Color, a, d, sp, s, r, t, ri float64, p Perturber) *Material

NewMaterial returns a new material

func (*Material) AddDiffuseTexture

func (m *Material) AddDiffuseTexture(name string, i image.Image) error

AddDiffuseTexture adds a texture mapped to a Canvas

func (*Material) ColorAtTexture

func (m *Material) ColorAtTexture(o Shaper, u, v float64) Color

ColorAtTexture returns the color at the u,v point based on the texture attached to the material Only works for SmoothTriangles, used during obj import

func (*Material) Equals

func (m *Material) Equals(m2 *Material) bool

Equals return true if the materials are the same

func (*Material) HasPattern

func (m *Material) HasPattern() bool

HasPattern returns true if a material has a pattern attached to it

func (*Material) HasTexture

func (m *Material) HasTexture() bool

HasTexture returns true if a material has a texture attached to it

func (*Material) PerturbNormal

func (m *Material) PerturbNormal(normal Vector, p Point) Vector

PerturbNormal applies the material perturbation function to the normal n at point p

func (*Material) SetPattern

func (m *Material) SetPattern(p Patterner)

SetPattern sets a pattern on a material

func (*Material) SetPerturber

func (m *Material) SetPerturber(p Perturber)

SetPerturber sets a perturber on a material

type Matrix

type Matrix [][]float64

Matrix defines a 2 diemnsional matrix

func IM

func IM() Matrix

IM returns a 4x4 identity Matrix

func NewMatrix

func NewMatrix(r, c int) Matrix

NewMatrix returns a new matrix or r rows and c columns

func NewMatrixFromData

func NewMatrixFromData(d [][]float64) Matrix

NewMatrixFromData returns a new matrix from the passed in data

func NewRotationX

func NewRotationX(r float64) Matrix

NewRotationX returns a 4x4 rotation matrix around the X axis

func NewRotationY

func NewRotationY(r float64) Matrix

NewRotationY returns a 4x4 rotation matrix around the Y axis

func NewRotationZ

func NewRotationZ(r float64) Matrix

NewRotationZ returns a 4x4 rotation matrix around the Z axis

func NewScaling

func NewScaling(x, y, z float64) Matrix

NewScaling returns a 4x4 scaling Matrix

func NewShearing

func NewShearing(xy, xz, yx, yz, zx, zy float64) Matrix

NewShearing returns a 4x4 shearing matrix

func NewTranslation

func NewTranslation(x, y, z float64) Matrix

NewTranslation returns a 4x4 translation Matrix

func ViewTransform

func ViewTransform(from, to Point, up Vector) Matrix

ViewTransform returns the view transform matrix given from, to and up vectors

func (Matrix) Cofactor

func (m Matrix) Cofactor(row, col int) float64

Cofactor returns the cofactor of a matrix at row, col

func (Matrix) Determinant

func (m Matrix) Determinant() float64

Determinant returns the determinant of a 2x2 matrix

func (Matrix) Dims

func (m Matrix) Dims() (r, c int)

Dims returns the row, column dimensions of the matrix

func (Matrix) Equals

func (m Matrix) Equals(m2 Matrix) bool

Equals compares the matrix with another one within a margin of error for each value

func (Matrix) Inverse

func (m Matrix) Inverse() Matrix

Inverse returns the inverse of a matrix

func (Matrix) IsInvertible

func (m Matrix) IsInvertible() bool

IsInvertible return true if the matrix is invertible

func (Matrix) Minor

func (m Matrix) Minor(row, col int) float64

Minor returns the minor of a matrix

func (Matrix) RotateX

func (m Matrix) RotateX(r float64) Matrix

RotateX rotates the matrix

func (Matrix) RotateY

func (m Matrix) RotateY(r float64) Matrix

RotateY rotates the matrix

func (Matrix) RotateZ

func (m Matrix) RotateZ(r float64) Matrix

RotateZ rotates the matrix

func (Matrix) Scale

func (m Matrix) Scale(x, y, z float64) Matrix

Scale scales the matrix

func (Matrix) Shear

func (m Matrix) Shear(xy, xz, yx, yz, zx, zy float64) Matrix

Shear shears the matrix

func (Matrix) Submatrix

func (m Matrix) Submatrix(row, col int) Matrix

Submatrix returns a submatrix

func (Matrix) TimesMatrix

func (m Matrix) TimesMatrix(m2 Matrix) Matrix

TimesMatrix multiplies m by m2 and returns a new matric, currently only handles 4x4 matricies

func (Matrix) Translate

func (m Matrix) Translate(x, y, z float64) Matrix

Translate translates the matrix

func (Matrix) Transpose

func (m Matrix) Transpose() Matrix

Transpose transposes a YxY matrix

type NoisePerturber

type NoisePerturber struct {
	// contains filtered or unexported fields
}

NoisePerturber perturbes based on noise

func NewNoisePerturber

func NewNoisePerturber(maxNoise float64) *NoisePerturber

NewNoisePerturber returns a perturber that makes waves on the shape

func (*NoisePerturber) Perturb

func (np *NoisePerturber) Perturb(v Vector, p Point) Vector

Perturb implements the Perturber interface

func (*NoisePerturber) SetNoise

func (np *NoisePerturber) SetNoise(n opensimplex.Noise)

SetNoise allows setting the noise generator (mostly used for tests)

func (*NoisePerturber) SetTransform

func (bp *NoisePerturber) SetTransform(m Matrix)

SetTransform sets the transform

func (*NoisePerturber) Transform

func (bp *NoisePerturber) Transform() Matrix

Transform returns the pattern transform

func (*NoisePerturber) TransformInverse

func (bp *NoisePerturber) TransformInverse() Matrix

TransformInverse returns the inverse of the perturber transform

type Operation

type Operation int

Operation defines the operation applied to a CSG

const (
	// Union combines the inputs into a single shape, prseving all external surfaces
	Union Operation = iota

	// Intersect preserves the portion of th einputs that share a volume
	Intersect

	// Difference preserves only the portion of the first shape where it's overlapped by the others
	Difference
)

type Patterner

type Patterner interface {
	// Returns the correct color at the given point on the given object for this pattern
	ColorAtObject(Shaper, Point) Color

	Transform() Matrix
	TransformInverse() Matrix
	SetTransform(Matrix)
}

Patterner is a pattern that can be applied to a material This does not do UV Mapping, the pattern is set on the 3D Space of the object

type PerturbedPattern

type PerturbedPattern struct {
	// contains filtered or unexported fields
}

PerturbedPattern jitters the points before passing them on to the real pattern Using Opensimplex: https://github.com/ojrac/opensimplex-go

func NewPerturbedPattern

func NewPerturbedPattern(p Patterner, maxNoise float64) *PerturbedPattern

NewPerturbedPattern returns a new perturbed patterner maxNoise is a [0, 1] value which clamps how much the noise affects the input

func (*PerturbedPattern) ColorAtObject

func (pp *PerturbedPattern) ColorAtObject(o Shaper, p Point) Color

ColorAtObject returns the color for the given pattern on the given object

func (*PerturbedPattern) SetTransform

func (bp *PerturbedPattern) SetTransform(m Matrix)

SetTransform sets the transform

func (*PerturbedPattern) Transform

func (bp *PerturbedPattern) Transform() Matrix

Transform returns the pattern transform

func (*PerturbedPattern) TransformInverse

func (bp *PerturbedPattern) TransformInverse() Matrix

TransformInverse returns the inverse of the pattern transform

type Perturber

type Perturber interface {
	Perturb(Vector, Point) Vector

	Transform() Matrix
	TransformInverse() Matrix
	SetTransform(Matrix)
}

Perturber defines an object that can be used to apply perturbation to the normal vectors of shapes

type Plane

type Plane struct {
	Shape
}

Plane implment a plan in xz extending infinitely in both x and z dimensions

func NewPlane

func NewPlane() *Plane

NewPlane returns a new plane

func (*Plane) Equal

func (pl *Plane) Equal(pl2 *Plane) bool

Equal returns true if the planes are equal

func (*Plane) Includes

func (pl *Plane) Includes(s Shaper) bool

Includes implements includes logic

func (*Plane) IntersectWith

func (pl *Plane) IntersectWith(r Ray, xs Intersections) Intersections

IntersectWith returns the 't' values of Ray r intersecting with the plane

func (*Plane) PrecomputeValues

func (pl *Plane) PrecomputeValues()

PrecomputeValues precomputes some values for render speedup

type PlaneMap

type PlaneMap struct{}

PlaneMap implements a plane map

func NewPlaneMap

func NewPlaneMap() *PlaneMap

NewPlaneMap returns a new plane map

func (*PlaneMap) Map

func (pm *PlaneMap) Map(p Point) (float64, float64)

Map implements the Mapper interface

type Point

type Point struct {
	// contains filtered or unexported fields
}

Point is a single point in 3D space. p[3] is always 1. Implements Tupler.

func NewPoint

func NewPoint(x, y, z float64) Point

NewPoint returns a new Point

func Origin

func Origin() Point

Origin returns the point at the origin

func (Point) AddScalar

func (p Point) AddScalar(t float64) Point

AddScalar adds a scalar to all the values of the point

func (Point) AddVector

func (p Point) AddVector(t Vector) Point

AddVector adds a point to a vector

func (Point) Equal

func (p Point) Equal(s Point) bool

Equal compares points

func (Point) Scale

func (p Point) Scale(s float64) Point

Scale scales the point

func (Point) SetW

func (p Point) SetW(a float64)

SetW sets w

func (Point) String

func (p Point) String() string

String returns ...

func (Point) SubPoint

func (p Point) SubPoint(t Point) Vector

SubPoint subtracts points

func (Point) SubVector

func (p Point) SubVector(t Vector) Point

SubVector subtracts a vector

func (Point) TimesMatrix

func (p Point) TimesMatrix(m Matrix) Point

TimesMatrix multiplies a point by the matrix

func (Point) ToObjectSpace

func (p Point) ToObjectSpace(s Shaper) Point

ToObjectSpace converts the given point from world space to object space

func (Point) ToWorldSpace

func (p Point) ToWorldSpace(s Shaper) Point

ToWorldSpace converts the given point from object space to world space

func (Point) W

func (p Point) W() float64

W returns the point's W coordinate

func (Point) X

func (p Point) X() float64

X returns the point's X coordinate

func (Point) Y

func (p Point) Y() float64

Y returns the point's y coordinate

func (Point) Z

func (p Point) Z() float64

Z returns the point's Z coordinate

type PointLight

type PointLight struct {
	// contains filtered or unexported fields
}

PointLight implements the light interface and is a single point light with no size

func NewPointLight

func NewPointLight(p Point, i Color) *PointLight

NewPointLight returns a new point light

func (*PointLight) Intensity

func (pl *PointLight) Intensity() Color

Intensity returns the intensity of the light

func (*PointLight) IsVisible

func (pl *PointLight) IsVisible() bool

IsVisible returns true if light is visible, point lights are never visible.

func (*PointLight) Position

func (pl *PointLight) Position() Point

Position returns the position of the light

func (*PointLight) RandomPosition

func (pl *PointLight) RandomPosition(rng *rand.Rand) Point

RandomPosition returns the position of the light

func (*PointLight) SetIntensity

func (pl *PointLight) SetIntensity(c Color)

SetIntensity sets the intensity of the light

func (*PointLight) Shape

func (pl *PointLight) Shape() Shaper

Shape returns the Shaper object of this light, point lights have no shape

type Ray

type Ray struct {
	Origin Point
	Dir    Vector
}

Ray describes a light ray

func NewRay

func NewRay(o Point, d Vector) Ray

NewRay returns a new ray

func (Ray) Equal

func (r Ray) Equal(s Ray) bool

Equal returns true if rays are equal within Epsilon of each other

func (Ray) Position

func (r Ray) Position(t float64) Point

Position returns the position of the point, set at r.Origin, following this ray at time t

func (Ray) Transform

func (r Ray) Transform(m Matrix) Ray

Transform returns a new ray transformed by the matrix

type RingPattern

type RingPattern struct {
	// contains filtered or unexported fields
}

RingPattern implements a ring pattern

func NewRingPattern

func NewRingPattern(c1, c2 Color) *RingPattern

NewRingPattern returns a new ring pattern with the given colors

func (*RingPattern) ColorAtObject

func (rp *RingPattern) ColorAtObject(o Shaper, p Point) Color

ColorAtObject returns the color for the given pattern on the given object

func (*RingPattern) SetTransform

func (bp *RingPattern) SetTransform(m Matrix)

SetTransform sets the transform

func (*RingPattern) Transform

func (bp *RingPattern) Transform() Matrix

Transform returns the pattern transform

func (*RingPattern) TransformInverse

func (bp *RingPattern) TransformInverse() Matrix

TransformInverse returns the inverse of the pattern transform

type Shape

type Shape struct {
	// contains filtered or unexported fields
}

Shape is the abstract shape

func (*Shape) Bounds

func (s *Shape) Bounds() Bound

Bounds returns the untransformed bounding box

func (*Shape) Equal

func (s *Shape) Equal(s2 *Shape) bool

Equal returns true if the shapes are equal

func (*Shape) HasMembers

func (s *Shape) HasMembers() bool

HasMembers returns true if this is a group that has members

func (*Shape) HasParent

func (s *Shape) HasParent() bool

HasParent returns True if this shape has a parent

func (*Shape) Includes

func (s *Shape) Includes(s2 Shaper) bool

Includes implements includes logic

func (*Shape) IntersectWith

func (s *Shape) IntersectWith(r Ray, xs Intersections) Intersections

IntersectWith implements Shaper interface

func (*Shape) Material

func (s *Shape) Material() *Material

Material returns the material of the shape

func (*Shape) Name

func (s *Shape) Name() string

Name returns the name of the shape

func (*Shape) NormalAt

func (s *Shape) NormalAt(p Point, xs *Intersection) Vector

NormalAt implements the Shaper interface

func (*Shape) NumShapes

func (s *Shape) NumShapes() int

NumShapes returns the number of shapes contained in this object

func (*Shape) Parent

func (s *Shape) Parent() Shaper

Parent returns the parent group this shape is part of

func (*Shape) PrecomputeValues

func (s *Shape) PrecomputeValues()

PrecomputeValues precomputes some values for render speedup

func (*Shape) RandomPosition

func (s *Shape) RandomPosition(rng *rand.Rand) Point

RandomPosition returns a random point on the surface

func (*Shape) SetMaterial

func (s *Shape) SetMaterial(m *Material)

SetMaterial sets the material of the shape

func (*Shape) SetName

func (s *Shape) SetName(n string)

SetName sets the name

func (*Shape) SetParent

func (s *Shape) SetParent(p Shaper)

SetParent sets the parents of the object

func (*Shape) SetTransform

func (s *Shape) SetTransform(m Matrix)

SetTransform sets the transformation matrix of the shape

func (*Shape) SetWorldConfig

func (s *Shape) SetWorldConfig(wc *WorldConfig)

SetWorldConfig attachs the world config to this object

func (*Shape) Transform

func (s *Shape) Transform() Matrix

Transform returns the transformation matrix of the shape

func (*Shape) TransformInverse

func (s *Shape) TransformInverse() Matrix

TransformInverse returns the inverse of the transformation matrix of the shape

func (*Shape) WorldConfig

func (s *Shape) WorldConfig() *WorldConfig

WorldConfig returns the world config attached to this object

type Shaper

type Shaper interface {
	Bounds() Bound

	HasMembers() bool

	Parent() Shaper
	HasParent() bool
	SetParent(Shaper)

	// If A is a Group, true if any child includes B
	// If A is a CSG, true if either child includes B
	// If A is anything else, true if A == B
	Includes(Shaper) bool

	IntersectWith(Ray, Intersections) Intersections
	NormalAt(Point, *Intersection) Vector
	PrecomputeValues()

	Material() *Material
	SetMaterial(*Material)

	WorldConfig() *WorldConfig
	SetWorldConfig(*WorldConfig)

	Name() string
	SetName(string)

	NumShapes() int

	// RandomPosition returns a andom point on the surface of the geometry
	RandomPosition(*rand.Rand) Point

	SetTransform(Matrix)
	Transform() Matrix

	TransformInverse() Matrix
}

Shaper represents an physical object

type SinePerturber

type SinePerturber struct {
	// contains filtered or unexported fields
}

SinePerturber perturbes based on the Sine wave

func NewSinePerturber

func NewSinePerturber() *SinePerturber

NewSinePerturber returns a perturber that makes waves on the shape

func (*SinePerturber) Perturb

func (sp *SinePerturber) Perturb(v Vector, p Point) Vector

Perturb implements the Perturber interface

func (*SinePerturber) SetTransform

func (bp *SinePerturber) SetTransform(m Matrix)

SetTransform sets the transform

func (*SinePerturber) Transform

func (bp *SinePerturber) Transform() Matrix

Transform returns the pattern transform

func (*SinePerturber) TransformInverse

func (bp *SinePerturber) TransformInverse() Matrix

TransformInverse returns the inverse of the perturber transform

type SmoothTriangle

type SmoothTriangle struct {
	P1, P2, P3 Point

	// Normals at each point
	N1, N2, N3 Vector

	// Texture coordinates at each point
	VT1, VT2, VT3 Point

	Triangle
}

SmoothTriangle is a triangle defined by 3 points in 3d space and the normals at those points

func NewSmoothTriangle

func NewSmoothTriangle(p1, p2, p3 Point, n1, n2, n3 Vector, vt1, vt2, vt3 Point) *SmoothTriangle

NewSmoothTriangle returns a new triangle

func (*SmoothTriangle) Equal

func (t *SmoothTriangle) Equal(t2 *SmoothTriangle) bool

Equal returns true if the mooth triangles are equal

func (*SmoothTriangle) Includes

func (t *SmoothTriangle) Includes(s Shaper) bool

Includes implements includes logic

func (*SmoothTriangle) IntersectWith

func (t *SmoothTriangle) IntersectWith(r Ray, xs Intersections) Intersections

IntersectWith returns the 't' value of Ray r intersecting with the triangle in sorted order

type Sphere

type Sphere struct {
	Center Point
	Radius float64
	Shape
}

Sphere is a spherical object, implements Shaper

func NewGlassSphere

func NewGlassSphere() *Sphere

NewGlassSphere returns a new Sphere centered at the origin with r=1, with a transparent material

func NewUnitSphere

func NewUnitSphere() *Sphere

NewUnitSphere returns a new Sphere centered at the origin with r=1

func (*Sphere) Equal

func (s *Sphere) Equal(s2 *Sphere) bool

Equal returns true if the spheres are equal

func (*Sphere) Includes

func (s *Sphere) Includes(s2 Shaper) bool

Includes implements includes logic

func (*Sphere) IntersectWith

func (s *Sphere) IntersectWith(r Ray, t Intersections) Intersections

IntersectWith returns the 't' values of Ray r intersecting with the Sphere

func (*Sphere) PrecomputeValues

func (s *Sphere) PrecomputeValues()

PrecomputeValues precomputes some values for render speedup

func (*Sphere) RandomPosition

func (s *Sphere) RandomPosition(rng *rand.Rand) Point

RandomPosition returns a random point on the surface of the sphere http://mathworld.wolfram.com/SpherePointPicking.html

type SphericalMap

type SphericalMap struct {
}

SphericalMap implements a spherical map

func NewSphericalMap

func NewSphericalMap() *SphericalMap

NewSphericalMap returns a new spherical map

func (*SphericalMap) Map

func (sm *SphericalMap) Map(p Point) (float64, float64)

Map implements the Mapper interface

type SpotLight

type SpotLight struct {
	// contains filtered or unexported fields
}

SpotLight implements the light interface and is a single point light with no size

func NewSpotLight

func NewSpotLight(from Point, i Color, angle float64, to Point) *SpotLight

NewSpotLight returns a new spot light

func (*SpotLight) Angle

func (l *SpotLight) Angle() float64

Angle returns the angle of the spot light

func (*SpotLight) Direction

func (l *SpotLight) Direction() Vector

Direction returns the direction of the spotlight

func (*SpotLight) Intensity

func (l *SpotLight) Intensity() Color

Intensity returns the intensity of the light

func (*SpotLight) IsVisible

func (l *SpotLight) IsVisible() bool

IsVisible returns true if light is visible, spot lights are never visible.

func (*SpotLight) Position

func (l *SpotLight) Position() Point

Position returns the position of the light

func (*SpotLight) RandomPosition

func (l *SpotLight) RandomPosition(rng *rand.Rand) Point

RandomPosition returns the position of the light

func (*SpotLight) SetIntensity

func (l *SpotLight) SetIntensity(c Color)

SetIntensity sets the intensity of the light

func (*SpotLight) Shape

func (l *SpotLight) Shape() Shaper

Shape returns the Shaper object of this light, spot lights have no shape

type StripedPattern

type StripedPattern struct {
	// contains filtered or unexported fields
}

StripedPattern is a pattern that overlays stripes

func NewStripedPattern

func NewStripedPattern(c1, c2 Color) *StripedPattern

NewStripedPattern returns a new striped pattern with the given colors

func (*StripedPattern) ColorAtObject

func (sp *StripedPattern) ColorAtObject(o Shaper, p Point) Color

ColorAtObject returns the color for the given pattern on the given object

func (*StripedPattern) SetTransform

func (bp *StripedPattern) SetTransform(m Matrix)

SetTransform sets the transform

func (*StripedPattern) Transform

func (bp *StripedPattern) Transform() Matrix

Transform returns the pattern transform

func (*StripedPattern) TransformInverse

func (bp *StripedPattern) TransformInverse() Matrix

TransformInverse returns the inverse of the pattern transform

type TextureMapPattern

type TextureMapPattern struct {
	// contains filtered or unexported fields
}

TextureMapPattern maps the child pattern using the provided map

func NewTextureMapPattern

func NewTextureMapPattern(p UVPatterner, m Mapper) *TextureMapPattern

NewTextureMapPattern returns a new texture map pattern For cubes, use NewCubeMapPattern, this one works for planes, spheres, cylinders and cones

func (*TextureMapPattern) ColorAtObject

func (tmp *TextureMapPattern) ColorAtObject(o Shaper, p Point) Color

ColorAtObject returns the color for the given pattern on the given object

func (*TextureMapPattern) SetTransform

func (bp *TextureMapPattern) SetTransform(m Matrix)

SetTransform sets the transform

func (*TextureMapPattern) Transform

func (bp *TextureMapPattern) Transform() Matrix

Transform returns the pattern transform

func (*TextureMapPattern) TransformInverse

func (bp *TextureMapPattern) TransformInverse() Matrix

TransformInverse returns the inverse of the pattern transform

type Triangle

type Triangle struct {
	P1, P2, P3 Point

	// edge1, edge2 and the normal
	E1, E2, Normal Vector

	Shape
}

Triangle is a triangle defined by 3 points in 3d space

func NewTriangle

func NewTriangle(p1, p2, p3 Point) *Triangle

NewTriangle returns a new triangle

func (*Triangle) Bounds

func (t *Triangle) Bounds() Bound

Bounds returns the untransformed bounding box

func (*Triangle) Equal

func (t *Triangle) Equal(t2 *Triangle) bool

Equal returns true if the triangles are equal

func (*Triangle) Includes

func (t *Triangle) Includes(s Shaper) bool

Includes implements includes logic

func (*Triangle) IntersectWith

func (t *Triangle) IntersectWith(r Ray, xs Intersections) Intersections

IntersectWith returns the 't' value of Ray r intersecting with the triangle in sorted order

func (*Triangle) PrecomputeValues

func (t *Triangle) PrecomputeValues()

PrecomputeValues precomputes some values for render speedup

type TriangleMesh

type TriangleMesh struct {
	// vertices of the mesh
	V []Point

	Triangles []*SmoothTriangle

	Shape
}

TriangleMesh is a mesh made up entirely of triangles

func NewMesh

func NewMesh(numFaces int, faceIndex, vertexIndex, normalIndex, textureIndex, materialIndex []int,
	verts []Point, normals []Vector, textures []Point, materials []*Material) *TriangleMesh

NewMesh generates a new polygon mesh by triangulating the input numFaces: total number of faces faceIndex: how many vertices each face is made of vertexIndex: lists the vertecies (indexed into verts) for each face verts: list of vertices

func (*TriangleMesh) Equal

func (m *TriangleMesh) Equal(m2 *TriangleMesh) bool

Equal returns true if the meshes are equal

func (*TriangleMesh) Includes

func (m *TriangleMesh) Includes(m2 Shaper) bool

Includes implements includes logic

func (*TriangleMesh) IntersectWith

func (m *TriangleMesh) IntersectWith(r Ray, t Intersections) Intersections

IntersectWith returns the 't' values of Ray r intersecting with the mesh

func (*TriangleMesh) IntersectWithBoundingBox

func (m *TriangleMesh) IntersectWithBoundingBox(r Ray, b Bound) bool

IntersectWithBoundingBox returns true if the ray intersects with the bounding box min and max define the bounding box

func (*TriangleMesh) NormalAt

func (m *TriangleMesh) NormalAt(p Point, xs *Intersection) Vector

NormalAt returns the normal vector at the given point on the surface of the mesh

func (*TriangleMesh) NumShapes

func (m *TriangleMesh) NumShapes() int

NumShapes returns the number of shapes contained in this object

func (*TriangleMesh) PrecomputeValues

func (m *TriangleMesh) PrecomputeValues()

PrecomputeValues precomputes some values for render speedup

func (*TriangleMesh) SetWorldConfig

func (m *TriangleMesh) SetWorldConfig(wc *WorldConfig)

SetWorldConfig attachs the world config to this object

type UVAlignCheckPattern

type UVAlignCheckPattern struct {
	// contains filtered or unexported fields
}

UVAlignCheckPattern ...

func NewUVAlignCheckPattern

func NewUVAlignCheckPattern(main, ul, ur, bl, br Color) *UVAlignCheckPattern

NewUVAlignCheckPattern returns a new ...

func (*UVAlignCheckPattern) UVColorAt

func (uap *UVAlignCheckPattern) UVColorAt(u, v float64) Color

UVColorAt returns the color at the 2D coordinate (u, v)

type UVCheckersPattern

type UVCheckersPattern struct {
	// contains filtered or unexported fields
}

UVCheckersPattern maps checkers to the surface of the object

func NewUVCheckersPattern

func NewUVCheckersPattern(w, h float64, a, b Color) *UVCheckersPattern

NewUVCheckersPattern returns a new UV mapped checkers pattern If you want your checkers to look "square" on the sphere, be sure and set the width to twice the height. This is because of how the spherical map is implemented. While both u and v go from 0 to 1, v maps 1 to π, but u maps 1 to 2π.

func (*UVCheckersPattern) UVColorAt

func (ucp *UVCheckersPattern) UVColorAt(u, v float64) Color

UVColorAt returns the color at the 2D coordinate (u, v)

type UVImagePattern

type UVImagePattern struct {
	// contains filtered or unexported fields
}

UVImagePattern maps an image to the surface of an object

func NewUVImagePattern

func NewUVImagePattern(filename string) (*UVImagePattern, error)

NewUVImagePattern returns a new image pattern

func NewUVImagePatternImage

func NewUVImagePatternImage(m image.Image) (*UVImagePattern, error)

NewUVImagePatternImage returns a new image pattern, input is an image.Image interface

func (*UVImagePattern) UVColorAt

func (uvip *UVImagePattern) UVColorAt(u, v float64) Color

UVColorAt returns the color at the 2D coordinate (u, v)

type UVPatterner

type UVPatterner interface {
	UVColorAt(float64, float64) Color
}

UVPatterner is a pattern that acceps UV coordinates

type Vector

type Vector struct {
	// contains filtered or unexported fields
}

Vector is a vector in 3D space. v[3] is always 0. Implements Tuple.

func NewVector

func NewVector(x, y, z float64) Vector

NewVector returns a new Vector

func (Vector) AddPoint

func (v Vector) AddPoint(t Point) Point

AddPoint adds a point to a vector

func (Vector) AddVector

func (v Vector) AddVector(t Vector) Vector

AddVector adds a vector to a vector

func (Vector) Cross

func (v Vector) Cross(w Vector) Vector

Cross returns the cross product of two vectors This returns a vector perpendicular to both of the original vectors

func (Vector) Dot

func (v Vector) Dot(w Vector) float64

Dot returns the dot product of the two vectors This is the cosine of the angle between two unit vectors

func (Vector) Equal

func (v Vector) Equal(s Vector) bool

Equal compares vectors

func (Vector) Magnitude

func (v Vector) Magnitude() float64

Magnitude computes the magnitude of the vector

func (Vector) MagnitudeNormalize

func (v Vector) MagnitudeNormalize() (float64, Vector)

MagnitudeNormalize returns both the magnitude and the normalized vector

func (Vector) Negate

func (v Vector) Negate() Vector

Negate negates the vector (subtracts it from the zero vector)

func (Vector) NormalToWorldSpace

func (v Vector) NormalToWorldSpace(s Shaper) Vector

NormalToWorldSpace converts the given vector from object space to world space

func (Vector) Normalize

func (v Vector) Normalize() Vector

Normalize normalizes a vector to a unit vector

func (Vector) Reflect

func (v Vector) Reflect(n Vector) Vector

Reflect returns the vector reflected around another one

func (Vector) Scale

func (v Vector) Scale(s float64) Vector

Scale scales the vector

func (Vector) SetW

func (v Vector) SetW(a float64)

SetW sets w

func (Vector) SetX

func (v Vector) SetX(a float64)

SetX sets x

func (Vector) SetY

func (v Vector) SetY(a float64)

SetY sets y

func (Vector) SetZ

func (v Vector) SetZ(a float64)

SetZ sets y

func (Vector) String

func (v Vector) String() string

String returns ...

func (Vector) SubVector

func (v Vector) SubVector(t Vector) Vector

SubVector subtracts vectors

func (Vector) TimesMatrix

func (v Vector) TimesMatrix(m Matrix) Vector

TimesMatrix multiplies the vector by the matrix

func (Vector) W

func (v Vector) W() float64

W returns the point's W coordinate

func (Vector) X

func (v Vector) X() float64

X returns the point's X coordinate

func (Vector) Y

func (v Vector) Y() float64

Y returns the point's y coordinate

func (Vector) Z

func (v Vector) Z() float64

Z returns the point's Z coordinate

type World

type World struct {
	Objects []Shaper
	Lights  []Light

	Config *WorldConfig
	// contains filtered or unexported fields
}

World holds everything in it

func NewDefaultTestWorld

func NewDefaultTestWorld() *World

NewDefaultTestWorld returns a world that many tests expect

func NewDefaultWorld

func NewDefaultWorld(width, height float64) *World

NewDefaultWorld returns a default world

func NewWorld

func NewWorld(config *WorldConfig) *World

NewWorld returns a new empty world

func (*World) AddLight

func (w *World) AddLight(l Light)

AddLight adds a new light to the world

func (*World) AddObject

func (w *World) AddObject(o Shaper)

AddObject adds an object into the world

func (*World) Camera

func (w *World) Camera() *Camera

Camera returns the world camera

func (*World) ColorAt

func (w *World) ColorAt(r Ray, remaining int, xs Intersections, rng *rand.Rand) Color

ColorAt returns the color in the world where the given ray hits

func (*World) IntensityAt

func (w *World) IntensityAt(p Point, l Light, xs Intersections, rng *rand.Rand) float64

IntensityAt returns the intensity of the light at point p

func (*World) Intersections

func (w *World) Intersections(r Ray, xs Intersections) Intersections

Intersections returns all the intersections in the world with the given ray (sorted)

func (*World) IsShadowed

func (w *World) IsShadowed(p Point, lp Point, xs Intersections) bool

IsShadowed returns true if p is in a shadow from the given light

func (*World) LintWorld

func (w *World) LintWorld()

LintWorld runs some common checks and prints out log messages to stdout

func (*World) PrecomputeValues

func (w *World) PrecomputeValues()

PrecomputeValues does some initial promcomputations to speed up render speed

func (*World) ReflectedColor

func (w *World) ReflectedColor(state *IntersectionState, remaining int, xs Intersections, rng *rand.Rand) Color

ReflectedColor returns the reflected color given an IntersectionState remaining controls how many times a light ray can bounce between the same objects

func (*World) RefractedColor

func (w *World) RefractedColor(state *IntersectionState, remaining int, xs Intersections, rng *rand.Rand) Color

RefractedColor returns the refracted color given an IntersectionState remaining controls how many times a light ray can bounce between the same objects

func (*World) RegisterMetrics

func (w *World) RegisterMetrics()

RegisterMetrics initializes metrics

func (*World) Render

func (w *World) Render(camera *Camera, canvas *Canvas)

Render renders the world using the world camera

func (*World) SetCamera

func (w *World) SetCamera(c *Camera)

SetCamera sets the world camera

func (*World) SetLights

func (w *World) SetLights(l Lights)

SetLights sets the world lights

func (*World) ShowInfo

func (w *World) ShowInfo()

ShowInfo dumps info about the world

type WorldConfig

type WorldConfig struct {
	// How many times to allow the ray to bounce between two objects (controls reflections of reflections)
	MaxRecusions int

	// Antialiasing support
	Antialias int

	// Parallelism, how many pixels to render at the same time
	Parallelism int

	// SoftShadow enables soft shadows
	SoftShadows bool

	// SoftShadowRays specifies how many shadow rays to cast, also used by area lights
	SoftShadowRays int

	// AreaLightRays specifies how many rays to cast for area lights
	AreaLightRays int

	// RenderPasses controls the display of the render to the screen
	RenderPasses int

	// BackfaceCulling disables drawing riangles facing away from the camera
	BackfaceCulling bool
}

WorldConfig collects various settings to configure the world

func NewWorldConfig

func NewWorldConfig() *WorldConfig

NewWorldConfig returns a new world config with default settings

Jump to

Keyboard shortcuts

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