hittable

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2022 License: GPL-3.0 Imports: 9 Imported by: 1

Documentation

Overview

Package hittable provides objects that are hittable by rays shot by the ray tracer. Some of these hittable objects are containers for other objects Some others are used to translate or rotate other objects

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHittablePdf added in v0.0.7

func NewHittablePdf(objects *HittableList, origin geo.Vec3) pdf.Pdf

NewHittablePdf creates a new instance of HittablePdf

func SortTrianglesByCenter added in v1.0.0

func SortTrianglesByCenter(list []Triangle, center float64, axis int) int

Types

type Hittable

type Hittable interface {
	PdfLightHittable
	Hit(r geo.Ray, rayLength util.Interval) (bool, *material.HitRecord)
	BoundingBox() aabb
	IsLight() bool
}

Hittable is the common interface for all objects in the ray tracing scene that can be hit by rays

func NewBoundingVolumeHierarchy

func NewBoundingVolumeHierarchy(list []Triangle) Hittable

NewBoundingVolumeHierarchy creates a new hittable object from the given hittable list The bounding Volume Hierarchy sorts the hittables in a binary tree where each node has a bounding box. This is to optimize the ray intersection search when having many hittable objects.

func NewBox

func NewBox(a geo.Vec3, b geo.Vec3, mat material.Material) Hittable

NewBox creates a new box shaped hittable object

func NewConstantMedium

func NewConstantMedium(boundary Hittable, density float64, color geo.Vec3) Hittable

NewConstantMedium creates a fog type hittable object where rays not only scatter at the edge of the object, but at random points inside the object The material of the boundary hittable is not used and can be nil

func NewMotionBlur

func NewMotionBlur(
	blurredHittable Hittable,
	blurDirection geo.Vec3,
) Hittable

NewMotionBlur creates a new hittable object that adds linear interpolated translation to its hittable based on the time of the ray. This gives the appearance of the object moving.

func NewObjModel added in v0.3.0

func NewObjModel(path, filename string, scale float64) (Hittable, error)

NewObjModel reads a Wavefront .obj file and creates a bvh containing all triangles. It also read materials from the referred .mat file. Support for colored and textured lambertian materials.

func NewObjModelWithDefaultMaterial added in v0.3.1

func NewObjModelWithDefaultMaterial(path, filename string, scale float64, defaultMaterial material.Material) (Hittable, error)

NewObjModelWithDefaultMaterial reads a Wavefront .obj file and creates a bvh containing all triangles. It also read materials from the referred .mat file. Support for colored and textured lambertian materials. Applies supplied default material if none in model

func NewQuad

func NewQuad(Q geo.Vec3, u geo.Vec3, v geo.Vec3, mat material.Material) Hittable

NewQuad creates a new rectangular flat hittable object

func NewRotationY

func NewRotationY(
	object Hittable,
	angle float64,
) Hittable

NewRotationY creates a hittable object that rotates the given hittable around the Y axis

func NewSphere

func NewSphere(
	center geo.Vec3,
	radius float64,
	mat material.Material,
) Hittable

NewSphere creates a new sphere shaped hittable object

func NewTranslation

func NewTranslation(
	object Hittable,
	offset geo.Vec3,
) Hittable

NewTranslation creates a hittable object that translates the given hittable by the givn offset vector

type HittableList

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

HittableList is a special type of hittable that is a container for a list of other hittable objects. Used to be able to have many objects in a scene

func NewHittableList

func NewHittableList() HittableList

NewHittableList creates new empty HittableList

func (*HittableList) Add

func (hl *HittableList) Add(h Hittable)

Add adds a new hittable object to this HittableList

func (*HittableList) BoundingBox

func (hl *HittableList) BoundingBox() aabb

BoundingBox returns the bounding box that encapsulates all hittables in the list

func (*HittableList) Hit

func (hl *HittableList) Hit(r geo.Ray, rayLength util.Interval) (bool, *material.HitRecord)

Hit Checks if the given ray hits any object in this list. And if so, returns the properties of that ray hit

func (*HittableList) IsLight added in v0.0.7

func (hl *HittableList) IsLight() bool

IsLight returns if a hittable list itself is a light, which it is not

func (*HittableList) List added in v0.0.7

func (hl *HittableList) List() []Hittable

List returns the current slice of hittables

func (*HittableList) PdfValue added in v0.0.7

func (hl *HittableList) PdfValue(origin, direction geo.Vec3) float64

PdfValue generates a medium pdf value for all hittables in list given an origin and a direction

func (*HittableList) RandomDirection added in v0.0.7

func (hl *HittableList) RandomDirection(origin geo.Vec3) geo.Vec3

RandomDirection generates a random direction for a random hittable in the list

type HittablePdf added in v0.0.7

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

HittablePdf is a wrapper for generating pdfs for a list of hittables

func (HittablePdf) Generate added in v0.0.7

func (p HittablePdf) Generate() geo.Vec3

Generate implements pdf.Pdf

func (HittablePdf) Value added in v0.0.7

func (p HittablePdf) Value(direction geo.Vec3) float64

Value implements pdf.Pdf

type NonPdfLightHittable added in v0.3.7

type NonPdfLightHittable struct{}

NonPdfLightHittable is used by hittables that never uses pdfs directly Will panic hittable is a light and other hittable has pdf generating material

func (NonPdfLightHittable) PdfValue added in v0.3.7

func (h NonPdfLightHittable) PdfValue(origin, direction geo.Vec3) float64

PdfValue panics if invoked

func (NonPdfLightHittable) RandomDirection added in v0.3.7

func (h NonPdfLightHittable) RandomDirection(origin geo.Vec3) geo.Vec3

RandomDirection panics if invoked

type PdfLightHittable added in v0.3.7

type PdfLightHittable interface {
	PdfValue(origin, direction geo.Vec3) float64
	RandomDirection(origin geo.Vec3) geo.Vec3
}

PdfLightHittable has methods used when other hittables have pdf scattering materials. This should be implemented by hittables that can have light materials.

type Triangle added in v1.0.0

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

func NewTriangle added in v0.3.0

func NewTriangle(v0, v1, v2 geo.Vec3, mat material.Material) Triangle

func NewTriangleWithTexCoords added in v0.3.0

func NewTriangleWithTexCoords(v0, v1, v2 geo.Vec3, tu0, tv0, tu1, tv1, tu2, tv2 float64, mat material.Material) Triangle

NewTriangle creates a new triangle flat hittable object A counter clockwise winding is expected

func (Triangle) BoundingBox added in v1.0.0

func (t Triangle) BoundingBox() aabb

func (Triangle) Center added in v1.0.0

func (t Triangle) Center(axis int) float64

Center returns the center point for the triangle

func (Triangle) Hit added in v1.0.0

func (t Triangle) Hit(r geo.Ray, rayLength util.Interval) (bool, *material.HitRecord)

func (Triangle) IsLight added in v1.0.0

func (t Triangle) IsLight() bool

func (Triangle) PdfValue added in v1.0.0

func (t Triangle) PdfValue(origin, direction geo.Vec3) float64

func (Triangle) RandomDirection added in v1.0.0

func (t Triangle) RandomDirection(origin geo.Vec3) geo.Vec3

Jump to

Keyboard shortcuts

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