particle ssbo

This commit is contained in:
John Alanbrook 2024-07-18 12:39:58 -05:00
parent 63239fa51a
commit 066b213fbe
8 changed files with 82 additions and 35 deletions

View file

@ -17,6 +17,12 @@ actor.spawn = function(script, config, callback){
return padawan; return padawan;
}; };
actor.tween = function(from,to,time,fn) {
var stop = tween(from,to,time,fn);
this.timers.push(stop);
return stop;
}
actor.spawn.doc = `Create a new actor, using this actor as the master, initializing it with 'script' and with data (as a JSON or Nota file) from 'config'.`; actor.spawn.doc = `Create a new actor, using this actor as the master, initializing it with 'script' and with data (as a JSON or Nota file) from 'config'.`;
actor.rm_pawn = function(pawn) actor.rm_pawn = function(pawn)
@ -36,26 +42,11 @@ actor.kill = function(){
this.__dead__ = true; this.__dead__ = true;
if (typeof this.die === 'function') this.die(); if (typeof this.die === 'function') this.die();
if (typeof this.stop === 'function') this.stop(); if (typeof this.stop === 'function') this.stop();
if (typeof this.garbage === 'function') this.garbage();
}; };
actor.kill.doc = `Remove this actor and all its padawans from existence.`; actor.kill.doc = `Remove this actor and all its padawans from existence.`;
actor.interval = function(fn, seconds) {
var cur;
var stop = function() {
cur();
}
var f = function() {
fn.call(this);
cur = this.delay(f,seconds);
}
cur = this.delay(f,seconds);
return stop;
}
actor.delay = function(fn, seconds) { actor.delay = function(fn, seconds) {
var timers = this.timers; var timers = this.timers;
var stop = function() { var stop = function() {
@ -64,7 +55,8 @@ actor.delay = function(fn, seconds) {
} }
function execute() { function execute() {
fn(); if (fn) fn();
if (stop.then) stop.then();
stop(); stop();
} }

View file

@ -726,16 +726,6 @@ game.loadurs = function() {
newur.data = data; newur.data = data;
} }
} }
return;
for (var file of io.glob("**.json").filter(f => !ur[f.name()])) {
if (file[0] === '.' || file[0] === '_') continue;
var newur = ur_from_file(file);
if (!newur) continue;
Object.assign(newur, {
data: file
});
}
}; };
game.ur = {}; game.ur = {};

View file

@ -178,9 +178,11 @@ render.make_shader = function(shader)
var data = json.decode(io.slurp(writejson)); var data = json.decode(io.slurp(writejson));
var filemod = io.mod(writejson); var filemod = io.mod(writejson);
if (!data.files) break breakme; if (!data.files) break breakme;
for (var i of data.files) for (var i of data.files) {
if (io.mod(i) > filemod) if (io.mod(i) > filemod) {
break breakme; break breakme;
}
}
profile.report(st, `CACHE make shader from ${file}`); profile.report(st, `CACHE make shader from ${file}`);
var shaderobj = json.decode(io.slurp(writejson)); var shaderobj = json.decode(io.slurp(writejson));
@ -426,6 +428,7 @@ var textshader;
var circleshader; var circleshader;
var polyshader; var polyshader;
var slice9shader; var slice9shader;
var parshader;
render.init = function() { render.init = function() {
textshader = render.make_shader("shaders/text_base.cg"); textshader = render.make_shader("shaders/text_base.cg");
@ -434,6 +437,7 @@ render.init = function() {
slice9shader = render.make_shader("shaders/9slice.cg"); slice9shader = render.make_shader("shaders/9slice.cg");
circleshader = render.make_shader("shaders/circle.cg"); circleshader = render.make_shader("shaders/circle.cg");
polyshader = render.make_shader("shaders/poly.cg"); polyshader = render.make_shader("shaders/poly.cg");
parshader = render.make_shader("shaders/baseparticle.cg");
render.textshader = textshader; render.textshader = textshader;
@ -635,6 +639,13 @@ render.slice9 = function(tex, pos, bb, scale = [tex.width,tex.height], color = C
var textssbo = render.text_ssbo(); var textssbo = render.text_ssbo();
render.emitter(emit)
{
var ssbo = emit.draw();
render.use_shader(particleshader);
render.draw(shape.quad, ssbo,
}
render.flush_text = function() render.flush_text = function()
{ {
if (!render.textshader) return; if (!render.textshader) return;

View file

@ -103,19 +103,20 @@ Ease.elastic = {
Ease.elastic.c4 = 2*Math.PI/3; Ease.elastic.c4 = 2*Math.PI/3;
Ease.elastic.c5 = 2*Math.PI / 4.5; Ease.elastic.c5 = 2*Math.PI / 4.5;
var tween = function(obj, val, to, time) var tween = function(from, to, time, fn)
{ {
var start = profile.secs(profile.now()); var start = profile.secs(profile.now());
var startval = obj[val];
var update = function(dt) { var update = function(dt) {
var elapsed = profile.secs(profile.now()) - start; var elapsed = profile.secs(profile.now()) - start;
obj[val] = startval.lerp(to, elapsed/time); fn(from.lerp(to,elapsed/time));
if (elapsed >= time) { if (elapsed >= time) {
obj[val] = to; fn(to);
if (stop.then) stop.then();
stop(); stop();
} }
}; };
var stop = Register.update.register(update); var stop = Register.update.register(update);
return stop;
} }
var Tween = { var Tween = {

View file

@ -1,7 +1,7 @@
#blend mix #blend mix
#depth off
#primitive triangle #primitive triangle
#cull none #cull none
#depth off
@vs vs @vs vs
in vec3 a_pos; in vec3 a_pos;

52
shaders/baseparticle.cg Normal file
View file

@ -0,0 +1,52 @@
#depth off
#blend mix
@vs vs
in vec2 a_pos;
in vec2 a_uv;
struct particle {
vec2 pos;
float angle;
float scale;
vec4 color;
};
readonly buffer ssbo {
particle par[];
};
out vec2 uv;
out vec2 fuv;
out vec4 color0;
vec2 pos;
uniform mat4 vp;
void main()
{
particle p = par[gl_InstanceIndex];
pos = p.pos+(a_pos);
color0 = p.color;
gl_Position = vp * vec4(pos, 0.0, 1.0);
}
@end
@fs fs
in vec2 uv;
in vec2 fuv;
in vec4 color0;
out vec4 color;
texture2D text;
sampler smp;
void main()
{
color = color0;
}
@end
@program text vs fs

View file

@ -1,5 +1,5 @@
#blend mix
#depth off #depth off
#blend mix
#primitive triangle #primitive triangle
#cull none #cull none

View file

@ -64,6 +64,7 @@ void emitter_emit(emitter *e, int count, transform *t)
void emitter_draw(emitter *e) void emitter_draw(emitter *e)
{ {
printf("drawing %d particles\n", arrlen(e->particles));
if (arrlen(e->particles) == 0) return; if (arrlen(e->particles) == 0) return;
arrsetlen(e->verts, arrlen(e->particles)); arrsetlen(e->verts, arrlen(e->particles));
for (int i = 0; i < arrlen(e->particles); i++) { for (int i = 0; i < arrlen(e->particles); i++) {