]> gitweb.factorcode.org Git - factor.git/blob - extra/gpu/effects/step/step.factor
Switch to https urls
[factor.git] / extra / gpu / effects / step / step.factor
1 ! Copyright (C) 2010 Erik Charlebois.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: destructors gpu.render gpu.shaders gpu.state gpu.util
4 images kernel math.rectangles ;
5 IN: gpu.effects.step
6
7 GLSL-SHADER: step-fragment-shader fragment-shader
8 const vec4 luminance = vec4(0.3, 0.59, 0.11, 0.0);
9 uniform sampler2D texture;
10 uniform sampler2D ramp;
11 varying vec2 texcoord;
12 void 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
20 UNIFORM-TUPLE: step-uniforms
21     { "texture" texture-uniform f }
22     { "ramp"    texture-uniform f } ;
23
24 GLSL-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 ;