surface

package
v0.0.0-...-4982ab1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package surface contains functions that populate images with lit textured surfaces.

  Surface
  Light -
	Ambient
    Directional
  Material
  BumpMap

Index

Constants

This section is empty.

Variables

View Source
var DefaultAmbient = &Ambient{color.NewFRGBA(col.RGBA{10, 10, 10, 255})}

DefaultAmbient is a low gray light.

View Source
var DefaultMaterial = &defaultMaterial{color.NewFRGBA(col.White), color.NewFRGBA(col.White)}

DefaultMaterial describes a material with 0 emissivity, full white ambient and directional, and no specular components.

Functions

func Cross

func Cross(a, b []float64) []float64

Cross calculates the cross product between two vectors.

func Dot

func Dot(a, b []float64) float64

Dot calculates the dot product between two vectors.

func Reflect

func Reflect(v, n []float64) []float64

Reflect returns v reflected in n

func Roughen

func Roughen(r float64, vec []float64) []float64

Roughen perturbates a vector by replacing it with a randomly orientented unit vector.

func Unit

func Unit(v []float64) []float64

Unit scales the vector to length 1.

Types

type Ambient

type Ambient struct {
	Color *color.FRGBA
}

Ambient describes an ambient light source.

func NewAmbient

func NewAmbient(col col.Color) *Ambient

NewAmbient returns a new ambient light source.

func (*Ambient) Eval2

func (a *Ambient) Eval2(x, y float64) (*color.FRGBA, []float64, float64, float64)

Eval2 implements the Light interface.

type BumpMap

type BumpMap struct {
	Ambient *Ambient
	Direct  Light
	Mat     Material
	Normals texture.VectorField
}

BumpMap collects the ambient light, a direct light, a material, and normal map required to describe an area. If the normal map is nil then the standard normal is use {0, 0, 1}

func (*BumpMap) Eval2

func (bm *BumpMap) Eval2(x, y float64) color.Color

Eval2 implements the ColorField interface.

type Directional

type Directional struct {
	Color     *color.FRGBA
	Direction []float64
}

Directional describes a directional light source. The direction is from the surface to the light, normalized.

func NewDirectional

func NewDirectional(col col.Color, dir []float64) *Directional

NewDirectional returns a new directional light source.

func (*Directional) Eval2

func (d *Directional) Eval2(x, y float64) (*color.FRGBA, []float64, float64, float64)

Eval2 implements the Light interface.

type Light

type Light interface {
	Eval2(x, y float64) (*color.FRGBA, []float64, float64, float64)
}

Light provides the At function to determine the color (RGB in [0,1]), unit direction, distance and power of a light at a location. If the direction is nil then the light is treated as an ambient one and any distance and power values ignored. If the distance is -ve then this is treated as a directional light at infinity. Otherwise the light is treated as a point light source with the power falling as the inverse square of the distance from the light.

type Material

type Material interface {
	Eval2(x, y float64) (*color.FRGBA, *color.FRGBA, *color.FRGBA, *color.FRGBA, float64, float64)
}

Material provides the At function to determine the emissive light, various reflectances, shininess and roughness at a location. Reflectances are ordered as ambient, diffuse and specular.

type Quaternion

type Quaternion struct {
	Vec []float64
	Ang float64
	// contains filtered or unexported fields
}

Quaternion holds a quaternion defined as a vector (unit) and angle.

func NewQuaternion

func NewQuaternion(v []float64, th float64) *Quaternion

func (*Quaternion) Apply

func (q *Quaternion) Apply(pts ...[]float64) [][]float64

Apply applies the quaternion to the set of supplied points.

func (*Quaternion) Rotation

func (q *Quaternion) Rotation() [][]float64

Rotation returns the rotation matrix that describes a point transformed by the quaternion.

type Surface

type Surface struct {
	Ambient Light
	Lights  []Light
	Mat     Material
	Normals texture.VectorField
}

Surface collects the ambient light, lights, a material, and normal map required to describe an area. If the normal map is nil then the standard normal is use {0, 0, 1}

func (*Surface) Eval2

func (s *Surface) Eval2(x, y float64) col.Color

Eval2 implements the ColorField interface.

Jump to

Keyboard shortcuts

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