-
Notifications
You must be signed in to change notification settings - Fork 56
Materials, Lighting and Shading
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:
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.
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.
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.
If might look like overkill, but a single render pixel of a geometry like a [Cube] mixes the following colors:
- Its vertex-color set by the [Cube]-Operator
- The material-color set by the closest [Material]
.Diffuse
-Parameter - The added color defined by all the [PointLight]s above
- 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.
- The alpha-Component of the Material-Diffuse color defines the transparency of the object. All other alpha-values are ignored.
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.
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.
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.
There are tons of potential reasons for this:
- Do you look into the right direction? Selec the render view and press "F" to reset the view.
- 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.
- Did you add a [PhongShader] but no [PointLights]?
- Is the PointLight attenuation too high?
- Is your geometry facing away? -> Add a WireFrameShader above your geometry to check.
- Is the Fog-Setting too high? -> Add a Fog Operator above your geometry.