skia2/resources/particles/cube.json
Brian Osman bf061a32ef Fix an (int + float) error in "cube" particle demo
Also fix a crash if you try to play an effect that has never compiled
correctly. (After the first compile, the arrays were always large enough
to set "dt" -- this code is all going to be reworked soon for SkVM, but
I hit this while diagnosing the type coercion error).

Change-Id: I5bfab539c7304bde2da36b0b0604991d5b5b303a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/354660
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2021-01-15 19:15:16 +00:00

94 lines
2.6 KiB
JSON

{
"MaxCount": 2000,
"Drawable": {
"Type": "SkCircleDrawable",
"Radius": 4
},
"EffectCode": [
"void effectSpawn(inout Effect effect) {",
" effect.lifetime = 2;",
" effect.rate = 200;",
"}",
""
],
"Code": [
"void spawn(inout Particle p) {",
" p.lifetime = 10;",
"}",
"",
"float4x4 rx(float rad) {",
" float c = cos(rad);",
" float s = sin(rad);",
" return float4x4(1, 0, 0, 0,",
" 0, c, -s, 0,",
" 0, s, c, 0,",
" 0, 0, 0, 1);",
"}",
"",
"float4x4 ry(float rad) {",
" float c = cos(rad);",
" float s = sin(rad);",
" return float4x4(c, 0, -s, 0,",
" 0, 1, 0, 0,",
" s, 0, c, 0,",
" 0, 0, 0, 1);",
"}",
"",
"float4x4 rz(float rad) {",
" float c = cos(rad);",
" float s = sin(rad);",
" return float4x4( c, s, 0, 0,",
" -s, c, 0, 0,",
" 0, 0, 1, 0,",
" 0, 0, 0, 1);",
"}",
"",
"void update(inout Particle p) {",
" float3 pos = float3(rand(p.seed), rand(p.seed), rand(p.seed));",
" if (rand(p.seed) < 0.33) {",
" if (pos.x > 0.5) {",
" pos.x = 1;",
" p.color.rgb = float3(1, 0.2, 0.2);",
" } else {",
" pos.x = 0;",
" p.color.rgb = float3(0.2, 1, 1);",
" }",
" } else if (rand(p.seed) < 0.5) {",
" if (pos.y > 0.5) {",
" pos.y = 1;",
" p.color.rgb = float3(0.2, 0.2, 1);",
" } else {",
" pos.y = 0;",
" p.color.rgb = float3(1, 1, 0.2);",
" }",
" } else {",
" if (pos.z > 0.5) {",
" pos.z = 1;",
" p.color.rgb = float3(0.2, 1, 0.2);",
" } else {",
" pos.z = 0;",
" p.color.rgb = float3(1, 0.2, 1);",
" }",
" }",
"",
" float s = effect.age * 2 - 1;",
" s = s < 0 ? -s : s;",
"",
" pos = pos * 2 - 1;",
" pos = mix(pos, normalize(pos), s);",
" pos = pos * 100;",
"",
" float age = float(effect.loop) + effect.age;",
" float4x4 mat = rx(age * radians(60))",
" * ry(age * radians(70))",
" * rz(age * radians(80));",
" pos = (mat * float4(pos, 1)).xyz;",
"",
" p.pos.x = pos.x;",
" p.pos.y = pos.y;",
" p.scale = ((pos.z + 50) / 100 + 0.5) / 2;",
"}",
""
],
"Bindings": []
}