I'm trying to implement two pass Gaussian blur using GLSL with Haskell and I don't know which library should I use to achieve result similar to the Löve2D Lua code presented below:
Löve2d code (main.lua
)
LG = love.graphics
function love.load()
time = love.timer.getTime()
img = LG.newImage("moonbow.jpg")
blur_pass = LG.newShader("pass.gs")
horizontal_canvas = LG.newCanvas(img:getDimensions())
vertical_canvas = LG.newCanvas(img:getDimensions())
LG.setCanvas(horizontal_canvas)
LG.setShader(blur_pass)
blur_pass:send("horizontal", true)
blur_pass:send("blurSize", 1 / img:getWidth())
LG.draw(img)
LG.setCanvas(vertical_canvas)
blur_pass:send("horizontal", false)
blur_pass:send("blurSize", 1 / img:getHeight())
LG.draw(horizontal_canvas)
LG.setShader()
LG.setCanvas()
time = love.timer.getTime() - time
end
function love.draw()
LG.draw(vertical_canvas)
LG.print("Time: " .. time * 10 .. "ms", 12, 12)
end
Löve2d GLSL shader (pass.gs
file)
float gauss[51] = float[](0.9637, 0.9606, 0.9572, 0.9533, 0.9489, 0.9438, 0.9379, 0.9311, 0.9231, 0.9136, 0.9023, 0.8886, 0.8720, 0.8515, 0.8259, 0.7934, 0.7515, 0.6966, 0.6236, 0.5258, 0.3963, 0.2354, 0.0764, 0.0031, 0.0000, 0.0000, 0.0000, 0.0031, 0.0764, 0.2354, 0.3963, 0.5258, 0.6236, 0.6966, 0.7515, 0.7934, 0.8259, 0.8515, 0.8720, 0.8886, 0.9023, 0.9136, 0.9231, 0.9311, 0.9379, 0.9438, 0.9489, 0.9533, 0.9572, 0.9606, 0.9637);
extern float blurSize;
extern bool horizontal;
vec4 effect(vec4 _color, Image texture, vec2 texture_coords, vec2 screen_coords) {
vec4 result = vec4(0);
float sum = 0.0;
if(horizontal) {
for(int i = 0; i <= 51; i++) {
result += Texel(texture, vec2(texture_coords.x - (float(i) - 25)*blurSize, texture_coords.y)) * (1.0 - gauss[i]);
sum += (1.0 - gauss[i]);
}
} else {
for(int i = 0; i <= 51; i++) {
result += Texel(texture, vec2(texture_coords.x, texture_coords.y - (float(i) - 25)*blurSize)) * (1.0 - gauss[i]);
sum += (1.0 - gauss[i]);
}
}
return result / sum;
}
I especially care about the ease of use of the library, multiple framebuffers (Canvases) and simple way of sending stuff to GLSL and back. So, Which Haskell GLSL binding do you recommend?
vinyl-gl
handles the second half of your question (marshalling things to GLSL and back). – Ozieozkum