tracer

package module
v0.0.0-...-56c4cad Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2019 License: MIT Imports: 10 Imported by: 0

README

forthebadge CircleCI

tracer.go

Ray tracer, written in Go (Clever name right?). Starting off with "Ray Tracing in One Weekend" by Peter Shirley, but with plans for expansion.

Enjoy :)

Sample render

Traced

Next Steps:

  • README show latest render
  • Ray Tracing: The Next Week
  • More Primitives
  • Distributed Parallelism

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackgroundColor

func BackgroundColor(ray Ray) mgl64.Vec3

func Div

func Div(v mgl64.Vec3, t float64) mgl64.Vec3

func Inverse

func Inverse(v mgl64.Vec3) mgl64.Vec3

func LinearInterpolation

func LinearInterpolation(t float64, color1, color2 mgl64.Vec3) mgl64.Vec3

func MulByVec

func MulByVec(v mgl64.Vec3, v2 mgl64.Vec3) mgl64.Vec3

func RGBASetVec3

func RGBASetVec3(i *image.RGBA, vecColor mgl64.Vec3, x, y int)

func RandVec3InUnitDisk

func RandVec3InUnitDisk() (p mgl64.Vec3)

func RandVec3InUnitSphere

func RandVec3InUnitSphere() (p mgl64.Vec3)

func Reflect

func Reflect(v mgl64.Vec3, n mgl64.Vec3) mgl64.Vec3

func Refract

func Refract(v mgl64.Vec3, n mgl64.Vec3, niOverNt float64) (refracted mgl64.Vec3, ok bool)

func ToColumns

func ToColumns(rect image.Rectangle, n int) []image.Rectangle

ToColumns splits a rectangle into n columns

func Trace

func Trace(ray Ray, world Primitive, bounces int) (color mgl64.Vec3)

Types

type Bounce

type Bounce struct {
	Attenuation mgl64.Vec3
	Scattered   Ray
}

type Camera

type Camera struct {
	Origin mgl64.Vec3
	// contains filtered or unexported fields
}

func NewCamera

func NewCamera(opts CameraOptions) Camera

func (*Camera) Ray

func (c *Camera) Ray(s, t float64) Ray

type CameraOptions

type CameraOptions struct {
	LookFrom, LookAt, Up                 mgl64.Vec3
	Fov, Aspect, Aperture, FocusDistance float64
}

type Dielectric

type Dielectric struct {
	RefractiveIndex float64
}

func (Dielectric) Scatter

func (d Dielectric) Scatter(ray Ray, rec *HitRecord) *Bounce

type HitRecord

type HitRecord struct {
	T         float64
	P, Normal mgl64.Vec3
	Material  Material
}

type Image

type Image struct {
	ImageOptions
	*image.RGBA
}

func NewImage

func NewImage(options ImageOptions) Image

func (*Image) Export

func (i *Image) Export() error

type ImageOptions

type ImageOptions struct {
	Width, Height int
	Path          string
}

type Lambertian

type Lambertian struct {
	Albedo mgl64.Vec3
}

func (Lambertian) Scatter

func (l Lambertian) Scatter(ray Ray, rec *HitRecord) *Bounce

type Material

type Material interface {
	Scatter(ray Ray, rec *HitRecord) *Bounce
}

type Metal

type Metal struct {
	Albedo    mgl64.Vec3
	Diffusion float64 // 0.0 to 1.0
}

func (Metal) Scatter

func (m Metal) Scatter(ray Ray, rec *HitRecord) *Bounce

type Primitive

type Primitive interface {
	// Future improvement: return *HitRecord instead of bool, nil return mean no hit found
	// Disadvantage: a new HitRecord is allocated every time a ray hits an object, instead of just once
	Hit(r Ray, tMin, tMax float64) *HitRecord
}

Future improvement: rename to "object" or "geometry" or something else, hittable seems so awkward

type Primitives

type Primitives struct {
	P []Primitive
}

func NewPrimitiveSlice

func NewPrimitiveSlice(primitives ...Primitive) Primitives

func (*Primitives) AddPrimitive

func (p *Primitives) AddPrimitive(primitive Primitive)

func (*Primitives) AddPrimitives

func (p *Primitives) AddPrimitives(primitives ...Primitive)

func (Primitives) Hit

func (p Primitives) Hit(r Ray, tMin, tMax float64) *HitRecord

type Ray

type Ray struct {
	Origin, Direction mgl64.Vec3
}

func (Ray) PointOnRay

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

type RenderOptions

type RenderOptions struct {
	CameraOptions
	ImageOptions
	Samples, Bounces int
}

RenderOptions describes all the options available to change how a scene is rendered

type Scene

type Scene struct {
	RenderOptions

	World Primitive
	// contains filtered or unexported fields
}

Scene describes everything needed to render and image

func NewScene

func NewScene(options RenderOptions, world Primitive) Scene

func (*Scene) Render

func (s *Scene) Render(img *image.RGBA)

func (*Scene) RenderParallel

func (s *Scene) RenderParallel(img *image.RGBA, n int)

RenderParallel renders the scene across n goroutines

func (*Scene) SamplePixel

func (s *Scene) SamplePixel(x, y float64) mgl64.Vec3

type Sphere

type Sphere struct {
	Center   mgl64.Vec3
	Radius   float64
	Material Material
}

func (Sphere) Hit

func (s Sphere) Hit(r Ray, tMin, tMax float64) *HitRecord

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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