diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-05-01 20:30:57 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-05-01 20:35:37 +0300 |
commit | eba06fee4996087febaa4cdb57bd0388f226cff1 (patch) | |
tree | 5c790a5d279f7816a743f02ba4aae8d0b30779b6 /source/blender | |
parent | c87f6242b952d3821d7bdbdd8075b27479791448 (diff) |
Basic Engine: Port depth shader (object selection) to shaderCreateInfo
This should have no functional changes.
Diffstat (limited to 'source/blender')
7 files changed, 98 insertions, 108 deletions
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index 58a7d6f31da..42ff565cd9b 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -424,6 +424,7 @@ set(GLSL_SRC engines/basic/shaders/conservative_depth_geom.glsl engines/basic/shaders/depth_vert.glsl + engines/basic/shaders/depth_pointcloud_vert.glsl engines/basic/shaders/depth_frag.glsl engines/overlay/shaders/common_overlay_lib.glsl diff --git a/source/blender/draw/engines/basic/basic_shader.c b/source/blender/draw/engines/basic/basic_shader.c index 41d62afe525..d7a8f23e3b3 100644 --- a/source/blender/draw/engines/basic/basic_shader.c +++ b/source/blender/draw/engines/basic/basic_shader.c @@ -32,80 +32,12 @@ static struct { BASIC_Shaders sh_data[GPU_SHADER_CFG_LEN]; } e_data = {{{NULL}}}; /* Engine data */ -static GPUShader *BASIC_shader_create_depth_sh(const GPUShaderConfigData *sh_cfg) -{ - return GPU_shader_create_from_arrays({ - .vert = (const char *[]){sh_cfg->lib, - datatoc_common_view_lib_glsl, - datatoc_depth_vert_glsl, - NULL}, - .frag = (const char *[]){datatoc_depth_frag_glsl, NULL}, - .defs = (const char *[]){sh_cfg->def, NULL}, - }); -} - -static GPUShader *BASIC_shader_create_pointcloud_depth_sh(const GPUShaderConfigData *sh_cfg) -{ - return GPU_shader_create_from_arrays({ - .vert = (const char *[]){sh_cfg->lib, - datatoc_common_view_lib_glsl, - datatoc_common_pointcloud_lib_glsl, - datatoc_depth_vert_glsl, - NULL}, - .frag = (const char *[]){datatoc_depth_frag_glsl, NULL}, - .defs = (const char *[]){sh_cfg->def, - "#define POINTCLOUD\n", - "#define INSTANCED_ATTR\n", - "#define UNIFORM_RESOURCE_ID\n", - NULL}, - }); -} - -static GPUShader *BASIC_shader_create_depth_conservative_sh(const GPUShaderConfigData *sh_cfg) -{ - return GPU_shader_create_from_arrays({ - .vert = (const char *[]){sh_cfg->lib, - datatoc_common_view_lib_glsl, - datatoc_depth_vert_glsl, - NULL}, - .geom = (const char *[]){sh_cfg->lib, - datatoc_common_view_lib_glsl, - datatoc_conservative_depth_geom_glsl, - NULL}, - .frag = (const char *[]){datatoc_depth_frag_glsl, NULL}, - .defs = (const char *[]){sh_cfg->def, "#define CONSERVATIVE_RASTER\n", NULL}, - }); -} - -static GPUShader *BASIC_shader_create_pointcloud_depth_conservative_sh( - const GPUShaderConfigData *sh_cfg) -{ - return GPU_shader_create_from_arrays({ - .vert = (const char *[]){sh_cfg->lib, - datatoc_common_view_lib_glsl, - datatoc_common_pointcloud_lib_glsl, - datatoc_depth_vert_glsl, - NULL}, - .geom = (const char *[]){sh_cfg->lib, - datatoc_common_view_lib_glsl, - datatoc_conservative_depth_geom_glsl, - NULL}, - .frag = (const char *[]){datatoc_depth_frag_glsl, NULL}, - .defs = (const char *[]){sh_cfg->def, - "#define CONSERVATIVE_RASTER\n", - "#define POINTCLOUD\n", - "#define INSTANCED_ATTR\n", - "#define UNIFORM_RESOURCE_ID\n", - NULL}, - }); -} - GPUShader *BASIC_shaders_depth_sh_get(eGPUShaderConfig config) { BASIC_Shaders *sh_data = &e_data.sh_data[config]; - const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[config]; if (sh_data->depth == NULL) { - sh_data->depth = BASIC_shader_create_depth_sh(sh_cfg); + sh_data->depth = GPU_shader_create_from_info_name( + config == GPU_SHADER_CFG_CLIPPED ? "basic_depth_mesh_clipped" : "basic_depth_mesh"); } return sh_data->depth; } @@ -113,9 +45,10 @@ GPUShader *BASIC_shaders_depth_sh_get(eGPUShaderConfig config) GPUShader *BASIC_shaders_pointcloud_depth_sh_get(eGPUShaderConfig config) { BASIC_Shaders *sh_data = &e_data.sh_data[config]; - const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[config]; if (sh_data->pointcloud_depth == NULL) { - sh_data->pointcloud_depth = BASIC_shader_create_pointcloud_depth_sh(sh_cfg); + sh_data->pointcloud_depth = GPU_shader_create_from_info_name( + config == GPU_SHADER_CFG_CLIPPED ? "basic_depth_pointcloud_clipped" : + "basic_depth_pointcloud"); } return sh_data->pointcloud_depth; } @@ -123,9 +56,10 @@ GPUShader *BASIC_shaders_pointcloud_depth_sh_get(eGPUShaderConfig config) GPUShader *BASIC_shaders_depth_conservative_sh_get(eGPUShaderConfig config) { BASIC_Shaders *sh_data = &e_data.sh_data[config]; - const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[config]; if (sh_data->depth_conservative == NULL) { - sh_data->depth_conservative = BASIC_shader_create_depth_conservative_sh(sh_cfg); + sh_data->depth_conservative = GPU_shader_create_from_info_name( + config == GPU_SHADER_CFG_CLIPPED ? "basic_depth_mesh_conservative_clipped" : + "basic_depth_mesh_conservative"); } return sh_data->depth_conservative; } @@ -133,10 +67,10 @@ GPUShader *BASIC_shaders_depth_conservative_sh_get(eGPUShaderConfig config) GPUShader *BASIC_shaders_pointcloud_depth_conservative_sh_get(eGPUShaderConfig config) { BASIC_Shaders *sh_data = &e_data.sh_data[config]; - const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[config]; if (sh_data->pointcloud_depth_conservative == NULL) { - sh_data->pointcloud_depth_conservative = BASIC_shader_create_pointcloud_depth_conservative_sh( - sh_cfg); + sh_data->pointcloud_depth_conservative = GPU_shader_create_from_info_name( + config == GPU_SHADER_CFG_CLIPPED ? "basic_depth_pointcloud_conservative_clipped" : + "basic_depth_pointcloud_conservative"); } return sh_data->pointcloud_depth_conservative; } diff --git a/source/blender/draw/engines/basic/shaders/conservative_depth_geom.glsl b/source/blender/draw/engines/basic/shaders/conservative_depth_geom.glsl index aa983869eeb..d478f37691e 100644 --- a/source/blender/draw/engines/basic/shaders/conservative_depth_geom.glsl +++ b/source/blender/draw/engines/basic/shaders/conservative_depth_geom.glsl @@ -1,3 +1,5 @@ +#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) /* Adaptation of Conservative Rasterization * from GPU Gems 2 @@ -7,14 +9,6 @@ * avoids triangles producing no fragments. */ -layout(triangles) in; -layout(triangle_strip, max_vertices = 3) out; - -RESOURCE_ID_VARYING - -uniform vec2 sizeViewport; -uniform vec2 sizeViewportInv; - void main() { /* Compute plane normal in ndc space. */ @@ -25,7 +19,7 @@ void main() /* Compute NDC bound box. */ vec4 bbox = vec4(min(min(pos0.xy, pos1.xy), pos2.xy), max(max(pos0.xy, pos1.xy), pos2.xy)); /* Convert to pixel space. */ - bbox = (bbox * 0.5 + 0.5) * sizeViewport.xyxy; + bbox = (bbox * 0.5 + 0.5) * drw_view.viewport_size.xyxy; /* Detect failure cases where triangles would produce no fragments. */ bvec2 is_subpixel = lessThan(bbox.zw - bbox.xy, vec2(1.0)); /* View aligned triangle. */ @@ -37,22 +31,20 @@ void main() if (all(is_subpixel)) { vec2 ofs = (i == 0) ? vec2(-1.0) : ((i == 1) ? vec2(2.0, -1.0) : vec2(-1.0, 2.0)); /* HACK: Fix cases where the triangle is too small make it cover at least one pixel. */ - gl_Position.xy += sizeViewportInv.xy * gl_Position.w * ofs; + gl_Position.xy += drw_view.viewport_size_inverse * gl_Position.w * ofs; } /* Test if the triangle is almost parralele with the view to avoid precision issues. */ else if (any(is_subpixel) || is_coplanar) { /* HACK: Fix cases where the triangle is Parallel to the view by deforming it slightly. */ vec2 ofs = (i == 0) ? vec2(-1.0) : ((i == 1) ? vec2(1.0, -1.0) : vec2(1.0)); - gl_Position.xy += sizeViewportInv.xy * gl_Position.w * ofs; + gl_Position.xy += drw_view.viewport_size_inverse * gl_Position.w * ofs; } else { /* Triangle expansion should happen here, but we decide to not implement it for * depth precision & performance reasons. */ } -#ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_set_clip_distance(gl_in[i].gl_ClipDistance); -#endif + view_clipping_distances_set(gl_in[i]); EmitVertex(); } EndPrimitive(); diff --git a/source/blender/draw/engines/basic/shaders/depth_pointcloud_vert.glsl b/source/blender/draw/engines/basic/shaders/depth_pointcloud_vert.glsl new file mode 100644 index 00000000000..b82edc61cee --- /dev/null +++ b/source/blender/draw/engines/basic/shaders/depth_pointcloud_vert.glsl @@ -0,0 +1,15 @@ + +#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) +#pragma BLENDER_REQUIRE(common_pointcloud_lib.glsl) + +void main() +{ + GPU_INTEL_VERTEX_SHADER_WORKAROUND + + vec3 world_pos = pointcloud_get_pos(); + + gl_Position = point_world_to_ndc(world_pos); + + view_clipping_distances(world_pos); +} diff --git a/source/blender/draw/engines/basic/shaders/depth_vert.glsl b/source/blender/draw/engines/basic/shaders/depth_vert.glsl index be2a7d56d19..7046979cf97 100644 --- a/source/blender/draw/engines/basic/shaders/depth_vert.glsl +++ b/source/blender/draw/engines/basic/shaders/depth_vert.glsl @@ -1,28 +1,14 @@ -#ifdef CONSERVATIVE_RASTER -RESOURCE_ID_VARYING -#endif - -#ifndef POINTCLOUD -in vec3 pos; -#endif +#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) void main() { GPU_INTEL_VERTEX_SHADER_WORKAROUND -#ifdef CONSERVATIVE_RASTER - PASS_RESOURCE_ID -#endif -#ifdef POINTCLOUD - vec3 world_pos = pointcloud_get_pos(); -#else vec3 world_pos = point_object_to_world(pos); -#endif gl_Position = point_world_to_ndc(world_pos); -#ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance(world_pos); -#endif + view_clipping_distances(world_pos); } diff --git a/source/blender/draw/engines/basic/shaders/infos/basic_depth_info.hh b/source/blender/draw/engines/basic/shaders/infos/basic_depth_info.hh new file mode 100644 index 00000000000..9914d264c63 --- /dev/null +++ b/source/blender/draw/engines/basic/shaders/infos/basic_depth_info.hh @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "gpu_shader_create_info.hh" + +/* -------------------------------------------------------------------- */ +/** \name Conservative Rasterization + * + * Allow selection of sub-pixel objects. + * \{ */ + +GPU_SHADER_CREATE_INFO(basic_conservative) + .geometry_layout(PrimitiveIn::TRIANGLES, PrimitiveOut::TRIANGLE_STRIP, 3) + .geometry_source("conservative_depth_geom.glsl"); + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Object types + * \{ */ + +GPU_SHADER_CREATE_INFO(basic_mesh) + .vertex_in(0, Type::VEC3, "pos") + .vertex_source("depth_vert.glsl") + .additional_info("draw_mesh"); + +GPU_SHADER_CREATE_INFO(basic_pointcloud) + .vertex_source("depth_pointcloud_vert.glsl") + .additional_info("draw_pointcloud"); + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Variations Declaration + * \{ */ + +#define BASIC_FINAL_VARIATION(name, ...) \ + GPU_SHADER_CREATE_INFO(name).additional_info(__VA_ARGS__).do_static_compilation(true); + +#define BASIC_CLIPPING_VARIATIONS(prefix, ...) \ + BASIC_FINAL_VARIATION(prefix##_clipped, "drw_clipped", __VA_ARGS__) \ + BASIC_FINAL_VARIATION(prefix, __VA_ARGS__) + +#define BASIC_CONSERVATIVE_VARIATIONS(prefix, ...) \ + BASIC_CLIPPING_VARIATIONS(prefix##_conservative, "basic_conservative", __VA_ARGS__) \ + BASIC_CLIPPING_VARIATIONS(prefix, __VA_ARGS__) + +#define BASIC_OBTYPE_VARIATIONS(prefix, ...) \ + BASIC_CONSERVATIVE_VARIATIONS(prefix##_mesh, "basic_mesh", __VA_ARGS__) \ + BASIC_CONSERVATIVE_VARIATIONS(prefix##_pointcloud, "basic_pointcloud", __VA_ARGS__) + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Depth shader types. + * \{ */ + +GPU_SHADER_CREATE_INFO(basic_depth).fragment_source("depth_frag.glsl"); + +BASIC_OBTYPE_VARIATIONS(basic_depth, "basic_depth"); + +/** \} */ diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index bfccf2fd602..356daa2f23c 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -441,6 +441,7 @@ list(APPEND SRC ${glsl_source_list_file}) list(APPEND INC ${CMAKE_CURRENT_BINARY_DIR}) set(SRC_SHADER_CREATE_INFOS + ../draw/engines/basic/shaders/infos/basic_depth_info.hh ../draw/engines/gpencil/shaders/infos/gpencil_info.hh ../draw/engines/gpencil/shaders/infos/gpencil_vfx_info.hh ../draw/engines/overlay/shaders/infos/antialiasing_info.hh |