Documentation
¶
Index ¶
- func Blend(a float64, matA Material, b float64, matB Material) Material
- func Flat(t texture.Texture) Material
- func Matte(t texture.Texture) Material
- func ReflectFresnel(n float64, transmitted Material) Material
- func Reflective(c Color) Material
- func Refractive(n float64) Material
- func Refractive2(n1, n2 float64) Material
- func Shiny(c texture.Texture, reflectivity float64) Material
- func Transparent(t texture.Texture, consumeRecursion bool) Material
- func TwoSided(front, back Material) Material
- type Func
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Blend ¶
Blend mixes two materials with certain weights. E.g.:
Blend(0.9, Mate(WHITE), 0.1, Reflective(WHITE)) // 90% mate + 10% reflective, like a shiny billiard ball.
func Flat ¶
Flat returns a material with flat shading. I.e., returns colors as-is, disregarding any lighting, shadows, etc. Such materials emit light (in an indirect way). Suited for large, dimly luminous surfaces like computer screens, the sky, etc.
func Matte ¶
Matte constructs a material with Lambertian ("diffuse") reflectance. E.g.: plaster, paper, rubber.
The texture determines the reflectivity in each point ("diffuse map"). It should be between 0 and 1 (in each color channel), for physicaly possible materials.
See https://en.wikipedia.org/wiki/Lambertian_reflectance.
The ray tracing algorithm implemented here is a flavour of bidirectional path tracing: A ray is shot forward from the camera onto the scene. When it hits a matte surface, we gather the light from all light sources to give the direct illumination. To that we add the (appropriately weighted) contribution of one random ray. This gives the indirect illumination. The random ray's color is determined recurively, thus again taking into account all light sources, etc. (up to a maximum depth).
E.g. in the sketch below, Ray a goes from the camera to a matte surface. At the intersection point we take into account the intensity of the light (properly checking for shadows, of course). To this we add the brightness seen by a properly chosen random ray b. This brightness again contains a contribution of the light source at the point where ray b intersects a matter surface, and so on.
light | \ | \ # | v # cam | / # \ | /b # a\ v / # ###############
This separation of direct and indirect illumination causes significantly faster convergence for the common case of relatively small light sources.
func ReflectFresnel ¶
func ReflectFresnel(n float64, transmitted Material) Material
ReflectFresnel is a transparent material with index of refraction n, on top of material transmitted. E.g. a wet or varnished material. This looks similar to simple reflection, but reflection is stronger under grazing incidence. E.g.:
ReflectFresnel(1.33, BLACK) // a thin film of water on a black surface ReflectFresnel(1.33, Diffuse(WHITE)) // milk ReflectFresnel(20, BLACK) // metal
func Reflective ¶
func Reflective(c Color) Material
A Reflective surface. E.g.:
Reflective(WHITE) // perfectly reflective, looks like shiny metal Reflective(WHITE.EV(-1)) // 50% reflective, looks like darker metal Reflective(RED) // Reflects only red, looks like metal in transparent red candy-wrap.
func Refractive ¶
func Refractive(n float64) Material
func Refractive2 ¶
func Refractive2(n1, n2 float64) Material
Refractive material with index of refraction n1 outside and n2 inside. E.g.:
Refractive2(1, 1.5) // glass in air Refractive2(1.5, 1) // air in glass
func Shiny ¶
Shiny is shorthand for Blend-ing diffuse + reflection, e.g.: Shiny(WHITE, 0.1) // a white billiard ball, 10% specular reflection
func Transparent ¶
TODO: always consume recursion