graphics

package
v0.0.0-...-e8cc267 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const MaxTraceDepth = 3 // The maximum depth for trace recursion

Variables

View Source
var (
	Zero     = NewVec(0, 0, 0)
	UnitX    = NewVec(1, 0, 0)
	UnitY    = NewVec(0, 1, 0)
	UnitZ    = NewVec(0, 0, 1)
	Identity = NewVec(1, 1, 1)
)

Commonly used vectors

View Source
var (
	Black = NewColor(0, 0, 0)
	Red   = NewColor(1, 0, 0)
	Green = NewColor(0, 1, 0)
	Blue  = NewColor(0, 0, 1)
	White = NewColor(1, 1, 1)
)

Commonly used colors

Functions

This section is empty.

Types

type Camera

type Camera struct {
	FieldOfView float64 // The field of view, in degrees
}

Represents a camera within the scene

type Color

type Color struct {
	R, G, B float64
}

Represents a color composed of red, green and blue

func NewColor

func NewColor(r, g, b float64) Color

Shorthand to create a new color with the given components

func (Color) Add

func (a Color) Add(b Color) Color

Adds the color piece-wise to the given color

func (Color) AddS

func (a Color) AddS(b float64) Color

Adds the given scalar amount to the color

func (Color) ConvertToRGBA

func (c Color) ConvertToRGBA() color.RGBA

Converts a color in floating point range (0.0 to 1.0) to a color with the given channel values

func (Color) Div

func (a Color) Div(b Color) Color

Divides the color piece-wise by the given color

func (Color) DivS

func (a Color) DivS(b float64) Color

Divides the color by the given scalar amount

func (Color) Mul

func (a Color) Mul(b Color) Color

Multiplies the color piece-wise by the given color

func (Color) MulS

func (a Color) MulS(b float64) Color

Multiplies the color by the given scalar amount

func (Color) Sub

func (a Color) Sub(b Color) Color

Subtracts the color piece-wise from the given color

func (Color) SubS

func (a Color) SubS(b float64) Color

Subtracts the given scalar amount from the color

type Light

type Light struct {
	Position Vector // The position of the light
	Emissive Color  // The emissive color of the light
}

Represents a light in the scene

type Material

type Material struct {
	Diffuse      Color   // The diffuse color of the material
	Transparency float64 // The transparency level of the material (between 0.0 and 1.0 inclusive)
	Reflectivity float64 // The reflectivity level of the material (between 0.0 and 1.0 inclusive)
}

Describes the material surface of an object within a scene

type Object

type Object interface {
	// Calculates whether the object Intersects the given ray and returns the distance.
	Intersects(ray Ray, distance *float64) bool
	GetMaterial() Material // The material of the object
	GetPosition() Vector   // The center position of the object
}

Represents an object in the scene

type Ray

type Ray struct {
	Origin, Direction Vector
}

Represents a ray projected in 3d space

func R

func R(origin, direction Vector) Ray

Shorthand to create a new ray with the given components

func (Ray) Position

func (r Ray) Position(distance float64) Vector

Calculates a point along the ray with the given distance

func (Ray) Reflect

func (r Ray) Reflect(point, normal Vector) Ray

Reflects the ray about the given point and normal

func (Ray) Refract

func (r Ray) Refract(point, normal Vector, inside bool) Ray

Refracts the ray about the given point and normal

type Scene

type Scene struct {
	Camera          Camera   // The scene camera
	Lights          []Light  // The world light sources
	Objects         []Object // The objects composing the scene itself
	BackgroundColor Color    // The background color of the scene
}

Represents a scene configuration for the ray-tracer; provides objects and materials which compose the scene structure and layout

func (*Scene) Render

func (scene *Scene) Render(dimensions image.Rectangle) *image.RGBA

Renders an RGBA image of the given dimensions using the given scene configuration via ray-tracing

type Sphere

type Sphere struct {
	Center   Vector
	Radius   float64
	Material Material
}

Represents a sphere that can be placed in a scene

func (Sphere) GetMaterial

func (sphere Sphere) GetMaterial() Material

func (Sphere) GetPosition

func (sphere Sphere) GetPosition() Vector

func (Sphere) GetRadius

func (sphere Sphere) GetRadius() float64

func (Sphere) Intersects

func (sphere Sphere) Intersects(ray Ray, distance *float64) bool

Calculates whether the sphere Intersects with the given ray and returns the hit distance.

type Vector

type Vector struct {
	X, Y, Z float64
}

Represents a vector in 3d space

func NewVec

func NewVec(x, y, z float64) Vector

Shorthand to create a new vector with the given components

func (Vector) Abs

func (a Vector) Abs() Vector

Calculates the absolute value of the vector piece-wise

func (Vector) Add

func (a Vector) Add(b Vector) Vector

Adds the vector piece-wise to the given vector

func (Vector) AddS

func (a Vector) AddS(b float64) Vector

Adds the given scalar amount to the vector

func (Vector) Cross

func (a Vector) Cross(b Vector) Vector

Calculates the cross product of this vector and the given vector

func (Vector) Div

func (a Vector) Div(b Vector) Vector

Divides the vector piece-wise by the given vector

func (Vector) DivS

func (a Vector) DivS(b float64) Vector

Divides the vector by the given scalar amount

func (Vector) Dot

func (a Vector) Dot(b Vector) float64

Calculates the dot product of this vector and the given vector

func (Vector) Length

func (a Vector) Length() float64

Calculates the length of this vector

func (Vector) LengthSquared

func (a Vector) LengthSquared() float64

Calculates the square length of this vector

func (Vector) Mul

func (a Vector) Mul(b Vector) Vector

Multiplies the vector piece-wise by the given vector

func (Vector) MulS

func (a Vector) MulS(b float64) Vector

Multiplies the vector by the given scalar amount

func (Vector) Negate

func (a Vector) Negate() Vector

Negates the vector

func (Vector) Normalize

func (a Vector) Normalize() Vector

Normalizes the vector

func (Vector) Sub

func (a Vector) Sub(b Vector) Vector

Subtracts the vector piece-wise from the given vector

func (Vector) SubS

func (a Vector) SubS(b float64) Vector

Subtracts the given scalar amount from the vector

Jump to

Keyboard shortcuts

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