©Anton Podvalny

Table of Contents

In this chapter we'll cover another simple light source - directional light. It represents an infinite parallel light source, such as a floodlight. Its direction is determined by the rotation part of the transform matrix.

Specific parameters


The LightDirect plugin type contains all the common parameters described in the section for Light Rectangle, along with the specific ones for Light Omni (except for decay). There are two more parameters specific for the directional light:

  • 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.
  • beamRadius - Radius of the beam around the light. This only determines where photons for caustics are shot from. Set to 0.0 if you want to disable the beam.

 

Example


Here we'll show how to add a LightDirect 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"]
    # LightDirect is a light source plugin that can be used to create physically accurate lights that cast rays from a specific direction.
    light = renderer.classes.LightDirect()
    # Specify the light position, rotation and scale.
    light.transform = vray.Transform(
        vray.Matrix(
            vray.Vector(-0.9715043, -1.387779e-017, 0.2370218),
            vray.Vector(0.1674119, 0.7078983, 0.6861874),
            vray.Vector(-0.1677873, 0.7063142, -0.6877262)),
        vray.Vector(0, 107.949804287337, 0))
    # Specify the color of the light in RGB float values and alpha(1.0f)
    light.color = vray.AColor(1, 1, 1)
    # Specify the light intensity based on the 'units' parameter.
    light.intensity = 3
    # Controls the softness of the shadows. Bigger values will produce softer shadows.
    light.spreadAngle = 0.176327
    # Specify shadow offset from the surface. Helps to prevent polygonal shadow artifacts on low-poly surfaces.
    light.shadowBias = 0.02
    # 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");
	// LightDirect is a light source plugin that can be used to create physically accurate lights that cast rays from a specific direction.
	LightDirect light = renderer.newPlugin<LightDirect>();
	// Specify the light position, rotation and scale.
	light.set_transform(Transform(
		Matrix(
			Vector(-0.9715043, -1.387779e-017, 0.2370218),
			Vector(0.1674119, 0.7078983, 0.6861874),
			Vector(-0.1677873, 0.7063142, -0.6877262)),
		Vector(0.0, 107.949804287337, 0.0)));
	// Specify the color of the light in RGB float values and alpha(1.0f)
	light.set_color(AColor(1.0, 1.0, 1.0));
	// Specify the light intensity based on the 'units' parameter.
	light.set_intensity(3);
	// Controls the softness of the shadows. Bigger values will produce softer shadows.
	light.set_spreadAngle(0.176327f);
	// Specify shadow offset from the surface. Helps to prevent polygonal shadow artifacts on low-poly surfaces.
	light.set_shadowBias(0.02f);
	// Start rendering.
	renderer.startSync();
	// Wait for rendering to end.
	renderer.waitForRenderEnd();
	return 0;
}
using System;
using System.IO;
using VRay;
using VRay.Plugins;

namespace _07_direct
{
    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");
                // LightDirect is a light source plugin that can be used to create physically accurate lights that cast rays from a specific direction.
                LightDirect light = renderer.NewPlugin<LightDirect>();
                // Specify the light position, rotation and scale.
                light.Transform = new Transform(
                    new Matrix(
                        new Vector(-0.9715043, -1.387779e-017, 0.2370218),
                        new Vector(0.1674119, 0.7078983, 0.6861874),
                        new Vector(-0.1677873, 0.7063142, -0.6877262)),
                    new Vector(0, 107.949804287337, 0));
                // Specify the color of the light in RGB float values and alpha = 1.
                light.Color = new AColor(1, 1, 1);
                // Specify the light intensity based on the 'units' parameter.
                light.Intensity = 3;
                // Controls the softness of the shadows. Bigger values will produce softer shadows.
                light.SpreadAngle = 0.176327F;
                // Specify shadow offset from the surface. Helps to prevent polygonal shadow artifacts on low-poly surfaces.
                light.ShadowBias = 0.02F;
                // 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"];
    // LightDirect is a light source plugin that can be used to create physically accurate lights that cast rays from a specific direction.
    var light = renderer.classes.LightDirect();
    // Specify the light position, rotation and scale.
    light.transform = vray.Transform(
        vray.Matrix(
            vray.Vector(-0.9715043, -1.387779e-017, 0.2370218),
            vray.Vector(0.1674119, 0.7078983, 0.6861874),
            vray.Vector(-0.1677873, 0.7063142, -0.6877262)),
        vray.Vector(0, 107.949804287337, 0));
    // Specify the color of the light in RGB float values and alpha(1.0f)
    light.color = vray.AColor(1, 1, 1);
    // Specify the light intensity based on the 'units' parameter.
    light.intensity = 3;
    // Controls the softness of the shadows. Bigger values will produce softer shadows.
    light.spreadAngle = 0.176327;
    // Specify shadow offset from the surface. Helps to prevent polygonal shadow artifacts on low-poly surfaces.
    light.shadowBias = 0.02;
    // Start rendering.
    renderer.start(function(err) {
        if (err) throw err;
        // Wait for rendering to end.
        renderer.waitForRenderEnd(function() {
            renderer.close();
        });
    });
});

Result



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

As you can notice, the directional light produces a lot of noise initialy.

  • No labels