User Tools

Site Tools


02_user_tutorials:04_light_modelling:light-modeling-first-steps

First steps on light modelling

This tutorial we show you the basics on how to do light modelling in GroIMP. For some more theoretical background pleas refer to the Introduction - A little bit of Theory page. For an advanced tutorial on spectral light modelling check out the Spectral light modelling tutorial.

GroIMP integrates two two main light model implementations, namely:

  • Twilight, a CPU-based implementation
  • GPUFlux, a GPU-based implementation

While they are both integrating various renderer and light model implementations, they differ in a few details we are not gonna be discuss here. Please refer to the Differences between the CPU and GPU light model page for details. The two main difference however are first that the GPU implementation is several times faster than the CPU implementation and second, that the GPU version is, beside the three channel RGB implementation, able to simulate the full visible light spectrum (spectral light modelling).

In the following, we focus on the three channel RGB versions of both the CPU and GPU implementations.

To set up a light model basically three steps are needed.

  • Definition/Initialization of the light model
  • Running the light model
  • Checking the scene objects for their light absorption

In GroIMP/XL, this can be done as following:

For the twilight (CPU-based) implementation:

import de.grogra.ray.physics.Spectrum;
 
//constants for the light model: number of rays and maximal recursion depth
const int RAYS = 1000000;
const int DEPTH = 10;
 
//initialize the scene
protected void init() {
 
  //create the actual 3D scene
  [
    Axiom ==> Box(0.1,1,1).(setShader(BLACK)) M(2) RL(180) 		
    LightNode.(setLight(new SpotLight().(setPower(100),setInnerAngle(0.02),setOuterAngle(0.055))));
  ]
 
  //make sure the changes on the graph are applied...
  {derive();}
  //so that we directly can continue and work on the graph
 
 
  // initialize the light model
  LightModel CPU_LM = new LightModel(RAYS, DEPTH);
 
  CPU_LM.compute(); // run the light model
 
  //check the scene objects for their light absorption
  Spectrum ms;
  [
    x:Box::> { ms = GPU_LM.getAbsorbedPower(x); }
  ]
  print("absorbed = "+ms);println(""+ms.integrate()+" = "+ms, 0xff0000);
}

For the GPUFlux (GPU-based) implementation:

import de.grogra.gpuflux.tracer.FluxLightModelTracer.MeasureMode;
import de.grogra.gpuflux.scene.experiment.Measurement;
 
//constants for the light model: number of rays and maximal recursion depth
const int RAYS = 1000000;
const int DEPTH = 10;
 
//initialize the scene
protected void init() {
 
  //create the actual 3D scene
  [
    Axiom ==> Box(0.1,1,1).(setShader(BLACK)) M(2) RL(180)
        LightNode.(setLight(new SpotLight().(setPower(100),setInnerAngle(0.02),setOuterAngle(0.055))));
  ]
 
  //make sure the changes on the graph are applied...
  {derive();}
  //so that we directly can continue and work on the graph
 
 
  // initialize the light model
  FluxLightModel GPU_LM = new FluxLightModel(RAYS, DEPTH);
  GPU_LM.setMeasureMode(MeasureMode.RGB); // user the Flux model in three channel 'RGB mode'
 
  GPU_LM.compute(); // run the light model
 
  //check the scene objects for their light absorption
  Measurement ms;
  [
    x:Box::> { ms = GPU_LM.getAbsorbedPowerMeasurement(x); }
  ]
  print("absorbed = "+ms);println(""+ms.integrate()+" = "+ms, 0xff0000);
}

To be continued…

02_user_tutorials/04_light_modelling/light-modeling-first-steps.txt · Last modified: 2025/01/24 15:51 by tim2