©Anton Podvalny

Table of Contents

Introduction & overview of lights


Good lighting is the most important thing for getting good photorealistic renders. It also affects image noise and performance. Some lights render faster and with less noise than others. Things that may affect noise and performance of lights are: having a texture instead of flat color; having a complex mesh; being an area light with small relative size.

We have a few photorealistic lights in V-Ray. In the first chapter we'll cover the Rectangular light.

Almost all of them have some common parameters:

  • Color, Color temperature (except SunLight, which calculates these using a realistic model)
  • Intensity (except SunLight which has multiplier)
  • Subdivs (except LightAmbient) - this parameter controls the number of samples when sampling the light, along with the DMC sampler settings.
  • Affect diffuse/specular (except LightAmbient) - we can exclude certain lamps from contributing to the diffuse/specular lighted objects.
  • Cast shadows (except LightAmbient) - we can exclude a lamp from the calculation of shadows.
  • Include/Exclude lists - we can exclude certain objects from being lit by this lamp.

The area lights are represented in the scene as objects, but can be invisible.

Rectangle light


Here's a picture of a textured rectangle light:

 

It can be rounded to a disc shape and also textured. The idea behind texturing a light is to simulate the imperfections of a real world light, instead of having solid color light among the whole light surface. Even studio softboxes are not perfect and their light contains darker spots in certain places. One can find textures of different softboxes online.

The texture files are re-sampled at a resolution controlled by a tex_resolution parameter which has a default value of 512 for dome and rectangle and 256 for mesh lights. So if the light texture looks too pixelated, especially on the dome environment, try increasing this resolution. This will of course increase memory usage and render time slightly.

Light parameters


Here's a list of the LightRectangle parameters. Most of them are common for all area lights:

  • enabled - true if the light is casting light (turned on) and false otherwise; it only makes sense to use this parameter if it is animated, or if another object depends on this node but it must not be rendered
  • transform - Transform in the scene
  • color - Color of the light
  • color_tex - A color texture that if present will override the color parameter
  • affectDiffuse - True if the light produces diffuse lighting and false otherwise.
  • affectSpecular - True if the light produces specular hilights and false otherwise.
  • affectAtmospherics - True if the light affects atmospheric effects.
  • diffuse_contribution - Diffuse contribution for the light.
  • specular_contribution - Specular contribution for the light.
  • atmospherics_contribution - Contribution of the light to atmospheric effects.
  • use_global_light_level - true if the light should use the global light level setting
  • bumped_below_surface_check - True if the bumped normal should be used to check if the light direction is below the surface.
  • nsamples - Number of parameter samples for motion blur.
  • shadows - true if the light casts shadows and false otherwise
  • shadowColor - The shadow color. Anything but black is not physically accurate.
  • shadowColor_tex - A color texture that if present will override the shadowColor parameter
  • shadowBias - Shadow offset from the surface. Helps to prevent polygonal shadow artifacts on low-poly surfaces.
  • photonSubdivs - Determines the number of photons emitted by this light when calculating the Global Photon Map. 1000 subdivs equal 1 million photons.
  • causticSubdivs - Determines the number of photons emitted by this light when calculating the Caustics Photon Map. 1000 subdivs equal 1 million photons.
  • diffuseMult - Multiplier for the diffuse photons.
  • causticMult - Multiplier for the caustics photons.
  • cutoffThreshold - Light cut-off threshold (speed optimization). If the light intensity for a point is below this threshold, the light will not be computed.
  • channels - Render channels the result of this light will be written to
  • channels_raw - Render channels the raw diffuse result of this light will be written to
  • channels_diffuse - Render channels the diffuse result of this light will be written to
  • channels_specular - Render channels the specular result of this light will be written to
  • channels_full - Render channels the full (direct+indirect) result of this light will be written to
  • units - Units for the intensity. Using correct units is essential when you are using the CameraPhysical. The light will automatically take the scene units scale into consideration to produce the correct result for the scale you are working with. The possible values are:
    • 0 - default - The color and multiplier directly determine the visible color of the light without any conversion. The light surface will appear with the given color in the final image when seen directly by the camera (assuming there is no color mapping involved).
    • 1 - lumens - Total emitted visible light power measured in lumens. When this setting is used, the intensity of the light will not depend on its size. A typical 100W electric bulb emits about 1500 lumens of light.
    • 2 - lm/m/m/sr - Visible light surface power measured in lumens per square meter per steradian. When this setting is used, the intensity of the light depends on its size.
    • 3 - watts - Total emitted visible light power measured in watts. When using this setting, the intensity of the light does not depend on its size. Keep in mind that this is not the same as the electric power consumed by a light bulb for example. A typical 100W light bulb only emits between 2 and 3 watts as visible light.
    • 4 - w/m/m/sr - Visible light surface power measured in watts per square meter per steradian. When this setting is used, the intensity of the light depends on its size.
  • intensity - Light intensity
  • intensity_tex - A float texture that if present will override the intensity parameter
  • subdivs - Number of samples that will be taken from this light
  • invisible - True if the light is NOT directly visible from the camera and false otherwise.
  • occludeLights - When enabled, the light will occlude other lights for shadow, GI and reflection rays when it's invisible
  • storeWithIrradianceMap - When this option is on and GI calculation is set to Irradiance map V-Ray will calculate the effects of this light and store them in the irradiance map. The result is that the irradiance map is computed more slowly but the rendering takes less time. You can also save the irradiance map and reuse it later.
  • affectReflections - True if the light appears in reflections and false otherwise.
  • noDecay - When enabled, the intensity of the light will have no fall off with distance. Normally the light intensity is inversely proportional to the square of the distance from the light (surfaces that are farther from the light are darker than surfaces which are closer to the light).
  • doubleSided - Whether the light emits in both sides
  • lightPortal - Specifies if the light is a portal light (0 - normal light, 1 - portal light, 2 - simple portal light)
  • objectID - Object ID for use by shaders, render elements, etc.
  • useMIS - This parameter is for debugging only. It should always be set to true in user scenes. When set to false, rendering quality is not optimal.
  • is_disc - The light is disc shaped
  • u_size - The u dimension of the light (actually half-width)
  • v_size - The v dimension of the light (actually half-height)
  • directional - Narrow the spread of the lighting and make the light directional
  • ignoreLightNormals - Normally, the surface of the source emits light equally in all directions. When this option is off, more light is emitted in the direction of the source surface normal.
  • rect_tex - The light texture
  • use_rect_tex - True if the texture should be used
  • tex_resolution - The texture presampling resolution
  • tex_adaptive - The adaptivity of the sampling to the texture brightness (0.0 - no adaptivity; 1.0 - full adaptivity)

 

Example


Here we'll show how to add a textured LightRectangle to a scene.

 

# Compatibility with Python 2.7.
from __future__ import print_function
# The directory containing the vray shared object should be present in the PYTHONPATH environment variable.
# Try to import the vray module from VRAY_SDK/python, if it is not in PYTHONPATH
import sys, os
VRAY_SDK = os.environ.get('VRAY_SDK')
if VRAY_SDK:
    sys.path.append(os.path.join(VRAY_SDK, 'python'))
import vray

SCENE_PATH = os.path.join(os.environ.get('VRAY_SDK'), 'scenes')
# Change process working directory to SCENE_PATH in order to be able to load relative scene resources.
os.chdir(SCENE_PATH)

# The renderer is automatically closed after the `with` block.
with vray.VRayRenderer() as renderer:
    # Register a simple log callback. Always useful for debugging.
    def dumpMsg(renderer, message, level, instant):
        if level == vray.LOGLEVEL_ERROR:
            print("[ERROR]", message)
        elif level == vray.LOGLEVEL_WARNING:
            print("[Warning]", message)
        elif level == vray.LOGLEVEL_INFO:
            print("[info]", message)
        # Uncomment for testing, but you might want to ignore these in real code
        #else: print("[debug]", message)
    renderer.setOnLogMessage(dumpMsg)
    # Load scene from a file.
    renderer.load(os.path.join(SCENE_PATH, 'lighting.vrscene'))
    # Remove original light source from the scene.
    del renderer.plugins["VRayLightDomeShape1"]
    texture = renderer.classes.TexRamp()
    # Specify the type of the Ramp texture.
    # Possible values are: 0 (V), 1 (U), 2 (U+V)/2, 3 (radial)
    #   4 (circular), 5 (box), 6 (UV), 7 (four corner), 8 (tartan)
    texture.type = 1
    # Specify colors of the texture.
    texture.colors = [
        vray.AColor(1, 0, 0, 1),
        vray.AColor(0, 1, 0, 1),
        vray.AColor(0, 0, 1, 1)
    ]
    # Specify positions for the colors.
    texture.positions = [0, 0.5, 1]
    # LightRectangle is a light source plugin that can be used to create physically accurate area lights.
    light = renderer.classes.LightRectangle()
    # Specify the light position, rotation and scale.
    light.transform = vray.Transform(
        vray.Matrix(
            vray.Vector(1, 0, 0),
            vray.Vector(0, 1, 0),
            vray.Vector(0, 0, 1)),
        vray.Vector(140.7293296245155, 56.40836324071937, 177.7345080979719))
    # Specify shadow offset from the surface. Helps to prevent polygonal shadow artifacts on low-poly surfaces.
    light.shadowBias = 0.02
    # Specify that the bumped normal should be used to check if the light direction is below the surface.
    light.bumped_below_surface_check = True
    # Specify the light intensity based on the 'units' parameter.
    light.intensity = 30
    # Specify the U dimension of the light (actually half-width).
    light.u_size = 40
    # Specify the V dimension of the light (actually half-height).
    light.v_size = 40
    # Specify the light texture.
    light.rect_tex = texture
    # Specify the use of a light texture. If "use_rect_tex = False" the 'color' of the light will be used instead.
    light.use_rect_tex = True
    # Start rendering.
    renderer.startSync()
    # Wait for rendering to end.
    renderer.waitForRenderEnd()
#define VRAY_RUNTIME_LOAD_PRIMARY
#include "vraysdk.hpp"
#include "vrayplugins.hpp"
#include "utils.h"

using namespace VRay;
using namespace VRay::Plugins;
using namespace std;

const char *BASE_PATH = getenv("VRAY_SDK");
string SCENE_PATH = (BASE_PATH ? string(BASE_PATH) : string(".")) + PATH_DELIMITER + "scenes";

int main() {
	// Change process working directory to SCENE_PATH in order to be able to load relative scene resources.
	changeCurrentDir(SCENE_PATH.c_str());
	// Load V-Ray SDK library.
	VRayInit init(NULL, true);
	// Create an instance of VRayRenderer with default options.
	// The renderer is automatically closed at the end of the current scope.
	VRayRenderer renderer;
	// It's recommended to always have a console log
	renderer.setOnLogMessage(logMessage);
	// Load scene from a file.
	renderer.load("lighting.vrscene");
	// Remove original light source from the scene.
	renderer.deletePlugin("VRayLightDomeShape1");
	TexRamp texture = renderer.newPlugin<TexRamp>();
	// Specify the type of the Ramp texture.
	// Possible values are:
	//   0 (V) - default, 1 (U), 2 (U + V) / 2, 3 (radial)
	//   4 (circular), 5 (box), 6 (UV), 7 (four corner), 8 (tartan)
	texture.set_type(1);
	// Specify colors of the texture.
	ValueList colors;
	colors.push_back(Value(AColor(1.0, 0.0, 0.0, 1.0)));
	colors.push_back(Value(AColor(0.0, 1.0, 0.0, 1.0)));
	colors.push_back(Value(AColor(0.0, 0.0, 1.0, 1.0)));
	texture.set_colors(colors);
	// Specify positions for the colors.
	ValueList positions;
	positions.push_back(Value(0));
	positions.push_back(Value(0.5f));
	positions.push_back(Value(1));
	texture.set_positions(positions);
	// LightRectangle is a light source plugin that can be used to create physically accurate area lights.
	LightRectangle light = renderer.newPlugin<LightRectangle>();
	// Specify the light position, rotation and scale.
	light.set_transform(Transform(
		Matrix(
			Vector(1.0, 0.0, 0.0),
			Vector(0.0, 1.0, 0.0),
			Vector(0.0, 0.0, 1.0)),
		Vector(140.7293296245155, 56.40836324071937, 177.7345080979719)));
	// Specify shadow offset from the surface. Helps to prevent polygonal shadow artifacts on low-poly surfaces.
	light.set_shadowBias(0.02f);
	// Specify that the bumped normal should be used to check if the light direction is below the surface.
	light.set_bumped_below_surface_check(true);
	// Specify the light intensity based on the 'units' parameter.
	light.set_intensity(30);
	// Specify the U dimension of the light (actually half-width).
	light.set_u_size(40);
	// Specify the V dimension of the light (actually half-height).
	light.set_v_size(40);
	// Specify the light texture.
	light.set_rect_tex(texture);
	// Specify the use of a light texture.
	// If "use_rect_tex = false" the 'color' of the light will be used instead.
	light.set_use_rect_tex(true);
	// Start rendering.
	renderer.startSync();
	// Wait for rendering to end.
	renderer.waitForRenderEnd();
	return 0;
}
using System;
using System.Collections.Generic;
using System.IO;
using VRay;
using VRay.Plugins;

namespace _texture
{
    class Program
    {
        static void Main(string[] args)
        {
            string SCENE_PATH = Path.Combine(Environment.GetEnvironmentVariable("VRAY_SDK"), "scenes");
            // Change process working directory to SCENE_PATH in order to be able to load relative scene resources.
            Directory.SetCurrentDirectory(SCENE_PATH);

            // Create an instance of VRayRenderer with default options. The renderer is automatically closed after the `using` block.
			using (VRayRenderer renderer = new VRayRenderer())
            {
                // Add a listener for any type of log message.
                renderer.LogMessage += new EventHandler<MessageEventArgs>((source, e) =>
                {
                    // You can remove the if for testing, but you might want to ignore Debug in real code
                    if (e.LogLevel != LogLevelType.Debug)
                    {
                        Console.WriteLine(String.Format("[{0}] {1}", e.LogLevel.ToString(), e.Message));
                    }
                });
                // Load scene from a file.
                renderer.Load("lighting.vrscene");
                // Remove original light source from the scene.
                renderer.DeletePlugin("VRayLightDomeShape1");
                TexRamp texture = renderer.NewPlugin<TexRamp>();
                // Specify the type of the Ramp texture.
                // Possible values are: 0 (V), 1 (U), 2 (U+V)/2, 3 (radial)
                //   4 (circular), 5 (box), 6 (UV), 7 (four corner), 8 (tartan)
                texture.TexRampType = 1;
                // Specify colors of the texture.
                texture.Colors = new List<object>() {
                    new AColor(1, 0, 0, 1),
                    new AColor(0, 1, 0, 1),
                    new AColor(0, 0, 1, 1)
                };
                // Specify positions for the colors.
                texture.Positions = new List<object>() { 0, 0.5, 1 };
                // LightRectangle is a light source plugin that can be used to create physically accurate area lights.
                LightRectangle light = renderer.NewPlugin<LightRectangle>();
                // Specify the light position, rotation and scale.
                light.Transform = new Transform(
                    new Matrix(
                        new Vector(1, 0, 0),
                        new Vector(0, 1, 0),
                        new Vector(0, 0, 1)),
                    new Vector(140.7293296245155, 56.40836324071937, 177.7345080979719));
                // Specify shadow offset from the surface. Helps to prevent polygonal shadow artifacts on low-poly surfaces.
                light.ShadowBias = 0.02F;
                // Specify that the bumped normal should be used to check if the light direction is below the surface.
                light.BumpedBelowSurfaceCheck = true;
                // Specify the number of parameter samples for motion blur.
                light.Nsamples = 1;
                // Specify the light intensity based on the 'units' parameter.
                light.Intensity = 30;
                // Specify the U dimension of the light (actually half-width).
                light.USize = 40;
                // Specify the V dimension of the light (actually half-height).
                light.VSize = 40;
                // Specify the light texture.
                light.RectTex = texture;
                // Specify the use of a light texture.
                // If "use_rect_tex = false" the 'color' of the light will be used instead.
                light.UseRectTex = true;
                // Start rendering.
                renderer.StartSync();
                // Wait for rendering to end.
                renderer.WaitForRenderEnd();
            }
        }
    }
}
var path = require('path');
var vray = require(path.join(process.env.VRAY_SDK, 'node', 'vray'));

var SCENE_PATH = path.join(process.env.VRAY_SDK, 'scenes');
// Change process working directory to SCENE_PATH in order to be able to load relative scene resources.
process.chdir(SCENE_PATH);

// Create an instance of VRayRenderer with default options.
var renderer = vray.VRayRenderer();
// It's recommended to always have a console log callback
renderer.on("logMessage", function(message, level, instant) {
	if (level == vray.LOGLEVEL_ERROR)
		console.log("[ERROR] ", message);
	else if (level == vray.LOGLEVEL_WARNING)
		console.log("[Warning] ", message);
	else if (level == vray.LOGLEVEL_INFO)
		console.log("[info] ", message);
	// Uncomment for testing, but you might want to ignore these in real code
	//else console.log("[debug] ", message);
});

// Load scene from a file asynchronously.
renderer.load("lighting.vrscene", function(err) {
    if (err) throw err;
    // Remove original light source from the scene.
    delete renderer.plugins["VRayLightDomeShape1"];
    var texture = renderer.classes.TexRamp();
    // Specify the type of the Ramp texture.
    // Possible values are: 0 (V), 1 (U), 2 (U+V)/2, 3 (radial)
    //   4 (circular), 5 (box), 6 (UV), 7 (four corner), 8 (tartan)
    texture.type = 1;
    // Specify colors of the texture.
    texture.colors = vray.List(
        vray.AColor(1, 0, 0, 1),
        vray.AColor(0, 1, 0, 1),
        vray.AColor(0, 0, 1, 1)
    );
    // Specify positions for the colors.
    texture.positions = vray.List(0, 0.5, 1);
    // LightRectangle is a light source plugin that can be used to create physically accurate area lights.
    var light = renderer.classes.LightRectangle();
    // Specify the light position, rotation and scale.
    light.transform = vray.Transform(
        vray.Matrix(
            vray.Vector(1, 0, 0),
            vray.Vector(0, 1, 0),
            vray.Vector(0, 0, 1)),
        vray.Vector(140.7293296245155, 56.40836324071937, 177.7345080979719));
    // Specify shadow offset from the surface. Helps to prevent polygonal shadow artifacts on low-poly surfaces.
    light.shadowBias = 0.02;
    // Specify that the bumped normal should be used to check if the light direction is below the surface.
    light.bumped_below_surface_check = true;
    // Specify the light intensity based on the 'units' parameter.
    light.intensity = 30;
    // Specify the U dimension of the light (actually half-width).
    light.u_size = 40;
    // Specify the V dimension of the light (actually half-height).
    light.v_size = 40;
    // Specify the light texture.
    light.rect_tex = texture;
    // Specify the use of a light texture. If "use_rect_tex = false" the 'color' of the light will be used instead.
    light.use_rect_tex = true;
    // Start rendering.
    renderer.start(function(err) {
        if (err) throw err;
        // Wait for rendering to end.
        renderer.waitForRenderEnd(function() {
            renderer.close();
        });
    });
});

Results


 

The scene used for this render is called "Lighting_Rect.vrscene" and can be found in the scene bundle (comments to the different parameters available inside).

The scene used for this render is called "Lighting_Rect_tex.vrscene" and can be found in the scene bundle (comments to the different parameters available inside).

 

The scene used for this render is called "Lighting_Rect_tex_alpha.vrscene" and can be found in the scene bundle  (comments to the different parameters available inside).
  • No labels