Versions in this module Expand all Collapse all v0 v0.1.0 Jan 24, 2023 v0.0.2 Sep 18, 2022 Changes in this version + const BounceTypeAny + const BounceTypeDiffuse + const BounceTypeSpecular + const ColorChannel + const EPS + const INF + const LightModeAll + const LightModeRandom + const SamplesChannel + const SpecularModeAll + const SpecularModeFirst + const SpecularModeNaive + const StandardDeviationChannel + const VarianceChannel + var Black = Color + var NoHit = Hit + var White = Color + func Clamp(x, lo, hi float64) float64 + func ClampInt(x, lo, hi int) int + func Degrees(radians float64) float64 + func Fract(x float64) float64 + func LoadImage(r io.Reader) (image.Image, error) + func Median(items []float64) float64 + func ParseFloats(items []string) []float64 + func ParseInts(items []string) []int + func Radians(degrees float64) float64 + func RelativePath(path1, path2 string) string + func SavePNG(w io.Writer, im image.Image) error + func SaveSTL(path string, mesh *Mesh) error + type Axis uint8 + const AxisNone + const AxisX + const AxisY + const AxisZ + type BounceType int + type Box struct + Max Vector + Min Vector + func BoxForShapes(shapes []Shape) Box + func BoxForTriangles(shapes []*Triangle) Box + func (a Box) Anchor(anchor Vector) Vector + func (a Box) Center() Vector + func (a Box) Contains(b Vector) bool + func (a Box) Extend(b Box) Box + func (a Box) InnerRadius() float64 + func (a Box) Intersects(b Box) bool + func (a Box) OuterRadius() float64 + func (a Box) Size() Vector + func (b *Box) Intersect(r Ray) (float64, float64) + func (b *Box) Partition(axis Axis, point float64) (left, right bool) + type Buffer struct + H int + Pixels []Pixel + W int + func NewBuffer(w, h int) *Buffer + func (b *Buffer) AddSample(x, y int, sample Color) + func (b *Buffer) Color(x, y int) Color + func (b *Buffer) Copy() *Buffer + func (b *Buffer) Image(channel Channel) image.Image + func (b *Buffer) Samples(x, y int) int + func (b *Buffer) StandardDeviation(x, y int) Color + func (b *Buffer) SubImage(x, y, w, h int, channel Channel) image.Image + func (b *Buffer) Variance(x, y int) Color + type Camera struct + func LookAt(eye, center, up Vector, fovy float64) Camera + func (c *Camera) CastRay(x, y, w, h int, u, v float64, rnd *rand.Rand) Ray + func (c *Camera) SetFocus(focalPoint Vector, apertureRadius float64) + type CapsuleSDF struct + A Vector + B Vector + Exponent float64 + Radius float64 + func (s *CapsuleSDF) BoundingBox() Box + func (s *CapsuleSDF) Evaluate(p Vector) float64 + type Channel int + type Color struct + B float64 + G float64 + R float64 + func HexColor(x int) Color + func Kelvin(K float64) Color + func NewColor(c color.Color) Color + func (a Color) Add(b Color) Color + func (a Color) DivScalar(b float64) Color + func (a Color) Max(b Color) Color + func (a Color) MaxComponent() float64 + func (a Color) Min(b Color) Color + func (a Color) MinComponent() float64 + func (a Color) Mix(b Color, pct float64) Color + func (a Color) Mul(b Color) Color + func (a Color) MulScalar(b float64) Color + func (a Color) Pow(b float64) Color + func (a Color) RGBA() color.RGBA + func (a Color) RGBA64() color.RGBA64 + func (a Color) Sub(b Color) Color + type ColorTexture struct + Data []Color + Height int + Width int + func (t *ColorTexture) BumpSample(u, v float64) Vector + func (t *ColorTexture) MulScalar(a float64) Texture + func (t *ColorTexture) NormalSample(u, v float64) Vector + func (t *ColorTexture) Pow(a float64) Texture + func (t *ColorTexture) Sample(u, v float64) Color + type Cube struct + Box Box + Material Material + Max Vector + Min Vector + func NewCube(min, max Vector, material Material) *Cube + func (c *Cube) BoundingBox() Box + func (c *Cube) Compile() + func (c *Cube) Intersect(r Ray) Hit + func (c *Cube) MaterialAt(p Vector) Material + func (c *Cube) Mesh() *Mesh + func (c *Cube) NormalAt(p Vector) Vector + func (c *Cube) UV(p Vector) Vector + type CubeSDF struct + Size Vector + func (s *CubeSDF) BoundingBox() Box + func (s *CubeSDF) Evaluate(p Vector) float64 + type Cylinder struct + Material Material + Radius float64 + Z0 float64 + Z1 float64 + func NewCylinder(radius, z0, z1 float64, material Material) *Cylinder + func (c *Cylinder) BoundingBox() Box + func (c *Cylinder) Compile() + func (c *Cylinder) MaterialAt(p Vector) Material + func (c *Cylinder) NormalAt(p Vector) Vector + func (c *Cylinder) UV(p Vector) Vector + func (shape *Cylinder) Intersect(ray Ray) Hit + type CylinderSDF struct + Height float64 + Radius float64 + func (s *CylinderSDF) BoundingBox() Box + func (s *CylinderSDF) Evaluate(p Vector) float64 + type DefaultSampler struct + DirectLighting bool + FirstHitSamples int + LightMode LightMode + MaxBounces int + SoftShadows bool + SpecularMode SpecularMode + func NewDirectSampler() *DefaultSampler + func NewSampler(firstHitSamples, maxBounces int) *DefaultSampler + func (s *DefaultSampler) Sample(scene *Scene, ray Ray, rnd *rand.Rand) Color + type DifferenceSDF struct + Items []SDF + func (s *DifferenceSDF) BoundingBox() Box + func (s *DifferenceSDF) Evaluate(p Vector) float64 + type Func func(x, y float64) float64 + type Function struct + Box Box + Function Func + Material Material + func (f *Function) BoundingBox() Box + func (f *Function) Compile() + func (f *Function) Contains(v Vector) bool + func (f *Function) Intersect(ray Ray) Hit + func (f *Function) MaterialAt(p Vector) Material + func (f *Function) NormalAt(p Vector) Vector + func (f *Function) UV(p Vector) Vector + type Hit struct + HitInfo *HitInfo + Shape Shape + T float64 + func (hit *Hit) Info(r Ray) HitInfo + func (hit *Hit) Ok() bool + type HitInfo struct + Inside bool + Material Material + Normal Vector + Position Vector + Ray Ray + Shape Shape + type IntersectionSDF struct + Items []SDF + func (s *IntersectionSDF) BoundingBox() Box + func (s *IntersectionSDF) Evaluate(p Vector) float64 + type LightMode int + type Material struct + BumpMultiplier float64 + BumpTexture Texture + Color Color + Emittance float64 + Gloss float64 + GlossTexture Texture + Index float64 + NormalTexture Texture + Reflectivity float64 + Texture Texture + Tint float64 + Transparent bool + func ClearMaterial(index, gloss float64) Material + func DiffuseMaterial(color Color) Material + func GlossyMaterial(color Color, index, gloss float64) Material + func LightMaterial(color Color, emittance float64) Material + func MaterialAt(shape Shape, point Vector) Material + func MetallicMaterial(color Color, gloss, tint float64) Material + func SpecularMaterial(color Color, index float64) Material + func TransparentMaterial(color Color, index, gloss, tint float64) Material + type Matrix struct + func Frustum(l, r, b, t, n, f float64) Matrix + func Identity() Matrix + func LookAtMatrix(eye, center, up Vector) Matrix + func Orthographic(l, r, b, t, n, f float64) Matrix + func Perspective(fovy, aspect, near, far float64) Matrix + func Rotate(v Vector, a float64) Matrix + func Scale(v Vector) Matrix + func Translate(v Vector) Matrix + func (a Matrix) Determinant() float64 + func (a Matrix) Inverse() Matrix + func (a Matrix) Mul(b Matrix) Matrix + func (a Matrix) MulBox(box Box) Box + func (a Matrix) MulDirection(b Vector) Vector + func (a Matrix) MulPosition(b Vector) Vector + func (a Matrix) MulRay(b Ray) Ray + func (a Matrix) Transpose() Matrix + func (m Matrix) Frustum(l, r, b, t, n, f float64) Matrix + func (m Matrix) Orthographic(l, r, b, t, n, f float64) Matrix + func (m Matrix) Perspective(fovy, aspect, near, far float64) Matrix + func (m Matrix) Rotate(v Vector, a float64) Matrix + func (m Matrix) Scale(v Vector) Matrix + func (m Matrix) Translate(v Vector) Matrix + type Mesh struct + Triangles []*Triangle + func LoadSTL(path string, material Material) (*Mesh, error) + func NewMesh(triangles []*Triangle) *Mesh + func NewSDFMesh(sdf SDF, box Box, step float64) *Mesh + func (a *Mesh) Add(b *Mesh) + func (m *Mesh) BoundingBox() Box + func (m *Mesh) Compile() + func (m *Mesh) Copy() *Mesh + func (m *Mesh) FitInside(box Box, anchor Vector) + func (m *Mesh) Intersect(r Ray) Hit + func (m *Mesh) MaterialAt(p Vector) Material + func (m *Mesh) MoveTo(position, anchor Vector) + func (m *Mesh) NormalAt(p Vector) Vector + func (m *Mesh) SaveSTL(path string) error + func (m *Mesh) SetMaterial(material Material) + func (m *Mesh) SmoothNormals() + func (m *Mesh) SmoothNormalsThreshold(radians float64) + func (m *Mesh) Transform(matrix Matrix) + func (m *Mesh) UV(p Vector) Vector + func (m *Mesh) UnitCube() + type Node struct + Axis Axis + Left *Node + Point float64 + Right *Node + Shapes []Shape + func NewNode(shapes []Shape) *Node + func (node *Node) Intersect(r Ray, tmin, tmax float64) Hit + func (node *Node) IntersectShapes(r Ray) Hit + func (node *Node) Partition(size int, axis Axis, point float64) (left, right []Shape) + func (node *Node) PartitionScore(axis Axis, point float64) int + func (node *Node) Split(depth int) + type Pixel struct + M Color + Samples int + V Color + func (p *Pixel) AddSample(sample Color) + func (p *Pixel) Color() Color + func (p *Pixel) StandardDeviation() Color + func (p *Pixel) Variance() Color + type Plane struct + Material Material + Normal Vector + Point Vector + func NewPlane(point, normal Vector, material Material) *Plane + func (p *Plane) BoundingBox() Box + func (p *Plane) Compile() + func (p *Plane) Intersect(ray Ray) Hit + func (p *Plane) MaterialAt(a Vector) Material + func (p *Plane) NormalAt(a Vector) Vector + func (p *Plane) UV(a Vector) Vector + type Ray struct + Direction Vector + Origin Vector + func (i Ray) Bounce(info *HitInfo, u, v float64, bounceType BounceType, rnd *rand.Rand) (Ray, bool, float64) + func (n Ray) Reflect(i Ray) Ray + func (n Ray) Reflectance(i Ray, n1, n2 float64) float64 + func (n Ray) Refract(i Ray, n1, n2 float64) Ray + func (r Ray) ConeBounce(theta, u, v float64, rnd *rand.Rand) Ray + func (r Ray) Position(t float64) Vector + func (r Ray) WeightedBounce(u, v float64, rnd *rand.Rand) Ray + type Renderer struct + AdaptiveExponent float64 + AdaptiveSamples int + AdaptiveThreshold float64 + Area renderArea + Buffer *Buffer + Camera *Camera + FireflySamples int + FireflyThreshold float64 + Sampler Sampler + SamplesPerPixel int + Scene *Scene + StratifiedSampling bool + func NewRenderer(scene *Scene, camera *Camera, sampler Sampler, w, h int) *Renderer + func (r *Renderer) IterativeRender(iterations int) image.Image + func (r *Renderer) Render() image.Image + func (r *Renderer) SetArea(x, y, w, h int) error + func (r *Renderer) TimedRender(duration time.Duration) image.Image + type RepeatSDF struct + Step Vector + func (s *RepeatSDF) BoundingBox() Box + func (s *RepeatSDF) Evaluate(p Vector) float64 + type SDF interface + BoundingBox func() Box + Evaluate func(p Vector) float64 + func NewCapsuleSDF(a, b Vector, radius float64) SDF + func NewCubeSDF(size Vector) SDF + func NewCylinderSDF(radius, height float64) SDF + func NewDifferenceSDF(items ...SDF) SDF + func NewIntersectionSDF(items ...SDF) SDF + func NewRepeatSDF(sdf SDF, step Vector) SDF + func NewScaleSDF(sdf SDF, factor float64) SDF + func NewSphereSDF(radius float64) SDF + func NewTorusSDF(major, minor float64) SDF + func NewTransformSDF(sdf SDF, matrix Matrix) SDF + func NewUnionSDF(items ...SDF) SDF + type SDFShape struct + Material Material + func (s *SDFShape) Compile() + func (s *SDFShape) Intersect(ray Ray) Hit + func (s *SDFShape) MaterialAt(p Vector) Material + func (s *SDFShape) NormalAt(p Vector) Vector + func (s *SDFShape) UV(p Vector) Vector + type STLHeader struct + Count uint32 + type STLTriangle struct + N [3]float32 + V1 [3]float32 + V2 [3]float32 + V3 [3]float32 + type Sampler interface + Sample func(scene *Scene, ray Ray, rnd *rand.Rand) Color + type ScaleSDF struct + Factor float64 + func (s *ScaleSDF) BoundingBox() Box + func (s *ScaleSDF) Evaluate(p Vector) float64 + type Scene struct + Color Color + Lights []Shape + Shapes []Shape + Texture Texture + TextureAngle float64 + func NewScene() *Scene + func (s *Scene) Add(shape Shape) + func (s *Scene) Compile() + func (s *Scene) Intersect(r Ray) Hit + func (s *Scene) RayCount() uint64 + type Shape interface + BoundingBox func() Box + Compile func() + Intersect func(Ray) Hit + MaterialAt func(Vector) Material + NormalAt func(Vector) Vector + UV func(Vector) Vector + func NewFunction(function Func, box Box, material Material) Shape + func NewSDFShape(sdf SDF, material Material) Shape + func NewSphere(center Vector, radius float64, material Material) Shape + func NewSphericalHarmonic(l, m int, pm, nm Material) Shape + func NewTransformedCylinder(v0, v1 Vector, radius float64, material Material) Shape + func NewTransformedShape(s Shape, m Matrix) Shape + type SpecularMode int + type Sphere struct + Box Box + Center Vector + Material Material + Radius float64 + func (s *Sphere) BoundingBox() Box + func (s *Sphere) Compile() + func (s *Sphere) Intersect(r Ray) Hit + func (s *Sphere) MaterialAt(p Vector) Material + func (s *Sphere) NormalAt(p Vector) Vector + func (s *Sphere) UV(p Vector) Vector + type SphereSDF struct + Exponent float64 + Radius float64 + func (s *SphereSDF) BoundingBox() Box + func (s *SphereSDF) Evaluate(p Vector) float64 + type SphericalHarmonic struct + NegativeMaterial Material + PositiveMaterial Material + func (s *SphericalHarmonic) BoundingBox() Box + func (s *SphericalHarmonic) Compile() + func (s *SphericalHarmonic) Evaluate(p Vector) float64 + func (s *SphericalHarmonic) EvaluateHarmonic(p Vector) float64 + func (s *SphericalHarmonic) Intersect(r Ray) Hit + func (s *SphericalHarmonic) MaterialAt(p Vector) Material + func (s *SphericalHarmonic) NormalAt(p Vector) Vector + func (s *SphericalHarmonic) UV(p Vector) Vector + type Texture interface + BumpSample func(u, v float64) Vector + MulScalar func(a float64) Texture + NormalSample func(u, v float64) Vector + Pow func(a float64) Texture + Sample func(u, v float64) Color + func GetTexture(name string, r io.Reader) Texture + func LoadTexture(r io.Reader) (Texture, error) + func NewTexture(im image.Image) Texture + type TorusSDF struct + MajorExponent float64 + MajorRadius float64 + MinorExponent float64 + MinorRadius float64 + func (s *TorusSDF) BoundingBox() Box + func (s *TorusSDF) Evaluate(p Vector) float64 + type TransformSDF struct + Inverse Matrix + Matrix Matrix + func (s *TransformSDF) BoundingBox() Box + func (s *TransformSDF) Evaluate(p Vector) float64 + type TransformedShape struct + Inverse Matrix + Matrix Matrix + func (s *TransformedShape) BoundingBox() Box + func (s *TransformedShape) Intersect(r Ray) Hit + type Tree struct + Box Box + Root *Node + func NewTree(shapes []Shape) *Tree + func (tree *Tree) Intersect(r Ray) Hit + type Triangle struct + Material *Material + N1 Vector + N2 Vector + N3 Vector + T1 Vector + T2 Vector + T3 Vector + V1 Vector + V2 Vector + V3 Vector + func NewTriangle(v1, v2, v3, t1, t2, t3 Vector, material Material) *Triangle + func (t *Triangle) Area() float64 + func (t *Triangle) Barycentric(p Vector) (u, v, w float64) + func (t *Triangle) BoundingBox() Box + func (t *Triangle) Compile() + func (t *Triangle) FixNormals() + func (t *Triangle) Intersect(r Ray) Hit + func (t *Triangle) MaterialAt(p Vector) Material + func (t *Triangle) Normal() Vector + func (t *Triangle) NormalAt(p Vector) Vector + func (t *Triangle) UV(p Vector) Vector + func (t *Triangle) Vertices() (Vector, Vector, Vector) + type UnionSDF struct + Items []SDF + func (s *UnionSDF) BoundingBox() Box + func (s *UnionSDF) Evaluate(p Vector) float64 + type Vector struct + X float64 + Y float64 + Z float64 + func Cone(direction Vector, theta, u, v float64, rnd *rand.Rand) Vector + func PoissonDisc(x1, y1, x2, y2, r float64, n int) []Vector + func RandomUnitVector(rnd *rand.Rand) Vector + func V(x, y, z float64) Vector + func (a Vector) Abs() Vector + func (a Vector) Add(b Vector) Vector + func (a Vector) AddScalar(b float64) Vector + func (a Vector) Cross(b Vector) Vector + func (a Vector) Div(b Vector) Vector + func (a Vector) DivScalar(b float64) Vector + func (a Vector) Dot(b Vector) float64 + func (a Vector) Length() float64 + func (a Vector) LengthN(n float64) float64 + func (a Vector) Max(b Vector) Vector + func (a Vector) MaxComponent() float64 + func (a Vector) Min(b Vector) Vector + func (a Vector) MinAxis() Vector + func (a Vector) MinComponent() float64 + func (a Vector) Mod(b Vector) Vector + func (a Vector) Mul(b Vector) Vector + func (a Vector) MulScalar(b float64) Vector + func (a Vector) Negate() Vector + func (a Vector) Normalize() Vector + func (a Vector) String() string + func (a Vector) Sub(b Vector) Vector + func (a Vector) SubScalar(b float64) Vector + func (n Vector) Reflect(i Vector) Vector + func (n Vector) Reflectance(i Vector, n1, n2 float64) float64 + func (n Vector) Refract(i Vector, n1, n2 float64) Vector + type Volume struct + Box Box + D int + Data []float64 + H int + W int + Windows []VolumeWindow + ZScale float64 + func NewVolume(box Box, images []image.Image, sliceSpacing float64, windows []VolumeWindow) *Volume + func (v *Volume) BoundingBox() Box + func (v *Volume) Compile() + func (v *Volume) Get(x, y, z int) float64 + func (v *Volume) Intersect(ray Ray) Hit + func (v *Volume) MaterialAt(p Vector) Material + func (v *Volume) NormalAt(p Vector) Vector + func (v *Volume) Sample(x, y, z float64) float64 + func (v *Volume) Sign(a Vector) int + func (v *Volume) UV(p Vector) Vector + type VolumeWindow struct + Hi float64 + Lo float64 + Material Material