Documentation
¶
Index ¶
- Constants
- Variables
- func ColorsDifferent(color1, color2 Color64, thresh float64) bool
- func ParseSetting(scene *Scene, setting string, value interface{})
- func ParseVector(floatArray interface{}) mgl64.Vec3
- func ReadSettingsFile(fileName string) interface{}
- func TransformVec3(m mgl64.Mat4, v mgl64.Vec3) mgl64.Vec3
- type BRDF
- type Background
- type Camera
- type Color64
- func (c Color64) Add(other Color64) Color64
- func (c Color64) B() float64
- func (c Color64) Clamp() Color64
- func (c Color64) G() float64
- func (c Color64) Len2() float64
- func (c Color64) Mul(val float64) Color64
- func (c Color64) NRGBA() color.NRGBA
- func (c Color64) Product(other Color64) Color64
- func (c Color64) R() float64
- type DirectionalLight
- type Intersecter
- type Intersection
- type Light
- type Material
- type MaterialAttribute
- type Object
- type Parser
- type Ray
- type Scene
- type SkyboxBackground
- type Sphere
- type Texture
- type UniformBackground
- type UniformColor
Constants ¶
const ( PrimaryRay = iota CollisionRay ReflectionRay RefractionRay ShadowRay NumRayTypes )
const (
AirIndex = 1.0003
)
const (
DirectionalLightDist = 1e10
)
const (
Rayε = 0.00001
)
Variables ¶
var ( DirectionalLightDefaultColor = Color64{1, 1, 1} DirectionalLightDefaultOrientation = mgl64.Vec3{0, -1, 0} )
var ( ImageHeightDefault = 1 ImageWidthDefault = 1 AdaptiveThresholdDefault = 0.0 AAMaxDivisionsDefault = 0 AAThresholdDefault = 0.0 MaxRecursiveDepthDefault = 1 AmbientLightDefault = Color64{0, 0, 0} BackgroundDefault = UniformBackground{Color64{0, 0, 0}} )
var Clamp01 = clamp(0.0, 1.0)
Functions ¶
func ColorsDifferent ¶
func ParseSetting ¶
func ParseVector ¶
ParseVector takes an interface{} which it assumes is actually a [3]float64 and converts it to a mgl64.Vec3.
func ReadSettingsFile ¶
func ReadSettingsFile(fileName string) interface{}
Types ¶
type BRDF ¶
type BRDF func(scene *Scene, ray *Ray, isect *Intersection) (color Color64)
A bidirectional reflectance distribution function. Returns the ratio of reflected radiance exiting along wr to the irradiance incident on the surface from direction wi. wi - normalized negative incomming light direction (toward light) wr - normalized outgoing direction (toward camera) type BRDF func(wi, wr mgl64.Vec3, isect Intersection) mgl64.Vec3
type Background ¶
type Color64 ¶
type Color64 [3]float64
func BlinnPhongBRDF ¶
func BlinnPhongBRDF(scene *Scene, ray *Ray, isect *Intersection) (color Color64)
func BlinnPhongBRDF(wi, wr mgl64.Vec3, isect Intersection) mgl64.Vec3 {
// diffuse := LambertianBRDF(wi, wr, isect)
// specular := ...
return mgl64.Vec3{0, 0, 0}
}
func LambertianBRDF ¶
func LambertianBRDF(scene *Scene, ray *Ray, isect *Intersection) (color Color64)
func LambertianBRDF(wi, wr mgl64.Vec3, isect Intersection) mgl64.Vec3 {
kd := isect.Object.Material.Diffuse.ColorAt(isect.UVCoords)
return mgl64.Vec3(kd).Mul(wi.Dot(isect.Normal))
}
func ParseColor64 ¶
func ParseColor64(floatArray interface{}) Color64
ParseColor64 takes an interface{} which it assumes is actually a [3]float64 and converts it to a Color64.
func ShadowAttenuation ¶
ShadowAttenuation takes the unnormalized direction to the light so we know when we've "hit" it.
type DirectionalLight ¶
DirectionalLight simulates a point light at an infinate distance. The opposite direction to it's orientation is used because more useful and saves work
func (*DirectionalLight) Attenuation ¶
func (l *DirectionalLight) Attenuation(scene *Scene, point mgl64.Vec3) Color64
type Intersecter ¶
type Intersecter interface {
// Intersect takes a ray in local coordinates and populates the intersection and
// returns true if the intersects the object. If the ray does not hit then isect
// is undefined and hit is false.
Intersect(*Ray, *Intersection) (hit bool)
GetObject() *Object
}
Intersecter describes a thing that intersects with a Ray.
type Intersection ¶
type Material ¶
type Material struct {
Name string
Emissive MaterialAttribute
Ambient MaterialAttribute
Diffuse MaterialAttribute
Specular MaterialAttribute
Reflective MaterialAttribute
Smoothness MaterialAttribute
Transmissive MaterialAttribute
Index MaterialAttribute
Normal MaterialAttribute
IsLiquid MaterialAttribute
BRDF BRDF
}
type MaterialAttribute ¶
type MaterialAttribute interface {
// ColorAt takes normalized coordinates and return the color at those coordinates.
ColorAt(mgl64.Vec2) Color64
}
MaterialAttribute is an interface for getting a color. Designed with texture mapping in mind.
type Object ¶
type Ray ¶
func (Ray) Reflect ¶
func (r Ray) Reflect(isect *Intersection) (reflRay Ray)
Reflect returns the reflected ray at the given Intersection.
type Scene ¶
type Scene struct {
// Camera Camera
ImageHeight int
ImageWidth int
AdaptiveThreshold float64
AAMaxDivisions int
AAThreshold float64
MaxRecursiveDepth int
AmbientLight Color64
Background Background
Lights []Light
Objects []Intersecter
}
func NewSceneFromFile ¶
NewSceneFromFile returns a new Scene populated from the settings in the given json file. The format of the file should follow the specification of scene/format.txt.
type SkyboxBackground ¶
type SkyboxBackground struct {
// contains filtered or unexported fields
}
func (SkyboxBackground) GetColor ¶
func (b SkyboxBackground) GetColor(ray *Ray) Color64
type Sphere ¶
type Sphere struct {
*Object
}
Sphere represents a sphere of radius 1 located at the origin.
type Texture ¶
Texture is a type that satisifies the MaterialAttribute interface. It enables the use of a png or jpeg image to specify an attribute of a material.
func NewTexture ¶
NewTexture creates a new Texture from the specified png/jpeg image. Textures are cached so calling this with the fileName more than once returns the same Texture.
type UniformBackground ¶
type UniformBackground struct {
Color Color64
}
func (UniformBackground) GetColor ¶
func (b UniformBackground) GetColor(ray *Ray) Color64
type UniformColor ¶
type UniformColor struct {
Color Color64
}
UniformColor represents a MaterialAttribute that is the same at every location.