User Tools

Site Tools


tutorials:light-modeling-first-steps

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tutorials:light-modeling-first-steps [2025/01/08 21:58] – created MHtutorials:light-modeling-first-steps [2025/01/22 16:04] (current) MH
Line 9: Line 9:
   * GPUFlux, a GPU-based implementation   * GPUFlux, a GPU-based implementation
  
-While they are both implementing various renderer and light model implementation, they differ in a few details we are not gonna be discuss here. 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 is able to simulate the full visible light spectrum (spectral light modelling).+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 [[:Tutorials:light-modeling-differences| 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 isbeside the three channel RGB implementationable 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.  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:
 +
 +<code java>
 +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);
 +}
 +</code>
 +
 +
 +For the GPUFlux (GPU-based) implementation:
 +
 +<code java>
 +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);
 +}
 +</code>
  
 To be continued... To be continued...
tutorials/light-modeling-first-steps.1736369915.txt.gz · Last modified: 2025/01/08 21:58 by MH