Okay, it worked. Just change what material I use to render the post processed gui elements.
The shader is from Shadertoy [link]. Used this article to convert it.
gui_ripple.fp
#version 140
in vec2 var_texcoord0;
out vec4 fragColor;
uniform sampler2D texture_sampler;
uniform params {
vec4 u_time;
vec4 u_res;
};
void main()
{
float time = u_time.x;
vec2 res = u_res.xy;
vec2 uv = var_texcoord0.xy;
float w = (0.5 - (uv.x)) * (res.x / res.y);
float h = 0.5 - uv.y;
float distanceFromCenter = sqrt(w * w + h * h);
float sinArg = distanceFromCenter * 10.0 - time * 10.0;
float slope = cos(sinArg) ;
vec4 color = texture(texture_sampler, uv + normalize(vec2(w, h)) * slope * 0.05);
if (color.a == 0) discard;
fragColor = color;
}
Note that I pass in a resolution scale so I can update it when the window size changes, and a time. Both from the render script.
self.time.x = self.time.x + dt
local constants = render.constant_buffer()
constants.u_time = self.time
...
local res = vmath.vector4(0)
if state.window_height > state.window_width then
local scale = state.window_height / state.window_width
res.x = 1.0
res.y = scale
else
local scale = state.window_width / state.window_height
res.x = scale
res.y = 1.0
end
constants.u_res = res
...
render.enable_texture(0, self.gui_pp_target, render.BUFFER_COLOR_BIT)
render.draw(predicates.gui_pp, { constants = constants })
render.disable_texture(0, self.gui_pp_target)
Also I set uv
to be equal to var_textcoord0
instead of multiplying by the resolution. Not sure why, it just worked when I did that.