Class: Ray::Effect::Grayscale

Inherits:
Ray::Effect show all
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

Instance Method Summary collapse

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.

Parameters:

  • ratio (Ray::Vector3) (defaults to: [0.299, 0.587, 0.114])

    Default ratio



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

#ratioRay::Vector3

Returns ratio.

Returns:



16
17
18
# File 'lib/ray/effect/grayscale.rb', line 16

def ratio
  @ratio
end

Instance Method Details

#codeObject



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

#defaultsObject



18
19
20
# File 'lib/ray/effect/grayscale.rb', line 18

def defaults
  {:ratio => @ratio}
end