Im trying to retrieve 2 colors in the fragment shader from the buffer colors. Im using buffer bit 0 and 1, but the 1 just uses the standard image i set in the editor. This is my code:
varying mediump vec2 var_texcoord0;
varying mediump vec2 pos;
uniform lowp sampler2D tex0;
uniform lowp sampler2D tex1;
uniform mediump vec4 BLUR_viewPort_Radius;
float weight[5] = float[] (0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216);
vec4 blur(int horizontal, vec2 TexCoords, sampler2D image);
void main()
{
vec2 p = var_texcoord0;
vec4 blurF = blur(int(BLUR_viewPort_Radius.w), p, tex1);
gl_FragColor = vec4(blurF.xyz, 1);
}
vec4 blur(int horizontal, vec2 TexCoords, sampler2D image)
{
vec2 tex_offset = 5.0 / textureSize(image, 0); // gets size of single texel
vec3 result = texture(image, TexCoords).rgb * weight[0]; // current fragment's contribution
if(horizontal == 1)
{
for(int i = 1; i < 5; ++i)
{
result += texture(image, TexCoords + vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
result += texture(image, TexCoords - vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
}
}
else
{
for(int i = 1; i < 5; ++i)
{
result += texture(image, TexCoords + vec2(0.0, tex_offset.y * i)).rgb * weight[i];
result += texture(image, TexCoords - vec2(0.0, tex_offset.y * i)).rgb * weight[i];
}
}
return vec4(result, 1.0);
}
and in the lua code i have these render targets:
local rgba_params = {
format = render.FORMAT_RGBA, width = render.get_window_width(), height = render.get_window_height(),
min_filter = render.FILTER_LINEAR, mag_filter = render.FILTER_LINEAR,
u_wrap = render.WRAP_CLAMP_TO_EDGE, v_wrap = render.WRAP_CLAMP_TO_EDGE
}
local depth_params = {
format = render.FORMAT_DEPTH,width = render.get_window_width(),height = render.get_window_height(),
min_filter = render.FILTER_LINEAR, mag_filter = render.FILTER_LINEAR,
u_wrap = render.WRAP_CLAMP_TO_EDGE, v_wrap = render.WRAP_CLAMP_TO_EDGE
}
self.blur_fbo[0] = render.render_target("blur1",{
[render.BUFFER_COLOR0_BIT] = rgba_params,
[render.BUFFER_COLOR1_BIT] = rgba_params,
[render.BUFFER_DEPTH_BIT] = depth_params
})
self.blur_fbo[1] = render.render_target("blur2",{
[render.BUFFER_COLOR0_BIT] = rgba_params,
[render.BUFFER_COLOR1_BIT] = rgba_params,
[render.BUFFER_DEPTH_BIT] = depth_params
})
self.bright = render.render_target("bright",{
[render.BUFFER_COLOR1_BIT] = rgba_params,
[render.BUFFER_DEPTH_BIT] = depth_params
})
these buffers are used this way:
local amount = 10
local horizontal = true
local not_hor, hor
local add_blur = 0
render.enable_material('bright')
render.disable_render_target(self.game_world_fbo)
render.enable_texture(0, self.game_world_fbo, render.BUFFER_COLOR0_BIT)
render.set_render_target(self.bright)
render.draw(self.post_processing_pred)
render.disable_render_target(self.bright)
render.enable_texture(1, self.bright, render.BUFFER_COLOR1_BIT)
render.enable_material('blur')
for i = 1, amount do
hor = boolToNumber(horizontal)
not_hor = boolToNumber(not horizontal)
render.enable_render_target(self.blur_fbo[hor])
render.set_render_target(self.blur_fbo[hor])
local constants = render.constant_buffer()
render.disable_render_target(self.blur_fbo[not_hor])
render.enable_texture(1, self.blur_fbo[not_hor], render.BUFFER_COLOR1_BIT)
if i == 10 then
add_blur = 1
end
constants.BLUR_viewPort_Radius = vmath.vector4(add_blur, 0,0, not_hor)
render.draw(self.post_processing_pred, {constants = constants})
render.disable_texture(0)
horizontal = not horizontal
end
render.disable_material()
But then i just get the standard image i set on the editor instead of the one on the FBO