pt

package
v0.0.0-...-23d6da2 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2016 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const EPS = 1e-9
View Source
const INF = 1e9

Variables

View Source
var NoAttenuation = Attenuation{1, 0, 0}
View Source
var NoHit = Hit{nil, INF}
View Source
var RenderConfig = struct {
	CameraSamples int
	HitSamples    int
	Bounces       int
	Width         int
	Height        int
}{
	-1,
	16,
	4,
	1024,
	768,
}

Functions

func ClampInt

func ClampInt(x, lo, hi int) int

func Degrees

func Degrees(radians float64) float64

func DurationString

func DurationString(d time.Duration) string

func Fract

func Fract(x float64) float64

func LoadJPG

func LoadJPG(path string) (image.Image, error)

func LoadMTL

func LoadMTL(path string, parent Material, materials map[string]*Material) error

func LoadPNG

func LoadPNG(path string) (image.Image, error)

func Median

func Median(items []float64) float64

func NumberString

func NumberString(x float64) string

func ParseFloats

func ParseFloats(items []string) []float64

func ParseInts

func ParseInts(items []string) []int

func Radians

func Radians(degrees float64) float64

func RelativePath

func RelativePath(path1, path2 string) string

func Render

func Render(scene *Scene, camera *Camera) chan pixelRenderResult

func RenderToWindow

func RenderToWindow(pixelRenderResult chan pixelRenderResult)

func SaveBinarySTL

func SaveBinarySTL(path string, mesh *Mesh) error

func SavePNG

func SavePNG(path string, im image.Image) error

Types

type Attenuation

type Attenuation struct {
	Constant  float64
	Linear    float64
	Quadratic float64
}

func LinearAttenuation

func LinearAttenuation(x float64) Attenuation

func QuadraticAttenuation

func QuadraticAttenuation(x float64) Attenuation

func (*Attenuation) Compute

func (a *Attenuation) Compute(d float64) float64

type Axis

type Axis uint8
const (
	AxisNone Axis = iota
	AxisX
	AxisY
	AxisZ
)

type Box

type Box struct {
	Min, Max Vector
}

func BoxForShapes

func BoxForShapes(shapes []Shape) Box

func BoxForTriangles

func BoxForTriangles(shapes []*Triangle) Box

func (Box) Anchor

func (a Box) Anchor(anchor Vector) Vector

func (Box) Center

func (a Box) Center() Vector

func (Box) Extend

func (a Box) Extend(b Box) Box

func (*Box) Intersect

func (b *Box) Intersect(r Ray) (float64, float64)

func (*Box) Partition

func (b *Box) Partition(axis Axis, point float64) (left, right bool)

func (Box) Size

func (a Box) Size() Vector

type Camera

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

func LookAt

func LookAt(eye, center, up Vector, fovy float64) Camera

func (*Camera) CastRay

func (c *Camera) CastRay(x, y int, u, v float64) Ray

func (*Camera) SetFocus

func (c *Camera) SetFocus(focalPoint Vector, apertureRadius float64)

type Color

type Color struct {
	R, G, B float64
}

func HexColor

func HexColor(x int) Color

func NewColor

func NewColor(c color.Color) Color

NewColor

func (Color) Add

func (a Color) Add(b Color) Color

func (Color) DivScalar

func (a Color) DivScalar(b float64) Color

func (Color) Max

func (a Color) Max(b Color) Color

func (Color) Min

func (a Color) Min(b Color) Color

func (Color) Mix

func (a Color) Mix(b Color, pct float64) Color

func (Color) Mul

func (a Color) Mul(b Color) Color

func (Color) MulScalar

func (a Color) MulScalar(b float64) Color

func (Color) Pow

func (a Color) Pow(b float64) Color

func (Color) RGBA

func (a Color) RGBA() color.RGBA

func (Color) Sub

func (a Color) Sub(b Color) Color

type ColorTexture

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

func (*ColorTexture) BumpSample

func (t *ColorTexture) BumpSample(u, v float64) Vector

func (*ColorTexture) NormalSample

func (t *ColorTexture) NormalSample(u, v float64) Vector

func (*ColorTexture) Sample

func (t *ColorTexture) Sample(u, v float64) Color

type Cube

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

func (*Cube) Box

func (c *Cube) Box() Box

func (*Cube) Color

func (c *Cube) Color(p Vector) Color

func (*Cube) Compile

func (c *Cube) Compile()

func (*Cube) Intersect

func (c *Cube) Intersect(r Ray) Hit

func (*Cube) Material

func (c *Cube) Material(p Vector) Material

func (*Cube) Normal

func (c *Cube) Normal(p Vector) Vector

func (*Cube) RandomPoint

func (c *Cube) RandomPoint() Vector

type Hit

type Hit struct {
	Shape Shape
	T     float64
}

func (*Hit) Info

func (hit *Hit) Info(r Ray) HitInfo

func (*Hit) Ok

func (hit *Hit) Ok() bool

type HitInfo

type HitInfo struct {
	Shape    Shape
	Position Vector
	Normal   Vector
	Ray      Ray
	Color    Color
	Material Material
	Inside   bool
}

type Material

type Material struct {
	Color          Color
	Texture        Texture
	NormalTexture  Texture
	BumpTexture    Texture
	BumpMultiplier float64
	Emittance      float64
	Attenuation    Attenuation
	Index          float64 // refractive index
	Gloss          float64 // reflection cone angle in radians
	Tint           float64 // specular and refractive tinting
	Transparent    bool
}

func ClearMaterial

func ClearMaterial(index, gloss float64) Material

func DiffuseMaterial

func DiffuseMaterial(color Color) Material

func GlossyMaterial

func GlossyMaterial(color Color, index, gloss float64) Material

func LightMaterial

func LightMaterial(color Color, emittance float64, attenuation Attenuation) Material

func SpecularMaterial

func SpecularMaterial(color Color, index float64) Material

func TransparentMaterial

func TransparentMaterial(color Color, index, gloss, tint float64) Material

type Matrix

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

func Frustum

func Frustum(l, r, b, t, n, f float64) Matrix

func Identity

func Identity() Matrix

func LookAtMatrix

func LookAtMatrix(eye, center, up Vector, fovy float64) Matrix

func Orthographic

func Orthographic(l, r, b, t, n, f float64) Matrix

func Perspective

func Perspective(fovy, aspect, near, far float64) Matrix

func Rotate

func Rotate(v Vector, a float64) Matrix

func Scale

func Scale(v Vector) Matrix

func Translate

func Translate(v Vector) Matrix

func (Matrix) Determinant

func (a Matrix) Determinant() float64

func (Matrix) Frustum

func (m Matrix) Frustum(l, r, b, t, n, f float64) Matrix

func (Matrix) Inverse

func (a Matrix) Inverse() Matrix

func (Matrix) Mul

func (a Matrix) Mul(b Matrix) Matrix

func (Matrix) MulBox

func (a Matrix) MulBox(box Box) Box

func (Matrix) MulDirection

func (a Matrix) MulDirection(b Vector) Vector

func (Matrix) MulPosition

func (a Matrix) MulPosition(b Vector) Vector

func (Matrix) MulRay

func (a Matrix) MulRay(b Ray) Ray

func (Matrix) Orthographic

func (m Matrix) Orthographic(l, r, b, t, n, f float64) Matrix

func (Matrix) Perspective

func (m Matrix) Perspective(fovy, aspect, near, far float64) Matrix

func (Matrix) Rotate

func (m Matrix) Rotate(v Vector, a float64) Matrix

func (Matrix) Scale

func (m Matrix) Scale(v Vector) Matrix

func (Matrix) Translate

func (m Matrix) Translate(v Vector) Matrix

func (Matrix) Transpose

func (a Matrix) Transpose() Matrix

type Mesh

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

func LoadBinarySTL

func LoadBinarySTL(path string, material Material) (*Mesh, error)

func LoadOBJ

func LoadOBJ(path string, parent Material) (*Mesh, error)

func LoadSTL

func LoadSTL(path string, material Material) (*Mesh, error)

func NewMesh

func NewMesh(triangles []*Triangle) *Mesh

func (*Mesh) Box

func (m *Mesh) Box() Box

func (*Mesh) Color

func (m *Mesh) Color(p Vector) Color

func (*Mesh) Compile

func (m *Mesh) Compile()

func (*Mesh) FitInside

func (m *Mesh) FitInside(box Box, anchor Vector)

func (*Mesh) Intersect

func (m *Mesh) Intersect(r Ray) Hit

func (*Mesh) Material

func (m *Mesh) Material(p Vector) Material

func (*Mesh) MoveTo

func (m *Mesh) MoveTo(position, anchor Vector)

func (*Mesh) Normal

func (m *Mesh) Normal(p Vector) Vector

func (*Mesh) RandomPoint

func (m *Mesh) RandomPoint() Vector

func (*Mesh) SaveBinarySTL

func (m *Mesh) SaveBinarySTL(path string) error

func (*Mesh) SmoothNormals

func (m *Mesh) SmoothNormals()

func (*Mesh) SmoothNormalsThreshold

func (m *Mesh) SmoothNormalsThreshold(radians float64)

func (*Mesh) Transform

func (m *Mesh) Transform(matrix Matrix)

func (*Mesh) Triangles

func (m *Mesh) Triangles() []*Triangle

func (*Mesh) UnitCube

func (m *Mesh) UnitCube()

func (*Mesh) UpdateBox

func (m *Mesh) UpdateBox()

type Node

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

func NewNode

func NewNode(shapes []Shape) *Node

func (*Node) Intersect

func (node *Node) Intersect(r Ray, tmin, tmax float64) Hit

func (*Node) IntersectShapes

func (node *Node) IntersectShapes(r Ray) Hit

func (*Node) Partition

func (node *Node) Partition(size int, axis Axis, point float64) (left, right []Shape)

func (*Node) PartitionScore

func (node *Node) PartitionScore(axis Axis, point float64) int

func (*Node) Split

func (node *Node) Split(depth int)

type Ray

type Ray struct {
	Origin, Direction Vector
}

func (Ray) Bounce

func (i Ray) Bounce(info *HitInfo, p, u, v float64) (Ray, bool)

func (Ray) ConeBounce

func (r Ray) ConeBounce(theta, u, v float64) Ray

func (Ray) Position

func (r Ray) Position(t float64) Vector

func (Ray) Reflect

func (n Ray) Reflect(i Ray) Ray

func (Ray) Reflectance

func (n Ray) Reflectance(i Ray, n1, n2 float64) float64

func (Ray) Refract

func (n Ray) Refract(i Ray, n1, n2 float64) Ray

func (Ray) WeightedBounce

func (r Ray) WeightedBounce(u, v float64) Ray

type STLHeader

type STLHeader struct {
	Count uint32
	// contains filtered or unexported fields
}

type STLTriangle

type STLTriangle struct {
	V1, V2, V3 [3]float32
	// contains filtered or unexported fields
}

type Scene

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

func (*Scene) Add

func (s *Scene) Add(shape Shape)

func (*Scene) Compile

func (s *Scene) Compile()

func (*Scene) DirectLight

func (s *Scene) DirectLight(n Ray) Color

func (*Scene) Intersect

func (s *Scene) Intersect(r Ray) Hit

func (*Scene) RayCount

func (s *Scene) RayCount() uint64

func (*Scene) Sample

func (s *Scene) Sample(r Ray, emission bool, samples, depth int) Color

func (*Scene) SetColor

func (s *Scene) SetColor(color Color)

func (*Scene) SetVisibility

func (s *Scene) SetVisibility(visibility float64)

func (*Scene) Shadow

func (s *Scene) Shadow(r Ray, light Shape, max float64) bool

type Shape

type Shape interface {
	Compile()
	Box() Box
	Intersect(Ray) Hit
	Color(Vector) Color
	Material(Vector) Material
	Normal(Vector) Vector
	RandomPoint() Vector
}

func NewCube

func NewCube(min, max Vector, material Material) Shape

func NewSphere

func NewSphere(center Vector, radius float64, material Material) Shape

func NewTransformedShape

func NewTransformedShape(s Shape, m Matrix) Shape

type Sphere

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

func (*Sphere) Box

func (s *Sphere) Box() Box

func (*Sphere) Color

func (s *Sphere) Color(p Vector) Color

func (*Sphere) Compile

func (s *Sphere) Compile()

func (*Sphere) Intersect

func (s *Sphere) Intersect(r Ray) Hit

func (*Sphere) Material

func (s *Sphere) Material(p Vector) Material

func (*Sphere) Normal

func (s *Sphere) Normal(p Vector) Vector

func (*Sphere) RandomPoint

func (s *Sphere) RandomPoint() Vector

type Texture

type Texture interface {
	Sample(u, v float64) Color
	NormalSample(u, v float64) Vector
	BumpSample(u, v float64) Vector
}

func GetTexture

func GetTexture(path string) Texture

func JPGTexture

func JPGTexture(path string) (Texture, error)

func LoadTexture

func LoadTexture(p string) (Texture, error)

func NewTexture

func NewTexture(im image.Image) Texture

func PNGTexture

func PNGTexture(path string) (Texture, error)

type TransformedShape

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

func (*TransformedShape) Box

func (s *TransformedShape) Box() Box

func (*TransformedShape) Color

func (s *TransformedShape) Color(p Vector) Color

func (*TransformedShape) Intersect

func (s *TransformedShape) Intersect(r Ray) Hit

func (*TransformedShape) Material

func (s *TransformedShape) Material(p Vector) Material

func (*TransformedShape) Normal

func (s *TransformedShape) Normal(p Vector) Vector

func (*TransformedShape) RandomPoint

func (s *TransformedShape) RandomPoint() Vector

type Tree

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

func NewTree

func NewTree(shapes []Shape) *Tree

func (*Tree) Intersect

func (tree *Tree) Intersect(r Ray) Hit

type Triangle

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

func NewTriangle

func NewTriangle(v1, v2, v3, t1, t2, t3 Vector, material Material) *Triangle

func (*Triangle) Area

func (t *Triangle) Area() float64

func (*Triangle) Barycentric

func (t *Triangle) Barycentric(p Vector) (u, v, w float64)

func (*Triangle) Box

func (t *Triangle) Box() Box

func (*Triangle) Color

func (t *Triangle) Color(p Vector) Color

func (*Triangle) Compile

func (t *Triangle) Compile()

func (*Triangle) FixNormals

func (t *Triangle) FixNormals()

func (*Triangle) Intersect

func (t *Triangle) Intersect(r Ray) Hit

func (*Triangle) Material

func (t *Triangle) Material(p Vector) Material

func (*Triangle) Normal

func (t *Triangle) Normal(p Vector) Vector

func (*Triangle) RandomPoint

func (t *Triangle) RandomPoint() Vector

func (*Triangle) UpdateBox

func (t *Triangle) UpdateBox()

func (*Triangle) Vertices

func (t *Triangle) Vertices() (Vector, Vector, Vector)

type Vector

type Vector struct {
	X, Y, Z float64
}

func PoissonDisc

func PoissonDisc(x1, y1, x2, y2, r float64, n int) []Vector

func (Vector) Add

func (a Vector) Add(b Vector) Vector

func (Vector) Cross

func (a Vector) Cross(b Vector) Vector

func (Vector) Div

func (a Vector) Div(b Vector) Vector

func (Vector) DivScalar

func (a Vector) DivScalar(b float64) Vector

func (Vector) Dot

func (a Vector) Dot(b Vector) float64

func (Vector) Length

func (a Vector) Length() float64

func (Vector) Max

func (a Vector) Max(b Vector) Vector

func (Vector) Min

func (a Vector) Min(b Vector) Vector

func (Vector) MinAxis

func (a Vector) MinAxis() Vector

func (Vector) MinComponent

func (a Vector) MinComponent() float64

func (Vector) Mul

func (a Vector) Mul(b Vector) Vector

func (Vector) MulScalar

func (a Vector) MulScalar(b float64) Vector

func (Vector) Normalize

func (a Vector) Normalize() Vector

func (Vector) Reflect

func (n Vector) Reflect(i Vector) Vector

func (Vector) Reflectance

func (n Vector) Reflectance(i Vector, n1, n2 float64) float64

func (Vector) Refract

func (n Vector) Refract(i Vector, n1, n2 float64) Vector

func (Vector) Sub

func (a Vector) Sub(b Vector) Vector

Jump to

Keyboard shortcuts

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