From 3969e30c6f8c6790a070fc4e428f887faee875f6 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Fri, 21 Feb 2025 10:21:44 +0100 Subject: [PATCH] SubDiv: Add base for polygon offset Subdiv shader library contains an optional part that shaders can include. As we are migrating each shader at a time there are now multiple PRs doing the same thing. Best to add the changes to main already so it doesn't add confusion during review. Pull Request: https://projects.blender.org/blender/blender/pulls/134906 --- source/blender/draw/CMakeLists.txt | 2 ++ source/blender/draw/intern/draw_shader.cc | 3 --- source/blender/draw/intern/draw_subdiv_defines.hh | 2 ++ source/blender/draw/intern/shaders/subdiv_info.hh | 6 ++++++ source/blender/draw/intern/shaders/subdiv_lib.glsl | 6 ++++++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index 2adf0b35724..41b1f901df2 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -187,6 +187,8 @@ set(SRC intern/draw_view.hh intern/draw_view_c.hh intern/draw_view_data.hh + intern/draw_subdiv_defines.hh + intern/draw_subdiv_shader_shared.hh intern/mesh_extractors/extract_mesh.hh engines/compositor/compositor_engine.h engines/eevee_next/eevee_ambient_occlusion.hh diff --git a/source/blender/draw/intern/draw_shader.cc b/source/blender/draw/intern/draw_shader.cc index 8bf71310e6d..a2bf4e83658 100644 --- a/source/blender/draw/intern/draw_shader.cc +++ b/source/blender/draw/intern/draw_shader.cc @@ -361,9 +361,6 @@ GPUShader *DRW_shader_subdiv_get(SubdivShaderType shader_type) defines = "#define GPU_AMD_DRIVER_BYTE_BUG\n"; } } - else if (shader_type == SubdivShaderType::BUFFER_CUSTOM_NORMALS_FINALIZE) { - defines = "#define CUSTOM_NORMALS\n"; - } e_data.subdiv_sh[uint(shader_type)] = GPU_shader_create_compute( compute_code, datatoc_subdiv_lib_glsl, defines, get_subdiv_shader_name(shader_type)); diff --git a/source/blender/draw/intern/draw_subdiv_defines.hh b/source/blender/draw/intern/draw_subdiv_defines.hh index d6f5698c9cc..a23b9977a52 100644 --- a/source/blender/draw/intern/draw_subdiv_defines.hh +++ b/source/blender/draw/intern/draw_subdiv_defines.hh @@ -16,6 +16,8 @@ #define SHADER_DATA_BUF_SLOT 0 /* Storage buffer bindings */ +#define SUBDIV_FACE_OFFSET_BUF_SLOT 0 + #define NORMALS_FINALIZE_VERTEX_NORMALS_BUF_SLOT 0 #define NORMALS_FINALIZE_VERTEX_LOOP_MAP_BUF_SLOT 1 #define NORMALS_FINALIZE_POS_NOR_BUF_SLOT 2 diff --git a/source/blender/draw/intern/shaders/subdiv_info.hh b/source/blender/draw/intern/shaders/subdiv_info.hh index 98406798aca..4544d43091d 100644 --- a/source/blender/draw/intern/shaders/subdiv_info.hh +++ b/source/blender/draw/intern/shaders/subdiv_info.hh @@ -19,6 +19,12 @@ TYPEDEF_SOURCE("draw_subdiv_shader_shared.hh") UNIFORM_BUF(SHADER_DATA_BUF_SLOT, DRWSubdivUboStorage, shader_data) GPU_SHADER_CREATE_END() +GPU_SHADER_CREATE_INFO(subdiv_polygon_offset_base) +DEFINE("SUBDIV_POLYGON_OFFSET") +STORAGE_BUF(SUBDIV_FACE_OFFSET_BUF_SLOT, READ, uint, subdiv_face_offset[]) +ADDITIONAL_INFO(subdiv_base) +GPU_SHADER_CREATE_END() + /* -------------------------------------------------------------------- */ /** \name Normals Finalize * \{ */ diff --git a/source/blender/draw/intern/shaders/subdiv_lib.glsl b/source/blender/draw/intern/shaders/subdiv_lib.glsl index 0b9c9508d6e..4a3d993dc48 100644 --- a/source/blender/draw/intern/shaders/subdiv_lib.glsl +++ b/source/blender/draw/intern/shaders/subdiv_lib.glsl @@ -8,7 +8,11 @@ #ifdef USE_GPU_SHADER_CREATE_INFO /* TODO: Do not use compute variables directly in a library. */ +# ifdef SUBDIV_POLYGON_OFFSET +COMPUTE_SHADER_CREATE_INFO(subdiv_polygon_offset_base) +# else COMPUTE_SHADER_CREATE_INFO(subdiv_base) +# endif #else layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in; @@ -210,4 +214,6 @@ uint coarse_face_index_from_subdiv_quad_index(uint subdiv_quad_index, uint coars return first - 1; } +#else +uint coarse_face_index_from_subdiv_quad_index(uint subdiv_quad_index, uint coarse_face_count); #endif