- Notifications
You must be signed in to change notification settings - Fork411
Writing a postprocess effect
Mikulas Florek edited this pageApr 12, 2020 ·1 revision
- duplicate file
pipelines/fxaa.lua
, let's call itpipelines/test.lua
- open the lua file and change the postprocess function to following:
functionpostprocess(env,transparent_phase,ldr_buffer,gbuffer0,gbuffer1,gbuffer_depth,shadowmap)ifnotenabledthenreturnldr_bufferendiftransparent_phase~="post_tonemap"thenreturnldr_bufferendlocalres=env.createRenderbuffer(1,1,true,"rgba8","test")env.beginBlock("test")iftest_shader==nilthentest_shader=env.preloadShader("pipelines/test.shd")endenv.setRenderTargets(res)env.drawArray(0,4,test_shader, {ldr_buffer },{},{},{depth_test=false,blending=""})env.endBlock()returnresend
As you can see, everyfxaa
string was replaced withtest
string.3. create filepipelines/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));}]]
- 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.