Hi.
I’m not terribly happy with it, but this is something I use when a UFO character fires a laser:
local kernel = { category = "generator", group = "enemy\_attack", name = "beam" } kernel.vertexData = { { name = "width", default = .07, min = 0, max = 1, index = 0 }, { name = "taper", default = .34, min = 0, max = 1, index = 1 }, { name = "frequency", default = .017, min = 0, max = 1, index = 2 }, { name = "falloff", default = 3.7, min = 0, max = 5, index = 3 } } kernel.isTimeDependent = true kernel.fragment = [[// Created by inigo quilez - iq/2013 // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. P\_DEFAULT float hash1 (P\_DEFAULT float n) { #if !defined(GL\_ES) || defined(GL\_FRAGMENT\_PRECISION\_HIGH) return fract(sin(n) \* 43758.5453); #else return fract(sin(n) \* 43.7585453); #endif } // Created by inigo quilez - iq/2013 // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. P\_DEFAULT float IQ (P\_DEFAULT vec2 x) { P\_DEFAULT vec2 p = floor(x); P\_DEFAULT vec2 f = fract(x); f = f \* f \* (3.0 - 2.0 \* f); P\_DEFAULT float n = p.x + p.y \* 57.0; return mix(mix(hash1(n + 0.0), hash1(n + 1.0), f.x), mix(hash1(n + 57.0), hash1(n + 58.0), f.x), f.y); } P\_POSITION float Height (P\_POSITION vec2 to\_uv) { P\_POSITION float t = 256. - abs(256. - mod(CoronaTotalTime, 512.)); P\_POSITION float taper\_base = max(0., CoronaVertexUserData.y); P\_POSITION float x = smoothstep(taper\_base, .5, abs(to\_uv.x)); P\_POSITION float y = CoronaVertexUserData.x \* (1. - x \* x); return y \* (.875 + IQ(-to\_uv.xx \* (1024. \* CoronaVertexUserData.z) + vec2(8.9, sign(to\_uv.y) \* 1.7) \* t) \* .125); } P\_COLOR vec4 FragmentKernel (P\_UV vec2 uv) { P\_COLOR vec4 color = CoronaColorScale(vec4(1.)); P\_POSITION vec2 to\_uv = uv - .5; P\_POSITION float h = Height(to\_uv); P\_POSITION float ratio = abs(to\_uv.y) / max(h, .0001); h \*= .17 \* (1. + IQ(vec2(uv.x, h))); P\_COLOR float white = 1. + pow(max(1. - ratio, 0.), .47); P\_COLOR vec3 mixed = mix(vec3(white), color.rgb, 1. - exp(-CoronaVertexUserData.w \* ratio) \* (1. - h)); return vec4(min(mixed, 1.), color.a) \* smoothstep(-.2671, 0., 1. - ratio); }]] graphics.defineEffect(kernel) local r = display.newRect(display.contentCenterX, display.contentCenterY, 500, 300) r:setFillColor(1, 0, 0) r.fill.effect = "generator.enemy\_attack.beam" -- none: r.fill.effect.taper = .5 -- less decay: r.fill.effect.width = .3
uv.x runs along the length of the beam and uv.y from side-to-side. I’d have to refresh myself on the rest. 