add bloom filter and test, bloom now works
[turbulence.git] / src / liquidity / bloom-filter.vala
blob9e3d285072732df9d20432596c195601d3598cab
1 /*
2 * liquidity/bloom-filter.vala
4 * Copyright (c) 2008 Patrick Walton <pcwalton@uchicago.edu>
5 * GLSL filter code by Romain Guy <http://www.curious-creature.org/
6 * 2007/02/20/fast-image-processing-with-jogl/>
7 */
9 using GLib;
10 using Gee;
12 namespace Liquidity {
13 public class BloomFilter : Filter {
14 protected override string# glsl_source {
15 get {
16 return
17 "uniform sampler2DRect rectTexture; " +
18 "uniform float brightPassThreshold;" +
19 "void main(void) {" +
20 " vec3 luminanceVector = vec3(0.2125, 0.7154, 0.0721);" +
21 " vec4 sample = texture2DRect(rectTexture, gl_TexCoord[0].st);" +
22 " float luminance = dot(luminanceVector, sample.rgb);" +
23 " luminance = max(0.0, luminance - brightPassThreshold);" +
24 " sample.rgb *= sign(luminance);" +
25 " sample.a = 1.0;" +
26 " gl_FragColor = sample;" +
27 "}" ;
31 private HashMap<string, weak Float> _glsl_params = null;
32 protected override HashMap<string, weak Float> glsl_params {
33 get {
34 if (_glsl_params == null) {
35 _glsl_params = new HashMap<string, weak Float>(str_hash,
36 str_equal);
39 * Ugh... awful hack. When will Gee support real hash maps
40 * that manage memory properly? :(
43 Float *fp = new Float(0.75F);
44 _glsl_params.set("brightPassThreshold", fp);
47 return _glsl_params;