1
1

Overlay: Port particle display shader to use shaderCreateInfo

This should have no functional changes.
This commit is contained in:
2022-05-01 18:40:48 +02:00
parent d02d1129f7
commit 6cad9c7964
4 changed files with 59 additions and 46 deletions

View File

@@ -881,18 +881,10 @@ GPUShader *OVERLAY_shader_paint_wire(void)
GPUShader *OVERLAY_shader_particle_dot(void)
{
const DRWContextState *draw_ctx = DRW_context_state_get();
const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
if (!sh_data->particle_dot) {
sh_data->particle_dot = GPU_shader_create_from_arrays({
.vert = (const char *[]){sh_cfg->lib,
datatoc_common_globals_lib_glsl,
datatoc_common_view_lib_glsl,
datatoc_particle_vert_glsl,
NULL},
.frag = (const char *[]){datatoc_common_view_lib_glsl, datatoc_particle_frag_glsl, NULL},
.defs = (const char *[]){sh_cfg->def, "#define USE_DOTS\n", NULL},
});
sh_data->particle_dot = GPU_shader_create_from_info_name(
draw_ctx->sh_cfg ? "overlay_particle_dot_clipped" : "overlay_particle_dot");
}
return sh_data->particle_dot;
}
@@ -900,18 +892,10 @@ GPUShader *OVERLAY_shader_particle_dot(void)
GPUShader *OVERLAY_shader_particle_shape(void)
{
const DRWContextState *draw_ctx = DRW_context_state_get();
const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
if (!sh_data->particle_shape) {
sh_data->particle_shape = GPU_shader_create_from_arrays({
.vert = (const char *[]){sh_cfg->lib,
datatoc_common_globals_lib_glsl,
datatoc_common_view_lib_glsl,
datatoc_particle_vert_glsl,
NULL},
.frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
.defs = (const char *[]){sh_cfg->def, "#define INSTANCED_ATTR\n", NULL},
});
sh_data->particle_shape = GPU_shader_create_from_info_name(
draw_ctx->sh_cfg ? "overlay_particle_shape_clipped" : "overlay_particle_shape");
}
return sh_data->particle_shape;
}

View File

@@ -275,3 +275,50 @@ GPU_SHADER_CREATE_INFO(overlay_gpencil_canvas_clipped)
.additional_info("overlay_gpencil_canvas", "drw_clipped");
/** \} */
/* -------------------------------------------------------------------- */
/** \name Particle
* \{ */
GPU_SHADER_INTERFACE_INFO(overlay_particle_iface, "").flat(Type::VEC4, "finalColor");
GPU_SHADER_CREATE_INFO(overlay_particle)
.sampler(0, ImageType::FLOAT_1D, "weightTex")
.push_constant(Type::VEC4, "color") /* Drawsize packed in alpha */
.vertex_in(0, Type::VEC3, "part_pos")
.vertex_in(1, Type::VEC4, "part_rot")
.vertex_in(2, Type::FLOAT, "part_val")
.vertex_out(overlay_particle_iface)
.vertex_source("particle_vert.glsl")
.additional_info("draw_globals");
GPU_SHADER_CREATE_INFO(overlay_particle_dot)
.do_static_compilation(true)
.define("USE_DOTS")
.define("vclass", "0")
.define("pos", "vec3(0.0)")
.fragment_out(0, Type::VEC4, "fragColor")
.fragment_out(1, Type::VEC4, "lineOutput")
.fragment_source("particle_frag.glsl")
.additional_info("overlay_particle", "draw_mesh");
GPU_SHADER_CREATE_INFO(overlay_particle_dot_clipped)
.do_static_compilation(true)
.additional_info("overlay_particle_dot", "drw_clipped");
GPU_SHADER_CREATE_INFO(overlay_particle_shape)
.do_static_compilation(true)
/* NOTE: Color already in Linear space. Which is what we want. */
.define("srgbTarget", "false")
/* Instantiated Attrs. */
.vertex_in(3, Type::VEC3, "pos")
.vertex_in(4, Type::INT, "vclass")
.fragment_out(0, Type::VEC4, "fragColor")
.fragment_source("gpu_shader_flat_color_frag.glsl")
.additional_info("overlay_particle", "draw_modelmat", "draw_resource_id_uniform");
GPU_SHADER_CREATE_INFO(overlay_particle_shape_clipped)
.do_static_compilation(true)
.additional_info("overlay_particle_shape", "drw_clipped");
/** \} */

View File

@@ -1,8 +1,5 @@
in vec4 finalColor;
layout(location = 0) out vec4 fragColor;
layout(location = 1) out vec4 lineOutput;
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
void main()
{

View File

@@ -1,34 +1,21 @@
uniform sampler1D weightTex;
uniform vec4 color; /* Drawsize packed in alpha */
/* ---- Instantiated Attrs ---- */
in vec3 pos;
in int vclass;
/* ---- Per instance Attrs ---- */
in vec3 part_pos;
in vec4 part_rot;
in float part_val;
#ifdef USE_DOTS
out vec4 finalColor;
#else
flat out vec4 finalColor;
#endif
#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
/* TODO(fclem): Share with C code. */
#define VCLASS_SCREENALIGNED (1 << 9)
#define VCLASS_EMPTY_AXES (1 << 11)
vec3 rotate(vec3 vec, vec4 quat)
{
/* The quaternion representation here stores the w component in the first index */
/* The quaternion representation here stores the w component in the first index. */
return vec + 2.0 * cross(quat.yzw, cross(quat.yzw, vec) + quat.x * vec);
}
void main()
{
/* Drawsize packed in alpha. */
float draw_size = color.a;
vec3 world_pos = part_pos;
@@ -52,7 +39,7 @@ void main()
/* Coloring */
if ((vclass & VCLASS_EMPTY_AXES) != 0) {
/* see VBO construction for explanation. */
/* See VBO construction for explanation. */
finalColor = vec4(clamp(pos * 10000.0, 0.0, 1.0), 1.0);
}
else if (part_val < 0.0) {
@@ -62,7 +49,5 @@ void main()
finalColor = vec4(texture(weightTex, part_val).rgb, 1.0);
}
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance(world_pos);
#endif
view_clipping_distances(world_pos);
}