LumixEngine/data/pipelines/particles.shd
2023-07-14 16:24:51 +02:00

62 lines
No EOL
1.6 KiB
Text

import "pipelines/surface_base.inc"
uniform("Frames cols", "int")
uniform("Frames rows", "int")
common("#define PARTICLES\n")
surface_shader_ex({
texture_slots = {
{
name = "Texture",
default_texture = "textures/common/white.tga"
}
},
vertex_preface = [[
layout(location = 0) in vec3 i_position;
layout(location = 1) in float i_scale;
layout(location = 2) in vec4 i_color;
layout(location = 3) in float i_rot;
layout(location = 4) in float i_frame;
layout(location = 5) in float i_emission;
layout(location = 0) out vec2 v_uv;
layout(location = 1) out vec4 v_color;
layout(location = 2) out float v_emission;
]],
vertex = [[
vec2 pos = vec2(gl_VertexID & 1, (gl_VertexID & 2) * 0.5);
uint frame = uint(i_frame);
v_uv = (pos + vec2(frame % u_frames_cols, frame / u_frames_cols)) / vec2(u_frames_cols, u_frames_rows);
vec3 dir = normalize(i_position);
float c = cos(i_rot);
float s = sin(i_rot);
mat2 rotm = mat2(c, s, -s, c);
pos = (pos * 2 - 1) * rotm;
pos *= i_scale;
v_color = i_color;
v_emission = i_emission;
gl_Position = Pass.projection * ((Pass.view * u_model * vec4(i_position.xyz, 1)) + vec4(pos.xy, 0, 0));
]],
fragment_preface = [[
layout(location = 0) in vec2 v_uv;
layout(location = 1) in vec4 v_color;
layout(location = 2) in float v_emission;
]],
fragment = [[
vec4 c = texture(t_texture, v_uv) * saturate(v_color);
data.N = vec3(0);
data.V = vec3(0);
data.wpos = vec3(0);
data.albedo = c.rgb;
data.alpha = c.a;
data.emission = v_emission;
data.shadow = 1;
data.ao = 1;
data.roughness = 1;
data.metallic = 0;
data.translucency = 0;
]]
})