Skip to content

Writing a postprocess effect

Mikulas Florek edited this page Apr 12, 2020 · 1 revision
  1. duplicate file pipelines/fxaa.lua, let's call it pipelines/test.lua
  2. open the lua file and change the postprocess function to following:
function postprocess(env, transparent_phase, ldr_buffer, gbuffer0, gbuffer1, gbuffer_depth, shadowmap)
	if not enabled then return ldr_buffer end
	if transparent_phase ~= "post_tonemap" then return ldr_buffer end
	local res = env.createRenderbuffer(1, 1, true, "rgba8", "test")
	env.beginBlock("test")
	if test_shader == nil then
		test_shader = env.preloadShader("pipelines/test.shd")
	end

	env.setRenderTargets(res)
	env.drawArray(0, 4, test_shader, 
		{ ldr_buffer },
		{},
		{},
		{ depth_test = false, blending = ""}
	)
	env.endBlock()
	return res
end

As you can see, every fxaa string was replaced with test string. 3. create file pipelines/test.shd with following content

vertex_shader [[
	
	out vec2 v_uv;
	
	void main()
	{
		v_uv = vec2(gl_VertexID & 1, (gl_VertexID & 2) * 0.5);
		gl_Position = vec4((gl_VertexID & 1) * 2 - 1, (gl_VertexID & 2) - 1, 0, 1);
	}
]]


fragment_shader [[
	in vec2 v_uv;
	out vec4 o_color;


	void main()
	{
		o_color.xyz = vec3(0, 0, 0);
		o_color.w = 1 - length(v_uv - vec2(0.5));
	}
]]
  1. add a new lua script component to your scene and use pipelines/test.lua as its source

If everything goes ok, you should see your postprocess effect - black in the center of scene view and white on edges.

Clone this wiki locally