skia2/resources/particles/cube.json
Brian Osman eddfc3562f Particles: Fake 3D example
Change-Id: I6d29290eb2962262bb080a86dc829c39986cae4f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/249226
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-10-17 20:10:05 +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, rand, rand);",
" if (rand < 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 < 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 = 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": []
}