Class: Ray::Effect::BlackAndWhite

Inherits:
Ray::Effect show all
Defined in:
lib/ray/effect/black_and_white.rb

Overview

A black and white effect. It considers the grayscale level of the image, and sets pixels that are darker than a given value to black, and the others to white.

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(value = 0.5, ratio = [0.299, 0.587, 0.114]) ⇒ BlackAndWhite

Returns a new instance of BlackAndWhite.

Parameters:

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

    Default ratio to compute grayscale

  • value (Float) (defaults to: 0.5)

    Minimal grayscale level of white pixels



13
14
15
16
# File 'lib/ray/effect/black_and_white.rb', line 13

def initialize(value = 0.5, ratio = [0.299, 0.587, 0.114])
  @ratio = ratio
  @value = value
end

Instance Attribute Details

#ratioRay::Vector3

Returns ratio.

Returns:



19
20
21
# File 'lib/ray/effect/black_and_white.rb', line 19

def ratio
  @ratio
end

Instance Method Details

#codeObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ray/effect/black_and_white.rb', line 25

def code
  return <<code
vec4 do_black_and_white(ray_black_and_white args, vec4 color) {
  float gray = dot(color.rgb, args.ratio);
  if (gray > args.value)
    return vec4(1, 1, 1, color.a);
  else
    return vec4(0, 0, 0, color.a);
}
code
end

#defaultsObject



21
22
23
# File 'lib/ray/effect/black_and_white.rb', line 21

def defaults
  {:ratio => @ratio, :value => @value}
end