Class: RBGL::Engine::Rasterizer::AttributeInterpolator
- Inherits:
-
Object
- Object
- RBGL::Engine::Rasterizer::AttributeInterpolator
- Defined in:
- lib/rbgl/engine/rasterizer/attribute_interpolator.rb
Instance Method Summary collapse
- #interpolate(vertices, weights) ⇒ Object
- #interpolate_depth(depths, weights) ⇒ Object
- #interpolate_values(values, weights) ⇒ Object
- #perspective_correct_weights(positions, weights) ⇒ Object
Instance Method Details
#interpolate(vertices, weights) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rbgl/engine/rasterizer/attribute_interpolator.rb', line 7 def interpolate(vertices, weights) result = ShaderIO.new interpolated_keys(vertices).each do |key| values = vertices.map { |vertex| vertex[key] } next if values.any?(&:nil?) result[key] = interpolate_values(values, weights) end result end |
#interpolate_depth(depths, weights) ⇒ Object
39 40 41 |
# File 'lib/rbgl/engine/rasterizer/attribute_interpolator.rb', line 39 def interpolate_depth(depths, weights) scalar(depths, weights) end |
#interpolate_values(values, weights) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rbgl/engine/rasterizer/attribute_interpolator.rb', line 20 def interpolate_values(values, weights) first = values.first case first when Larb::Vec2 vector2(values, weights) when Larb::Vec3 vector3(values, weights) when Larb::Vec4 vector4(values, weights) when Larb::Color color(values, weights) when Numeric scalar(values, weights) else first end end |
#perspective_correct_weights(positions, weights) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/rbgl/engine/rasterizer/attribute_interpolator.rb', line 43 def perspective_correct_weights(positions, weights) corrected = positions.zip(weights).map do |position, weight| weight * inverse_clip_w(position) end total = corrected.sum return weights if total.zero? corrected.map { |weight| weight / total } end |