Tuesday, June 19, 2012

Lights in Gladius

‹prev | My Chain | next›

With an improved understanding of transforms in Gladius and CubicVR.js, I turn my attention instead to light sources.

I have removed a revolving light source leaving only the one defined along with the camera:
    space.add( new engine.simulation.Entity( "camera",
      [
        new engine.core.Transform( [0, 0, 0] ),
        new cubicvr.Camera({
          targeted: true
        }),
        new cubicvr.Light()
      ]
    ));
When the objects are close up (3 units away), the light is fairly bright:



When I double the distance, the reflection off the surfaces is significantly dimmed:



And when I move the objects 20 units away, the reflection from the light is very dim indeed:



All of that is to be expected, of course. The further objects in the real world are from a light, the harder they are to be seen. But, I the light source is made brighter:
    space.add( new engine.simulation.Entity( "camera",
      [
        new engine.core.Transform( [0, 1, -1] ),
        new cubicvr.Camera({
          targeted: true
        }),
        new cubicvr.Light({
          direction: [1,1,-1],
          type: "area",
          distance: 20.0,
          intensity: 200.0
        })
      ]
    ));
Then even the distant objects should be much brighter. Except there is no change:



I am at a loss to explain this. Fiddling with any CubicVR Light and Camera seemingly has no effect. Perhaps this has something to do with being the first light / camera added?

To answer that, I can add another light. The trouble is, if I continue to add lights with the same constructor arguments as above, there is no change. So I borrow from the light definition in the original Gladius samples, which use a second class LightDefinition:
    var lightDefinition = new cubicvr.LightDefinition({
      intensity: 20,
      distance: 20,
      light_type: cubicvr.LightDefinition.LightTypes.POINT,
      method: cubicvr.LightDefinition.LightingMethods.DYNAMIC
    })

    space.add( new engine.simulation.Entity( "camera",
      [
        new engine.core.Transform( [0, 0, 0] ),
        new cubicvr.Camera({
          targeted: true
        }),
        new cubicvr.Light( lightDefinition )
      ]
    ));
With that, I finally get my faraway planets nice and shiny:



And, in fact, if I add that back to the original light:
    var lightDefinition = new cubicvr.LightDefinition({
      intensity: 20,
      distance: 20,
      light_type: cubicvr.LightDefinition.LightTypes.POINT,
      method: cubicvr.LightDefinition.LightingMethods.DYNAMIC
    })

    space.add( new engine.simulation.Entity( "camera",
      [
        new engine.core.Transform( [0, 0, 0] ),
        new cubicvr.Camera({
          targeted: true
        }),
        new cubicvr.Light( lightDefinition )
      ]
    ));
Then I again get the same nice light on my faraway object. If I attempt to put those same arguments back in the Light constructor:
    space.add( new engine.simulation.Entity( "camera",
      [
        new engine.core.Transform( [0, 0, 0] ),
        new cubicvr.Camera({
          targeted: true
        }),
        new cubicvr.Light({
          intensity: 20,
          distance: 20,
          light_type: cubicvr.LightDefinition.LightTypes.POINT,
          method: cubicvr.LightDefinition.LightingMethods.DYNAMIC
        })
      ]
    ));
Then again I am back to the very dark light source only. So it seems that, in Gladius, the LightDefinition class is pretty much a requirement.

Day #422

No comments:

Post a Comment