PageRenderTime 16ms CodeModel.GetById 10ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/extra/gpu/effects/step/step.factor

http://github.com/abeaumont/factor
Unknown | 40 lines | 35 code | 5 blank | 0 comment | 0 complexity | c1e9468cc646e5b4e9e8bb187c84aeac MD5 | raw file
 1! Copyright (C) 2010 Erik Charlebois.
 2! See http://factorcode.org/license.txt for BSD license.
 3USING: destructors gpu.render gpu.shaders gpu.state gpu.textures
 4gpu.util images kernel locals math.rectangles ;
 5IN: gpu.effects.step
 6
 7GLSL-SHADER: step-fragment-shader fragment-shader
 8const vec4 luminance = vec4(0.3, 0.59, 0.11, 0.0);
 9uniform sampler2D texture;
10uniform sampler2D ramp;
11varying vec2 texcoord;
12void main()
13{
14    vec4 col = texture2D(texture, texcoord);
15    float l = dot(col, luminance);
16    gl_FragColor = texture2D(ramp, vec2(l, 0.0));
17}
18;
19
20UNIFORM-TUPLE: step-uniforms
21    { "texture" texture-uniform f }
22    { "ramp"    texture-uniform f } ;
23
24GLSL-PROGRAM: step-program window-vertex-shader step-fragment-shader window-vertex-format ;
25
26: (step-texture) ( texture ramp texture dim -- )
27    { 0 0 } swap <rect> <viewport-state> set-gpu-state
28    [ step-uniforms boa ] dip {
29        { "primitive-mode" [ 2drop triangle-strip-mode ] }
30        { "uniforms"       [ drop ] }
31        { "vertex-array"   [ 2drop <window-vertex-buffer> step-program <program-instance> <vertex-array> ] }
32        { "indexes"        [ 2drop T{ index-range f 0 4 } ] }
33        { "framebuffer"    [ nip ] }
34    } 2<render-set> render ;
35
36:: step-texture ( texture ramp dim -- texture )
37    dim RGB float-components <2d-render-texture> :> ( target-framebuffer target-texture )
38    texture ramp target-framebuffer dim (step-texture)
39    target-framebuffer dispose
40    target-texture ;