rendering

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 14 Imported by: 0

README

Rendering

Package for rendering meshes generated from polyform.

Straight up a 1:1 implementation based on the guide "Ray Tracing in One Weekend" by Peter Shirley

Benchmarking

The demo scene from "Ray Tracing in One Weekend" has been put into a golang benchmark. If you try implementing optimizations, you can use this to test out what's going on.

go test rendering/render_test.go -run BenchmarkBunnyRender -bench=BenchmarkBunnyRender -cpuprofile cpu.prof
go tool pprof -svg cpu.prof > cpu.svg

Making a Video

Some examples output frames to a video that then need to get stitched together. For that I use ffmpeg:

ffmpeg -framerate 24 -pattern_type glob -i '*.png' -c:v libx264 -pix_fmt yuv420p -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" out.mp4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderToFile added in v0.4.0

func RenderToFile(
	maxRayBounce, samplesPerPixel, imageWidth int,
	hittables []Hittable,
	camera Camera,
	imgPath string,
	completion chan<- float64,
) error

Types

type BVHNode

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

func NewBVHFromMesh

func NewBVHFromMesh(mesh modeling.Mesh, mat Material) *BVHNode

func NewBVHTree

func NewBVHTree(objects []Hittable, start, end int, startTime, endTime float64) *BVHNode

func (BVHNode) BoundingBox

func (bvhn BVHNode) BoundingBox(startTime, endTime float64) *geometry.AABB

func (BVHNode) Hit

func (bvhn BVHNode) Hit(r *TemporalRay, min, max float64, hitRecord *HitRecord) bool

type Camera

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

func NewCamera

func NewCamera(
	vfov, aspectRatio, aperture, focusDist float64,
	origin, lookAt, up vector3.Float64,
	timeStart, timeEnd float64,
	background sample.Vec3ToVec3,
) Camera

func NewDefaultCamera added in v0.4.0

func NewDefaultCamera(
	aspectRatio float64,
	origin, lookAt vector3.Float64,
	time, shutter float64,
) Camera

func (Camera) GetRay

func (c Camera) GetRay(r *rand.Rand, s, t float64) TemporalRay

type HitList

type HitList []Hittable

func (HitList) BoundingBox

func (h HitList) BoundingBox(startTime, endTime float64) *geometry.AABB

func (HitList) Hit

func (h HitList) Hit(r *TemporalRay, min, max float64, hitRecord *HitRecord) bool

type HitRecord

type HitRecord struct {
	Distance   float64
	Point      vector3.Float64
	Normal     vector3.Float64
	FrontFace  bool
	Material   Material
	UV         vector2.Float64
	Float3Data map[string]vector3.Float64
	Float2Data map[string]vector2.Float64
}

func NewHitRecord

func NewHitRecord() *HitRecord

func (*HitRecord) SetFaceNormal

func (h *HitRecord) SetFaceNormal(ray TemporalRay, outwardNormal vector3.Float64)

type Hittable

type Hittable interface {
	Hit(r *TemporalRay, min, max float64, hitRecord *HitRecord) bool
	BoundingBox(startTime, endTime float64) *geometry.AABB
}

type Material

type Material interface {
	Scatter(in geometry.Ray, rec *HitRecord, attenuation *vector3.Float64, scattered *geometry.Ray) bool
	Emitted(uv vector2.Float64, pont vector3.Float64) vector3.Float64
}

type Mesh

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

func NewMesh

func NewMesh(mesh modeling.Mesh, mat Material) Mesh

func NewMeshWithAttributes added in v0.4.0

func NewMeshWithAttributes(mesh modeling.Mesh, mat Material, v3Data, v2Data []string) Mesh

func (Mesh) BoundingBox

func (m Mesh) BoundingBox(startTime, endTime float64) *geometry.AABB

func (Mesh) GetMaterial

func (s Mesh) GetMaterial() Material

func (Mesh) Hit

func (s Mesh) Hit(ray *TemporalRay, minDistance, maxDistance float64, hitRecord *HitRecord) bool

func (Mesh) Hit2 added in v0.4.0

func (s Mesh) Hit2(ray *TemporalRay, minDistance, maxDistance float64, hitRecord *HitRecord) bool

type SortBoxByXAxis

type SortBoxByXAxis []Hittable

func (SortBoxByXAxis) Len

func (a SortBoxByXAxis) Len() int

func (SortBoxByXAxis) Less

func (a SortBoxByXAxis) Less(i, j int) bool

func (SortBoxByXAxis) Swap

func (a SortBoxByXAxis) Swap(i, j int)

type SortBoxByYAxis

type SortBoxByYAxis []Hittable

func (SortBoxByYAxis) Len

func (a SortBoxByYAxis) Len() int

func (SortBoxByYAxis) Less

func (a SortBoxByYAxis) Less(i, j int) bool

func (SortBoxByYAxis) Swap

func (a SortBoxByYAxis) Swap(i, j int)

type SortBoxByZAxis

type SortBoxByZAxis []Hittable

func (SortBoxByZAxis) Len

func (a SortBoxByZAxis) Len() int

func (SortBoxByZAxis) Less

func (a SortBoxByZAxis) Less(i, j int) bool

func (SortBoxByZAxis) Swap

func (a SortBoxByZAxis) Swap(i, j int)

type Sphere

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

func NewAnimatedSphere

func NewAnimatedSphere(radius float64, mat Material, animation sample.FloatToVec3) *Sphere

func NewSphere

func NewSphere(center vector3.Float64, radius float64, mat Material) *Sphere

func (Sphere) BoundingBox

func (s Sphere) BoundingBox(startTime, endTime float64) *geometry.AABB

func (Sphere) GetMaterial

func (s Sphere) GetMaterial() Material

func (Sphere) Hit

func (s Sphere) Hit(ray *TemporalRay, minDistance, maxDistance float64, hitRecord *HitRecord) bool

func (Sphere) UV

type TemporalRay

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

func NewTemporalRay

func NewTemporalRay(origin vector3.Float64, direction vector3.Float64, time float64) TemporalRay

func (TemporalRay) At

func (TemporalRay) Direction

func (r TemporalRay) Direction() vector3.Float64

func (TemporalRay) Origin

func (r TemporalRay) Origin() vector3.Float64

func (TemporalRay) Ray

func (r TemporalRay) Ray() geometry.Ray

type Texture

type Texture interface {
	Value(uv vector2.Float64, p vector3.Float64) vector3.Float64
}

type Tree

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

func NewBVH

func NewBVH(items []Hittable, startTime, endTime float64) Tree

func (Tree) BoundingBox

func (bvh Tree) BoundingBox(startTime, endTime float64) *geometry.AABB

func (Tree) Hit

func (bvh Tree) Hit(r *TemporalRay, min, max float64, hitRecord *HitRecord) bool

type Triangle

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

func (Triangle) BoundingBox

func (tri Triangle) BoundingBox(start, stop float64) *geometry.AABB

func (Triangle) Hit

func (tri Triangle) Hit(ray *TemporalRay, minDistance, maxDistance float64, hitRecord *HitRecord) bool

type XYRectangle

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

func NewXYRectangle

func NewXYRectangle(bottomLeft, topRight vector2.Float64, depth float64, mat Material) XYRectangle

func (XYRectangle) BoundingBox

func (xyr XYRectangle) BoundingBox(startTime, endTime float64) *geometry.AABB

func (XYRectangle) Hit

func (xyr XYRectangle) Hit(ray *TemporalRay, minDistance, maxDistance float64, hitRecord *HitRecord) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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