display

package
v0.0.0-...-084007b Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2023 License: CC0-1.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	White = NewColor(1.0, 1.0, 1.0)
	Black = Color{}
)

Functions

This section is empty.

Types

type AABB

type AABB struct {
	Min geometry.Vec
	Max geometry.Vec
}

AABB represents an axis-aligned bounding box.

func NewAABB

func NewAABB(min geometry.Vec, max geometry.Vec) *AABB

NewAABB creates a new AABB.

func (*AABB) Add

func (ab *AABB) Add(ab2 *AABB) *AABB

Add combines two bounding boxes.

func (*AABB) Corners

func (ab *AABB) Corners() []geometry.Vec

Corners returns the vector representing the corners of the bounding box.

func (*AABB) Extend

func (ab *AABB) Extend(v geometry.Vec) *AABB

Extend expands the bounding box to include the given vector v.

func (*AABB) Hit

func (ab *AABB) Hit(ray *geometry.Ray, dMin float64, dMax float64) bool

Hit returns true if the given ray hits the bounding box.

type BVH

type BVH struct {
	Left  HitBoxer
	Right HitBoxer
	// contains filtered or unexported fields
}

func NewBVH

func NewBVH(depth int, time0 float64, time1 float64, h ...HitBoxer) *BVH

func (*BVH) Box

func (b *BVH) Box(t0 float64, t1 float64) *AABB

func (*BVH) Hit

func (b *BVH) Hit(ray *geometry.Ray, dMin float64, dMax float64) (bool, *HitRecord)

type Block

type Block struct {
	List
}

Block represents a 3-dimensional block or box made up of rectangles.

func NewBlock

func NewBlock(min geometry.Vec, max geometry.Vec, material Material) *Block

NewBlock returns a new Block.

type Checker

type Checker struct {
	Size float64
	Odd  Texture
	Even Texture
}

Checker represents a 2-color checkerboard pattern.

func NewChecker

func NewChecker(size float64, t0 Texture, t1 Texture) Checker

NewChecker returns a new Checker.

func (Checker) At

func (c Checker) At(u float64, v float64, p geometry.Vec) Color

At returns the Color of the ray at the given point along the checkerboard pattern.

type Color

type Color struct {
	geometry.Vec
}

Color represents an RGB color value.

func NewColor

func NewColor(e0, e1, e2 float64) Color

NewColor creates a new color.

func (Color) Add

func (c Color) Add(c2 Color) Color

Add returns the sum of two colors.

func (Color) Blue

func (c Color) Blue() float64

Blue returns the color's third element.

func (Color) Green

func (c Color) Green() float64

Green returns the color's second element.

func (Color) Mul

func (c Color) Mul(c2 Color) Color

Mul returns the multiplication of two colors.

func (Color) PixelValue

func (c Color) PixelValue() uint32

PixelValue converts a Color into a pixel value.

func (Color) Red

func (c Color) Red() float64

Red returns the color's first element.

func (Color) Scale

func (c Color) Scale(n float64) Color

Scale returns color scaled by a scalar.

type Dielectric

type Dielectric struct {
	RefIndex float64
	// contains filtered or unexported fields
}

Dielectric represents a clear material.

func NewDielectric

func NewDielectric(refIndex float64) Dielectric

NewDielectric creates a new material with a given index of refraction.

func (Dielectric) Emit

func (n Dielectric) Emit(rec *HitRecord) Color

Emit returns Black.

func (Dielectric) Scatter

func (d Dielectric) Scatter(r *geometry.Ray, rec *HitRecord) (bool, *Color, *geometry.Ray)

Scatter reflects or refracts light rays based on the index of refraction.

type Flip

type Flip struct {
	Child HitBoxer
}

Flip contains a HitBoxer that can be flipped.

func NewFlip

func NewFlip(child HitBoxer) *Flip

NewFlip creates a new Flip.

func (*Flip) Box

func (f *Flip) Box(t0 float64, t1 float64) *AABB

Box returns the bounding box that encloses the child surface.

func (*Flip) Hit

func (f *Flip) Hit(r *geometry.Ray, tMin float64, tMax float64) (bool, *HitRecord)

Hit calculates if the ray hits the HitBoxer. If so, the normal of the HitRecord is inverted.

type HitBoxer

type HitBoxer interface {
	Hit(r *geometry.Ray, tMin float64, tMax float64) (bool, *HitRecord)
	Box(t0 float64, t1 float64) *AABB
}

HitBoxer represents something that can be hit by a ray

type HitRecord

type HitRecord struct {
	Material Material // the material associated to this record
	// contains filtered or unexported fields
}

type Image

type Image struct {
	X    int
	Y    int
	Data image.Image
}

func NewImage

func NewImage(rc io.ReadCloser) (*Image, error)

func (*Image) At

func (i *Image) At(u float64, v float64, p geometry.Vec) Color

type Isotropic

type Isotropic struct {
	Rnd geometry.Rnd
	// contains filtered or unexported fields
}

Isotropic represents a material of constant density.

func NewIsotropic

func NewIsotropic(albedo Solid, rnd geometry.Rnd) *Isotropic

NewIsotropic returns a new Isotropic.

func (Isotropic) Emit

func (n Isotropic) Emit(rec *HitRecord) Color

Emit returns Black.

func (*Isotropic) Scatter

func (i *Isotropic) Scatter(r *geometry.Ray, rec *HitRecord) (bool, *Color, *geometry.Ray)

Scatter reflects light in a random direction.

type Lambertian

type Lambertian struct {
	Albedo Texture
	// contains filtered or unexported fields
}

Lambertian represents a Lambertian material attenuated by an Albedo.

func NewLambertian

func NewLambertian(albedo Texture) Lambertian

NewLambertian creates a new Lambertian material with a given color.

func (Lambertian) Emit

func (n Lambertian) Emit(rec *HitRecord) Color

Emit returns Black.

func (Lambertian) Scatter

func (l Lambertian) Scatter(r *geometry.Ray, rec *HitRecord) (bool, *Color, *geometry.Ray)

Scatter scatters light rays in a Lambertian pattern.

type Light

type Light struct {
	Solid Solid
}

Light represents a material that emits light.

func NewLight

func NewLight(c Color) *Light

NewLight returns a new Light.

func (Light) Emit

func (l Light) Emit(rec *HitRecord) Color

Emit returns the Color of the ray at the coordinates of the given HitRecord.

func (Light) Scatter

func (l Light) Scatter(r *geometry.Ray, rec *HitRecord) (bool, *Color, *geometry.Ray)

Scatter does not reflect light rays. A light source emits rays but does not reflect rays.

type List

type List struct {
	Hittables []HitBoxer
}

List holds a list of Hittables.

func NewList

func NewList(h ...HitBoxer) *List

NewList creates a new list of Hittables.

func (*List) Add

func (w *List) Add(h ...HitBoxer) int

Add adds a Hittable to the List.

func (*List) Box

func (w *List) Box(t0 float64, t1 float64) *AABB

func (*List) Hit

func (w *List) Hit(r *geometry.Ray, tMin float64, tMax float64) (bool, *HitRecord)

Hit returns the first intersection between the Ray r and the Hittables in the List.

type Material

type Material interface {
	Scatter(r *geometry.Ray, rec *HitRecord) (wasScattered bool, attenuation *Color, scattered *geometry.Ray)
	Emit(rec *HitRecord) Color
}

Material represents a material that scatters light.

type Metal

type Metal struct {
	Albedo Color
	Rough  float64
	// contains filtered or unexported fields
}

Metal represents a reflective material.

func NewMetal

func NewMetal(albedo Color, roughness float64) Metal

NewMetal creates a new Metal material with a given color and roughness.

func (Metal) Emit

func (n Metal) Emit(rec *HitRecord) Color

Emit returns Black.

func (Metal) Scatter

func (m Metal) Scatter(r *geometry.Ray, rec *HitRecord) (bool, *Color, *geometry.Ray)

Scatter reflects light rays.

type MovingSphere

type MovingSphere struct {
	Center0  geometry.Vec
	Center1  geometry.Vec
	T0       float64
	T1       float64
	Radius   float64
	Material Material
}

MovingSphere represents a sphere that moves from Center0 to Center1 over t0 to t1.

func NewMovingSphere

func NewMovingSphere(center0 geometry.Vec, center1 geometry.Vec, t0 float64, t1 float64, radius float64, material Material) *MovingSphere

NewMovingSphere creates a new Sphere with two centers separated by times t0 and t1.

func (*MovingSphere) Box

func (s *MovingSphere) Box(t0 float64, t1 float64) *AABB

Box returns the bounding box of the MovingSphere.

func (*MovingSphere) Center

func (s *MovingSphere) Center(t float64) geometry.Vec

func (*MovingSphere) Hit

func (s *MovingSphere) Hit(r *geometry.Ray, dMin float64, dMax float64) (bool, *HitRecord)

Hit finds the first intersection between a ray and the moving sphere's surface.

func (*MovingSphere) UV

type Noise

type Noise struct {
	Rnd   geometry.Rnd
	Scale float64
	// contains filtered or unexported fields
}

Noise represents a texture with a random pattern.

func NewNoise

func NewNoise(rnd geometry.Rnd, scale float64) Noise

NewNoise returns a new Noise.

func (Noise) At

func (n Noise) At(u float64, v float64, p geometry.Vec) Color

At returns the color at the given coordinates when accounting for the texture pattern.

type Perlin

type Perlin struct {
	Rnd geometry.Rnd
	// contains filtered or unexported fields
}

func NewPerlin

func NewPerlin(rnd geometry.Rnd) Perlin

func (Perlin) GenerateTrilinear

func (per Perlin) GenerateTrilinear(p geometry.Vec) float64

type Rectangle

type Rectangle struct {
	Min      geometry.Vec
	Max      geometry.Vec
	Axis     int
	Material Material
}

Rectangle represents a 2-dimensional rectangle.

func NewRectangle

func NewRectangle(min geometry.Vec, max geometry.Vec, material Material) *Rectangle

NewRectangle returns a new Rectangle.

func (*Rectangle) Box

func (rect *Rectangle) Box(t0, t1 float64) (box *AABB)

Box returns the axis-Aligned bounding box encompassing the Rectangle.

func (*Rectangle) Hit

func (rect *Rectangle) Hit(ray *geometry.Ray, dMin float64, dMax float64) (bool, *HitRecord)

Hit finds the first intersection between a ray and the rectangle's surface.

type RotateY

type RotateY struct {
	Child HitBoxer
	// contains filtered or unexported fields
}

RotateY contains a surface that is rotated along the Y-axis.

func NewRotateY

func NewRotateY(child HitBoxer, angle float64) *RotateY

NewRotateY returns a new RotateY.

func (*RotateY) Box

func (r *RotateY) Box(t0 float64, t1 float64) *AABB

Box returns a bounding box that encloses the surface.

func (*RotateY) Hit

func (r *RotateY) Hit(ray *geometry.Ray, tMin float64, tMax float64) (bool, *HitRecord)

Hit calculates if the ray hits the HitBoxer. If so, the normal and point of the HitRecord are rotated.

type Solid

type Solid struct {
	Color Color
}

Solid represents a single solid color.

func NewSolid

func NewSolid(color Color) Solid

NewSolid returns a new Solid.

func (Solid) At

func (s Solid) At(u float64, v float64, p geometry.Vec) Color

At returns the Color of the ray.

type Sphere

type Sphere struct {
	Center   geometry.Vec
	Radius   float64
	Material Material
}

Sphere represents a sphere with a Center and a Radius.

func NewSphere

func NewSphere(center geometry.Vec, radius float64, material Material) *Sphere

NewSphere creates a new Sphere.

func (*Sphere) Box

func (s *Sphere) Box(t0 float64, t1 float64) *AABB

Box returns the bounding box of the Sphere.

func (*Sphere) Hit

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

Hit finds the first intersection between a ray and the sphere's surface.

func (*Sphere) Surface

func (s *Sphere) Surface(p geometry.Vec) (geometry.Unit, Material)

Surface returns the normal and material at point p on the Sphere.

func (*Sphere) UV

func (s *Sphere) UV(p geometry.Vec, t float64) (float64, float64)

type Texture

type Texture interface {
	At(u float64, v float64, p geometry.Vec) Color
}

type Translate

type Translate struct {
	Child  HitBoxer
	Offset geometry.Vec
}

Translate contains a HitBoxer that is translated according to a vector.

func NewTranslate

func NewTranslate(child HitBoxer, offset geometry.Vec) *Translate

NewTranslate returns a new Translate.

func (*Translate) Box

func (t *Translate) Box(t0 float64, t1 float64) *AABB

Box returns the translated bounding box for the Child HitBoxer.

func (*Translate) Hit

func (t *Translate) Hit(r *geometry.Ray, tMin float64, tMax float64) (bool, *HitRecord)

Hit calculates if the ray hits the HitBoxer. If so, the point of the HitRecord is translated.

type Volume

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

Volume represents a HitBoxer filled with a material with a given density.

func NewVolume

func NewVolume(box HitBoxer, density float64, phase Material) *Volume

NewVolume returns a new volume.

func (*Volume) Box

func (v *Volume) Box(t0 float64, t1 float64) *AABB

func (*Volume) Hit

func (v *Volume) Hit(ray *geometry.Ray, dMin float64, dMax float64) (bool, *HitRecord)

Jump to

Keyboard shortcuts

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