Class: Ray::Effect::Grayscale
- Inherits:
-
Ray::Effect
- Object
- Ray::Effect
- Ray::Effect::Grayscale
- Defined in:
- lib/ray/effect/grayscale.rb
Overview
A grayscale effect. To accomplish it, it computes the dot product of the color by a ratio, and assigns the result to red, green, and blue components. Alpha component is preserved.
Instance Attribute Summary collapse
-
#ratio ⇒ Ray::Vector3
Ratio.
Instance Method Summary collapse
- #code ⇒ Object
- #defaults ⇒ Object
-
#initialize(ratio = [0.299, 0.587, 0.114]) ⇒ Grayscale
constructor
A new instance of Grayscale.
Methods inherited from Ray::Effect
#apply_defaults, attribute, attributes, effect_name, #header, #name, #struct
Constructor Details
#initialize(ratio = [0.299, 0.587, 0.114]) ⇒ Grayscale
Returns a new instance of Grayscale.
11 12 13 |
# File 'lib/ray/effect/grayscale.rb', line 11 def initialize(ratio = [0.299, 0.587, 0.114]) @ratio = ratio end |
Instance Attribute Details
#ratio ⇒ Ray::Vector3
Returns ratio.
16 17 18 |
# File 'lib/ray/effect/grayscale.rb', line 16 def ratio @ratio end |
Instance Method Details
#code ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/ray/effect/grayscale.rb', line 22 def code return <<code vec4 do_grayscale(ray_grayscale args, vec4 color) { float gray = dot(color.rgb, args.ratio); return vec4(gray, gray, gray, color.a); } code end |
#defaults ⇒ Object
18 19 20 |
# File 'lib/ray/effect/grayscale.rb', line 18 def defaults {:ratio => @ratio} end |