tracer

package
v0.0.0-...-6c61b44 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2017 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clamp

func Clamp(value, min, max float32) float32

Types

type Accumulator

type Accumulator struct {
	Data   []Color
	Bounds image.Rectangle
	// contains filtered or unexported fields
}

func NewAccumulator

func NewAccumulator(bounds image.Rectangle) *Accumulator

func (*Accumulator) DrawContents

func (a *Accumulator) DrawContents(screen wde.Image)

func (*Accumulator) NextFrame

func (a *Accumulator) NextFrame()

func (*Accumulator) Reset

func (a *Accumulator) Reset()

func (*Accumulator) SetPixel

func (a *Accumulator) SetPixel(x, y int, color Color) Color

type Camera

type Camera struct {
	Eye, Direction, Up Vector
	// contains filtered or unexported fields
}

func NewCamera

func NewCamera(eye, direction, up Vector, dImagePlane, imagePlaneWidth, imagePlaneHeight float64, moveSpeed, lookSpeed float64) *Camera

func (*Camera) GenerateRays

func (c *Camera) GenerateRays(pixelDimensions, area image.Rectangle, aaFactor float64) []*RayInfo

func (*Camera) Move

func (c *Camera) Move(direction Vector)

x = strafe, y = forward/backward, z = up/down

func (*Camera) Rotate

func (c *Camera) Rotate(deltaPhi, deltaTheta float64)

type CameraMoveDirection

type CameraMoveDirection int

type Color

type Color struct {
	R, G, B float32
}

func (Color) Add

func (c Color) Add(c2 Color) Color

func (Color) Divide

func (c Color) Divide(scalar float32) Color

func (Color) Multiply

func (c Color) Multiply(scalar float32) Color

func (Color) MultiplyC

func (c Color) MultiplyC(c2 Color) Color

type Intersectable

type Intersectable interface {
	Intersect(ray Ray) (intersected bool, t float64, n Vector)
	Material() Material
}

type Material

type Material struct {
	Color       Color
	Type        MaterialType
	Specularity float32
}

type MaterialType

type MaterialType int
const (
	Light   MaterialType = -1
	Diffuse              = 0
)

type Plane

type Plane struct {
	Primitive
	Normal Vector
	D      float64
}

func NewPlane

func NewPlane(normal Vector, d float64, material Material) *Plane

func (*Plane) Intersect

func (p *Plane) Intersect(ray Ray) (intersected bool, t float64, n Vector)

type Primitive

type Primitive struct {
	Intersectable
	// contains filtered or unexported fields
}

func (Primitive) Material

func (p Primitive) Material() Material

type Quad

type Quad struct {
	Primitive
	P1, P2, P3, P4 Vector
	Normal         Vector
}

func NewQuad

func NewQuad(p1, p2, p3, p4 Vector, material Material) *Quad

func (*Quad) Intersect

func (q *Quad) Intersect(ray Ray) (intersected bool, t float64, n Vector)

todo don't use triangles

type Ray

type Ray struct {
	Origin    Vector
	Direction Vector
}

func (*Ray) Point

func (r *Ray) Point(t float64) Vector

type RayInfo

type RayInfo struct {
	Ray  Ray //todo multiple rays per pixel
	X, Y int //Pixel location
}

type Scene

type Scene struct {
	Objects    []Intersectable
	Background Color
}

func DefaultScene

func DefaultScene() *Scene

func NewScene

func NewScene() *Scene

func (*Scene) AddObject

func (s *Scene) AddObject(t Intersectable)

type Sphere

type Sphere struct {
	Primitive
	Center Vector
	Radius float64
	// contains filtered or unexported fields
}

func NewSphere

func NewSphere(center Vector, radius float64, material Material) *Sphere

func (*Sphere) Intersect

func (s *Sphere) Intersect(ray Ray) (intersected bool, t float64, n Vector)

type Tracer

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

func NewTracer

func NewTracer(camera *Camera, aaFactor float64, maxBounces int) *Tracer

func (*Tracer) TraceRay

func (t *Tracer) TraceRay(ray Ray, scene *Scene, bouncesLeft int) Color

func (*Tracer) TraceRegion

func (t *Tracer) TraceRegion(maxDimensions, region image.Rectangle, acc *Accumulator, scene *Scene, iterations int)

type Triangle

type Triangle struct {
	Primitive
	P1, P2, P3 Vector
	Normal     Vector
}

func NewTriangle

func NewTriangle(p1, p2, p3 Vector, material Material) *Triangle

func (*Triangle) Intersect

func (tr *Triangle) Intersect(ray Ray) (intersected bool, t float64, n Vector)

Intersect Intersects a ray with a triangle using the Möller–Trumbore algorithm

type Vector

type Vector struct {
	X, Y, Z float64
}

func NewVector

func NewVector(x, y, z float64) Vector

func (Vector) Add

func (v1 Vector) Add(v2 Vector) Vector

func (Vector) Cross

func (v1 Vector) Cross(v2 Vector) Vector

func (Vector) Dot

func (v1 Vector) Dot(v2 Vector) float64

func (Vector) Length

func (v Vector) Length() float64

func (Vector) LengthSquared

func (v Vector) LengthSquared() float64

func (Vector) Multiply

func (v Vector) Multiply(scalar float64) Vector

func (Vector) Normalize

func (v Vector) Normalize() Vector

func (Vector) Subtract

func (v1 Vector) Subtract(v2 Vector) Vector

Jump to

Keyboard shortcuts

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