CODE SAMPLE - 2D Meta Ball Shader(HLSL)
Simple deferred 2d metaballing.
In the engine all textures are batched. For this specific effect all textures are batched to their own target using a standard texture shader. Once all of the textures using this effect have been batched the metaball pixel shader takes the old target and rerenders over the final scene with color and threshold modifications.
Texture2D metaTexture : register(t1);
cbuffer MetaBuffer { float alpha; float threshold; float strength; float multiplier; float4 metaColor; }; float4 MetaBallPixelShader(PixelInputType input) : SV_TARGET { float4 fragColor; fragColor = metaTexture.Sample(SampleType, input.tex); if(fragColor.w > threshold) { fragColor.a = alpha; } else { fragColor *= strength } fragColor *= metaColor; return fragColor; } |
Left: Composite of all textures rendered to an off texture with a standard texture shader.
Right: Final Rendering after meta ball shader is applied to the the scene. |