Documentation
¶
Index ¶
- func HDRToImage(filename string) image.Image
- func Render(w *World)
- func RenderLive(w *World)
- func RenderToFile(w *World, output string)
- func Schlick(s *IntersectionState) float64
- type AreaLight
- type AreaSpotLight
- func (al *AreaSpotLight) Angle() float64
- func (al *AreaSpotLight) Direction() Vector
- func (al *AreaSpotLight) Intensity() Color
- func (al *AreaSpotLight) IsVisible() bool
- func (al *AreaSpotLight) Position() Point
- func (al *AreaSpotLight) RandomPosition(rng *rand.Rand) Point
- func (al *AreaSpotLight) SetIntensity(c Color)
- func (al *AreaSpotLight) Shape() Shaper
- type BlendedPattern
- type Bound
- type CSG
- func (csg *CSG) Equal(csg2 *CSG) bool
- func (csg *CSG) FilterIntersections(xs Intersections) Intersections
- func (csg *CSG) Includes(s2 Shaper) bool
- func (csg *CSG) IntersectWith(r Ray, xs Intersections) Intersections
- func (csg *CSG) IntersectionAllowed(op Operation, lhit, inl, inr bool) bool
- func (csg *CSG) NormalAt(p Point, xs *Intersection) Vector
- func (csg *CSG) PrecomputeValues()
- type Camera
- type Canvas
- type CheckerPattern
- type Color
- type Colors
- type Cone
- type Cube
- type CubeMap
- type CubeMapPattern
- type Cylinder
- type CylinderMap
- type GradientPattern
- type Group
- func (g *Group) AddMember(m Shaper)
- func (g *Group) AddMembers(m ...Shaper)
- func (g *Group) Equal(g2 *Group) bool
- func (g *Group) HasMembers() bool
- func (g *Group) Includes(s Shaper) bool
- func (g *Group) IntersectWith(r Ray, t Intersections) Intersections
- func (g *Group) IntersectWithBoundingBox(r Ray, b Bound) bool
- func (g *Group) Members() []Shaper
- func (g *Group) NormalAt(p Point, xs *Intersection) Vector
- func (g *Group) NumShapes() int
- func (g *Group) PrecomputeValues()
- func (g *Group) SetWorldConfig(wc *WorldConfig)
- type ImageHeightmapPerturber
- func (ip *ImageHeightmapPerturber) Perturb(normal Vector, p Point) Vector
- func (bp *ImageHeightmapPerturber) SetTransform(m Matrix)
- func (bp *ImageHeightmapPerturber) Transform() Matrix
- func (bp *ImageHeightmapPerturber) TransformInverse() Matrix
- func (ip *ImageHeightmapPerturber) UVColorAt(u, v float64) Color
- type Intersection
- type IntersectionState
- type Intersections
- type Light
- type Lights
- type Mapper
- type Material
- func (m *Material) AddDiffuseTexture(name string, i image.Image) error
- func (m *Material) ColorAtTexture(o Shaper, u, v float64) Color
- func (m *Material) Equals(m2 *Material) bool
- func (m *Material) HasPattern() bool
- func (m *Material) HasTexture() bool
- func (m *Material) PerturbNormal(normal Vector, p Point) Vector
- func (m *Material) SetPattern(p Patterner)
- func (m *Material) SetPerturber(p Perturber)
- type Matrix
- func IM() Matrix
- func NewMatrix(r, c int) Matrix
- func NewMatrixFromData(d [][]float64) Matrix
- func NewRotationX(r float64) Matrix
- func NewRotationY(r float64) Matrix
- func NewRotationZ(r float64) Matrix
- func NewScaling(x, y, z float64) Matrix
- func NewShearing(xy, xz, yx, yz, zx, zy float64) Matrix
- func NewTranslation(x, y, z float64) Matrix
- func ViewTransform(from, to Point, up Vector) Matrix
- func (m Matrix) Cofactor(row, col int) float64
- func (m Matrix) Determinant() float64
- func (m Matrix) Dims() (r, c int)
- func (m Matrix) Equals(m2 Matrix) bool
- func (m Matrix) Inverse() Matrix
- func (m Matrix) IsInvertible() bool
- func (m Matrix) Minor(row, col int) float64
- func (m Matrix) RotateX(r float64) Matrix
- func (m Matrix) RotateY(r float64) Matrix
- func (m Matrix) RotateZ(r float64) Matrix
- func (m Matrix) Scale(x, y, z float64) Matrix
- func (m Matrix) Shear(xy, xz, yx, yz, zx, zy float64) Matrix
- func (m Matrix) Submatrix(row, col int) Matrix
- func (m Matrix) TimesMatrix(m2 Matrix) Matrix
- func (m Matrix) Translate(x, y, z float64) Matrix
- func (m Matrix) Transpose() Matrix
- type NoisePerturber
- type Operation
- type Patterner
- type PerturbedPattern
- type Perturber
- type Plane
- type PlaneMap
- type Point
- func (p Point) AddScalar(t float64) Point
- func (p Point) AddVector(t Vector) Point
- func (p Point) Equal(s Point) bool
- func (p Point) Scale(s float64) Point
- func (p Point) SetW(a float64)
- func (p Point) String() string
- func (p Point) SubPoint(t Point) Vector
- func (p Point) SubVector(t Vector) Point
- func (p Point) TimesMatrix(m Matrix) Point
- func (p Point) ToObjectSpace(s Shaper) Point
- func (p Point) ToWorldSpace(s Shaper) Point
- func (p Point) W() float64
- func (p Point) X() float64
- func (p Point) Y() float64
- func (p Point) Z() float64
- type PointLight
- type Ray
- type RingPattern
- type Shape
- func (s *Shape) Bounds() Bound
- func (s *Shape) Equal(s2 *Shape) bool
- func (s *Shape) HasMembers() bool
- func (s *Shape) HasParent() bool
- func (s *Shape) Includes(s2 Shaper) bool
- func (s *Shape) IntersectWith(r Ray, xs Intersections) Intersections
- func (s *Shape) Material() *Material
- func (s *Shape) Name() string
- func (s *Shape) NormalAt(p Point, xs *Intersection) Vector
- func (s *Shape) NumShapes() int
- func (s *Shape) Parent() Shaper
- func (s *Shape) PrecomputeValues()
- func (s *Shape) RandomPosition(rng *rand.Rand) Point
- func (s *Shape) SetMaterial(m *Material)
- func (s *Shape) SetName(n string)
- func (s *Shape) SetParent(p Shaper)
- func (s *Shape) SetTransform(m Matrix)
- func (s *Shape) SetWorldConfig(wc *WorldConfig)
- func (s *Shape) Transform() Matrix
- func (s *Shape) TransformInverse() Matrix
- func (s *Shape) WorldConfig() *WorldConfig
- type Shaper
- type SinePerturber
- type SmoothTriangle
- type Sphere
- type SphericalMap
- type SpotLight
- func (l *SpotLight) Angle() float64
- func (l *SpotLight) Direction() Vector
- func (l *SpotLight) Intensity() Color
- func (l *SpotLight) IsVisible() bool
- func (l *SpotLight) Position() Point
- func (l *SpotLight) RandomPosition(rng *rand.Rand) Point
- func (l *SpotLight) SetIntensity(c Color)
- func (l *SpotLight) Shape() Shaper
- type StripedPattern
- type TextureMapPattern
- type Triangle
- type TriangleMesh
- func (m *TriangleMesh) Equal(m2 *TriangleMesh) bool
- func (m *TriangleMesh) Includes(m2 Shaper) bool
- func (m *TriangleMesh) IntersectWith(r Ray, t Intersections) Intersections
- func (m *TriangleMesh) IntersectWithBoundingBox(r Ray, b Bound) bool
- func (m *TriangleMesh) NormalAt(p Point, xs *Intersection) Vector
- func (m *TriangleMesh) NumShapes() int
- func (m *TriangleMesh) PrecomputeValues()
- func (m *TriangleMesh) SetWorldConfig(wc *WorldConfig)
- type UVAlignCheckPattern
- type UVCheckersPattern
- type UVImagePattern
- type UVPatterner
- type Vector
- func (v Vector) AddPoint(t Point) Point
- func (v Vector) AddVector(t Vector) Vector
- func (v Vector) Cross(w Vector) Vector
- func (v Vector) Dot(w Vector) float64
- func (v Vector) Equal(s Vector) bool
- func (v Vector) Magnitude() float64
- func (v Vector) MagnitudeNormalize() (float64, Vector)
- func (v Vector) Negate() Vector
- func (v Vector) NormalToWorldSpace(s Shaper) Vector
- func (v Vector) Normalize() Vector
- func (v Vector) Reflect(n Vector) Vector
- func (v Vector) Scale(s float64) Vector
- func (v Vector) SetW(a float64)
- func (v Vector) SetX(a float64)
- func (v Vector) SetY(a float64)
- func (v Vector) SetZ(a float64)
- func (v Vector) String() string
- func (v Vector) SubVector(t Vector) Vector
- func (v Vector) TimesMatrix(m Matrix) Vector
- func (v Vector) W() float64
- func (v Vector) X() float64
- func (v Vector) Y() float64
- func (v Vector) Z() float64
- type World
- func (w *World) AddLight(l Light)
- func (w *World) AddObject(o Shaper)
- func (w *World) Camera() *Camera
- func (w *World) ColorAt(r Ray, remaining int, xs Intersections, rng *rand.Rand) Color
- func (w *World) IntensityAt(p Point, l Light, xs Intersections, rng *rand.Rand) float64
- func (w *World) Intersections(r Ray, xs Intersections) Intersections
- func (w *World) IsShadowed(p Point, lp Point, xs Intersections) bool
- func (w *World) LintWorld()
- func (w *World) PrecomputeValues()
- func (w *World) ReflectedColor(state *IntersectionState, remaining int, xs Intersections, rng *rand.Rand) Color
- func (w *World) RefractedColor(state *IntersectionState, remaining int, xs Intersections, rng *rand.Rand) Color
- func (w *World) RegisterMetrics()
- func (w *World) Render(camera *Camera, canvas *Canvas)
- func (w *World) SetCamera(c *Camera)
- func (w *World) SetLights(l Lights)
- func (w *World) ShowInfo()
- type WorldConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HDRToImage ¶
HDRToImage return an hdr image as an image.Image interface
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 ¶
NewAreaLight returns a new area light
func (*AreaLight) RandomPosition ¶
RandomPosition implements the Light interface
func (*AreaLight) SetIntensity ¶
SetIntensity sets the intensity of the light
type AreaSpotLight ¶
type AreaSpotLight struct { Shaper // contains filtered or unexported fields }
AreaSpotLight shines in a direction and is a shape
func NewAreaSpotLight ¶
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
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 (*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) 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 ¶
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 (*Camera) RayForPixel ¶
RayForPixel returns a ray that starts at the camera and passes through x,y on the canvas
func (*Camera) SetTransform ¶
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 (*Canvas) ExportToPNG ¶
ExportToPNG exports the canvas to a png file
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 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 (Color) Blend ¶
Blend blends two colors together by multiplying the rgb components by each other This is the Hadamard product (or Shur product)
func (Color) GreyScale ¶
GreyScale returns the GreyScale value of this color from https://stackoverflow.com/questions/17615963/standard-rgb-to-grayscale-conversion
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 ¶
NewClosedCone returns a new closed cone capped at min and max (y axis values, exclusive)
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 (*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
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 ¶
NewClosedCylinder returns a new closed cylinder capped at min and max (y axis values, exclusive)
func NewCylinder ¶
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) 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 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 (*Group) AddMembers ¶
AddMembers adds a new member to this group
func (*Group) HasMembers ¶
HasMembers returns true if this is a group that has members
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 ¶
IntersectWithBoundingBox returns true if the ray intersects with the bounding box min and max define the bounding box
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) 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 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 ¶
NewMaterial returns a new material
func (*Material) AddDiffuseTexture ¶
AddDiffuseTexture adds a texture mapped to a Canvas
func (*Material) ColorAtTexture ¶
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) HasPattern ¶
HasPattern returns true if a material has a pattern attached to it
func (*Material) HasTexture ¶
HasTexture returns true if a material has a texture attached to it
func (*Material) PerturbNormal ¶
PerturbNormal applies the material perturbation function to the normal n at point p
func (*Material) SetPattern ¶
SetPattern sets a pattern on a material
func (*Material) SetPerturber ¶
SetPerturber sets a perturber on a material
type Matrix ¶
type Matrix [][]float64
Matrix defines a 2 diemnsional matrix
func NewMatrixFromData ¶
NewMatrixFromData returns a new matrix from the passed in data
func NewRotationX ¶
NewRotationX returns a 4x4 rotation matrix around the X axis
func NewRotationY ¶
NewRotationY returns a 4x4 rotation matrix around the Y axis
func NewRotationZ ¶
NewRotationZ returns a 4x4 rotation matrix around the Z axis
func NewShearing ¶
NewShearing returns a 4x4 shearing matrix
func NewTranslation ¶
NewTranslation returns a 4x4 translation Matrix
func ViewTransform ¶
ViewTransform returns the view transform matrix given from, to and up vectors
func (Matrix) Determinant ¶
Determinant returns the determinant of a 2x2 matrix
func (Matrix) Equals ¶
Equals compares the matrix with another one within a margin of error for each value
func (Matrix) IsInvertible ¶
IsInvertible return true if the matrix is invertible
func (Matrix) TimesMatrix ¶
TimesMatrix multiplies m by m2 and returns a new matric, currently only handles 4x4 matricies
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 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 (*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 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 (Point) TimesMatrix ¶
TimesMatrix multiplies a point by the matrix
func (Point) ToObjectSpace ¶
ToObjectSpace converts the given point from world space to object space
func (Point) ToWorldSpace ¶
ToWorldSpace converts the given point from object space to world space
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 ¶
Ray describes a light ray
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) HasMembers ¶
HasMembers returns true if this is a group that has members
func (*Shape) IntersectWith ¶
func (s *Shape) IntersectWith(r Ray, xs Intersections) Intersections
IntersectWith implements Shaper interface
func (*Shape) NormalAt ¶
func (s *Shape) NormalAt(p Point, xs *Intersection) Vector
NormalAt implements the Shaper interface
func (*Shape) PrecomputeValues ¶
func (s *Shape) PrecomputeValues()
PrecomputeValues precomputes some values for render speedup
func (*Shape) RandomPosition ¶
RandomPosition returns a random point on the surface
func (*Shape) SetMaterial ¶
SetMaterial sets the material of the shape
func (*Shape) SetTransform ¶
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) TransformInverse ¶
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 ¶
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) 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 ¶
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
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 ¶
NewSpotLight returns a new spot light
func (*SpotLight) IsVisible ¶
IsVisible returns true if light is visible, spot lights are never visible.
func (*SpotLight) RandomPosition ¶
RandomPosition returns the position of the light
func (*SpotLight) SetIntensity ¶
SetIntensity sets the intensity of the light
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 (*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 ¶
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 (Vector) Cross ¶
Cross returns the cross product of two vectors This returns a vector perpendicular to both of the original vectors
func (Vector) Dot ¶
Dot returns the dot product of the two vectors This is the cosine of the angle between two unit vectors
func (Vector) MagnitudeNormalize ¶
MagnitudeNormalize returns both the magnitude and the normalized vector
func (Vector) NormalToWorldSpace ¶
NormalToWorldSpace converts the given vector from object space to world space
func (Vector) TimesMatrix ¶
TimesMatrix multiplies the vector by the matrix
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 ¶
NewDefaultWorld returns a default world
func (*World) IntensityAt ¶
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
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
Source Files
¶
- camera.go
- canvas.go
- color.go
- cone.go
- config.go
- csg.go
- cube.go
- cylinder.go
- geometry.go
- group.go
- hdr.go
- intersect.go
- light.go
- linter.go
- map.go
- material.go
- matrix.go
- mesh.go
- opengl.go
- parser.go
- pattern.go
- perturb.go
- plane.go
- point.go
- ray.go
- render.go
- smooth_triangle.go
- sphere.go
- triangle.go
- uvpattern.go
- vector.go
- world.go