SpecialFX is a plugin for advanced users of libGDX. This helper for special effects will save you some headaches if you want to combine shaders and/or make multiple passes with a given shader. It allows an easy implementation of the ping-pong technique.
To use this plugin, you have to know how to create and use a shader program, what's a texture unit, and how to create and use a FrameBuffer object.
How to use it:
1) Declare in Globals the chain of effects (lgSpecialFX) and its parameters (lgSpecialFX_Param), e.g.:
2) In LG_Create or LG_Resize, initialize the Param class, set the parameters, and create your chain of effects by adding the effects in the exact order of their application, e.g.:
3) Call the Apply function in LG_Render. You can also set dynamic parameters in LG_Render, e.g.:
The examples show some common post-processing FX (blur, bloom, pixelation, gamma, night vision, vignette, hue and saturation). If you want to use the blur algorithm of Kasawe, here are various settings (the key of this map is the blur kernel size):
Iterations.Put(7, Array As Int(0, 0))
Iterations.Put(15, Array As Int(0, 1, 1))
Iterations.Put(23, Array As Int(0, 1, 1, 2))
Iterations.Put(35, Array As Int(0, 1, 2, 2, 3))
Iterations.Put(63, Array As Int(0, 1, 2, 3, 4, 4, 5))
Iterations.Put(127, Array As Int(0, 1, 2, 3, 4, 5, 7, 8, 9, 10))
The library is provided with its Java source code.
To use this plugin, you have to know how to create and use a shader program, what's a texture unit, and how to create and use a FrameBuffer object.
How to use it:
1) Declare in Globals the chain of effects (lgSpecialFX) and its parameters (lgSpecialFX_Param), e.g.:
B4X:
Dim RetroFX As lgSpecialFX
Dim RetroFX_Param As lgSpecialFX_Param
2) In LG_Create or LG_Resize, initialize the Param class, set the parameters, and create your chain of effects by adding the effects in the exact order of their application, e.g.:
B4X:
FXParam.Initialize
FXParam.SetFloatParam("bias", skPix.Value)
FXParam.SetFloatParam("gamma", (skGamma.Value + 1) / 10)
FXParam.SetFloatParamArray("rectangle", Array As Float(0.2, 0.2, 0.6, 0.6))
FX.AddEffect(MipMapShader, FXParam, Null, FirstBuffer, "FX")
FX.AddEffect(GammaShader, FXParam, FirstBuffer, SecondBuffer, "FX")
3) Call the Apply function in LG_Render. You can also set dynamic parameters in LG_Render, e.g.:
B4X:
NightVisionFX_Param.SetFloatParam("cosTime", MU.Cos(Time * 1000))
NightVisionFX.Apply(Null)
The examples show some common post-processing FX (blur, bloom, pixelation, gamma, night vision, vignette, hue and saturation). If you want to use the blur algorithm of Kasawe, here are various settings (the key of this map is the blur kernel size):
Iterations.Put(7, Array As Int(0, 0))
Iterations.Put(15, Array As Int(0, 1, 1))
Iterations.Put(23, Array As Int(0, 1, 1, 2))
Iterations.Put(35, Array As Int(0, 1, 2, 2, 3))
Iterations.Put(63, Array As Int(0, 1, 2, 3, 4, 4, 5))
Iterations.Put(127, Array As Int(0, 1, 2, 3, 4, 5, 7, 8, 9, 10))
The library is provided with its Java source code.
Attachments
Last edited: