Documentation ¶
Index ¶
- Constants
- Variables
- func Add3(t1, t2, t3 Tuple4, out *Tuple4)
- func AddPtr(t1, t2 Tuple4, t3 *Tuple4)
- func AddPtr2(t1, t2 *Tuple4, t3 *Tuple4)
- func Cofactor3x3(m1 Mat3x3, row, col int) float64
- func Cofactor4x4(m1 Mat4x4, row, col int) float64
- func Cross2(a *Tuple4, b *Tuple4, c *Tuple4)
- func CrossProduct(f1, f2, out *Tuple4)
- func Determinant2x2(m1 Mat2x2) float64
- func Determinant3x3(m1 Mat3x3) float64
- func Determinant4x4(m1 Mat4x4) float64
- func Divide(s Shape, threshold int)
- func Dot(t1 Tuple4, t2 Tuple4) float64
- func DotPtr(t1 *Tuple4, t2 *Tuple4) float64
- func Eq(a, b float64) bool
- func Equals(m1, m2 Mat4x4) bool
- func Equals2x2(m1, m2 Mat2x2) bool
- func Equals3x3(m1, m2 Mat3x3) bool
- func HadamardPtr(t1 *Tuple4, t2 Tuple4, out *Tuple4)
- func IntersectRayWithBox(ray Ray, BoundingBox *BoundingBox) bool
- func IntersectionAllowed(op string, lhit, inl, inr bool) bool
- func IntersectionEqual(i1, i2 Intersection) bool
- func IsInvertible(m1 Mat4x4) bool
- func Magnitude(t1 Tuple4) float64
- func MagnitudePtr(t1 *Tuple4) float64
- func MakeSubGroup(g *Group, shapes ...Shape)
- func Minor3x3(m1 Mat3x3, row, col int) float64
- func Minor4x4(m1 Mat4x4, row, col int) float64
- func MultiplyByScalarPtr(t1 Tuple4, scalar float64, out *Tuple4)
- func MultiplyByTuplePtr(m *Mat4x4, f2 *Tuple4, _f4 *Tuple4)
- func MultiplyByTupleUsingPointers(m1 *Mat4x4, t, out *Tuple4)
- func MultiplyByTupleUsingValues(m1 Mat4x4, t Tuple4, out *Tuple4)
- func NegatePtr(t1 Tuple4, out *Tuple4)
- func NormalToWorldPtr(shape Shape, normal *Tuple4)
- func NormalizePtr(t1 *Tuple4, out *Tuple4)
- func NormalizePtr2(t1 Tuple4, out *Tuple4)
- func OrientAreaLight(light *AreaLight, source Tuple4, target Tuple4)
- func PartitionChildren(g *Group) (*Group, *Group)
- func PositionPtr(r Ray, distance float64, out *Tuple4)
- func PrepareComputationForIntersectionPtr(i Intersection, r Ray, comps *Computation, xs ...Intersection)
- func ReflectPtr(vec Tuple4, normal Tuple4, out *Tuple4)
- func Schlick(comps Computation) float64
- func ShadowIntersect(w World, r Ray, distance float64, inRay *Ray) bool
- func SplitBounds(b1 *BoundingBox) (*BoundingBox, *BoundingBox)
- func SubPtr(t1, t2 Tuple4, out *Tuple4)
- func TransformRayPtr(r Ray, m1 Mat4x4, out *Ray)
- func TupleEquals(t1, t2 Tuple4) bool
- func TupleXYZEq(t1, t2 Tuple4) bool
- func WorldToObjectPtr(shape Shape, point Tuple4, out *Tuple4)
- type AreaLight
- type BoundingBox
- func BoundsOf(shape Shape) *BoundingBox
- func NewBoundingBox(pointA Tuple4, pointB Tuple4) *BoundingBox
- func NewBoundingBoxF(x1, y1, z1, x2, y2, z2 float64) *BoundingBox
- func NewEmptyBoundingBox() *BoundingBox
- func ParentSpaceBounds(shape Shape) *BoundingBox
- func TransformBoundingBox(bbox *BoundingBox, m1 Mat4x4) *BoundingBox
- type CSG
- func (c *CSG) Bounds()
- func (c *CSG) CastsShadow() bool
- func (c *CSG) GetInverse() Mat4x4
- func (c *CSG) GetInverseTranspose() Mat4x4
- func (c *CSG) GetLocalRay() Ray
- func (c *CSG) GetMaterial() Material
- func (c *CSG) GetParent() Shape
- func (c *CSG) GetTransform() Mat4x4
- func (c *CSG) ID() int64
- func (c *CSG) IntersectLocal(ray Ray) []Intersection
- func (c *CSG) Name() string
- func (c *CSG) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
- func (c *CSG) SetMaterial(material Material)
- func (c *CSG) SetParent(shape Shape)
- func (c *CSG) SetTransform(transform Mat4x4)
- type Camera
- type Canvas
- type CheckerPattern
- type Computation
- type Cone
- func (c *Cone) CastsShadow() bool
- func (c *Cone) GetInverse() Mat4x4
- func (c *Cone) GetInverseTranspose() Mat4x4
- func (c *Cone) GetLocalRay() Ray
- func (c *Cone) GetMaterial() Material
- func (c *Cone) GetParent() Shape
- func (c *Cone) GetTransform() Mat4x4
- func (c *Cone) ID() int64
- func (c *Cone) IntersectLocal(ray Ray) []Intersection
- func (c *Cone) Name() string
- func (c *Cone) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
- func (c *Cone) SetMaterial(material Material)
- func (c *Cone) SetParent(shape Shape)
- func (c *Cone) SetTransform(transform Mat4x4)
- type Cube
- func (c *Cube) CastsShadow() bool
- func (c *Cube) GetInverse() Mat4x4
- func (c *Cube) GetInverseTranspose() Mat4x4
- func (c *Cube) GetLocalRay() Ray
- func (c *Cube) GetMaterial() Material
- func (c *Cube) GetParent() Shape
- func (c *Cube) GetTransform() Mat4x4
- func (c *Cube) ID() int64
- func (c *Cube) Init()
- func (c *Cube) IntersectLocal(ray Ray) []Intersection
- func (c *Cube) Name() string
- func (c *Cube) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
- func (c *Cube) SetMaterial(material Material)
- func (c *Cube) SetParent(shape Shape)
- func (c *Cube) SetTransform(transform Mat4x4)
- type Cylinder
- func (c *Cylinder) CastsShadow() bool
- func (c *Cylinder) GetInverse() Mat4x4
- func (c *Cylinder) GetInverseTranspose() Mat4x4
- func (c *Cylinder) GetLocalRay() Ray
- func (c *Cylinder) GetMaterial() Material
- func (c *Cylinder) GetParent() Shape
- func (c *Cylinder) GetTransform() Mat4x4
- func (c *Cylinder) ID() int64
- func (c *Cylinder) Init()
- func (c *Cylinder) IntersectLocal(ray Ray) []Intersection
- func (c *Cylinder) Name() string
- func (c *Cylinder) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
- func (c *Cylinder) SetMaterial(material Material)
- func (c *Cylinder) SetParent(shape Shape)
- func (c *Cylinder) SetTransform(transform Mat4x4)
- type GradientPattern
- type Group
- func (g *Group) AddChild(s Shape)
- func (g *Group) AddChildren(shapes ...Shape)
- func (g *Group) Bounds()
- func (g *Group) BoundsToCube() *Cube
- func (g *Group) CastsShadow() bool
- func (g *Group) GetInverse() Mat4x4
- func (g *Group) GetInverseTranspose() Mat4x4
- func (g *Group) GetLocalRay() Ray
- func (g *Group) GetMaterial() Material
- func (g *Group) GetParent() Shape
- func (g *Group) GetTransform() Mat4x4
- func (g *Group) ID() int64
- func (g *Group) IntersectLocal(ray Ray) []Intersection
- func (g *Group) Name() string
- func (g *Group) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
- func (g *Group) SetMaterial(material Material)
- func (g *Group) SetParent(shape Shape)
- func (g *Group) SetTransform(transform Mat4x4)
- type Intersection
- func FilterIntersections(csg *CSG, xs []Intersection) []Intersection
- func Hit(intersections []Intersection) (Intersection, bool)
- func IntersectRayWithShape(s Shape, r2 Ray) []Intersection
- func IntersectRayWithShapePtr(s Shape, r2 Ray, in *Ray) []Intersection
- func IntersectWithWorldPtr(w World, r Ray, xs Intersections, inRay *Ray) []Intersection
- func IntersectWithWorldPtrForShadow(w World, r Ray, xs Intersections, inRay *Ray) []Intersection
- func NewIntersection(t float64, s Shape) Intersection
- func NewIntersectionUV(t float64, s Shape, u, v float64) Intersection
- type Intersections
- type Light
- type LightData
- type LightSource
- type Mat2x2
- type Mat3x3
- type Mat4x4
- func Inverse(m1 Mat4x4) Mat4x4
- func Multiply(m1 Mat4x4, m2 Mat4x4) Mat4x4
- func New4x4() Mat4x4
- func NewIdentityMatrix() Mat4x4
- func NewMat4x4(elems []float64) Mat4x4
- func RotateX(radians float64) Mat4x4
- func RotateY(radians float64) Mat4x4
- func RotateZ(radians float64) Mat4x4
- func Scale(x, y, z float64) Mat4x4
- func Shear(xy, xz, yx, yz, zx, zy float64) Mat4x4
- func ShearBy(args []float64) Mat4x4
- func Translate(x, y, z float64) Mat4x4
- func Transpose(m1 Mat4x4) Mat4x4
- func ViewTransform(from, to, up Tuple4) Mat4x4
- type Material
- func NewDefaultMaterial() Material
- func NewDefaultReflectiveMaterial(reflectivity float64) Material
- func NewGlassMaterial(refractiveIndex float64) Material
- func NewMaterial(color Tuple4, ambient float64, diffuse float64, specular float64, ...) Material
- func NewMaterialWithReflectivity(color Tuple4, ambient float64, diffuse float64, specular float64, ...) Material
- type Mtl
- type Pattern
- type Plane
- func (p *Plane) CastsShadow() bool
- func (p *Plane) GetInverse() Mat4x4
- func (p *Plane) GetInverseTranspose() Mat4x4
- func (p *Plane) GetLocalRay() Ray
- func (p *Plane) GetMaterial() Material
- func (p *Plane) GetParent() Shape
- func (p *Plane) GetTransform() Mat4x4
- func (p *Plane) ID() int64
- func (p *Plane) IntersectLocal(ray Ray) []Intersection
- func (p *Plane) Name() string
- func (p *Plane) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
- func (p *Plane) SetMaterial(m Material)
- func (p *Plane) SetParent(shape Shape)
- func (p *Plane) SetTransform(translation Mat4x4)
- type Ray
- type RingPattern
- type Shape
- type SmoothTriangle
- func (s *SmoothTriangle) Barycentric(p Tuple4, u *float64, v *float64, w *float64)
- func (s *SmoothTriangle) CastsShadow() bool
- func (s *SmoothTriangle) GetInverse() Mat4x4
- func (s *SmoothTriangle) GetInverseTranspose() Mat4x4
- func (s *SmoothTriangle) GetLocalRay() Ray
- func (s *SmoothTriangle) GetMaterial() Material
- func (s *SmoothTriangle) GetParent() Shape
- func (s *SmoothTriangle) GetTransform() Mat4x4
- func (s *SmoothTriangle) ID() int64
- func (s *SmoothTriangle) IntersectLocal(ray Ray) []Intersection
- func (s *SmoothTriangle) Name() string
- func (s *SmoothTriangle) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
- func (s *SmoothTriangle) SetMaterial(material Material)
- func (s *SmoothTriangle) SetParent(shape Shape)
- func (s *SmoothTriangle) SetTransform(transform Mat4x4)
- type Sphere
- func (s *Sphere) CastsShadow() bool
- func (s *Sphere) GetInverse() Mat4x4
- func (s *Sphere) GetInverseTranspose() Mat4x4
- func (s *Sphere) GetLocalRay() Ray
- func (s *Sphere) GetMaterial() Material
- func (s *Sphere) GetParent() Shape
- func (s *Sphere) GetTransform() Mat4x4
- func (s *Sphere) ID() int64
- func (s *Sphere) IntersectLocal(r Ray) []Intersection
- func (s *Sphere) Name() string
- func (s *Sphere) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
- func (s *Sphere) SetMaterial(m Material)
- func (s *Sphere) SetParent(shape Shape)
- func (s *Sphere) SetTransform(translation Mat4x4)
- type StripePattern
- type TestPattern
- type Triangle
- func (t *Triangle) CastsShadow() bool
- func (t *Triangle) GetInverse() Mat4x4
- func (t *Triangle) GetInverseTranspose() Mat4x4
- func (t *Triangle) GetLocalRay() Ray
- func (t *Triangle) GetMaterial() Material
- func (t *Triangle) GetParent() Shape
- func (t *Triangle) GetTransform() Mat4x4
- func (t *Triangle) ID() int64
- func (t *Triangle) IntersectLocal(ray Ray) []Intersection
- func (t *Triangle) Name() string
- func (t *Triangle) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
- func (t *Triangle) SetMaterial(material Material)
- func (t *Triangle) SetParent(shape Shape)
- func (t *Triangle) SetTransform(transform Mat4x4)
- type Tuple4
- func Add(t1, t2 Tuple4) Tuple4
- func Cross(t1 Tuple4, t2 Tuple4) Tuple4
- func DivideByScalar(t1 Tuple4, scalar float64) Tuple4
- func Hadamard(t1 Tuple4, t2 Tuple4) Tuple4
- func Lighting(material Material, object Shape, light LightSource, ...) Tuple4
- func LightingPointLight(material Material, object Shape, light Light, ...) Tuple4
- func MultiplyByScalar(t1 Tuple4, scalar float64) Tuple4
- func MultiplyByTuple(m1 Mat4x4, t Tuple4) Tuple4
- func Negate(t1 Tuple4) Tuple4
- func NewColor(r, g, b float64) Tuple4
- func NewPoint(x, y, z float64) Tuple4
- func NewTuple() Tuple4
- func NewTupleOf(x, y, z, w float64) Tuple4
- func NewVector(x, y, z float64) Tuple4
- func NormalAt(s Shape, worldPoint Tuple4, intersection *Intersection) Tuple4
- func NormalToWorld(shape Shape, normal Tuple4) Tuple4
- func Normalize(t1 Tuple4) Tuple4
- func PatternAtShape(pattern Pattern, s Shape, worldPoint Tuple4) Tuple4
- func PointOnLight(light AreaLight, u, v float64) Tuple4
- func PointOnLightNoRandom(light AreaLight, u, v float64) Tuple4
- func Position(r Ray, distance float64) Tuple4
- func Reflect(vec Tuple4, normal Tuple4) Tuple4
- func Sub(t1, t2 Tuple4) Tuple4
- func T4F32(x, y, z float32, w float64) Tuple4
- func WorldToObject(shape Shape, point Tuple4) Tuple4
- func (t Tuple4) Add(t2 Tuple4) Tuple4
- func (t *Tuple4) AddNoRet(t2 Tuple4)
- func (t *Tuple4) AddNoRetPtr(t2 *Tuple4)
- func (t Tuple4) Get(row int) float64
- func (t Tuple4) IsPoint() bool
- func (t Tuple4) IsVector() bool
- func (t Tuple4) Multiply(scalar float64) Tuple4
- func (t Tuple4) ResetPoint() Tuple4
- func (t Tuple4) ResetVector() Tuple4
- type World
Constants ¶
const Epsilon = 0.001
const TriThreshold = 0.00000000001
Variables ¶
var IdentityMatrix = identity.Matrix
Functions ¶
func Cofactor3x3 ¶
Cofactor3x3 may change the sign of the computed minor of the passed matrix
func Cofactor4x4 ¶
Cofactor4x4 may change the sign of the computed minor of the passed matrix
func CrossProduct ¶
func CrossProduct(f1, f2, out *Tuple4)
func Determinant2x2 ¶
Determinant2x2 returns A-D minus B-C for a [A,B] [C,D] Matrix.
func Determinant3x3 ¶
Determinant3x3 takes the first row of the passed matrix, summing the colvalue * Cofactor of the same col
func Dot ¶
Dot product is the sum of the products of the corresponding entries of the two sequences of numbers a product is simply put the result of a multiplication. The dot product of two tuples is simply t1.x * t2.x + t1.y * t2.y + t1.z * t2.z + t1[3] * t2[3]
func HadamardPtr ¶
func IntersectRayWithBox ¶
func IntersectRayWithBox(ray Ray, BoundingBox *BoundingBox) bool
func IntersectionAllowed ¶
func IntersectionEqual ¶
func IntersectionEqual(i1, i2 Intersection) bool
func IsInvertible ¶
func Magnitude ¶
Magnitude measures the length of the passed vector. It's basically pythagoras sqrt(x2 + y2 + z2 + w2)
func MagnitudePtr ¶
func MakeSubGroup ¶
func Minor3x3 ¶
Minor3x3 computes the submatrix at row/col and returns the determinant of the computed matrix.
func Minor4x4 ¶
Minor4x4 computes the submatrix at row/col and returns the determinant of the computed matrix.
func MultiplyByScalarPtr ¶
func MultiplyByTuplePtr ¶
func NormalToWorldPtr ¶
func NormalizePtr ¶
func NormalizePtr2 ¶
func OrientAreaLight ¶
func PartitionChildren ¶
func PositionPtr ¶
func PrepareComputationForIntersectionPtr ¶
func PrepareComputationForIntersectionPtr(i Intersection, r Ray, comps *Computation, xs ...Intersection)
func ReflectPtr ¶
in - normal * 2 * dot(in, normal)
func Schlick ¶
func Schlick(comps Computation) float64
func SplitBounds ¶
func SplitBounds(b1 *BoundingBox) (*BoundingBox, *BoundingBox)
SplitBounds splits the passed bounding box perpendicular of its longest axis. (Impl from bonus chapter)
func TransformRayPtr ¶
func TupleEquals ¶
func TupleXYZEq ¶
func WorldToObjectPtr ¶
Types ¶
type AreaLight ¶
type AreaLight struct { Corner Tuple4 UVec Tuple4 USteps int VVec Tuple4 VSteps int Intensity Tuple4 Samples float64 Position Tuple4 }
func NewAreaLight ¶
type BoundingBox ¶
func BoundsOf ¶
func BoundsOf(shape Shape) *BoundingBox
func NewBoundingBox ¶
func NewBoundingBox(pointA Tuple4, pointB Tuple4) *BoundingBox
func NewBoundingBoxF ¶
func NewBoundingBoxF(x1, y1, z1, x2, y2, z2 float64) *BoundingBox
func NewEmptyBoundingBox ¶
func NewEmptyBoundingBox() *BoundingBox
func ParentSpaceBounds ¶
func ParentSpaceBounds(shape Shape) *BoundingBox
func TransformBoundingBox ¶
func TransformBoundingBox(bbox *BoundingBox, m1 Mat4x4) *BoundingBox
func (*BoundingBox) Add ¶
func (b *BoundingBox) Add(p Tuple4)
func (*BoundingBox) ContainsBox ¶
func (b *BoundingBox) ContainsBox(b2 *BoundingBox) bool
func (*BoundingBox) ContainsPoint ¶
func (b *BoundingBox) ContainsPoint(p Tuple4) bool
func (*BoundingBox) MergeWith ¶
func (b *BoundingBox) MergeWith(b2 *BoundingBox)
type CSG ¶
type CSG struct { Id int64 Transform Mat4x4 Inverse Mat4x4 InverseTranspose Mat4x4 Left Shape Right Shape Operation string Material Material Label string BoundingBox *BoundingBox CastShadow bool // contains filtered or unexported fields }
func (*CSG) CastsShadow ¶
func (*CSG) GetInverse ¶
func (*CSG) GetInverseTranspose ¶
func (*CSG) GetLocalRay ¶
func (*CSG) GetMaterial ¶
func (*CSG) GetTransform ¶
func (*CSG) IntersectLocal ¶
func (c *CSG) IntersectLocal(ray Ray) []Intersection
func (*CSG) NormalAtLocal ¶
func (c *CSG) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
func (*CSG) SetMaterial ¶
func (*CSG) SetTransform ¶
type Camera ¶
type Canvas ¶
func (*Canvas) WritePixel ¶
func (*Canvas) WritePixelMutex ¶
func (*Canvas) WritePixelToIndex ¶
type CheckerPattern ¶
func NewCheckerPattern ¶
func NewCheckerPattern(colorA Tuple4, colorB Tuple4) *CheckerPattern
func (*CheckerPattern) GetInverse ¶
func (c *CheckerPattern) GetInverse() Mat4x4
func (*CheckerPattern) GetTransform ¶
func (c *CheckerPattern) GetTransform() Mat4x4
func (*CheckerPattern) PatternAt ¶
func (c *CheckerPattern) PatternAt(point Tuple4) Tuple4
func (*CheckerPattern) SetPatternTransform ¶
func (c *CheckerPattern) SetPatternTransform(transform Mat4x4)
type Computation ¶
type Computation struct { T float64 Object Shape Point Tuple4 EyeVec Tuple4 NormalVec Tuple4 Inside bool OverPoint Tuple4 UnderPoint Tuple4 ReflectVec Tuple4 N1 float64 N2 float64 // contains filtered or unexported fields }
func NewComputation ¶
func NewComputation() Computation
func PrepareComputationForIntersection ¶
func PrepareComputationForIntersection(i Intersection, r Ray, xs ...Intersection) Computation
TODO refactor so tests uses the other one instead.
type Cone ¶
type Cone struct { Id int64 Transform Mat4x4 Inverse Mat4x4 InverseTranspose Mat4x4 Material Material Label string MinY float64 MaxY float64 Closed bool CastShadow bool // contains filtered or unexported fields }
func NewConeMMC ¶
func (*Cone) CastsShadow ¶
func (*Cone) GetInverse ¶
func (*Cone) GetInverseTranspose ¶
func (*Cone) GetLocalRay ¶
func (*Cone) GetMaterial ¶
func (*Cone) GetTransform ¶
func (*Cone) IntersectLocal ¶
func (c *Cone) IntersectLocal(ray Ray) []Intersection
func (*Cone) NormalAtLocal ¶
func (c *Cone) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
func (*Cone) SetMaterial ¶
func (*Cone) SetTransform ¶
type Cube ¶
type Cube struct { Id int64 Transform Mat4x4 Inverse Mat4x4 InverseTranspose Mat4x4 Material Material Label string CastShadow bool // contains filtered or unexported fields }
func (*Cube) CastsShadow ¶
func (*Cube) GetInverse ¶
func (*Cube) GetInverseTranspose ¶
func (*Cube) GetLocalRay ¶
func (*Cube) GetMaterial ¶
func (*Cube) GetTransform ¶
func (*Cube) IntersectLocal ¶
func (c *Cube) IntersectLocal(ray Ray) []Intersection
func (*Cube) NormalAtLocal ¶
func (c *Cube) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
NormalAtLocal uses the fact that given a unit cube, the point of the surface axis X,Y or Z is always either 1.0 for positive XYZ and -1.0 for negative XYZ. I.e - if the point is 0.4, 1, -0.5, we know that the point is on the top Y surface and we can return a 0,1,0 normal
func (*Cube) SetMaterial ¶
func (*Cube) SetTransform ¶
type Cylinder ¶
type Cylinder struct { Id int64 Transform Mat4x4 Inverse Mat4x4 InverseTranspose Mat4x4 Material Material Label string MinY float64 MaxY float64 CastShadow bool // contains filtered or unexported fields }
func NewCylinder ¶
func NewCylinder() *Cylinder
func NewCylinderMM ¶
func NewCylinderMMC ¶
func (*Cylinder) CastsShadow ¶
func (*Cylinder) GetInverse ¶
func (*Cylinder) GetInverseTranspose ¶
func (*Cylinder) GetLocalRay ¶
func (*Cylinder) GetMaterial ¶
func (*Cylinder) GetTransform ¶
func (*Cylinder) IntersectLocal ¶
func (c *Cylinder) IntersectLocal(ray Ray) []Intersection
func (*Cylinder) NormalAtLocal ¶
func (c *Cylinder) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
func (*Cylinder) SetMaterial ¶
func (*Cylinder) SetTransform ¶
type GradientPattern ¶
func NewGradientPattern ¶
func NewGradientPattern(from, to Tuple4) *GradientPattern
func (*GradientPattern) GetInverse ¶
func (g *GradientPattern) GetInverse() Mat4x4
func (*GradientPattern) GetTransform ¶
func (g *GradientPattern) GetTransform() Mat4x4
func (*GradientPattern) PatternAt ¶
func (g *GradientPattern) PatternAt(point Tuple4) Tuple4
func (*GradientPattern) SetPatternTransform ¶
func (g *GradientPattern) SetPatternTransform(transform Mat4x4)
type Group ¶
type Group struct { Id int64 Transform Mat4x4 Inverse Mat4x4 InverseTranspose Mat4x4 Material Material Mtl Mtl Label string Children []Shape InnerRays []Ray XsCache Intersections BoundingBox *BoundingBox CastShadow bool // contains filtered or unexported fields }
func (*Group) AddChildren ¶
func (*Group) BoundsToCube ¶
func (*Group) CastsShadow ¶
func (*Group) GetInverse ¶
func (*Group) GetInverseTranspose ¶
func (*Group) GetLocalRay ¶
func (*Group) GetMaterial ¶
func (*Group) GetTransform ¶
func (*Group) IntersectLocal ¶
func (g *Group) IntersectLocal(ray Ray) []Intersection
func (*Group) NormalAtLocal ¶
func (g *Group) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
func (*Group) SetMaterial ¶
func (*Group) SetTransform ¶
type Intersection ¶
func FilterIntersections ¶
func FilterIntersections(csg *CSG, xs []Intersection) []Intersection
func Hit ¶
func Hit(intersections []Intersection) (Intersection, bool)
Hit finds the first intersection with a positive T (the passed intersections are assumed to have been sorted already)
func IntersectRayWithShape ¶
func IntersectRayWithShape(s Shape, r2 Ray) []Intersection
TODO only used by unit tests, fix so tests use IntersectRayWithShapePtr and remove
func IntersectRayWithShapePtr ¶
func IntersectRayWithShapePtr(s Shape, r2 Ray, in *Ray) []Intersection
func IntersectWithWorldPtr ¶
func IntersectWithWorldPtr(w World, r Ray, xs Intersections, inRay *Ray) []Intersection
func IntersectWithWorldPtrForShadow ¶
func IntersectWithWorldPtrForShadow(w World, r Ray, xs Intersections, inRay *Ray) []Intersection
func NewIntersection ¶
func NewIntersection(t float64, s Shape) Intersection
func NewIntersectionUV ¶
func NewIntersectionUV(t float64, s Shape, u, v float64) Intersection
type Intersections ¶
type Intersections []Intersection
func (Intersections) Len ¶
func (xs Intersections) Len() int
func (Intersections) Less ¶
func (xs Intersections) Less(i, j int) bool
func (Intersections) Swap ¶
func (xs Intersections) Swap(i, j int)
type LightData ¶
type LightData struct { Ambient Tuple4 Diffuse Tuple4 Specular Tuple4 EffectiveColor Tuple4 LightVec Tuple4 ReflectVec Tuple4 }
LightData is used for pre-allocated memory for lighting computations.
func NewLightData ¶
func NewLightData() LightData
type LightSource ¶
type Mat2x2 ¶
type Mat2x2 [4]float64
func Submatrix3x3 ¶
Submatrix3x3 extracts the 2x2 submatrix after deleting row and col from the passed 3x3
type Mat3x3 ¶
type Mat3x3 [9]float64
func Submatrix4x4 ¶
Submatrix4x4 extracts the 3x3 submatrix after deleting row and col from the passed 4x4
type Mat4x4 ¶
type Mat4x4 [16]float64
func NewIdentityMatrix ¶
func NewIdentityMatrix() Mat4x4
func Translate ¶
Translate creates a translation matrix from the identity matrix, setting wx, wy, wz to the passed xyz coords.
func ViewTransform ¶
type Material ¶
type Material struct { Color Tuple4 Ambient float64 Diffuse float64 Specular float64 Shininess float64 Pattern Pattern Reflectivity float64 Transparency float64 RefractiveIndex float64 Name string }
func NewDefaultMaterial ¶
func NewDefaultMaterial() Material
func NewGlassMaterial ¶
func NewMaterial ¶
func (*Material) HasPattern ¶
type Plane ¶
type Plane struct { Id int64 Transform Mat4x4 Inverse Mat4x4 InverseTranspose Mat4x4 Material Material Label string CastShadow bool // contains filtered or unexported fields }
func (*Plane) CastsShadow ¶
func (*Plane) GetInverse ¶
func (*Plane) GetInverseTranspose ¶
func (*Plane) GetLocalRay ¶
func (*Plane) GetMaterial ¶
func (*Plane) GetTransform ¶
func (*Plane) IntersectLocal ¶
func (p *Plane) IntersectLocal(ray Ray) []Intersection
func (*Plane) NormalAtLocal ¶
func (p *Plane) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
func (*Plane) SetMaterial ¶
SetMaterial passes a pointer to the Plane on which to set the material
func (*Plane) SetTransform ¶
SetTransform passes a pointer to the Plane on which to apply the translation matrix
type Ray ¶
func TransformRay ¶
type RingPattern ¶
func NewRingPattern ¶
func NewRingPattern(a Tuple4, b Tuple4) *RingPattern
func (*RingPattern) GetInverse ¶
func (r *RingPattern) GetInverse() Mat4x4
func (*RingPattern) GetTransform ¶
func (r *RingPattern) GetTransform() Mat4x4
func (*RingPattern) PatternAt ¶
func (r *RingPattern) PatternAt(point Tuple4) Tuple4
func (*RingPattern) SetPatternTransform ¶
func (r *RingPattern) SetPatternTransform(transform Mat4x4)
type Shape ¶
type Shape interface { ID() int64 GetTransform() Mat4x4 GetInverse() Mat4x4 GetInverseTranspose() Mat4x4 SetTransform(transform Mat4x4) GetMaterial() Material SetMaterial(material Material) IntersectLocal(ray Ray) []Intersection NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4 GetLocalRay() Ray GetParent() Shape SetParent(shape Shape) CastsShadow() bool Name() string }
type SmoothTriangle ¶
type SmoothTriangle struct { P1 Tuple4 P2 Tuple4 P3 Tuple4 E1 Tuple4 E2 Tuple4 N Tuple4 N1 Tuple4 N2 Tuple4 N3 Tuple4 Material Material CastShadow bool Label string D00 float64 D01 float64 D11 float64 Denom float64 // contains filtered or unexported fields }
func DefaultSmoothTriangle ¶
func DefaultSmoothTriangle() *SmoothTriangle
func NewSmoothTriangle ¶
func (*SmoothTriangle) Barycentric ¶
func (s *SmoothTriangle) Barycentric(p Tuple4, u *float64, v *float64, w *float64)
Barycentric computes barycentric coordinates (u, v, w) for point p with respect to triangle defined by pre-computed vectors E1 and E2, which was derived into points d00, d01, d11 and denominator in constructor func.
func (*SmoothTriangle) CastsShadow ¶
func (s *SmoothTriangle) CastsShadow() bool
func (*SmoothTriangle) GetInverse ¶
func (s *SmoothTriangle) GetInverse() Mat4x4
func (*SmoothTriangle) GetInverseTranspose ¶
func (s *SmoothTriangle) GetInverseTranspose() Mat4x4
func (*SmoothTriangle) GetLocalRay ¶
func (s *SmoothTriangle) GetLocalRay() Ray
func (*SmoothTriangle) GetMaterial ¶
func (s *SmoothTriangle) GetMaterial() Material
func (*SmoothTriangle) GetParent ¶
func (s *SmoothTriangle) GetParent() Shape
func (*SmoothTriangle) GetTransform ¶
func (s *SmoothTriangle) GetTransform() Mat4x4
func (*SmoothTriangle) ID ¶
func (s *SmoothTriangle) ID() int64
func (*SmoothTriangle) IntersectLocal ¶
func (s *SmoothTriangle) IntersectLocal(ray Ray) []Intersection
func (*SmoothTriangle) Name ¶
func (s *SmoothTriangle) Name() string
func (*SmoothTriangle) NormalAtLocal ¶
func (s *SmoothTriangle) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
func (*SmoothTriangle) SetMaterial ¶
func (s *SmoothTriangle) SetMaterial(material Material)
func (*SmoothTriangle) SetParent ¶
func (s *SmoothTriangle) SetParent(shape Shape)
func (*SmoothTriangle) SetTransform ¶
func (s *SmoothTriangle) SetTransform(transform Mat4x4)
type Sphere ¶
type Sphere struct { Id int64 Transform Mat4x4 Inverse Mat4x4 InverseTranspose Mat4x4 Material Material Label string CastShadow bool // contains filtered or unexported fields }
func NewGlassSphere ¶
func NewGlassSphere() *Sphere
func (*Sphere) CastsShadow ¶
func (*Sphere) GetInverse ¶
func (*Sphere) GetInverseTranspose ¶
func (*Sphere) GetLocalRay ¶
func (*Sphere) GetMaterial ¶
func (*Sphere) GetTransform ¶
func (*Sphere) IntersectLocal ¶
func (s *Sphere) IntersectLocal(r Ray) []Intersection
IntersectLocal implements Sphere-ray intersection
func (*Sphere) NormalAtLocal ¶
func (s *Sphere) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
func (*Sphere) SetMaterial ¶
SetMaterial passes a pointer to the Sphere on which to set the material
func (*Sphere) SetTransform ¶
SetTransform passes a pointer to the Sphere on which to apply the translation matrix
type StripePattern ¶
func NewStripePattern ¶
func NewStripePattern(colorA Tuple4, colorB Tuple4) *StripePattern
func (*StripePattern) GetInverse ¶
func (p *StripePattern) GetInverse() Mat4x4
func (*StripePattern) GetTransform ¶
func (p *StripePattern) GetTransform() Mat4x4
func (*StripePattern) PatternAt ¶
func (p *StripePattern) PatternAt(point Tuple4) Tuple4
func (*StripePattern) SetPatternTransform ¶
func (p *StripePattern) SetPatternTransform(transform Mat4x4)
type TestPattern ¶
func NewTestPattern ¶
func NewTestPattern() *TestPattern
func (*TestPattern) GetInverse ¶
func (t *TestPattern) GetInverse() Mat4x4
func (*TestPattern) GetTransform ¶
func (t *TestPattern) GetTransform() Mat4x4
func (*TestPattern) PatternAt ¶
func (t *TestPattern) PatternAt(point Tuple4) Tuple4
func (*TestPattern) SetPatternTransform ¶
func (t *TestPattern) SetPatternTransform(transform Mat4x4)
type Triangle ¶
type Triangle struct { P1 Tuple4 P2 Tuple4 P3 Tuple4 E1 Tuple4 E2 Tuple4 N Tuple4 Material Material CastShadow bool Label string }
func (*Triangle) CastsShadow ¶
func (*Triangle) GetInverse ¶
func (*Triangle) GetInverseTranspose ¶
func (*Triangle) GetLocalRay ¶
func (*Triangle) GetMaterial ¶
func (*Triangle) GetTransform ¶
func (*Triangle) IntersectLocal ¶
func (t *Triangle) IntersectLocal(ray Ray) []Intersection
func (*Triangle) NormalAtLocal ¶
func (t *Triangle) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
func (*Triangle) SetMaterial ¶
func (*Triangle) SetTransform ¶
type Tuple4 ¶
type Tuple4 [4]float64
func DivideByScalar ¶
func LightingPointLight ¶
func LightingPointLight(material Material, object Shape, light Light, position, eyeVec, normalVec Tuple4, inShadow bool, lightData LightData) Tuple4
LightingPointLight computes the color of a given pixel given phong shading a point light
func MultiplyByScalar ¶
func MultiplyByTuple ¶
func NewTupleOf ¶
func NormalToWorld ¶
func Normalize ¶
Normalize measures the length (magnitude) of the passed Vector. Each component in t1 is then divided my the magnitude in order to Normalize it to unit (1) size.
func PointOnLight ¶
func PointOnLightNoRandom ¶
func Position ¶
Position multiplies direction of ray with the passed distance and adds the result onto the origin. Used for finding the position along a ray.
func WorldToObject ¶
func (*Tuple4) AddNoRetPtr ¶
func (Tuple4) ResetPoint ¶
func (Tuple4) ResetVector ¶
Source Files ¶
- CrossProduct_amd64.go
- MultiplyMatrixByVec64_amd64.go
- boundingbox.go
- bvh.go
- canvas.go
- computations.go
- cone.go
- constants.go
- csg.go
- cube.go
- cylinder.go
- group.go
- intersection.go
- light.go
- mat2x2.go
- mat3x3.go
- mat4x4.go
- material.go
- matrix.go
- mtl.go
- normal.go
- pattern.go
- plane.go
- rays.go
- rotation.go
- scaling.go
- shape.go
- shearing.go
- smoothtriangle.go
- sphere.go
- translation.go
- triangle.go
- tuple.go
- view.go
- world.go