gotracer

package module
v0.0.0-...-3626a0a Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2015 License: MIT Imports: 11 Imported by: 0

README

GoTracer

Documentation

Index

Constants

View Source
const (
	PrimaryRay = iota
	CollisionRay
	ReflectionRay
	RefractionRay
	ShadowRay
	NumRayTypes
)
View Source
const (
	AirIndex = 1.0003
)
View Source
const (
	DirectionalLightDist = 1e10
)
View Source
const (
	Rayε = 0.00001
)

Variables

View Source
var (
	DirectionalLightDefaultColor       = Color64{1, 1, 1}
	DirectionalLightDefaultOrientation = mgl64.Vec3{0, -1, 0}
)
View Source
var (
	ImageHeightDefault       = 1
	ImageWidthDefault        = 1
	AdaptiveThresholdDefault = 0.0
	AAMaxDivisionsDefault    = 0
	AAThresholdDefault       = 0.0
	MaxRecursiveDepthDefault = 1
	AmbientLightDefault      = Color64{0, 0, 0}
	BackgroundDefault        = UniformBackground{Color64{0, 0, 0}}
)
View Source
var Clamp01 = clamp(0.0, 1.0)
View Source
var SettingParsers map[string]Parser = make(map[string]Parser)

Functions

func ColorsDifferent

func ColorsDifferent(color1, color2 Color64, thresh float64) bool

func ParseSetting

func ParseSetting(scene *Scene, setting string, value interface{})

func ParseVector

func ParseVector(floatArray interface{}) mgl64.Vec3

ParseVector takes an interface{} which it assumes is actually a [3]float64 and converts it to a mgl64.Vec3.

func ReadSettingsFile

func ReadSettingsFile(fileName string) interface{}

func TransformVec3

func TransformVec3(m mgl64.Mat4, v mgl64.Vec3) mgl64.Vec3

TransformVec3 is used to transform a vector by a matrix.

Types

type BRDF

type BRDF func(scene *Scene, ray *Ray, isect *Intersection) (color Color64)

A bidirectional reflectance distribution function. Returns the ratio of reflected radiance exiting along wr to the irradiance incident on the surface from direction wi. wi - normalized negative incomming light direction (toward light) wr - normalized outgoing direction (toward camera) type BRDF func(wi, wr mgl64.Vec3, isect Intersection) mgl64.Vec3

type Background

type Background interface {
	GetColor(ray *Ray) Color64
}

type Camera

type Camera struct {
}

type Color64

type Color64 [3]float64

func BlinnPhongBRDF

func BlinnPhongBRDF(scene *Scene, ray *Ray, isect *Intersection) (color Color64)
func BlinnPhongBRDF(wi, wr mgl64.Vec3, isect Intersection) mgl64.Vec3 {
	// diffuse := LambertianBRDF(wi, wr, isect)
	// specular := ...
	return mgl64.Vec3{0, 0, 0}
}

func LambertianBRDF

func LambertianBRDF(scene *Scene, ray *Ray, isect *Intersection) (color Color64)
func LambertianBRDF(wi, wr mgl64.Vec3, isect Intersection) mgl64.Vec3 {
	kd := isect.Object.Material.Diffuse.ColorAt(isect.UVCoords)
	return mgl64.Vec3(kd).Mul(wi.Dot(isect.Normal))
}

func ParseColor64

func ParseColor64(floatArray interface{}) Color64

ParseColor64 takes an interface{} which it assumes is actually a [3]float64 and converts it to a Color64.

func ShadowAttenuation

func ShadowAttenuation(scene *Scene, dir mgl64.Vec3, point mgl64.Vec3) Color64

ShadowAttenuation takes the unnormalized direction to the light so we know when we've "hit" it.

func (Color64) Add

func (c Color64) Add(other Color64) Color64

func (Color64) B

func (c Color64) B() float64

func (Color64) Clamp

func (c Color64) Clamp() Color64

func (Color64) G

func (c Color64) G() float64

func (Color64) Len2

func (c Color64) Len2() float64

func (Color64) Mul

func (c Color64) Mul(val float64) Color64

func (Color64) NRGBA

func (c Color64) NRGBA() color.NRGBA

func (Color64) Product

func (c Color64) Product(other Color64) Color64

func (Color64) R

func (c Color64) R() float64

type DirectionalLight

type DirectionalLight struct {
	Color          Color64
	OrientationInv mgl64.Vec3
	Dir            mgl64.Vec3
}

DirectionalLight simulates a point light at an infinate distance. The opposite direction to it's orientation is used because more useful and saves work

func (*DirectionalLight) Attenuation

func (l *DirectionalLight) Attenuation(scene *Scene, point mgl64.Vec3) Color64

func (*DirectionalLight) Direction

func (l *DirectionalLight) Direction(from mgl64.Vec3) mgl64.Vec3

type Intersecter

type Intersecter interface {
	// Intersect takes a ray in local coordinates and populates the intersection and
	// returns true if the intersects the object. If the ray does not hit then isect
	// is undefined and hit is false.
	Intersect(*Ray, *Intersection) (hit bool)
	GetObject() *Object
}

Intersecter describes a thing that intersects with a Ray.

type Intersection

type Intersection struct {
	Normal   mgl64.Vec3
	T        float64
	Material *Material
	UVCoords mgl64.Vec2
}

type Light

type Light interface {
	Attenuation(scene *Scene, point mgl64.Vec3) Color64
	Direction(from mgl64.Vec3) mgl64.Vec3
}

type Material

type Material struct {
	Name         string
	Emissive     MaterialAttribute
	Ambient      MaterialAttribute
	Diffuse      MaterialAttribute
	Specular     MaterialAttribute
	Reflective   MaterialAttribute
	Smoothness   MaterialAttribute
	Transmissive MaterialAttribute
	Index        MaterialAttribute
	Normal       MaterialAttribute
	IsLiquid     MaterialAttribute
	BRDF         BRDF
}

type MaterialAttribute

type MaterialAttribute interface {
	// ColorAt takes normalized coordinates and return the color at those coordinates.
	ColorAt(mgl64.Vec2) Color64
}

MaterialAttribute is an interface for getting a color. Designed with texture mapping in mind.

type Object

type Object struct {
	Transform    mgl64.Mat4
	TransformInv mgl64.Mat4
	// T3it = Transform.Mat3().Inv().Transpose()
	T3it     mgl64.Mat3
	Material *Material
}

func NewObject

func NewObject(transform mgl64.Mat4, material *Material) *Object

type Parser

type Parser func(scene *Scene, value interface{})

type Ray

type Ray struct {
	Type   int
	Origin mgl64.Vec3
	Dir    mgl64.Vec3
}

func (Ray) At

func (r Ray) At(t float64) mgl64.Vec3

At returns the point marked by the ray at t

func (Ray) Reflect

func (r Ray) Reflect(isect *Intersection) (reflRay Ray)

Reflect returns the reflected ray at the given Intersection.

func (Ray) Refract

func (r Ray) Refract(isect *Intersection, n1, n2 float64) (refrRay Ray)

Refract returns the refracted ray at the given intersection.

func (Ray) Transform

func (r Ray) Transform(transform *mgl64.Mat4) (newRay Ray, len float64)

Transform transforms the ray by the given matrix. The length of the ray after the tranformation has uses so it is returned as well.

type Scene

type Scene struct {
	// Camera Camera
	ImageHeight       int
	ImageWidth        int
	AdaptiveThreshold float64
	AAMaxDivisions    int
	AAThreshold       float64
	MaxRecursiveDepth int
	AmbientLight      Color64
	Background        Background
	Lights            []Light
	Objects           []Intersecter
}

func NewScene

func NewScene() *Scene

NewScene returns an empty scene with default values.

func NewSceneFromFile

func NewSceneFromFile(fileName string) *Scene

NewSceneFromFile returns a new Scene populated from the settings in the given json file. The format of the file should follow the specification of scene/format.txt.

func (*Scene) Intersect

func (scene *Scene) Intersect(ray *Ray, isect *Intersection) (found bool)

Intersect finds the first object that the given Ray intersects. hit will be false if no intersection was found.

type SkyboxBackground

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

func (SkyboxBackground) GetColor

func (b SkyboxBackground) GetColor(ray *Ray) Color64

type Sphere

type Sphere struct {
	*Object
}

Sphere represents a sphere of radius 1 located at the origin.

func (*Sphere) GetObject

func (s *Sphere) GetObject() *Object

func (*Sphere) Intersect

func (s *Sphere) Intersect(r *Ray, isect *Intersection) (hit bool)

Intersect calculates the intersection between a ray and a unit sphere at the origin.

type Texture

type Texture struct {
	Width  float64
	Height float64
	// contains filtered or unexported fields
}

Texture is a type that satisifies the MaterialAttribute interface. It enables the use of a png or jpeg image to specify an attribute of a material.

func NewTexture

func NewTexture(fileName string) *Texture

NewTexture creates a new Texture from the specified png/jpeg image. Textures are cached so calling this with the fileName more than once returns the same Texture.

func (*Texture) ColorAt

func (t *Texture) ColorAt(coord mgl64.Vec2) (color Color64)

Performs bilinear interpolation at points between pixels. See MaterialAttribute.ColorAt.

type UniformBackground

type UniformBackground struct {
	Color Color64
}

func (UniformBackground) GetColor

func (b UniformBackground) GetColor(ray *Ray) Color64

type UniformColor

type UniformColor struct {
	Color Color64
}

UniformColor represents a MaterialAttribute that is the same at every location.

func (UniformColor) ColorAt

func (c UniformColor) ColorAt(_ mgl64.Vec2) Color64

Directories

Path Synopsis
The raytracer application takes a scene as a json file and produces a rendered version of that scene as a png or jpeg image.
The raytracer application takes a scene as a json file and produces a rendered version of that scene as a png or jpeg image.
bvh
ray
vec
js
lib

Jump to

Keyboard shortcuts

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