materials

package
v0.0.0-...-405cb25 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2020 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Blend

func Blend(a float64, matA Material, b float64, matB Material) Material

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

func Flat(t texture.Texture) Material

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

func Matte(t texture.Texture) Material

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

func Shiny(c texture.Texture, reflectivity float64) Material

Shiny is shorthand for Blend-ing diffuse + reflection, e.g.: Shiny(WHITE, 0.1) // a white billiard ball, 10% specular reflection

func Transparent

func Transparent(t texture.Texture, consumeRecursion bool) Material

TODO: always consume recursion

func TwoSided

func TwoSided(front, back Material) Material

A TwoSided material consists of a front-facing material (seen when looking towards the surface normal) and a back-facing material (seen when looking at the back side of the surface).

Types

type Func

type Func func(ctx *Ctx, s *Scene, r *Ray, h HitCoords) Color

func BlendMap

func BlendMap(t texture.Texture, a, b Material) Func

func (Func) Shade

func (f Func) Shade(ctx *Ctx, s *Scene, r *Ray, h HitCoords) Color

Jump to

Keyboard shortcuts

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