Class: Processing::Shader

Inherits:
Object
  • Object
show all
Includes:
Xot::Inspectable
Defined in:
lib/processing/shader.rb

Overview

Shader object.

Instance Method Summary collapse

Constructor Details

#initialize(vertSrc, fragSrc) ⇒ Shader

Initialize shader object.

Parameters:

  • vertSrc (String)

    vertex shader source

  • fragSrc (String)

    fragment shader source



18
19
20
# File 'lib/processing/shader.rb', line 18

def initialize(vertSrc, fragSrc)
  @shader = Rays::Shader.new modifyFragSource__(fragSrc), vertSrc, ENV__
end

Instance Method Details

#set(name, a) ⇒ Object #set(name, a, b) ⇒ Object #set(name, a, b, c) ⇒ Object #set(name, a, b, c, d) ⇒ Object #set(name, nums) ⇒ Object #set(name, vec) ⇒ Object #set(name, vec, ncoords) ⇒ Object #set(name, tex) ⇒ Object Also known as: setUniform

Sets uniform variables.

Parameters:

  • name (String)

    uniform variable name

  • a (Numeric)

    int or float value

  • b (Numeric)

    int or float value

  • c (Numeric)

    int or float value

  • d (Numeric)

    int or float value

  • nums (Array)

    int or float array

  • vec (Vector)

    vector

  • ncoords (Integer)

    number of coordinates, max 4

  • tex (Image)

    texture image

See Also:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/processing/shader.rb', line 46

def set(name, *args)
  arg = args.first
  case
  when Array === arg
    @shader.uniform name, *arg
  when Numeric === arg
    @shader.uniform name, *args
  when Vector === arg
    vec, ncoords = args
    @shader.uniform name, vec.getInternal__.to_a(ncoords || 3)
  when arg.respond_to?(:getInternal__)
    @shader.uniform name, arg.getInternal__
  else
    raise ArgumentError
  end
end