我正在尝试使用带有 Haskell 的GLSL实现两次高斯模糊,我不知道应该使用哪个库来获得类似于下面提供的Löve2DLua代码的结果:
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
pass.gs
文件)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;
}
我特别关心库的易用性,多帧缓冲区(画布)以及发送内容到GLSL的简单方法背部。 那么,你推荐哪种Haskell GLSL绑定?