Method: Mittsu::ShadowMapPlugin#create_virtual_light

Defined in:
lib/mittsu/opengl/plugins/shadow_map_plugin.rb

#create_virtual_light(light, cascade) ⇒ Object



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/mittsu/opengl/plugins/shadow_map_plugin.rb', line 287

def create_virtual_light(light, cascade)
  DirectionalLight.new.tap do |virtual_light|
    virtual_light.is_virtual = true

    virtual_light.only_shadow = true
    virtual_light.cast_shadow = true

    virtual_light.shadow_camera_near = light.shadow_camera_near
    virtual_light.shadow_camera_far = light.shadow_camera_far

    virtual_light.shadow_camera_left = light.shadow_camera_left
    virtual_light.shadow_camera_right = light.shadow_camera_right
    virtual_light.shadow_camera_bottom = light.shadow_camera_bottom
    virtual_light.shadow_camera_top = light.shadow_camera_top

    virtual_light.shadow_camera_visible = light.shadow_camera_visible

    virtual_light.shadow_darkness = light.shadow_darkness

    virtual_light.shadow_darkness = light.shadow_darkness

    virtual_light.shadow_bias = light.shadow_cascade_bias[cascade]
    virtual_light.shadow_map_width = light.shadow_cascade_width[cascade]
    virtual_light.shadow_map_height = light.shadow_cascade_height[cascade]

    points_world = virtual_light.points_world = []
    points_frustum = virtual_light.points_frustum = []

    8.times do
      points_world << Vector3.new
      points_frustum << Vector3.new
    end

    near_z = light.shadow_cascade_near_z[cascade]
    far_z = light.shadow_cascade_far_z[cascade]

    points_frustum[0].set(-1.0, -1.0, near_z)
    points_frustum[1].set( 1.0, -1.0, near_z)
    points_frustum[2].set(-1.0,  1.0, near_z)
    points_frustum[3].set( 1.0,  1.0, near_z)

    points_frustum[4].set(-1.0, -1.0, far_z)
    points_frustum[5].set( 1.0, -1.0, far_z)
    points_frustum[6].set(-1.0,  1.0, far_z)
    points_frustum[7].set( 1.0,  1.0, far_z)
  end
end