Overlay: Port image empty shader to use shaderCreateInfo

This should have no functional changes.
This commit is contained in:
Clément Foucault
2022-05-01 16:18:26 +02:00
parent 1c992cc647
commit d33801e2bf
4 changed files with 52 additions and 20 deletions
@@ -745,19 +745,11 @@ GPUShader *OVERLAY_shader_edit_uv_mask_image(void)
GPUShader *OVERLAY_shader_image(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->image) {
sh_data->image = GPU_shader_create_from_arrays({
.vert = (const char *[]){sh_cfg->lib,
datatoc_common_view_lib_glsl,
datatoc_image_vert_glsl,
NULL},
.frag = (const char *[]){datatoc_common_colormanagement_lib_glsl,
datatoc_image_frag_glsl,
NULL},
.defs = (const char *[]){sh_cfg->def, NULL},
});
/* TODO(fclem): Do we want to allow clipping reference images? */
sh_data->image = GPU_shader_create_from_info_name(0 ? "overlay_image_clipped" :
"overlay_image");
}
return sh_data->image;
}
@@ -1,20 +1,20 @@
uniform bool depthSet;
uniform bool isCameraBackground;
in vec3 pos;
out vec2 uvs;
#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
void main()
{
vec3 world_pos = point_object_to_world(pos);
if (isCameraBackground) {
vec3 vP = (ModelMatrix * vec4(pos, 1.0)).xyz;
gl_Position = point_view_to_ndc(vP);
/* Model matrix converts to view position to avoid jittering (see T91398). */
gl_Position = point_view_to_ndc(world_pos);
/* Camera background images are not really part of the 3D space.
* It makes no sense to apply clipping on them. */
view_clipping_distances_bypass();
}
else {
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
view_clipping_distances(world_pos);
}
if (depthSet) {
@@ -22,6 +22,7 @@ void main()
* This mimics the effect of infinite projection matrix
* (see http://www.terathon.com/gdc07_lengyel.pdf). */
gl_Position.z = gl_Position.w - 2.4e-7;
view_clipping_distances_bypass();
}
uvs = pos.xy * 0.5 + 0.5;
@@ -224,3 +224,30 @@ GPU_SHADER_CREATE_INFO(overlay_motion_path_point_clipped)
.additional_info("overlay_motion_path_point", "drw_clipped");
/** \} */
/* -------------------------------------------------------------------- */
/** \name Image Empty
* \{ */
GPU_SHADER_INTERFACE_INFO(overlay_image_iface, "").smooth(Type::VEC2, "uvs");
GPU_SHADER_CREATE_INFO(overlay_image)
.do_static_compilation(true)
.push_constant(Type::BOOL, "depthSet")
.push_constant(Type::BOOL, "isCameraBackground")
.push_constant(Type::BOOL, "imgPremultiplied")
.push_constant(Type::BOOL, "imgAlphaBlend")
.push_constant(Type::VEC4, "color")
.vertex_in(0, Type::VEC3, "pos")
.vertex_out(overlay_image_iface)
.sampler(0, ImageType::FLOAT_2D, "imgTexture")
.fragment_out(0, Type::VEC4, "fragColor")
.vertex_source("image_vert.glsl")
.fragment_source("image_frag.glsl")
.additional_info("draw_mesh");
GPU_SHADER_CREATE_INFO(overlay_image_clipped)
.do_static_compilation(true)
.additional_info("overlay_image", "drw_clipped");
/** \} */
@@ -16,6 +16,18 @@ void view_clipping_distances(vec3 wpos)
# endif
}
void view_clipping_distances_bypass()
{
# ifdef USE_WORLD_CLIP_PLANES
gl_ClipDistance[0] = 1.0;
gl_ClipDistance[1] = 1.0;
gl_ClipDistance[2] = 1.0;
gl_ClipDistance[3] = 1.0;
gl_ClipDistance[4] = 1.0;
gl_ClipDistance[5] = 1.0;
# endif
}
/* Kept as define for compiler compatibility. */
# ifdef USE_WORLD_CLIP_PLANES
# define view_clipping_distances_set(c) \