| 1 |
/* clang-format off */ |
| 2 |
#[modes] |
| 3 |
|
| 4 |
mode_default = |
| 5 |
|
| 6 |
#[specializations] |
| 7 |
|
| 8 |
MODE_3D = false |
| 9 |
|
| 10 |
#[vertex] |
| 11 |
|
| 12 |
#include "stdlib_inc.glsl" |
| 13 |
|
| 14 |
// ParticleData |
| 15 |
layout(location = 0) in highp vec4 color; |
| 16 |
layout(location = 1) in highp vec4 velocity_flags; |
| 17 |
layout(location = 2) in highp vec4 custom; |
| 18 |
layout(location = 3) in highp vec4 xform_1; |
| 19 |
layout(location = 4) in highp vec4 xform_2; |
| 20 |
#ifdef MODE_3D |
| 21 |
layout(location = 5) in highp vec4 xform_3; |
| 22 |
#endif |
| 23 |
|
| 24 |
/* clang-format on */ |
| 25 |
out highp vec4 out_xform_1; //tfb: |
| 26 |
out highp vec4 out_xform_2; //tfb: |
| 27 |
#ifdef MODE_3D |
| 28 |
out highp vec4 out_xform_3; //tfb:MODE_3D |
| 29 |
#endif |
| 30 |
flat out highp uvec4 instance_color_custom_data; //tfb: |
| 31 |
|
| 32 |
uniform lowp vec3 sort_direction; |
| 33 |
uniform highp float frame_remainder; |
| 34 |
|
| 35 |
uniform highp vec3 align_up; |
| 36 |
uniform highp uint align_mode; |
| 37 |
|
| 38 |
uniform highp mat4 inv_emission_transform; |
| 39 |
|
| 40 |
#define TRANSFORM_ALIGN_DISABLED uint(0) |
| 41 |
#define TRANSFORM_ALIGN_Z_BILLBOARD uint(1) |
| 42 |
#define TRANSFORM_ALIGN_Y_TO_VELOCITY uint(2) |
| 43 |
#define TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY uint(3) |
| 44 |
|
| 45 |
#define PARTICLE_FLAG_ACTIVE uint(1) |
| 46 |
|
| 47 |
#define FLT_MAX float(3.402823466e+38) |
| 48 |
|
| 49 |
void main() { |
| 50 |
// Set scale to zero and translate to -INF so particle will be invisible |
| 51 |
// even for materials that ignore rotation/scale (i.e. billboards). |
| 52 |
mat4 txform = mat4(vec4(0.0), vec4(0.0), vec4(0.0), vec4(-FLT_MAX, -FLT_MAX, -FLT_MAX, 0.0)); |
| 53 |
if (bool(floatBitsToUint(velocity_flags.w) & PARTICLE_FLAG_ACTIVE)) { |
| 54 |
#ifdef MODE_3D |
| 55 |
txform = transpose(mat4(xform_1, xform_2, xform_3, vec4(0.0, 0.0, 0.0, 1.0))); |
| 56 |
#else |
| 57 |
txform = transpose(mat4(xform_1, xform_2, vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0))); |
| 58 |
#endif |
| 59 |
|
| 60 |
if (align_mode == TRANSFORM_ALIGN_DISABLED) { |
| 61 |
// nothing |
| 62 |
} else if (align_mode == TRANSFORM_ALIGN_Z_BILLBOARD) { |
| 63 |
mat3 local = mat3(normalize(cross(align_up, sort_direction)), align_up, sort_direction); |
| 64 |
local = local * mat3(txform); |
| 65 |
txform[0].xyz = local[0]; |
| 66 |
txform[1].xyz = local[1]; |
| 67 |
txform[2].xyz = local[2]; |
| 68 |
} else if (align_mode == TRANSFORM_ALIGN_Y_TO_VELOCITY) { |
| 69 |
vec3 v = velocity_flags.xyz; |
| 70 |
float s = (length(txform[0]) + length(txform[1]) + length(txform[2])) / 3.0; |
| 71 |
if (length(v) > 0.0) { |
| 72 |
txform[1].xyz = normalize(v); |
| 73 |
} else { |
| 74 |
txform[1].xyz = normalize(txform[1].xyz); |
| 75 |
} |
| 76 |
|
| 77 |
txform[0].xyz = normalize(cross(txform[1].xyz, txform[2].xyz)); |
| 78 |
txform[2].xyz = vec3(0.0, 0.0, 1.0) * s; |
| 79 |
txform[0].xyz *= s; |
| 80 |
txform[1].xyz *= s; |
| 81 |
} else if (align_mode == TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY) { |
| 82 |
vec3 sv = velocity_flags.xyz - sort_direction * dot(sort_direction, velocity_flags.xyz); //screen velocity |
| 83 |
|
| 84 |
if (length(sv) == 0.0) { |
| 85 |
sv = align_up; |
| 86 |
} |
| 87 |
|
| 88 |
sv = normalize(sv); |
| 89 |
|
| 90 |
txform[0].xyz = normalize(cross(sv, sort_direction)) * length(txform[0]); |
| 91 |
txform[1].xyz = sv * length(txform[1]); |
| 92 |
txform[2].xyz = sort_direction * length(txform[2]); |
| 93 |
} |
| 94 |
|
| 95 |
txform[3].xyz += velocity_flags.xyz * frame_remainder; |
| 96 |
|
| 97 |
#ifndef MODE_3D |
| 98 |
// In global mode, bring 2D particles to local coordinates |
| 99 |
// as they will be drawn with the node position as origin. |
| 100 |
txform = inv_emission_transform * txform; |
| 101 |
#endif |
| 102 |
} |
| 103 |
txform = transpose(txform); |
| 104 |
|
| 105 |
instance_color_custom_data.x = packHalf2x16(color.xy); |
| 106 |
instance_color_custom_data.y = packHalf2x16(color.zw); |
| 107 |
instance_color_custom_data.z = packHalf2x16(custom.xy); |
| 108 |
instance_color_custom_data.w = packHalf2x16(custom.zw); |
| 109 |
out_xform_1 = txform[0]; |
| 110 |
out_xform_2 = txform[1]; |
| 111 |
#ifdef MODE_3D |
| 112 |
out_xform_3 = txform[2]; |
| 113 |
#endif |
| 114 |
} |
| 115 |
|
| 116 |
/* clang-format off */ |
| 117 |
#[fragment] |
| 118 |
|
| 119 |
void main() { |
| 120 |
} |
| 121 |
/* clang-format on */ |