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

http://github.com/abeaumont/factor · Factor · 40 lines · 33 code · 5 blank · 2 comment · 4 complexity · c1e9468cc646e5b4e9e8bb187c84aeac MD5 · raw file

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