Method: Mittsu::ShadowMapPlugin#update_shadow_camera

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

#update_shadow_camera(camera, light) ⇒ Object

fit shadow camera’s ortho frustum to camera frustum



368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# File 'lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb', line 368

def update_shadow_camera(camera, light)
  shadow_camera = light.shadow_camera
  points_frustum = light.pointa_frustum
  points_world = light.points_world

  @min.set(Float::INFINITY, Float::INFINITY, Float::INFINITY)
  @max.set(-Float::INFINITY, -Float::INFINITY, -Float::INFINITY)

  8.times do |i|
    p = points_world[i]

    p.copy(points_frustum[i])
    p.unproject(camera)

    p.apply_matrix4(shadow_camera.matrix_world_inverse)

    @min.x = p.x if (p.x < @min.x)
    @max.x = p.x if (p.x > @max.x)

    @min.y = p.y if (p.y < @min.y)
    @max.y = p.y if (p.y > @max.y)

    @min.z = p.z if (p.z < @min.z)
    @max.z = p.z if (p.z > @max.z)
  end

  shadow_camera.left = @min.x
  shadow_camera.right = @max.x
  shadow_camera.top = @max.y
  shadow_camera.bottom = @min.y

  # can't really fit near/far
  # shadow_camera.near = @min.x
  # shadow_camera.far = @max.z

  shadow_camera.update_projection_matrix
end