Tutorial
3 - Lights
|
|
This tutorial assumes you have a basic
understanding of "4D Blue" functions, especially that you know how to
move, adjust and rename objects. In this tutorial we will start from an
existing simple scene and by using various lights and adjusting their
parameters see how a very different lighting situations can be created with
"4D Blue". Please be aware that lights are still being constantly
updated and in the future they are likely to change and be optimized. |
|
Step 1 - Creating or loading the simple
scene.
|
|
|
In this tutorial, you can either create your
own simple scene or preload an existing one. If you decide to create your own
scene, make sure that it has at least few objects with various materials, and
a single camera. If you decide to use the existing scene please download it
now Download "Tutorial 3" sample scene.
|
Step 2 - Light types.
|
|
|
"4D Blue" right now supports six
different light types. Some of them are fairly simple and very fast and some
can get very complicated and expensive during rendering. In the following
steps, each one of them will be explained in detail and demonstrated by an
example.
|
Step 3 - Explaining light parameters.
|
|
|
When you create a new light, the light
constructor contains 4 different tabs. The first one "General"
specifies the most important light parameters like the light type, color,
intensity, and so on. Based on the light type some of the parameters might be
enabled or disabled in all of the tabs as they are not needed or used.
-
"
|
|
-
"Cone Angle"
specifies how wide the spotlight full attenuation area is.
-
"Penumbra Angle"
specifies at what maximum angle the light attenuation falls to zero.
-
"Texture"
specifies whether the light should use a texture rather than the specified
color to illuminate the surfaces.
-
"Aspect Ratio"
and "Roll" are only used if a texture and a spotlight are
used at the same time. They control how projection texture should be
adjusted. Sometimes the projection texture is not square and the aspect ratio
needs to be adjusted, and “Roll” controls whether the texture should
be rotated and by how much.
|
|
-
"Min Samples"
controls what the minimum number of samples tested are for area lights. Sampling
area lights is a two step process. First the minimum number of samples is
tested and if all the samples are in shade or are lighted, further sampling
is not needed and the point is assumed to not be in the "penumbra"
range. Otherwise, the full number of samples is used to determine the light
attenuation at a given point. Usually “Max
Samples” should be about 4 times
more than the minimum samples number. Adjust these numbers until the quality
of the soft shadows satisfies your requirements. The more the samples, the
better the result, but the longer it takes.
-
"Size" is used
only for simple area lights that can be used with point or spot lights. It
creates a virtual sphere of the specified size and uses points on it to
evaluate the light contribution.
-
"Jitter Samples"
controls whether the samples on the sphere should be regular or randomly
picked.
-
"Poly Object" is
used for lights that are not often well defined and need to be more
constrained. It can be used with "Object Lights", "Directional
Lights", and "Sky Lights". For "Object Lights", it
specifies the light source object, while the other two lights serve as filter
- i.e. only light rays that pass through the object will illuminate the
surface. That property is very handy during Global Illumination simulations.
-
"Use Vertex Color"
specifies whether the light color or the object vertex color should be used
as a light color.
|
|
Global Illumination parameters will be
explained more in the GI Tutorial.
-
"Sample Rays"
control the number of rays that are used to sample the environment
surrounding the intersection point to evaluate the light intensity.
-
"Sky Up Vector"
specifies the direction that the sky top is pointing.
-
"Sky Lighting Model"
specifies which lighting model should be used. Sunny day and partly cloudy
day models also need additional sun direction vectors.
-
"Trace Lights Rays"
specifies whether the illumination should be evaluated by tracing rays
through the scene. It gives the best and the most accurate result, but can be
very expensive. I already have few ideas on how to speed it up in the future
but for now it is slow.
|
Step 4 - Ambient Light
|
|
|
Ambient light is used to specify the minimum
amount of light that reaches every point in the scene. It is clearly only
used when full GI simulation is not used and ambient light are in fact
disabled when Global Illumination is enabled. Ambient intensity is only
specified by the light color.
|
|
For this test adjust the color value to about
70.
|
|
The scene in the preview should look like the
one on the left image.
|
|
Here is the final rendering with only ambient
light. No shadows are present and the scene looks plain.
|
Step 5 - Point Lights
|
|
|
Unlike ambient lights, point lights are
clearly specified in the space. For this example, move the light to (1, 3,
-2). Also reduce the existing ambient light value to about 40.
|
|
Adjust the light intensity until you are
satisfied. I think a value between 3 and 6 should be a good one.
|
|
Here is the final rendering with ambient and
point light. The image clearly looks better with the objects’ shapes
being well defined. The shadows also help the eyes to clearly place the
objects in the space.
|
Step 6 - Using soft shadows with point and
spot lights.
|
|
|
Using the existing point light, adjust the
area parameters to the ones like on the left image.
|
|
The soft shadows will not be rendered until
we also turn them on in the "Rendering Setup".
|
|
The image looks almost like the previous one
with the exception that the shadows are no longer sharp. They are in fact
nicely soft.
|
Step 7 - Setting up Spot Lights.
|
|
|
Delete the ambient light as we no longer need
it. Adjust the existing point light intensity to 20 and change its type to
"Spot Light". Also set its area size back to 0 again. Then adjust
the light "Look At" vector.
|
|
The "Look At" vector specifies the
direction at which the light is pointing. A vector (-0.15, 0.5, 0.3) seems to
be pretty good.
|
|
Finally adjust the spotlight properties as
shown on the left image.
|
|
Spotlight allows us to nicely narrow down the
area where the light has an effect. They are very practical as most real life
lights are like that.
|
Step 8 - Using a projection texture.
|
|
|
Create a new "2D Bitmap" texture
and name it "Texture Bitmap". Load your favorite image map.
|
|
Set up your newly created texture in the
light constructor. You might need to select another object and then select
the light again in order for the texture to be available in the combo box (an
existing bug).
|
|
Using a texture with a spotlight can produce
very interesting light environment. A simpler black and white filter could
also be used to produce spotlights of all possible shapes.
|
Step 9 - Creating a Directional Light.
|
|
|
Directional lights are very useful for
simulating distant lights, for example, the sun. They don't have a specified
point in space, but they have a direction. Enter (-0.5, -0.5, -0.6) for the
"Look At" vector for the light.
|
|
Switch to "Directional Light".
Notice that you can no longer specify decay rate as the light intensity
doesn’t change. Adjust the intensity to 1.0
|
|
Directional Light gives very straight shadows
and no decay in the light intensity.
|
Step 10 - Creating an Object Light.
|
|
|
Object Lights use an existing object in the
scene as a light source. This way you can have lights of all kinds of shapes
and orientations. Start with creating a polygonal plane object. Use the
dimensions from the left image.
|
|
Adjust the new object positions to (0.0, 5.0,
-1.0). To make the preview look as close as possible to the final rendered
image adjust the light position to the center of the object also at (0.0,
5.0, -1.0). The quick D3D preview can’t handle such complex light type
so it is still using the light position even that it will not be used during
the final render.
|
|
The view from the top should look like the
one on the left image.
|
|
Set the light type to "Object
Light". Select the newly created object in the "Poly Object"
combo box. You might need to reselect the light (again a small bug). You will
need to adjust the "Min Samples" and "Max Samples" to
achieve a satisfying quality. Usually the larger the object, the more samples
are need. Our object is fairly large, and I would start with 16 and 64 for
min and max numbers.
|
|
Adjust the intensity again to 20.0
|
|
The rendered image produced good soft
shadows, but they are bit noisy. That could be reduced using more samples at
a cost of longer rendering times. As you notice, the specular highlights are
not very accurate as our light is no longer a sphere like light. The problem
is that specular highlight is a fairly artificial thing to begin with.
|
|
By changing the shaders and assigning an
ambient material to the light object, we can achieve more realistic specular
highlights. But that would be beyond the scope of this tutorial.
|
Step 11 - Sky Lights
|
|
|
Sky Lights work by sampling a hemisphere
above the surface point and evaluating the light contribution from all
directions on that hemisphere. There are many models used to evaluate the
value of each of the sample points on the hemisphere. Some of these methods
simulate real sun light intensity distribution, and they need a direction
vector to the sun. Always place sky light at the origin. Then adjust the
"Look At" Point to point in the direction of the sun.
|
|
Experiment with different sky light types and
see how they work. For some you might need to adjust the intensity of the
light until you achieve a desired effect.
|
|
A "Cloudy Day" Sky light.
|
|
A "Clear Sky" Sky light.
|
Step 12 - Using HDR Textures with Sky Lights.
|
|
|
For this step you will need a HDR light
probe. They are fairly difficult to create, but fortunately a few very good
probes can be found on Paul Debevec web site: Light Probes. Install them into the
HDR directory. Once that is completed, create new HDR texture and name it
"Texture HDR". Load your favorite light probe. In my case, I'm
using "The Grace Cathedral".
|
|
When you load a HDR image, you can adjust the
exposure ratio which specifies how bright the image is and their gamma
correction. For light probes, it is also often helpful to reduce their
resolution to minimize the noise in the final rendered images. Set the new
texture in the "Texture" Combo box in the "Extra" tab of
the light constructor.
|
|
Here is the final rendered image. It is a bit
noisy, because we only used 64 samples. Overall, the color looks like an
average of all the colors present in the HDR image, but that is what we
expected.
|
Step 13 - Using HDR Texture on a Sky Sphere.
|
|
|
In this step, we are going to create a sphere
that will serve us as a sky sphere. Create new polygonal sphere and adjust
its constructor as shown on the left. Rename the new object as "Sky
Sphere".
|
|
In the "Nodes Toolbar", select the
new object and in the context menu select "Properties...". Then
turn off the cast shadows flag. We clearly don't want the sky sphere to cast
any shadows.
|
|
We need to create a new material for our sky
sphere. In the material editor, create new material and rename it to "Material
Sky". The material we need should not depend on the lights at all in the
scene, so we are going to use "SurfaceGI AmbientTexture" material.
Setup the material shader as shown on the left image.
|
|
Select the "Sky Sphere" object and
in the "Surfaces Toolbar", select all surfaces and flip their
normals. The sphere is after all outside and we are looking at it from its
inside.
|
|
In the light constructor, set the "Sky
Light Model" to uniform. Also enable "Trace Lights Rays" which
will force the renderer to shoot rays through the scene and recursively trace
them. This way, the caustics will be evaluated as well. The rendering now can
really take a while.
|
|
The final image should be like the one on the
left. The Sky sphere is clearly visible in reflections, and the fact that we
enabled "Trace Light Rays" gives us a nice realistic caustics on
the floor, produced by the lights passing through the glass sphere.
|