Documentation
¶
Overview ¶
Package gotrace is a simple raytracer inspired by Peter Shirley's books.
package main import "github.com/teobouvard/gotrace" func main() { scene := gotrace.BookScene() scene.Render(400, -1, 500, 50) }
Index ¶
- Variables
- type Actor
- type Bbox
- type Box
- type Camera
- type CheckerTexture
- type Collection
- type ConstantTexture
- type Dielectric
- type DiffuseLight
- type FlipFace
- type Fog
- type Geometry
- type HitRecord
- type Image
- type Index
- type Isotropic
- type Lambertian
- type Marble
- type Material
- type Metal
- type MovingSphere
- type Noise
- type Ray
- type RectXY
- type RectXZ
- type RectYZ
- type RotateY
- type Scene
- type Sphere
- type Texture
- type Translate
- type Vec3
- func (u Vec3) Add(v Vec3) Vec3
- func (u Vec3) AsArray() [3]float64
- func (u Vec3) Cross(v Vec3) Vec3
- func (u Vec3) Div(t float64) Vec3
- func (u Vec3) Dot(v Vec3) float64
- func (u Vec3) GetColor(samples int) color.RGBA
- func (u Vec3) Mul(v Vec3) Vec3
- func (u Vec3) Neg() Vec3
- func (u Vec3) Norm() float64
- func (u Vec3) Reflect(n Vec3) Vec3
- func (u Vec3) Refract(n Vec3, nRatio float64) (bool, Vec3)
- func (u Vec3) Scale(t float64) Vec3
- func (u Vec3) SquareNorm() float64
- func (u Vec3) Sub(v Vec3) Vec3
- func (u Vec3) Unit() Vec3
Constants ¶
This section is empty.
Variables ¶
var ( BLACK = Vec3{0, 0, 0} WHITE = Vec3{1, 1, 1} RED = Vec3{1, 0, 0} GREEN = Vec3{0, 1, 0} BLUE = Vec3{0, 0, 1} )
Colors
Functions ¶
This section is empty.
Types ¶
type Actor ¶
type Actor struct {
// contains filtered or unexported fields
}
Actor is an object on the scene having a shape and a material
type Bbox ¶
Bbox is a bounding box of a geometry
type Box ¶ added in v0.2.0
type Box struct {
// contains filtered or unexported fields
}
Box is a cube
type Camera ¶
type Camera struct { AspectRatio float64 // contains filtered or unexported fields }
A Camera is the eye through which the the scene is observed
type CheckerTexture ¶
type CheckerTexture struct {
// contains filtered or unexported fields
}
CheckerTexture is a checkboard-like texture
type Collection ¶
type Collection []Actor
A Collection is a group of Actors
func (*Collection) Add ¶
func (c *Collection) Add(actors ...Actor)
Add appends new Actors to the collection
func (Collection) Bound ¶
func (c Collection) Bound(tMin float64, tMax float64) (bool, *Bbox)
Bound computes the bounding box of a Collection
func (Collection) Comparator ¶
func (c Collection) Comparator(startTime, endTime float64, axis int) func(i, j int) bool
Comparator returns a comparison function of objects in the collection along the given axis. Used for Index sorting.
type ConstantTexture ¶
type ConstantTexture struct {
// contains filtered or unexported fields
}
ConstantTexture is a uniform texture with a single color
type Dielectric ¶
type Dielectric struct {
// contains filtered or unexported fields
}
Dielectric is a glass-like material
type DiffuseLight ¶ added in v0.2.0
type DiffuseLight struct {
// contains filtered or unexported fields
}
DiffuseLight is a light-emitting material
type FlipFace ¶ added in v0.2.0
type FlipFace struct {
// contains filtered or unexported fields
}
FlipFace is a geometry wrapper for flipping the front face of the wrapped geometry
type Fog ¶ added in v0.2.0
type Fog struct {
// contains filtered or unexported fields
}
Fog is a volumetric medium
type Geometry ¶
type Geometry interface { Hit(ray Ray, tMin float64, tMax float64) (bool, *HitRecord) Bound(startTime float64, endTime float64) (bool, *Bbox) }
Geometry interface
Hit ¶
@in
ray : a light ray tMin : closer objects are not considered tMax : further objects are not considered
@out
bool : if the ray hit the geometry HitRecord : information about the hit, or nil
Bound ¶
@in
startTime : the starting time for bounding endTime : the ending time for bounding
@out
bool : if the geometry can be bounded (false for infinite planes) Bbox : bounding box (aabb) of the geometry, if applicable
func NewRotateY ¶ added in v0.2.0
NewRotateY constructs a rotated object around the Y axis
type Image ¶ added in v0.2.0
type Image struct {
// contains filtered or unexported fields
}
Image is a texture mapped to an image file
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is a binary tree forming a bounding volume hierarchy of objects satisfying the geometry interface
func NewIndex ¶
func NewIndex(world Collection, start, end int, startTime, endTime float64) *Index
NewIndex builds a bounding volume hierarchy
type Isotropic ¶ added in v0.2.0
type Isotropic struct {
// contains filtered or unexported fields
}
Isotropic is a material scattering in random direction
type Lambertian ¶
type Lambertian struct {
// contains filtered or unexported fields
}
Lambertian is a diffuse material
type Marble ¶ added in v0.2.0
type Marble struct {
// contains filtered or unexported fields
}
Marble is a marble-like texture
type Material ¶
type Material interface { Scatter(ray Ray, hit HitRecord) (bool, Vec3, Ray) Emit(u, v float64, pos Vec3) Vec3 }
Material define the way actors interact with a ray
Scatter ¶
@in
ray : an incident ray hit : the record for the hit of the ray with a geometry
@out
bool : true if the material scatters the ray Vec3 : the attenuation of the scattered ray Ray : the scattered ray
type Metal ¶
type Metal struct {
// contains filtered or unexported fields
}
Metal is a reflective material
type MovingSphere ¶
type MovingSphere struct { CenterStart Vec3 CenterStop Vec3 Radius float64 // contains filtered or unexported fields }
MovingSphere geometry
type Noise ¶ added in v0.2.0
type Noise struct {
// contains filtered or unexported fields
}
Noise is an opensimplex noise
type RectXY ¶ added in v0.2.0
type RectXY struct {
// contains filtered or unexported fields
}
RectXY is a rectangular shape in the XY plane (z=k), bounded by x0, x1, y0 and y1
type RectXZ ¶ added in v0.2.0
type RectXZ struct {
// contains filtered or unexported fields
}
RectXZ is a rectangular shape in the XZ plane (y=k), bounded by x0, x1, z0 and z1
type RectYZ ¶ added in v0.2.0
type RectYZ struct {
// contains filtered or unexported fields
}
RectYZ is a rectangular shape in the YZ plane (x=k), bounded by y0, y1, z0 and z1
type RotateY ¶ added in v0.2.0
type RotateY struct {
// contains filtered or unexported fields
}
RotateY is a wrapper around a geometry, which is rotated around the Y axis
type Scene ¶
type Scene struct {
// contains filtered or unexported fields
}
Scene is the whole scene to be rendered
func CornellBox ¶ added in v0.2.0
func CornellBox() *Scene
CornellBox is a the classic cornell box scene
func EarthScene ¶ added in v0.2.0
func EarthScene() *Scene
EarthScene is a scene demonstrating image textures
func FinalScene ¶ added in v0.2.0
func FinalScene() *Scene
FinalScene is the last scene of Ray Tracing: The Next Week
func FoggyCornellBox ¶ added in v0.2.0
func FoggyCornellBox() *Scene
FoggyCornellBox is a the cornell box scene with fog objects
func LightMarbleScene ¶ added in v0.2.0
func LightMarbleScene() *Scene
LightMarbleScene is a scene with a black and white marble with lights
func MarbleScene ¶ added in v0.2.0
func MarbleScene() *Scene
MarbleScene is a scene with a black and white marble
func MovingSpheres ¶
func MovingSpheres() *Scene
MovingSpheres creates the scene on the cover of the first book, with bouncing balls
type Texture ¶
Texture interface
Value ¶
@in
u, v : coordinates of the point
@out
Vec3 : color at the given coordinates
type Translate ¶ added in v0.2.0
type Translate struct {
// contains filtered or unexported fields
}
Translate is a wrapper around a geometry, which is offset by a translation vector
type Vec3 ¶
type Vec3 struct {
X, Y, Z float64
}
Vec3 defines a 3-dimensional vector
func MaxCoord ¶ added in v0.2.0
MaxCoord returns a new vector corresponding to the element-wise maximum of the two vectors
func MinCoord ¶ added in v0.2.0
MinCoord returns a new vector corresponding to the element-wise minimum of the two vectors
func RandSphere ¶
RandSphere returns vector drawn from a lambertian distribution inside the unit sphere
func RandVecInterval ¶
RandVecInterval returns a random vector with coordinates in [low, high)
func (Vec3) SquareNorm ¶
SquareNorm returns the square of the euclidean norm of u