Skip to content

Materials, Lighting and Shading

Thomas Mann edited this page Mar 29, 2016 · 1 revision

Watch this tutorial

Watch Tutorial


Keep Reading

Tooll is meant to be as flexible as possible. Sometimes, however, this comes with a cost of complexity. Rendering and Lighting is a good example for this.

To get the most out of tooll, you have to understand some basic concepts:

Tooll uses a contextual scene-graph

When rendering a scene, tooll traverses the node-tree from top to bottom and left to right. During is, a context is filled with information of how to render geometry. This "Context" contains:

  • the [Camera]-matrix

  • the object [Transform] matrix

  • the texture [Transform] matrix

  • a list of [PointLight]s

  • [Material]-settings

  • [Fog]-settings

  • [Rasterizer]-settings

  • [DepthStencil]-settings

  • [Blend]-settings

  • [SetTexture]-assignment

  • [Shader]

The settings and the shader will be overwritten by the one closes to the geometry (e.g. furthers down). In other words, several stacked [Material]-Operator will not blend but replace each other.

Tooll has a default render setup

To avoid frustration, tooll has meaningful defaults for all of these. If no ''Shader'' is set, Tooll will use it's internal ''DefaultShader'' with two point-lights that are positioned relative to the current camera.

If you want to use your own lights, you have to insert a new [Shader]-Operator. A good choice is [PhongShader]. With this a setup-might look like this:

[Camera] [Material] [PointLight] [PointLight] [PhongShader] [Transform] [Cube]

Take a look at the [RenderScenes]-introduction.

Tooll is shader-driven

The Phong-shading model

The definition of [PointLight]s and [Material]s is derived from the standard shader model of open-gl. To be honest: it's awkward and non-intuitive. Most aspects will become obvious by playing around. Some of them, however, are not that obvious.

Why is it black? - colors affecting a geometry

If might look like overkill, but a single render pixel of a geometry like a [Cube] mixes the following colors:

  1. Its vertex-color set by the [Cube]-Operator
  2. The material-color set by the closest [Material] .Diffuse-Parameter
  3. The added color defined by all the [PointLight]s above
  4. The color in the Texture assigned with [SetTexture]

There important, and rather confusing thing that you have to keep in mind, is that these colors are multiplied. The values are defined as numbers from 0 (for black) to 1 (for light) or even greater than 1 (for – well – even brighter). And as you might remember from school, if any factor of a multiplication is 0, the result is 0: in other words: if either one of your light, material, vertex-color or texture is black, the object will be black.

Transparency

  1. The alpha-Component of the Material-Diffuse color defines the transparency of the object. All other alpha-values are ignored.

The PointLight-Paramters

The PointLight.Intensity-Parameters are a factor for the.Diffuse, .Spectral and .Emmissive colors. You can unfold the parameter group to the component-names. They can be much bigger than 1 and even be negative for some straight forward non-physically based hacking.

Attenuation

The .Attenuation-Paramaters are very important. They define how quickly the light decays with its distance from the source. The higher the values, the quicker the light-intensity is reduced:

  • Linear – getting darker slowly
  • Quadratic
  • Exponential - Light drops off extremely quickly. This gives nice lit zones around a PointLight.

But where are my point-lights?

In the render-view enable the debug-view by pressing the [Gizmo]-Button in the top right corner. This will show gizmos at the position of the lights. You increase the .GizmoSize parameter to find them easier.

Some Pitfalls

Oh no! My scene is black

There are tons of potential reasons for this:

  1. Do you look into the right direction? Selec the render view and press "F" to reset the view.
  2. Is the camera Inside your object, e.g. inside a big cube? -> Click into the view and move back with "S" or by turning the mouse-wheel.
  3. Did you add a [PhongShader] but no [PointLights]?
  4. Is the PointLight attenuation too high?
  5. Is your geometry facing away? -> Add a WireFrameShader above your geometry to check.
  6. Is the Fog-Setting too high? -> Add a Fog Operator above your geometry.