{
  "name": "Meteor Strike",
  "dimension": "3d",
  "slot": "action_bar",
  "width": 256,
  "height": 128,
  "textBaseline": 128,
  "placement": {
    "x": 0,
    "y": 0
  },
  "shapes": [],
  "texts": [],
  "heads": [],
  "images": [],
  "bars": [],
  "triggers": [],
  "world": {
    "glsl": "// A meteor. FALLING it is a tumbling rock with glowing cracks, white-hot on\r\n// its leading face, trailing fire and smoke up its own +Y: a server turns the\r\n// object so the trail points back along the way it is moving. IMPACT is the\r\n// strike, with the ground at the bottom of the object: a flash, a fireball\r\n// dome, a dust ring racing out, a column of smoke climbing, and a crater that\r\n// glows and cools to embers.\r\nconst int STATE_FALLING = 0;\r\nconst int STATE_IMPACT = 1;\r\n\r\nconst float GROUND = -0.92;\r\nconst vec3 ROCK = vec3(0.0, -0.6, 0.0);\r\n\r\nfloat rockD(vec3 p, float time) {\r\n    vec3 q = p - ROCK;\r\n    q.xy = rpw_rot(time * 1.7) * q.xy;\r\n    q.yz = rpw_rot(time * 1.1) * q.yz;\r\n    float n = rpw_noise(q * 9.0 + rpw_seed) * 0.6 + rpw_noise(q * 21.0) * 0.4;\r\n    return (length(q) - 0.17 - 0.05 * n) * 0.7;\r\n}\r\n\r\nvec4 drawRock(vec3 ro, vec3 rd, float t0, float t1, float time, vec3 light, out float tHit) {\r\n    tHit = -1.0;\r\n    float t = t0;\r\n    for (int i = 0; i < 70; i++) {\r\n        vec3 p = ro + rd * t;\r\n        float d = rockD(p, time);\r\n        if (d < 0.0015) {\r\n            tHit = t;\r\n            vec3 e = vec3(0.002, 0.0, 0.0);\r\n            vec3 n = normalize(vec3(rockD(p + e.xyy, time) - rockD(p - e.xyy, time),\r\n                                    rockD(p + e.yxy, time) - rockD(p - e.yxy, time),\r\n                                    rockD(p + e.yyx, time) - rockD(p - e.yyx, time)));\r\n            vec3 q = p - ROCK;\r\n            q.xy = rpw_rot(time * 1.7) * q.xy;\r\n            q.yz = rpw_rot(time * 1.1) * q.yz;\r\n            float crack = smoothstep(0.04, 0.0, abs(rpw_noise(q * 14.0) - 0.5));\r\n            vec3 base = vec3(0.16, 0.13, 0.12) * (0.35 + 0.65 * max(dot(n, normalize(vec3(0.4, 0.8, 0.3))), 0.0)) * light;\r\n            float lead = smoothstep(0.1, -0.9, n.y);\r\n            vec3 col = base + vec3(1.0, 0.45, 0.1) * crack * 1.6 + vec3(1.0, 0.85, 0.55) * lead * lead * 1.5;\r\n            return vec4(col, 1.0);\r\n        }\r\n        t += d;\r\n        if (t > t1) break;\r\n    }\r\n    return vec4(0.0);\r\n}\r\n\r\nvec4 drawFalling(vec3 ro, vec3 rd, float t0, float t1, float time, vec3 light, inout float depth) {\r\n    float tRock;\r\n    vec4 rock = drawRock(ro, rd, t0, t1, time, light, tRock);\r\n    float tEnd = tRock > 0.0 ? tRock : t1;\r\n    vec3 col = vec3(0.0);\r\n    float alpha = 0.0;\r\n    float hit = -1.0;\r\n    float dt = (tEnd - t0) / 48.0;\r\n    for (int i = 0; i < 48; i++) {\r\n        float t = t0 + (float(i) + 0.5) * dt;\r\n        vec3 p = ro + rd * t;\r\n        float along = p.y - ROCK.y;\r\n        if (along < -0.05) continue;\r\n        float w = 0.07 + 0.22 * along;\r\n        float turb = rpw_fbm(vec3(p.xz * 7.0, p.y * 5.0 - time * 6.0));\r\n        float r = length(p.xz) + (turb - 0.5) * 0.12 * (0.3 + along);\r\n        float dens = exp(-pow(r / w, 2.0) * 2.0) * (1.0 - smoothstep(0.6, 1.6, along)) * smoothstep(-0.05, 0.05, along);\r\n        if (dens < 0.002) continue;\r\n        float a = clamp(dens * dt * 22.0, 0.0, 1.0);\r\n        float heat = exp(-along * 2.2);\r\n        vec3 fire = mix(vec3(0.95, 0.25, 0.05), vec3(1.0, 0.92, 0.65), heat) * (1.0 + 2.5 * heat);\r\n        vec3 smoke = vec3(0.3, 0.28, 0.27) * light;\r\n        vec3 c = mix(smoke, fire, smoothstep(0.12, 0.45, heat + 0.3 * turb));\r\n        col += (1.0 - alpha) * c * a;\r\n        alpha += (1.0 - alpha) * a;\r\n        if (hit < 0.0 && alpha > 0.3) hit = t;\r\n        if (alpha > 0.98) break;\r\n    }\r\n    if (tRock > 0.0) {\r\n        col += (1.0 - alpha) * rock.rgb;\r\n        alpha = 1.0;\r\n        if (hit < 0.0) hit = tRock;\r\n    }\r\n    if (alpha < 0.004) return vec4(0.0);\r\n    depth = hit > 0.0 ? hit : t0;\r\n    return vec4(col / alpha, alpha);\r\n}\r\n\r\n// The strike, st seconds in: density and heat at p. Every part is a\r\n// distance, roughened by noise before it becomes density, so edges billow.\r\nvec2 strike(vec3 p, float st) {\r\n    vec3 g = p - vec3(0.0, GROUND, 0.0);\r\n    float n = rpw_fbm(p * 6.5 + vec3(0.0, -st * 0.5, rpw_seed));\r\n    float rough = (n - 0.5) * 0.22;\r\n    float R = 0.46 * (1.0 - exp(-st * 4.0));\r\n    float domeD = length(g * vec3(1.0, 1.15, 1.0)) - R;\r\n    float dome = smoothstep(0.05, -0.08, domeD + rough) * step(-0.02, g.y) * exp(-st * 0.7);\r\n    float ringR = 0.1 + 0.8 * (1.0 - exp(-st * 1.4));\r\n    float ringD = length(vec2(length(g.xz) - ringR, g.y * 1.8)) - 0.05 - 0.06 * clamp(st, 0.0, 1.5);\r\n    float ring = smoothstep(0.04, -0.05, ringD + rough) * (1.0 - smoothstep(1.5, 5.0, st)) * step(-0.02, g.y);\r\n    float top = 0.9 * (1.0 - exp(-st * 0.3));\r\n    float h = clamp(g.y / max(top, 0.01), 0.0, 1.0);\r\n    float plumeD = length(g.xz + vec2(0.06, 0.03) * h * h) - (0.09 + 0.2 * h * h);\r\n    float plume = smoothstep(0.05, -0.06, plumeD + rough * 1.4) * step(0.0, g.y) * smoothstep(top + 0.08, top - 0.12, g.y)\r\n                * smoothstep(0.5, 2.5, st) * (1.0 - smoothstep(16.0, 30.0, st));\r\n    float dens = dome * 1.4 + ring * 1.2 + plume * 0.9;\r\n    float heat = exp(-st * 1.2) * smoothstep(0.02, -0.15, domeD + rough) + exp(-st * 5.0) * dome;\r\n    return vec2(dens, clamp(heat, 0.0, 1.0));\r\n}\r\n\r\nvec4 drawImpact(vec3 ro, vec3 rd, float t0, float t1, float st, float time, vec3 light, inout float depth) {\r\n    vec3 col = vec3(0.0);\r\n    float alpha = 0.0;\r\n    float hit = -1.0;\r\n    // The crater, where the ray meets the ground.\r\n    float tG = abs(rd.y) > 1e-4 ? (GROUND - ro.y) / rd.y : -1.0;\r\n    float tEnd = (tG > t0 && tG < t1) ? tG : t1;\r\n    float dt = (tEnd - t0) / 56.0;\r\n    for (int i = 0; i < 56; i++) {\r\n        float t = t0 + (float(i) + 0.5) * dt;\r\n        vec3 p = ro + rd * t;\r\n        vec2 s = strike(p, st);\r\n        float flash = exp(-st * 9.0) * smoothstep(0.3, 0.0, length(p - vec3(0.0, GROUND + 0.05, 0.0)));\r\n        float dens = s.x + flash * 4.0;\r\n        if (dens < 0.002) continue;\r\n        float a = clamp(dens * dt * 11.0, 0.0, 1.0);\r\n        float heat = max(s.y, flash);\r\n        vec3 fire = mix(vec3(0.9, 0.22, 0.04), vec3(1.0, 0.88, 0.55), heat * heat) * (1.0 + 2.2 * heat);\r\n        vec3 dust = vec3(0.42, 0.37, 0.31) * light * (0.6 + 0.4 * clamp((p.y - GROUND) * 2.0, 0.0, 1.0));\r\n        vec3 c = mix(dust, fire, smoothstep(0.05, 0.35, heat));\r\n        col += (1.0 - alpha) * c * a;\r\n        alpha += (1.0 - alpha) * a;\r\n        if (hit < 0.0 && alpha > 0.3) hit = t;\r\n        if (alpha > 0.98) break;\r\n    }\r\n    if (tG > t0 && tG < t1 && alpha < 0.98) {\r\n        vec3 p = ro + rd * tG;\r\n        float r = length(p.xz);\r\n        float bowl = smoothstep(0.3, 0.18, r);\r\n        float rim = exp(-abs(r - 0.3) * 30.0) * 0.6;\r\n        float cool = max(exp(-st / 10.0), 0.12);\r\n        float crack = smoothstep(0.06, 0.0, abs(rpw_noise(vec3(p.xz * 18.0, rpw_seed)) - 0.5));\r\n        float flicker = 0.85 + 0.15 * sin(time * 7.0 + p.x * 40.0);\r\n        vec3 lava = vec3(1.0, 0.35, 0.05) * (0.4 + 1.6 * crack) * cool * flicker;\r\n        vec3 scorch = vec3(0.08, 0.07, 0.06) * light;\r\n        float a = bowl * 0.95 + rim;\r\n        vec3 c = mix(scorch, scorch + lava, bowl);\r\n        if (a > 0.004) {\r\n            col += (1.0 - alpha) * c * a;\r\n            alpha += (1.0 - alpha) * clamp(a, 0.0, 1.0);\r\n            if (hit < 0.0 && alpha > 0.3) hit = tG;\r\n        }\r\n    }\r\n    if (alpha < 0.004) return vec4(0.0);\r\n    depth = hit > 0.0 ? hit : t0;\r\n    return vec4(col / alpha, alpha);\r\n}\r\n\r\nvec4 object(vec3 ro, vec3 rd, float t0, float t1, float time, vec3 light, inout float depth) {\r\n    if (rpw_state == STATE_IMPACT) return drawImpact(ro, rd, t0, t1, rpw_state_time, time, light, depth);\r\n    return drawFalling(ro, rd, t0, t1, time, light, depth);\r\n}\r\n",
    "prompt": "A meteor: a tumbling rock with glowing cracks trailing fire and smoke, that strikes the ground in a flash, a fireball, a dust ring and a smoking crater.",
    "size": 6
  }
}