Class: Mittsu::DirectionalLight

Inherits:
Light show all
Defined in:
lib/mittsu/lights/directional_light.rb,
lib/mittsu/renderers/opengl/lights/directional_light.rb

Defined Under Namespace

Classes: Cache

Constant Summary collapse

TYPE =
:directional

Constants inherited from Object3D

Object3D::DefaultUp

Instance Attribute Summary collapse

Attributes inherited from Light

#camera_helper, #color, #distance, #intensity, #only_shadow

Attributes inherited from Object3D

#active, #children, #frustum_culled, #geometry, #id, #initted, #matrix, #matrix_auto_update, #matrix_world, #matrix_world_needs_update, #model_view_matrix, #morph_target_influences, #name, #parent, #position, #quaternion, #receive_shadow, #render_order, #renderer, #rotation, #rotation_auto_update, #scale, #type, #up, #user_data, #uuid, #visible

Instance Method Summary collapse

Methods inherited from Light

null_remaining_lights, #project, #setup, #type

Methods inherited from Object3D

#active?, #add, #add_opengl_object, #apply_matrix, #buffer_material, #deinit, #get_object_by_id, #get_object_by_name, #get_object_by_property, #get_world_direction, #get_world_position, #get_world_quaternion, #get_world_rotation, #get_world_scale, #init, #init_geometry, #load_uniforms_matrices, #local_to_world, #look_at, #print_tree, #project, #raycast, #remove, #rotate_on_axis, #rotate_x, #rotate_y, #rotate_z, #set_rotation_from_axis_angle, #set_rotation_from_euler, #set_rotation_from_matrix, #set_rotation_from_quaternion, #setup_matrices, #to_json, #to_s, #translate_on_axis, #translate_x, #translate_y, #translate_z, #traverse, #traverse_ancestors, #traverse_visible, #update_matrix, #update_matrix_world, #world_to_local

Methods included from EventDispatcher

#add_event_listener, #dispatch_event, #has_event_listener, #remove_event_listener

Constructor Details

#initialize(color = nil, intensity = 1.0) ⇒ DirectionalLight

Returns a new instance of DirectionalLight.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/mittsu/lights/directional_light.rb', line 32

def initialize(color = nil, intensity = 1.0)
  super(color)

  @type = 'DirectionalLight'

  @position.set(0.0, 1.0, 0.0)
  @target = Object3D.new

  @intensity = intensity

  @cast_shadow = false
  @only_shadow = false

  #

  @shadow_camera_near = 50.0
  @shadow_camera_far = 5000.0

  @shadow_camera_left = -500.0
  @shadow_camera_right = 500.0
  @shadow_camera_top = 500.0
  @shadow_camera_bottom = -500.0

  @shadow_camera_visible = false

  @shadow_bias = 0
  @shadow_darkness = 0.5

  @shadow_map_width = 512
  @shadow_map_height = 512

  #

  @shadow_cascade = false

  @shadow_cascade_offset = Vector3.new(0.0, 0.0, -1000.0)
  @shadow_cascade_count = 2

  @shadow_cascade_bias = [0, 0, 0]
  @shadow_cascade_width = [512, 512, 512]
  @shadow_cascade_height = [512, 512, 512]

  @shadow_cascade_near_z = [-1.000, 0.990, 0.998]
  @shadow_cascade_far_z  = [0.990, 0.998, 1.000]

  @shadow_cascade_array = []

  #

  @shadow_map = nil
  @shadow_map_size = nil
  @shadow_camera = nil
  @shadow_matrix = nil
end

Instance Attribute Details

#cast_shadowObject

Returns the value of attribute cast_shadow.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def cast_shadow
  @cast_shadow
end

#shadow_biasObject

Returns the value of attribute shadow_bias.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_bias
  @shadow_bias
end

#shadow_cameraObject

Returns the value of attribute shadow_camera.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_camera
  @shadow_camera
end

#shadow_camera_bottomObject

Returns the value of attribute shadow_camera_bottom.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_camera_bottom
  @shadow_camera_bottom
end

#shadow_camera_farObject

Returns the value of attribute shadow_camera_far.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_camera_far
  @shadow_camera_far
end

#shadow_camera_leftObject

Returns the value of attribute shadow_camera_left.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_camera_left
  @shadow_camera_left
end

#shadow_camera_nearObject

Returns the value of attribute shadow_camera_near.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_camera_near
  @shadow_camera_near
end

#shadow_camera_rightObject

Returns the value of attribute shadow_camera_right.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_camera_right
  @shadow_camera_right
end

#shadow_camera_topObject

Returns the value of attribute shadow_camera_top.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_camera_top
  @shadow_camera_top
end

#shadow_camera_visibleObject

Returns the value of attribute shadow_camera_visible.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_camera_visible
  @shadow_camera_visible
end

#shadow_cascadeObject

Returns the value of attribute shadow_cascade.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_cascade
  @shadow_cascade
end

#shadow_cascade_arrayObject

Returns the value of attribute shadow_cascade_array.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_cascade_array
  @shadow_cascade_array
end

#shadow_cascade_biasObject

Returns the value of attribute shadow_cascade_bias.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_cascade_bias
  @shadow_cascade_bias
end

#shadow_cascade_countObject

Returns the value of attribute shadow_cascade_count.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_cascade_count
  @shadow_cascade_count
end

#shadow_cascade_far_zObject

Returns the value of attribute shadow_cascade_far_z.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_cascade_far_z
  @shadow_cascade_far_z
end

#shadow_cascade_heightObject

Returns the value of attribute shadow_cascade_height.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_cascade_height
  @shadow_cascade_height
end

#shadow_cascade_near_zObject

Returns the value of attribute shadow_cascade_near_z.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_cascade_near_z
  @shadow_cascade_near_z
end

#shadow_cascade_offsetObject

Returns the value of attribute shadow_cascade_offset.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_cascade_offset
  @shadow_cascade_offset
end

#shadow_cascade_widthObject

Returns the value of attribute shadow_cascade_width.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_cascade_width
  @shadow_cascade_width
end

#shadow_darknessObject

Returns the value of attribute shadow_darkness.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_darkness
  @shadow_darkness
end

#shadow_mapObject

Returns the value of attribute shadow_map.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_map
  @shadow_map
end

#shadow_map_heightObject

Returns the value of attribute shadow_map_height.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_map_height
  @shadow_map_height
end

#shadow_map_sizeObject

Returns the value of attribute shadow_map_size.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_map_size
  @shadow_map_size
end

#shadow_map_widthObject

Returns the value of attribute shadow_map_width.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_map_width
  @shadow_map_width
end

#shadow_matrixObject

Returns the value of attribute shadow_matrix.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def shadow_matrix
  @shadow_matrix
end

#targetObject

Returns the value of attribute target.



5
6
7
# File 'lib/mittsu/lights/directional_light.rb', line 5

def target
  @target
end

Instance Method Details

#cloneObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/mittsu/lights/directional_light.rb', line 87

def clone
  light = DirectionalLight.new
  super(light)

  light.target = @target.clone

  light.intensity = @intensity

  light.cast_shadow = @cast_shadow
  light.only_shadow = @only_shadow

  #

  light.shadow_camera_near = @shadow_camera_near
  light.shadow_camera_far = @shadow_camera_far

  light.shadow_camera_left = @shadow_camera_left
  light.shadow_camera_right = @shadow_camera_right
  light.shadow_camera_top = @shadow_camera_top
  light.shadow_camera_bottom = @shadow_camera_bottom

  light.shadow_camera_visible = @shadow_camera_visible

  light.shadow_bias = @shadow_bias
  light.shadow_darkness = @shadow_darkness

  light.shadow_map_width = @shadow_map_width
  light.shadow_map_height = @shadow_map_height

  #

  light.shadow_cascade = @shadow_cascade

  light.shadow_cascade_offset.copy(@shadow_cascade_offset)
  light.shadow_cascade_count = @shadow_cascade_count

  light.shadow_cascade_bias = @shadow_cascade_bias.dup
  light.shadow_cascade_width = @shadow_cascade_width.dup
  light.shadow_cascade_height = @shadow_cascade_height.dup

  light.shadow_cascade_near_z = @shadow_cascade_near_z.dup
  light.shadow_cascade_far_z  = @shadow_cascade_far_z.dup
end

#setup_specific(index) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mittsu/renderers/opengl/lights/directional_light.rb', line 15

def setup_specific(index)
  offset = index * 3

  @_direction.set_from_matrix_position(matrix_world)
  @_vector3.set_from_matrix_position(target.matrix_world)
  @_direction.sub(@_vector3)
  @_direction.normalize

  positions = @cache.positions
  positions[offset]     = @_direction.x
  positions[offset + 1] = @_direction.y
  positions[offset + 2] = @_direction.z

  OpenGLHelper.set_color_linear(@cache.colors, offset, color, intensity)
end

#to_symObject



31
32
33
# File 'lib/mittsu/renderers/opengl/lights/directional_light.rb', line 31

def to_sym
  :directional
end

#virtual?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/mittsu/lights/directional_light.rb', line 131

def virtual?
  false
end