You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-24 15:26:15 +00:00
Add Particle Shader Userdata
* Adds optional vec4 USERDATA1 .. USERDATA6 to particles, allowing to store custom data. * This data is allocated on demand, so shaders that do not use it do not cost more.
This commit is contained in:
@@ -112,6 +112,24 @@ struct ParticleData {
|
||||
uint flags;
|
||||
vec4 color;
|
||||
vec4 custom;
|
||||
#ifdef USERDATA1_USED
|
||||
vec4 userdata1;
|
||||
#endif
|
||||
#ifdef USERDATA2_USED
|
||||
vec4 userdata2;
|
||||
#endif
|
||||
#ifdef USERDATA3_USED
|
||||
vec4 userdata3;
|
||||
#endif
|
||||
#ifdef USERDATA4_USED
|
||||
vec4 userdata4;
|
||||
#endif
|
||||
#ifdef USERDATA5_USED
|
||||
vec4 userdata5;
|
||||
#endif
|
||||
#ifdef USERDATA6_USED
|
||||
vec4 userdata6;
|
||||
#endif
|
||||
};
|
||||
|
||||
layout(set = 1, binding = 1, std430) restrict buffer Particles {
|
||||
|
||||
@@ -16,6 +16,9 @@ struct ParticleData {
|
||||
uint flags;
|
||||
vec4 color;
|
||||
vec4 custom;
|
||||
#ifdef USERDATA_COUNT
|
||||
vec4 userdata[USERDATA_COUNT];
|
||||
#endif
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 1, std430) restrict readonly buffer Particles {
|
||||
@@ -57,7 +60,7 @@ layout(push_constant, std430) uniform Params {
|
||||
bool order_by_lifetime;
|
||||
uint lifetime_split;
|
||||
bool lifetime_reverse;
|
||||
uint pad;
|
||||
bool copy_mode_2d;
|
||||
}
|
||||
params;
|
||||
|
||||
@@ -201,25 +204,22 @@ void main() {
|
||||
txform = mat4(vec4(0.0), vec4(0.0), vec4(0.0), vec4(0.0)); //zero scale, becomes invisible
|
||||
}
|
||||
|
||||
#ifdef MODE_2D
|
||||
if (params.copy_mode_2d) {
|
||||
uint write_offset = gl_GlobalInvocationID.x * (2 + 1 + 1); //xform + color + custom
|
||||
|
||||
uint write_offset = gl_GlobalInvocationID.x * (2 + 1 + 1); //xform + color + custom
|
||||
instances.data[write_offset + 0] = txform[0];
|
||||
instances.data[write_offset + 1] = txform[1];
|
||||
instances.data[write_offset + 2] = particles.data[particle].color;
|
||||
instances.data[write_offset + 3] = particles.data[particle].custom;
|
||||
} else {
|
||||
uint write_offset = gl_GlobalInvocationID.x * (3 + 1 + 1); //xform + color + custom
|
||||
|
||||
instances.data[write_offset + 0] = txform[0];
|
||||
instances.data[write_offset + 1] = txform[1];
|
||||
instances.data[write_offset + 2] = particles.data[particle].color;
|
||||
instances.data[write_offset + 3] = particles.data[particle].custom;
|
||||
|
||||
#else
|
||||
|
||||
uint write_offset = gl_GlobalInvocationID.x * (3 + 1 + 1); //xform + color + custom
|
||||
|
||||
instances.data[write_offset + 0] = txform[0];
|
||||
instances.data[write_offset + 1] = txform[1];
|
||||
instances.data[write_offset + 2] = txform[2];
|
||||
instances.data[write_offset + 3] = particles.data[particle].color;
|
||||
instances.data[write_offset + 4] = particles.data[particle].custom;
|
||||
#endif //MODE_2D
|
||||
instances.data[write_offset + 0] = txform[0];
|
||||
instances.data[write_offset + 1] = txform[1];
|
||||
instances.data[write_offset + 2] = txform[2];
|
||||
instances.data[write_offset + 3] = particles.data[particle].color;
|
||||
instances.data[write_offset + 4] = particles.data[particle].custom;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user