gbrt

package
v0.0.0-...-498d591 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2023 License: Unlicense Imports: 25 Imported by: 0

Documentation

Overview

Package grbt contains code for a ray tracer in beam.

Index

Constants

View Source
const (
	ArcCircle = ArcType(iota)
	ArcSemi
	ArcQuarter
	ArcThreeQuarter
)

Arcs of varying completion

View Source
const (
	DirRight = Dir(iota)
	DirDown
	DirLeft
	DirUp
)

Directions

View Source
const (
	HitNone = HitType(iota)
	HitLetterBlack
	HitLetterWhite
	HitLetterRed
	HitLetterGreen
	HitLetterBlue
	HitLetterYellow
	HitGopherBlue
	HitGopherTeal
	HitWall
	HitSun
	HitAABB
)

HitTypes for known materials.

Variables

This section is empty.

Functions

func BeamTracer

func BeamTracer(position Vec, img ImageConfig, word, dir string) *beam.Pipeline

BeamTracer runs the ray tracer as a Apache Beam Pipeline on the runner of choice.

func OrdinaryTracer

func OrdinaryTracer(origin Vec, cfg ImageConfig, word, dir string)

OrdinaryTracer is a standard implementation of a ray tracer for validation and performance comparison purposes.

func OutputPath

func OutputPath(dir, word string, samples int) string

OutputPath generates a png file path based on the given directory, path and number of samples.

func RandomVal

func RandomVal() float64

RandomVal returns a random float64 between 0 and 1.

func RayMarching

func RayMarching(origin, direction Vec, scene *Scene) (hitType HitType, hitPos, hitNorm Vec)

RayMarching performs signed sphere marching Returns hitType and updated hit positions & normal.

func ValidateWord

func ValidateWord(word string) error

ValidateWord checks that the word can be printed by the letter models.

Types

type Arc

type Arc struct {
	Center Vec
	T      ArcType
	D      Dir
	R      Float
}

Arc represents a limited configurations of parts of a circle

type ArcType

type ArcType int

ArcType is the kind of circle we're getting out of this.

type CombinePixelsFn

type CombinePixelsFn struct {
	SamplesCount int
}

CombinePixelsFn combines the contributions from multiple pixels.

func (*CombinePixelsFn) AddInput

func (fn *CombinePixelsFn) AddInput(ctx context.Context, a, b Vec) Vec

AddInput sums together the colour contributions for a pixel. Typically on the lifted side of a CombineFn

func (*CombinePixelsFn) ExtractOutput

func (fn *CombinePixelsFn) ExtractOutput(colour Vec) Vec

ExtractOutput does the Reinhard tone mapping for this pixel.

func (*CombinePixelsFn) MergeAccumulators

func (fn *CombinePixelsFn) MergeAccumulators(ctx context.Context, a, b Vec) Vec

MergeAccumulators sums together the colour contributions for a pixel.

type Dir

type Dir int

Dir indicates a cardinal direction

type Float

type Float float64

Float is a convenience type incase I decide to change the precision later.

func BoxTest

func BoxTest(position, lowerLeft, upperRight Vec) Float

BoxTest is the Rectangle CSG equation. Returns minimum signed distance from space carved by lowerLeft vertex and opposite rectangle vertex upperRight.

func Clamp

func Clamp(v, upper, lower Float) Float

Clamp returns the value v, but restricted to the upper and lower bounds.

func Max

func Max(l, r Float) Float

Max returns the maximum of two Floats.

func Min

func Min(l, r Float) Float

Min returns the minimum of two Floats.

func SphereTest

func SphereTest(position, center Vec, radius Float) Float

SphereTest is the Sphere CSG equation.

type HitType

type HitType int

HitType is the material being struck by the ray.

type ImageConfig

type ImageConfig struct {
	Width, Height    float64
	Samples, Bounces int64

	Goal, Left, Up Vec
}

ImageConfig contains properties of the generated image, used to generate initial rays.

type Letter

type Letter struct {
	Char   string
	Lines  [][2][2]Float
	Curves []Arc
	// contains filtered or unexported fields
}

Letter models character with CSG. Separate Positions I think. That will get subtracted from the ray's position.

func (*Letter) Initialize

func (m *Letter) Initialize()

Initialize sets the bounding box for the letter.

func (*Letter) Query

func (m *Letter) Query(position Vec) (Float, HitType)

Query checks if we hit/are in this letter.

func (*Letter) Width

func (m *Letter) Width() Float

Width returns the unit width of the letters.

type MakeImageFn

type MakeImageFn struct {
	Width, Height int
	Out           string
}

MakeImageFn writes the image to wherever.

func (*MakeImageFn) ProcessElement

func (f *MakeImageFn) ProcessElement(ctx context.Context, _ beam.T, iter func(*PixelColour) bool) (bool, error)

ProcessElement iterates over all the functions and writes Writes the file to the designated spot.

type Model

type Model interface {
	// Initialize does any necessary precomputations on the model
	// eg. Handle AABBs? How do we propagate those up the scene graph?
	Initialize()

	// Query calculates the distance to the model from the position.
	Query(position Vec) (distance Float, material HitType)
}

Model is where we're going to hang all the geometry stuff.

type Obj

type Obj struct {
	Vertices []Vec
	Faces    [][4]uint32
	// contains filtered or unexported fields
}

Obj represents a single object set of connected polygons.

func (*Obj) Initialize

func (m *Obj) Initialize()

Initialize precomputes information from the data.

func (*Obj) Query

func (m *Obj) Query(position Vec) (Float, HitType)

Query checks which triangle we're closest to.

type Pixel

type Pixel struct {
	X, Y int
}

Pixel is an x,y coordinate in an image. Used as a key for grouping sample rays back together.

type PixelColour

type PixelColour struct {
	K Pixel
	C Vec
}

PixelColour combines a pixel with its colour.

func ToPixelColour

func ToPixelColour(k Pixel, colour Vec) PixelColour

ToPixelColour combines pixels with it's colour.

type PositionedModel

type PositionedModel struct {
	Pos Vec
	Model
}

PositionedModel is a model with a "global" position with the scene. This is where rotations etc need to be handled to translate from world space to model space.

func (*PositionedModel) Query

func (m *PositionedModel) Query(position Vec) (Float, HitType)

Query converts the position form World Space to Model space, and queries the model.

type Room

type Room struct {
}

Room is the room that contains the scene.

func (*Room) Initialize

func (m *Room) Initialize()

Initialize is a No-op for Room.

func (*Room) Query

func (m *Room) Query(position Vec) (Float, HitType)

Query is a checks colliding with the room.

type Scene

type Scene struct {
	Ms []*PositionedModel
	// contains filtered or unexported fields
}

Scene is the what is being Ray Traced.

func (*Scene) Initialize

func (s *Scene) Initialize()

Initialize recursively initializes the rest of the scene.

func (*Scene) Query

func (s *Scene) Query(position Vec) (Float, HitType)

Query samples the Scene and returns the closest collision.

type Sphere

type Sphere struct {
	Radius   Float
	Material HitType
}

Sphere models a sphere.

func (*Sphere) Initialize

func (m *Sphere) Initialize()

Initialize provides a default material if needed.

func (*Sphere) Query

func (m *Sphere) Query(position Vec) (Float, HitType)

Query checks the distance of position from the Sphere.

type TraceFn

type TraceFn struct {
	// TODO retype Vec to Position or something.
	// requires redoing doing all the math for type safety.
	Position Vec
	Bounces  int64
	// TODO move this to a side input
	Word string
	// contains filtered or unexported fields
}

TraceFn creates rays from the pixels.

func (*TraceFn) ProcessElement

func (f *TraceFn) ProcessElement(k Pixel, ray Vec) (Pixel, Vec)

ProcessElement actualy traces the scene of the image and returns the colour contribution of this sample. TODO retype the returned thing to a colour, instead of a vec.

func (*TraceFn) Setup

func (f *TraceFn) Setup()

Setup do the one time setup for the scene.

type Vec

type Vec struct {
	X, Y, Z Float
}

Vec is a vector of 3 Floats.

func MonoVec

func MonoVec(v float64) Vec

MonoVec produces a vector with all the values set to v.

func Trace

func Trace(origin, direction Vec, scene *Scene, maxBounces int64) Vec

Trace casts rays, and handles bounces, returning the colour.

func (Vec) Cross

func (v Vec) Cross(b Vec) Vec

Cross calculates the Cross product of two vectors.

func (Vec) Dot

func (v Vec) Dot(r Vec) Float

Dot calculates the dot product of two vectors.

func (Vec) Dot2

func (v Vec) Dot2() Float

Dot2 performs a dot product against v itself.

func (Vec) InvSqrt

func (v Vec) InvSqrt() Vec

InvSqrt returns the inverse square root.

func (Vec) Minus

func (v Vec) Minus(r Vec) Vec

Minus subtracts r from v.

func (Vec) Plus

func (v Vec) Plus(r Vec) Vec

Plus adds two vectors together.

func (Vec) Times

func (v Vec) Times(r Vec) Vec

Times multiplies vectors together.

Jump to

Keyboard shortcuts

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