Sha256: 525e5f0671f86c9c604398225958620853ba4a96d149165b4ddb883dc5654f08

Contents?: true

Size: 873 Bytes

Versions: 2

Compression:

Stored size: 873 Bytes

Contents

$:.unshift File.expand_path(File.dirname(__FILE__) + "/../../lib")
$:.unshift File.expand_path(File.dirname(__FILE__) + "/../../ext")

require 'ray'

Ray::Shader.use_old!

Ray::Game.new("Shaders test") do
  register do
    add_hook :quit, method(:exit!)
  end

  scene :shader do
    @shape = Ray::Polygon.circle([200, 200], 100, Ray::Color.black)
    @shape.each do |point|
      point.color = Ray::Color.new(rand(256), rand(256), rand(256))
    end

    @shape.shader = Ray::Shader.new :frag => StringIO.new(<<-SHADER)
      #version 110

      uniform vec3 ratio;
      varying vec4 var_Color;

      void main() {
        float gray   = dot(var_Color.rgb, ratio);
        gl_FragColor = vec4(gray, gray, gray, 1.0);
      }
    SHADER

    @shape.shader[:ratio] = [0.299, 0.587, 0.114]

    render do |win|
      win.draw @shape
    end
  end

  push_scene :shader
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ray-0.2.1 samples/shaders/shape.rb
ray-0.2.0 samples/shaders/shape.rb