Created
January 21, 2014 10:37
-
-
Save alepez/8537782 to your computer and use it in GitHub Desktop.
glsl shader generator for vertical blur with weights from Pascal Triangle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
## first parameter is the row number from pascal triangle | |
def triangle(n) | |
ret = [] | |
(0..n).each{|r| | |
lst=[1] | |
term=1 | |
k=1 | |
(0..r-1).step(1){|index| | |
term=term*(r-k+1)/k | |
lst.push term | |
k+=1 | |
} | |
ret = lst | |
} | |
return ret | |
end | |
row = triangle(ARGV[0].to_i) | |
sum = row.reduce(:+).to_f | |
weights = row.map { |v| v / sum } | |
len = row.size | |
print "vec2 uv = gl_TexCoord[0].xy;\n" | |
print "vec4 sum = vec4( 0.0 );\n" | |
print "float bs = blurSize / resolution.y;\n" | |
len.times do |i| | |
offset = (i - (len-1)/2.0) / len | |
printf "sum += texture2D(tex, vec2(uv.x, uv.y + bs * #{offset})) * #{weights[i]};\n" | |
end | |
print "gl_FragColor = sum;\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment