diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-05-01 18:39:32 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-05-01 18:39:32 +0300 |
commit | cc268238ea9414535b4fdb12ce715ad881e0e3a5 (patch) | |
tree | ae07c232c28033708a6df4a00a8b86da1cf41f1f /source/blender | |
parent | ba22aa879720e7afed49dc86d3df563c03fd223c (diff) |
Overlay: Port wireframe shader to use shaderCreateInfo
This should have no functional changes.
Diffstat (limited to 'source/blender')
6 files changed, 73 insertions, 70 deletions
diff --git a/source/blender/draw/engines/overlay/overlay_shader.c b/source/blender/draw/engines/overlay/overlay_shader.c index 69b76389c4c..320fc2417c6 100644 --- a/source/blender/draw/engines/overlay/overlay_shader.c +++ b/source/blender/draw/engines/overlay/overlay_shader.c @@ -1012,19 +1012,10 @@ struct GPUShader *OVERLAY_shader_volume_gridlines(bool color_with_flags, bool co GPUShader *OVERLAY_shader_wireframe_select(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->wireframe_select) { - sh_data->wireframe_select = GPU_shader_create_from_arrays({ - .vert = (const char *[]){sh_cfg->lib, - datatoc_common_view_lib_glsl, - datatoc_common_globals_lib_glsl, - datatoc_gpu_shader_common_obinfos_lib_glsl, - datatoc_wireframe_vert_glsl, - NULL}, - .frag = (const char *[]){datatoc_wireframe_frag_glsl, NULL}, - .defs = (const char *[]){sh_cfg->def, "#define SELECT_EDGES\n", NULL}, - }); + sh_data->wireframe_select = GPU_shader_create_from_info_name( + draw_ctx->sh_cfg ? "overlay_wireframe_select_clipped" : "overlay_wireframe_select"); } return sh_data->wireframe_select; } @@ -1032,24 +1023,12 @@ GPUShader *OVERLAY_shader_wireframe_select(void) GPUShader *OVERLAY_shader_wireframe(bool custom_bias) { 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->wireframe[custom_bias]) { - sh_data->wireframe[custom_bias] = GPU_shader_create_from_arrays({ - .vert = (const char *[]){sh_cfg->lib, - datatoc_common_view_lib_glsl, - datatoc_common_globals_lib_glsl, - datatoc_gpu_shader_common_obinfos_lib_glsl, - datatoc_wireframe_vert_glsl, - NULL}, - .frag = (const char *[]){datatoc_common_view_lib_glsl, - datatoc_common_globals_lib_glsl, - datatoc_wireframe_frag_glsl, - NULL}, - .defs = (const char *[]){sh_cfg->def, - custom_bias ? "#define CUSTOM_DEPTH_BIAS\n" : NULL, - NULL}, - }); + sh_data->wireframe[custom_bias] = GPU_shader_create_from_info_name( + custom_bias ? (draw_ctx->sh_cfg ? "overlay_wireframe_custom_depth_clipped" : + "overlay_wireframe_custom_depth") : + (draw_ctx->sh_cfg ? "overlay_wireframe_clipped" : "overlay_wireframe")); } return sh_data->wireframe[custom_bias]; } diff --git a/source/blender/draw/engines/overlay/shaders/infos/wireframe_info.hh b/source/blender/draw/engines/overlay/shaders/infos/wireframe_info.hh new file mode 100644 index 00000000000..43367121d6a --- /dev/null +++ b/source/blender/draw/engines/overlay/shaders/infos/wireframe_info.hh @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_INTERFACE_INFO(overlay_wireframe_iface, "") + .flat(Type::VEC2, "edgeStart") + .smooth(Type::VEC4, "finalColor") + .no_perspective(Type::VEC2, "edgePos"); + +GPU_SHADER_CREATE_INFO(overlay_wireframe) + .do_static_compilation(true) + .push_constant(Type::FLOAT, "wireStepParam") + .push_constant(Type::FLOAT, "wireOpacity") + .push_constant(Type::BOOL, "useColoring") + .push_constant(Type::BOOL, "isTransform") + .push_constant(Type::BOOL, "isObjectColor") + .push_constant(Type::BOOL, "isRandomColor") + .push_constant(Type::BOOL, "isHair") + .push_constant(Type::MAT4, "hairDupliMatrix") + /* Scene Depth texture copy for manual depth test. */ + .sampler(0, ImageType::DEPTH_2D, "depthTex") + .vertex_in(0, Type::VEC3, "pos") + .vertex_in(1, Type::VEC3, "nor") + .vertex_in(2, Type::FLOAT, "wd") /* wiredata */ + .vertex_out(overlay_wireframe_iface) + .vertex_source("wireframe_vert.glsl") + .fragment_source("wireframe_frag.glsl") + .fragment_out(0, Type::VEC4, "fragColor") + .fragment_out(1, Type::VEC4, "lineOutput") + .additional_info("draw_mesh", "draw_object_infos", "draw_globals"); + +GPU_SHADER_CREATE_INFO(overlay_wireframe_clipped) + .do_static_compilation(true) + .additional_info("overlay_wireframe", "drw_clipped"); + +GPU_SHADER_CREATE_INFO(overlay_wireframe_custom_depth) + .do_static_compilation(true) + .define("CUSTOM_DEPTH_BIAS") + .additional_info("overlay_wireframe"); + +GPU_SHADER_CREATE_INFO(overlay_wireframe_custom_depth_clipped) + .do_static_compilation(true) + .additional_info("overlay_wireframe_custom_depth", "drw_clipped"); + +GPU_SHADER_CREATE_INFO(overlay_wireframe_select) + .do_static_compilation(true) + .define("SELECT_EDGES") + .additional_info("overlay_wireframe"); + +GPU_SHADER_CREATE_INFO(overlay_wireframe_select_clipped) + .do_static_compilation(true) + .additional_info("overlay_wireframe_select", "drw_clipped"); diff --git a/source/blender/draw/engines/overlay/shaders/wireframe_frag.glsl b/source/blender/draw/engines/overlay/shaders/wireframe_frag.glsl index 5c8c22c57d9..bc28d7a8a36 100644 --- a/source/blender/draw/engines/overlay/shaders/wireframe_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/wireframe_frag.glsl @@ -1,16 +1,5 @@ -/* Scene Depth texture copy for manual depth test. */ -uniform sampler2D depthTex; - -flat in vec2 edgeStart; - -#ifndef SELECT_EDGES -in vec4 finalColor; -noperspective in vec2 edgePos; - -layout(location = 0) out vec4 fragColor; -layout(location = 1) out vec4 lineOutput; -#endif +#pragma BLENDER_REQUIRE(common_view_lib.glsl) void main() { @@ -28,17 +17,18 @@ void main() vec2 dir = lineOutput.xy * 2.0 - 1.0; bool dir_horiz = abs(dir.x) > abs(dir.y); - vec2 uv = gl_FragCoord.xy * sizeViewportInv.xy; + vec2 uv = gl_FragCoord.xy * drw_view.viewport_size_inverse; float depth_occluder = texture(depthTex, uv).r; float depth_min = depth_occluder; + vec2 texel_uv_size = drw_view.viewport_size_inverse; if (dir_horiz) { - depth_min = min(depth_min, texture(depthTex, uv + vec2(-sizeViewportInv.x, 0.0)).r); - depth_min = min(depth_min, texture(depthTex, uv + vec2(sizeViewportInv.x, 0.0)).r); + depth_min = min(depth_min, texture(depthTex, uv + vec2(-texel_uv_size.x, 0.0)).r); + depth_min = min(depth_min, texture(depthTex, uv + vec2(texel_uv_size.x, 0.0)).r); } else { - depth_min = min(depth_min, texture(depthTex, uv + vec2(0, -sizeViewportInv.y)).r); - depth_min = min(depth_min, texture(depthTex, uv + vec2(0, sizeViewportInv.y)).r); + depth_min = min(depth_min, texture(depthTex, uv + vec2(0, -texel_uv_size.y)).r); + depth_min = min(depth_min, texture(depthTex, uv + vec2(0, texel_uv_size.y)).r); } float delta = abs(depth_occluder - depth_min); diff --git a/source/blender/draw/engines/overlay/shaders/wireframe_vert.glsl b/source/blender/draw/engines/overlay/shaders/wireframe_vert.glsl index 8d26aa89f13..41bd7791dd7 100644 --- a/source/blender/draw/engines/overlay/shaders/wireframe_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/wireframe_vert.glsl @@ -1,23 +1,5 @@ - -uniform float wireStepParam; -uniform float wireOpacity; -uniform bool useColoring; -uniform bool isTransform; -uniform bool isObjectColor; -uniform bool isRandomColor; -uniform bool isHair; -uniform mat4 hairDupliMatrix; - -in vec3 pos; -in vec3 nor; -in float wd; /* wiredata */ - -flat out vec2 edgeStart; - -#ifndef SELECT_EDGES -out vec4 finalColor; -noperspective out vec2 edgePos; -#endif +#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) float get_edge_sharpness(float wd) { @@ -114,7 +96,7 @@ void main() wofs = normal_world_to_view(wofs); /* Push vertex half a pixel (maximum) in normal direction. */ - gl_Position.xy += wofs.xy * sizeViewportInv.xy * gl_Position.w; + gl_Position.xy += wofs.xy * drw_view.viewport_size_inverse * gl_Position.w; /* Push the vertex towards the camera. Helps a bit. */ gl_Position.z -= facing_ratio * curvature * 1.0e-6 * gl_Position.w; @@ -154,10 +136,9 @@ void main() #ifdef SELECT_EDGES /* HACK: to avoid losing sub-pixel object in selections, we add a bit of randomness to the * wire to at least create one fragment that will pass the occlusion query. */ - gl_Position.xy += sizeViewportInv.xy * gl_Position.w * ((gl_VertexID % 2 == 0) ? -1.0 : 1.0); + gl_Position.xy += drw_view.viewport_size_inverse * gl_Position.w * + ((gl_VertexID % 2 == 0) ? -1.0 : 1.0); #endif -#ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance(wpos); -#endif + view_clipping_distances(wpos); } diff --git a/source/blender/draw/intern/shaders/draw_view_info.hh b/source/blender/draw/intern/shaders/draw_view_info.hh index 7329f2ed677..38f042aa30b 100644 --- a/source/blender/draw/intern/shaders/draw_view_info.hh +++ b/source/blender/draw/intern/shaders/draw_view_info.hh @@ -80,7 +80,7 @@ GPU_SHADER_CREATE_INFO(drw_clipped).define("USE_WORLD_CLIP_PLANES"); GPU_SHADER_CREATE_INFO(draw_globals) .typedef_source("draw_common_shader_shared.h") - .uniform_buf(1, "GlobalsUboStorage", "globalsBlock", Frequency::PASS); + .uniform_buf(7, "GlobalsUboStorage", "globalsBlock", Frequency::PASS); /** \} */ diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 8cff3d079c2..2f4a6edd4dd 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -453,6 +453,7 @@ set(SRC_SHADER_CREATE_INFOS ../draw/engines/overlay/shaders/infos/outline_info.hh ../draw/engines/overlay/shaders/infos/paint_info.hh ../draw/engines/overlay/shaders/infos/volume_info.hh + ../draw/engines/overlay/shaders/infos/wireframe_info.hh ../draw/engines/select/shaders/infos/select_id_info.hh ../draw/engines/workbench/shaders/infos/workbench_composite_info.hh ../draw/engines/workbench/shaders/infos/workbench_effect_antialiasing_info.hh |