diff options
Diffstat (limited to 'source/blender/gpu')
34 files changed, 415 insertions, 279 deletions
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 1d6a5031d7e..0f7e804de9e 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -210,6 +210,7 @@ data_to_c_simple(shaders/gpu_shader_2D_point_uniform_size_varying_color_outline_ data_to_c_simple(shaders/gpu_shader_2D_edituvs_points_vert.glsl SRC) data_to_c_simple(shaders/gpu_shader_2D_edituvs_facedots_vert.glsl SRC) data_to_c_simple(shaders/gpu_shader_2D_edituvs_edges_vert.glsl SRC) +data_to_c_simple(shaders/gpu_shader_2D_edituvs_edges_frag.glsl SRC) data_to_c_simple(shaders/gpu_shader_2D_edituvs_faces_vert.glsl SRC) data_to_c_simple(shaders/gpu_shader_2D_edituvs_stretch_vert.glsl SRC) diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h index ab16bfc43c4..41a29a4d45d 100644 --- a/source/blender/gpu/GPU_buffers.h +++ b/source/blender/gpu/GPU_buffers.h @@ -37,6 +37,7 @@ struct DMFlagMat; struct GSet; struct MLoop; struct MLoopCol; +struct MPropCol; struct MLoopTri; struct MPoly; struct MVert; @@ -82,6 +83,7 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers, const int *sculpt_face_sets, const int face_sets_color_seed, const int face_sets_color_default, + const struct MPropCol *vtcol, const int update_flags); void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers, diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h index ab507d852e8..1cd5c4d519e 100644 --- a/source/blender/gpu/GPU_draw.h +++ b/source/blender/gpu/GPU_draw.h @@ -86,7 +86,7 @@ void GPU_create_smoke_coba_field(struct FluidModifierData *mmd); void GPU_create_smoke_velocity(struct FluidModifierData *mmd); /* Delayed free of OpenGL buffers by main thread */ -void GPU_free_unused_buffers(struct Main *bmain); +void GPU_free_unused_buffers(void); #ifdef __cplusplus } diff --git a/source/blender/gpu/GPU_vertex_buffer.h b/source/blender/gpu/GPU_vertex_buffer.h index fe45ec7b78b..f9bdf726930 100644 --- a/source/blender/gpu/GPU_vertex_buffer.h +++ b/source/blender/gpu/GPU_vertex_buffer.h @@ -80,6 +80,8 @@ void GPU_vertbuf_init_with_format_ex(GPUVertBuf *, const GPUVertFormat *, GPUUsa #define GPU_vertbuf_init_with_format(verts, format) \ GPU_vertbuf_init_with_format_ex(verts, format, GPU_USAGE_STATIC) +GPUVertBuf *GPU_vertbuf_duplicate(GPUVertBuf *verts); + uint GPU_vertbuf_size_get(const GPUVertBuf *); void GPU_vertbuf_data_alloc(GPUVertBuf *, uint v_len); void GPU_vertbuf_data_resize(GPUVertBuf *, uint v_len); diff --git a/source/blender/gpu/GPU_vertex_format.h b/source/blender/gpu/GPU_vertex_format.h index 61b14a4c5c0..34bfbb27823 100644 --- a/source/blender/gpu/GPU_vertex_format.h +++ b/source/blender/gpu/GPU_vertex_format.h @@ -124,6 +124,10 @@ BLI_INLINE const char *GPU_vertformat_attr_name_get(const GPUVertFormat *format, return format->names + attr->names[n_idx]; } +/* WARNING: Can only rename using a string with same character count. + * WARNING: This removes all other aliases of this attrib */ +void GPU_vertformat_attr_rename(GPUVertFormat *format, int attr, const char *new_name); + void GPU_vertformat_safe_attr_name(const char *attr_name, char *r_safe_name, uint max_len); /* format conversion */ diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c index cef90d57ef5..9c21f9040da 100644 --- a/source/blender/gpu/intern/gpu_buffers.c +++ b/source/blender/gpu/intern/gpu_buffers.c @@ -34,6 +34,7 @@ #include "BLI_hash.h" #include "BLI_math.h" #include "BLI_math_color.h" +#include "BLI_math_color_blend.h" #include "BLI_utildefines.h" #include "DNA_meshdata_types.h" @@ -227,12 +228,13 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers, const int *sculpt_face_sets, const int face_sets_color_seed, const int face_sets_color_default, + const MPropCol *vtcol, const int update_flags) { const bool show_mask = vmask && (update_flags & GPU_PBVH_BUFFERS_SHOW_MASK) != 0; - const bool show_vcol = vcol && (update_flags & GPU_PBVH_BUFFERS_SHOW_VCOL) != 0; const bool show_face_sets = sculpt_face_sets && (update_flags & GPU_PBVH_BUFFERS_SHOW_SCULPT_FACE_SETS) != 0; + const bool show_vcol = (vcol || vtcol) && (update_flags & GPU_PBVH_BUFFERS_SHOW_VCOL) != 0; bool empty_mask = true; bool default_face_set = true; @@ -244,8 +246,8 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers, GPUVertBufRaw pos_step = {0}; GPUVertBufRaw nor_step = {0}; GPUVertBufRaw msk_step = {0}; - GPUVertBufRaw col_step = {0}; GPUVertBufRaw fset_step = {0}; + GPUVertBufRaw col_step = {0}; GPU_vertbuf_attr_get_raw_data(buffers->vert_buf, g_vbo_id.pos, &pos_step); GPU_vertbuf_attr_get_raw_data(buffers->vert_buf, g_vbo_id.nor, &nor_step); @@ -312,25 +314,33 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers, *(uchar *)GPU_vertbuf_raw_step(&msk_step) = cmask; empty_mask = empty_mask && (cmask == 0); - + /* Vertex Colors. */ if (show_vcol) { - const uint loop_index = lt->tri[j]; - const MLoopCol *mcol = &vcol[loop_index]; - ushort scol[4]; - scol[0] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->r]); - scol[1] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->g]); - scol[2] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->b]); - scol[3] = unit_float_to_ushort_clamp(mcol->a * (1.0f / 255.0f)); - memcpy(GPU_vertbuf_raw_step(&col_step), scol, sizeof(scol)); + ushort scol[4] = {USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX}; + if (vtcol) { + scol[0] = unit_float_to_ushort_clamp(vtcol[vtri[j]].color[0]); + scol[1] = unit_float_to_ushort_clamp(vtcol[vtri[j]].color[1]); + scol[2] = unit_float_to_ushort_clamp(vtcol[vtri[j]].color[2]); + scol[3] = unit_float_to_ushort_clamp(vtcol[vtri[j]].color[3]); + memcpy(GPU_vertbuf_raw_step(&col_step), scol, sizeof(scol)); + } + else { + const uint loop_index = lt->tri[j]; + const MLoopCol *mcol = &vcol[loop_index]; + scol[0] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->r]); + scol[1] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->g]); + scol[2] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->b]); + scol[3] = unit_float_to_ushort_clamp(mcol->a * (1.0f / 255.0f)); + memcpy(GPU_vertbuf_raw_step(&col_step), scol, sizeof(scol)); + } } - /* Face Sets. */ memcpy(GPU_vertbuf_raw_step(&fset_step), face_set_color, sizeof(uchar) * 3); } } - - gpu_pbvh_batch_init(buffers, GPU_PRIM_TRIS); } + + gpu_pbvh_batch_init(buffers, GPU_PRIM_TRIS); } /* Get material index from the first face of this buffer. */ diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index b03b0fc0b1e..f07e3ed70d7 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -60,7 +60,8 @@ #include "PIL_time.h" -static void gpu_free_image_immediate(Image *ima); +static void gpu_free_image(Image *ima, const bool immediate); +static void gpu_free_unused_buffers(void); //* Checking powers of two for images since OpenGL ES requires it */ #ifdef WITH_DDS @@ -859,9 +860,13 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, ImBuf *ibuf, return NULL; } + /* Free any unused GPU textures, since we know we are in a thread with OpenGL + * context and might as well ensure we have as much space free as possible. */ + gpu_free_unused_buffers(); + /* currently, gpu refresh tagging is used by ima sequences */ if (ima->gpuflag & IMA_GPU_REFRESH) { - gpu_free_image_immediate(ima); + gpu_free_image(ima, true); ima->gpuflag &= ~IMA_GPU_REFRESH; } @@ -1338,63 +1343,65 @@ void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, i #endif } -static LinkNode *image_free_queue = NULL; -static ThreadMutex img_queue_mutex = BLI_MUTEX_INITIALIZER; +/* Delayed GPU texture free. Image datablocks can be deleted by any thread, + * but there may not be any active OpenGL context. In that case we push them + * into a queue and free the buffers later. */ +static LinkNode *gpu_texture_free_queue = NULL; +static ThreadMutex gpu_texture_queue_mutex = BLI_MUTEX_INITIALIZER; -static void gpu_queue_image_for_free(Image *ima) +static void gpu_free_unused_buffers() { - BLI_mutex_lock(&img_queue_mutex); - BLI_linklist_prepend(&image_free_queue, ima); - BLI_mutex_unlock(&img_queue_mutex); -} - -void GPU_free_unused_buffers(Main *bmain) -{ - if (!BLI_thread_is_main()) { + if (gpu_texture_free_queue == NULL) { return; } - BLI_mutex_lock(&img_queue_mutex); - - /* images */ - for (LinkNode *node = image_free_queue; node; node = node->next) { - Image *ima = node->link; + BLI_mutex_lock(&gpu_texture_queue_mutex); - /* check in case it was freed in the meantime */ - if (bmain && BLI_findindex(&bmain->images, ima) != -1) { - GPU_free_image(ima); + if (gpu_texture_free_queue != NULL) { + for (LinkNode *node = gpu_texture_free_queue; node; node = node->next) { + GPUTexture *tex = node->link; + GPU_texture_free(tex); } - } - BLI_linklist_free(image_free_queue, NULL); - image_free_queue = NULL; + BLI_linklist_free(gpu_texture_free_queue, NULL); + gpu_texture_free_queue = NULL; + } - BLI_mutex_unlock(&img_queue_mutex); + BLI_mutex_unlock(&gpu_texture_queue_mutex); } -static void gpu_free_image_immediate(Image *ima) +static void gpu_free_image(Image *ima, const bool immediate) { for (int eye = 0; eye < 2; eye++) { for (int i = 0; i < TEXTARGET_COUNT; i++) { - /* free glsl image binding */ if (ima->gputexture[i][eye] != NULL) { - GPU_texture_free(ima->gputexture[i][eye]); + if (immediate) { + GPU_texture_free(ima->gputexture[i][eye]); + } + else { + BLI_mutex_lock(&gpu_texture_queue_mutex); + BLI_linklist_prepend(&gpu_texture_free_queue, ima->gputexture[i][eye]); + BLI_mutex_unlock(&gpu_texture_queue_mutex); + } + ima->gputexture[i][eye] = NULL; } } } - ima->gpuflag &= ~(IMA_GPU_MIPMAP_COMPLETE); + ima->gpuflag &= ~IMA_GPU_MIPMAP_COMPLETE; } -void GPU_free_image(Image *ima) +void GPU_free_unused_buffers() { - if (!BLI_thread_is_main()) { - gpu_queue_image_for_free(ima); - return; + if (BLI_thread_is_main()) { + gpu_free_unused_buffers(); } +} - gpu_free_image_immediate(ima); +void GPU_free_image(Image *ima) +{ + gpu_free_image(ima, BLI_thread_is_main()); } void GPU_free_images(Main *bmain) diff --git a/source/blender/gpu/intern/gpu_draw_smoke.c b/source/blender/gpu/intern/gpu_draw_smoke.c index 80c59ed47c9..67947df0ff7 100644 --- a/source/blender/gpu/intern/gpu_draw_smoke.c +++ b/source/blender/gpu/intern/gpu_draw_smoke.c @@ -99,6 +99,7 @@ static void create_color_ramp(const struct ColorBand *coba, float *data) { for (int i = 0; i < TFUNC_WIDTH; i++) { BKE_colorband_evaluate(coba, (float)i / TFUNC_WIDTH, &data[i * 4]); + straight_to_premul_v4(&data[i * 4]); } } @@ -115,7 +116,7 @@ static GPUTexture *create_transfer_function(int type, const struct ColorBand *co break; } - GPUTexture *tex = GPU_texture_create_1d(TFUNC_WIDTH, GPU_RGBA8, data, NULL); + GPUTexture *tex = GPU_texture_create_1d(TFUNC_WIDTH, GPU_SRGB8_A8, data, NULL); MEM_freeN(data); diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index ab55fcfb1e0..fbeb2edc266 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -71,7 +71,7 @@ static struct GPUGlobal { int samples_color_texture_max; float line_width_range[2]; /* workaround for different calculation of dfdy factors on GPUs. Some GPUs/drivers - * calculate dfdy in shader differently when drawing to an offscreen buffer. First + * calculate dfdy in shader differently when drawing to an off-screen buffer. First * number is factor on screen and second is off-screen */ float dfdyfactors[2]; float max_anisotropy; @@ -84,9 +84,9 @@ static struct GPUGlobal { * GL_TEXTURE_MAX_LEVEL is higher than the target mip. * We need a workaround in this cases. */ bool mip_render_workaround; - /* There is an issue with the glBlitFramebuffer on MacOS with radeon pro graphics. - * Blitting depth with GL_DEPTH24_STENCIL8 is buggy so the workaround is to use - * GPU_DEPTH32F_STENCIL8. Then Blitting depth will work but blitting stencil will + /* There is an issue with the #glBlitFramebuffer on MacOS with radeon pro graphics. + * Blitting depth with#GL_DEPTH24_STENCIL8 is buggy so the workaround is to use + * #GPU_DEPTH32F_STENCIL8. Then Blitting depth will work but blitting stencil will * still be broken. */ bool depth_blitting_workaround; /* Crappy driver don't know how to map framebuffer slot to output vars... @@ -96,7 +96,7 @@ static struct GPUGlobal { /* Some crappy Intel drivers don't work well with shaders created in different * rendering contexts. */ bool context_local_shaders_workaround; - /* Intel drivers exhibit artifacts when using glCopyImageSubData & workbench antialiasing. + /* Intel drivers exhibit artifacts when using #glCopyImageSubData & workbench anti-aliasing. * (see T76273) */ bool texture_copy_workaround; } GG = {1, 0}; @@ -288,6 +288,19 @@ void gpu_extensions_init(void) } } + if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_UNIX, GPU_DRIVER_OPENSOURCE) && + strstr(renderer, "AMD VERDE")) { + /* We have issues with this specific renderer. (see T74024) */ + GG.unused_fb_slot_workaround = true; + GG.broken_amd_driver = true; + } + + if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_UNIX, GPU_DRIVER_OPENSOURCE) && + strstr(version, "Mesa 19.3.4")) { + /* Fix slowdown on this particular driver. (see T77641) */ + GG.broken_amd_driver = true; + } + if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_MAC, GPU_DRIVER_OFFICIAL)) { if (strstr(renderer, "AMD Radeon Pro") || strstr(renderer, "AMD Radeon R9") || strstr(renderer, "AMD Radeon RX")) { diff --git a/source/blender/gpu/intern/gpu_platform.c b/source/blender/gpu/intern/gpu_platform.c index a758787466f..5cabde61bc3 100644 --- a/source/blender/gpu/intern/gpu_platform.c +++ b/source/blender/gpu/intern/gpu_platform.c @@ -44,6 +44,8 @@ static struct GPUPlatformGlobal { char *gpu_name; } GPG = {false}; +/* Remove this? */ +#if 0 typedef struct GPUPlatformSupportTest { eGPUSupportLevel support_level; eGPUDeviceType device; @@ -53,6 +55,7 @@ typedef struct GPUPlatformSupportTest { const char *renderer; const char *version; } GPUPlatformSupportTest; +#endif eGPUSupportLevel GPU_platform_support_level(void) { diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c index 8c03567b95f..711147a61e9 100644 --- a/source/blender/gpu/intern/gpu_shader.c +++ b/source/blender/gpu/intern/gpu_shader.c @@ -117,6 +117,7 @@ extern char datatoc_gpu_shader_2D_point_uniform_size_varying_color_outline_aa_ve extern char datatoc_gpu_shader_2D_edituvs_points_vert_glsl[]; extern char datatoc_gpu_shader_2D_edituvs_facedots_vert_glsl[]; extern char datatoc_gpu_shader_2D_edituvs_edges_vert_glsl[]; +extern char datatoc_gpu_shader_2D_edituvs_edges_frag_glsl[]; extern char datatoc_gpu_shader_2D_edituvs_faces_vert_glsl[]; extern char datatoc_gpu_shader_2D_edituvs_stretch_vert_glsl[]; @@ -1171,12 +1172,12 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = { [GPU_SHADER_2D_UV_EDGES] = { .vert = datatoc_gpu_shader_2D_edituvs_edges_vert_glsl, - .frag = datatoc_gpu_shader_flat_color_frag_glsl, + .frag = datatoc_gpu_shader_2D_edituvs_edges_frag_glsl, }, [GPU_SHADER_2D_UV_EDGES_SMOOTH] = { .vert = datatoc_gpu_shader_2D_edituvs_edges_vert_glsl, - .frag = datatoc_gpu_shader_2D_smooth_color_frag_glsl, + .frag = datatoc_gpu_shader_2D_edituvs_edges_frag_glsl, .defs = "#define SMOOTH_COLOR\n", }, [GPU_SHADER_2D_UV_FACES] = diff --git a/source/blender/gpu/intern/gpu_state.c b/source/blender/gpu/intern/gpu_state.c index 908f5fa5771..30b258a73d1 100644 --- a/source/blender/gpu/intern/gpu_state.c +++ b/source/blender/gpu/intern/gpu_state.c @@ -208,7 +208,7 @@ typedef struct { uint is_cull_face : 1; uint is_depth_test : 1; uint is_dither : 1; - uint is_lighting : 1; + /* uint is_lighting : 1; */ /* UNUSED */ uint is_line_smooth : 1; uint is_color_logic_op : 1; uint is_multisample : 1; diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c index a985d45162c..56e82b94fd2 100644 --- a/source/blender/gpu/intern/gpu_texture.c +++ b/source/blender/gpu/intern/gpu_texture.c @@ -677,12 +677,14 @@ static bool gpu_texture_check_capacity( GPUTexture *tex, GLenum proxy, GLenum internalformat, GLenum data_format, GLenum data_type) { if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_WIN, GPU_DRIVER_ANY) || + GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_MAC, GPU_DRIVER_OFFICIAL) || GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_UNIX, GPU_DRIVER_OFFICIAL)) { /* Some AMD drivers have a faulty `GL_PROXY_TEXTURE_..` check. * (see T55888, T56185, T59351). * Checking with `GL_PROXY_TEXTURE_..` doesn't prevent `Out Of Memory` issue, * it just states that the OGL implementation can support the texture. - * So manually check the maximum size and maximum number of layers. */ + * So manually check the maximum size and maximum number of layers. + * Same thing happens on Nvidia/macOS 10.15 (T78175). */ switch (proxy) { case GL_PROXY_TEXTURE_2D_ARRAY: if ((tex->d < 0) || (tex->d > GPU_max_texture_layers())) { @@ -1772,8 +1774,13 @@ void GPU_texture_unbind(GPUTexture *tex) void GPU_texture_unbind_all(void) { if (GLEW_ARB_multi_bind) { - glBindTextures(0, GPU_max_textures(), NULL); - glBindSamplers(0, GPU_max_textures(), NULL); + /* Some drivers crash because of the NULL array even if that's explicitly + * allowed by the spec... *sigh* (see T77549). */ + GLuint texs[32] = {0}; + int count = min_ii(32, GPU_max_textures()); + + glBindTextures(0, count, texs); + glBindSamplers(0, count, texs); return; } diff --git a/source/blender/gpu/intern/gpu_vertex_buffer.c b/source/blender/gpu/intern/gpu_vertex_buffer.c index 25daabe601d..3b4d469542c 100644 --- a/source/blender/gpu/intern/gpu_vertex_buffer.c +++ b/source/blender/gpu/intern/gpu_vertex_buffer.c @@ -85,6 +85,35 @@ void GPU_vertbuf_init_with_format_ex(GPUVertBuf *verts, } } +GPUVertBuf *GPU_vertbuf_duplicate(GPUVertBuf *verts) +{ + GPUVertBuf *verts_dst = GPU_vertbuf_create(GPU_USAGE_STATIC); + /* Full copy. */ + *verts_dst = *verts; + GPU_vertformat_copy(&verts_dst->format, &verts->format); + + if (verts->vbo_id) { + uint buffer_sz = GPU_vertbuf_size_get(verts); + + verts_dst->vbo_id = GPU_buf_alloc(); + + glBindBuffer(GL_COPY_READ_BUFFER, verts->vbo_id); + glBindBuffer(GL_COPY_WRITE_BUFFER, verts_dst->vbo_id); + + glBufferData(GL_COPY_WRITE_BUFFER, buffer_sz, NULL, convert_usage_type_to_gl(verts->usage)); + + glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0, buffer_sz); +#if VRAM_USAGE + vbo_memory_usage += GPU_vertbuf_size_get(verts); +#endif + } + + if (verts->data) { + verts_dst->data = MEM_dupallocN(verts->data); + } + return verts_dst; +} + /** Same as discard but does not free. */ void GPU_vertbuf_clear(GPUVertBuf *verts) { diff --git a/source/blender/gpu/intern/gpu_vertex_format.c b/source/blender/gpu/intern/gpu_vertex_format.c index b84a7e0f554..585a22277b2 100644 --- a/source/blender/gpu/intern/gpu_vertex_format.c +++ b/source/blender/gpu/intern/gpu_vertex_format.c @@ -262,6 +262,20 @@ int GPU_vertformat_attr_id_get(const GPUVertFormat *format, const char *name) return -1; } +void GPU_vertformat_attr_rename(GPUVertFormat *format, int attr_id, const char *new_name) +{ + BLI_assert(attr_id > -1 && attr_id < format->attr_len); + GPUVertAttr *attr = &format->attrs[attr_id]; + char *attr_name = (char *)GPU_vertformat_attr_name_get(format, attr, 0); + BLI_assert(strlen(attr_name) == strlen(new_name)); + int i = 0; + while (attr_name[i] != '\0') { + attr_name[i] = new_name[i]; + i++; + } + attr->name_len = 1; +} + /* Encode 8 original bytes into 11 safe bytes. */ static void safe_bytes(char out[11], const char data[8]) { diff --git a/source/blender/gpu/shaders/gpu_shader_2D_edituvs_edges_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_edituvs_edges_frag.glsl new file mode 100644 index 00000000000..108fc85c4a5 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_2D_edituvs_edges_frag.glsl @@ -0,0 +1,30 @@ + + +uniform float dashWidth; + +#ifdef SMOOTH_COLOR +noperspective in vec4 finalColor; +#else +flat in vec4 finalColor; +#endif + +noperspective in vec2 stipple_pos; +flat in vec2 stipple_start; + +out vec4 fragColor; + +void main() +{ + fragColor = finalColor; + + /* Avoid passing viewport size */ + vec2 dd = fwidth(stipple_pos); + + float dist = distance(stipple_start, stipple_pos) / max(dd.x, dd.y); + + if (fract(dist / dashWidth) > 0.5) { + fragColor.rgb = vec3(0.0); + } + + fragColor = blender_srgb_to_framebuffer_space(fragColor); +} diff --git a/source/blender/gpu/shaders/gpu_shader_2D_edituvs_edges_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_edituvs_edges_vert.glsl index 02bbe545436..69fe5c93a61 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_edituvs_edges_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_edituvs_edges_vert.glsl @@ -12,6 +12,9 @@ noperspective out vec4 finalColor; flat out vec4 finalColor; #endif +noperspective out vec2 stipple_pos; +flat out vec2 stipple_start; + /* TODO: Port drawing to draw manager and * remove constants duplications. */ #define VERT_UV_SELECT (1 << 3) @@ -28,5 +31,8 @@ void main() gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0); gl_Position.z = float(!is_select); + /* Avoid precision loss. */ + stipple_start = stipple_pos = 500.0 + 500.0 * (gl_Position.xy / gl_Position.w); + finalColor = (is_select) ? selectColor : edgeColor; } diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl index bdc87baf924..21c7f79a57c 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl @@ -1,11 +1,67 @@ uniform vec3 checkerColorAndSize; -noperspective in vec4 finalColor; +noperspective in vec2 uvInterp; noperspective in float butCo; flat in float discardFac; +flat in float shadeTri; +flat in vec2 outRectSize; +flat in vec4 outRoundCorners; +noperspective in vec4 innerColor; +flat in vec4 borderColor; +flat in vec4 embossColor; +flat in float lineWidth; out vec4 fragColor; +vec3 compute_masks(vec2 uv) +{ + bool upper_half = uv.y > outRectSize.y * 0.5; + bool right_half = uv.x > outRectSize.x * 0.5; + float corner_rad; + + /* Correct aspect ratio for 2D views not using uniform scalling. + * uv is already in pixel space so a uniform scale should give us a ratio of 1. */ + float ratio = (butCo != -2.0) ? (dFdy(uv.y) / dFdx(uv.x)) : 1.0; + vec2 uv_sdf = uv; + uv_sdf.x *= ratio; + + if (right_half) { + uv_sdf.x = outRectSize.x * ratio - uv_sdf.x; + } + if (upper_half) { + uv_sdf.y = outRectSize.y - uv_sdf.y; + corner_rad = right_half ? outRoundCorners.z : outRoundCorners.w; + } + else { + corner_rad = right_half ? outRoundCorners.y : outRoundCorners.x; + } + + /* Signed distance field from the corner (in pixel). + * inner_sdf is sharp and outer_sdf is rounded. */ + uv_sdf -= corner_rad; + float inner_sdf = max(0.0, min(uv_sdf.x, uv_sdf.y)); + float outer_sdf = -length(min(uv_sdf, 0.0)); + float sdf = inner_sdf + outer_sdf + corner_rad; + + /* Fade emboss at the border. */ + float emboss_size = clamp((upper_half) ? 0.0 : (uv.x / corner_rad), 0.0, 1.0); + + /* Clamp line width to be at least 1px wide. This can happen if the projection matrix + * has been scaled (i.e: Node editor)... */ + float line_width = (lineWidth > 0.0) ? max(fwidth(uv.y), lineWidth) : 0.0; + + const float aa_radius = 0.5; + vec3 masks; + masks.x = smoothstep(-aa_radius, aa_radius, sdf); + masks.y = smoothstep(-aa_radius, aa_radius, sdf - line_width); + masks.z = smoothstep(-aa_radius, aa_radius, sdf + line_width * emboss_size); + + /* Compose masks together to avoid having too much alpha. */ + masks.zx = max(vec2(0.0), masks.zx - masks.xy); + + return masks; +} + vec4 do_checkerboard() { float size = checkerColorAndSize.z; @@ -25,16 +81,32 @@ void main() discard; } - fragColor = finalColor; - - if (butCo > 0.5) { - vec4 checker = do_checkerboard(); - fragColor = mix(checker, fragColor, fragColor.a); - } + vec3 masks = compute_masks(uvInterp); if (butCo > 0.0) { + /* Alpha checker widget. */ + if (butCo > 0.5) { + vec4 checker = do_checkerboard(); + fragColor = mix(checker, innerColor, innerColor.a); + } + else { + /* Set alpha to 1.0. */ + fragColor = innerColor; + } fragColor.a = 1.0; } + else { + /* Premultiply here. */ + fragColor = innerColor * vec4(innerColor.aaa, 1.0); + } + fragColor *= masks.y; + fragColor += masks.x * borderColor; + fragColor += masks.z * embossColor; + + /* Un-premult because the blend equation is already doing the mult. */ + if (fragColor.a > 0.0) { + fragColor.rgb /= fragColor.a; + } fragColor = blender_srgb_to_framebuffer_space(fragColor); } diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl index d7cc851556b..2fd5effccce 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl @@ -1,127 +1,7 @@ -#define BIT_RANGE(x) uint((1 << x) - 1) - -/* 2 bits for corner */ -/* Attention! Not the same order as in UI_interface.h! - * Ordered by drawing order. */ -#define BOTTOM_LEFT 0u -#define BOTTOM_RIGHT 1u -#define TOP_RIGHT 2u -#define TOP_LEFT 3u -#define CNR_FLAG_RANGE BIT_RANGE(2) - -/* 4bits for corner id */ -#define CORNER_VEC_OFS 2u -#define CORNER_VEC_RANGE BIT_RANGE(4) -const vec2 cornervec[9] = vec2[9](vec2(0.0, 1.0), - vec2(0.02, 0.805), - vec2(0.067, 0.617), - vec2(0.169, 0.45), - vec2(0.293, 0.293), - vec2(0.45, 0.169), - vec2(0.617, 0.076), - vec2(0.805, 0.02), - vec2(1.0, 0.0)); - -/* 4bits for jitter id */ -#define JIT_OFS 6u -#define JIT_RANGE BIT_RANGE(4) -const vec2 jit[9] = vec2[9](vec2(0.468813, -0.481430), - vec2(-0.155755, -0.352820), - vec2(0.219306, -0.238501), - vec2(-0.393286, -0.110949), - vec2(-0.024699, 0.013908), - vec2(0.343805, 0.147431), - vec2(-0.272855, 0.269918), - vec2(0.095909, 0.388710), - vec2(0.0, 0.0)); - -/* 2bits for other flags */ -#define INNER_FLAG uint(1 << 10) /* is inner vert */ -#define EMBOSS_FLAG uint(1 << 11) /* is emboss vert */ - -/* 2bits for color */ -#define COLOR_OFS 12u -#define COLOR_RANGE BIT_RANGE(2) -#define COLOR_INNER 0u -#define COLOR_EDGE 1u -#define COLOR_EMBOSS 2u - -/* 2bits for trias type */ -#define TRIA_FLAG uint(1 << 14) /* is tria vert */ -#define TRIA_FIRST INNER_FLAG /* is first tria (reuse INNER_FLAG) */ - -/* We can reuse the CORNER_* bits for tria */ -#define TRIA_VEC_RANGE BIT_RANGE(6) - -/* Some GPUs have performanse issues with this array being const (Doesn't fit in the registers?). - * To resolve this issue, store the array as a uniform buffer. - * (The array is still stored in the registry, but indexing is done in the uniform buffer.) */ -uniform vec2 triavec[43] = vec2[43]( - - /* ROUNDBOX_TRIA_ARROWS */ - vec2(-0.170000, 0.400000), - vec2(-0.050000, 0.520000), - vec2(0.250000, 0.000000), - vec2(0.470000, -0.000000), - vec2(-0.170000, -0.400000), - vec2(-0.050000, -0.520000), - vec2(0.170000, 0.400000), - vec2(0.050000, 0.520000), - vec2(-0.250000, 0.000000), - vec2(-0.470000, -0.000000), - vec2(0.170000, -0.400000), - vec2(0.050000, -0.520000), - - /* ROUNDBOX_TRIA_SCROLL - circle tria (triangle strip) */ - vec2(0.000000, 1.000000), - vec2(0.382684, 0.923879), - vec2(-0.382683, 0.923880), - vec2(0.707107, 0.707107), - vec2(-0.707107, 0.707107), - vec2(0.923879, 0.382684), - vec2(-0.923879, 0.382684), - vec2(1.000000, 0.000000), - vec2(-1.000000, 0.000000), - vec2(0.923879, -0.382684), - vec2(-0.923879, -0.382684), - vec2(0.707107, -0.707107), - vec2(-0.707107, -0.707107), - vec2(0.382684, -0.923879), - vec2(-0.382683, -0.923880), - vec2(0.000000, -1.000000), - - /* ROUNDBOX_TRIA_MENU - menu arrows */ - vec2(-0.51, 0.07), - vec2(-0.4, 0.18), - vec2(-0.05, -0.39), - vec2(-0.05, -0.17), - vec2(0.41, 0.07), - vec2(0.3, 0.18), - - /* ROUNDBOX_TRIA_CHECK - check mark */ - vec2(-0.67000, 0.020000), - vec2(-0.500000, 0.190000), - vec2(-0.130000, -0.520000), - vec2(-0.130000, -0.170000), - vec2(0.720000, 0.430000), - vec2(0.530000, 0.590000), - -/* ROUNDBOX_TRIA_HOLD_ACTION_ARROW - hold action arrows */ -#define OX (-0.32) -#define OY (0.1) -#define SC (0.35 * 2) - // vec2(-0.5 + SC, 1.0 + OY), vec2( 0.5, 1.0 + OY), vec2( 0.5, 0.0 + OY + SC), - vec2((0.5 - SC) + OX, 1.0 + OY), - vec2(-0.5 + OX, 1.0 + OY), - vec2(-0.5 + OX, SC + OY) -#undef OX -#undef OY -#undef SC -); uniform mat4 ModelViewProjectionMatrix; -#define MAX_PARAM 11 +#define MAX_PARAM 12 #ifdef USE_INSTANCE # define MAX_INSTANCE 6 uniform vec4 parameters[MAX_PARAM * MAX_INSTANCE]; @@ -147,105 +27,152 @@ uniform vec4 parameters[MAX_PARAM]; #define tria2Size parameters[gl_InstanceID * MAX_PARAM + 10].y #define shadeDir parameters[gl_InstanceID * MAX_PARAM + 10].z #define alphaDiscard parameters[gl_InstanceID * MAX_PARAM + 10].w +#define triaType parameters[gl_InstanceID * MAX_PARAM + 11].x /* We encode alpha check and discard factor together. */ #define doAlphaCheck (alphaDiscard < 0.0) #define discardFactor abs(alphaDiscard) -in uint vflag; - -noperspective out vec4 finalColor; +noperspective out vec2 uvInterp; +flat out vec2 outRectSize; +flat out vec4 outRoundCorners; +noperspective out vec4 innerColor; +flat out vec4 borderColor; +flat out vec4 embossColor; +flat out float lineWidth; noperspective out float butCo; flat out float discardFac; vec2 do_widget(void) { - uint cflag = vflag & CNR_FLAG_RANGE; - uint vofs = (vflag >> CORNER_VEC_OFS) & CORNER_VEC_RANGE; - bool is_inner = (vflag & INNER_FLAG) != 0u; - - vec2 v = cornervec[vofs]; - /* Scale by corner radius */ - v *= roundCorners[cflag] * ((is_inner) ? radsi : rads); - /* Flip in the right direction and osition to corner */ - vec4 rct = (is_inner) ? recti : rect; - if (cflag == BOTTOM_LEFT) { - v += rct.xz; - } - else if (cflag == BOTTOM_RIGHT) { - v = vec2(-v.y, v.x); - v += rct.yz; + lineWidth = abs(rect.x - recti.x); + vec2 emboss_ofs = vec2(0.0, -lineWidth); + vec2 v_pos[4] = vec2[4](rect.xz + emboss_ofs, rect.xw, rect.yz + emboss_ofs, rect.yw); + vec2 pos = v_pos[gl_VertexID]; + + uvInterp = pos - rect.xz; + outRectSize = rect.yw - rect.xz; + outRoundCorners = rads * roundCorners; + + vec2 uv = uvInterp / outRectSize; + float fac = clamp((shadeDir > 0.0) ? uv.y : uv.x, 0.0, 1.0); + /* Note innerColor is premultiplied inside the fragment shader. */ + if (doAlphaCheck) { + innerColor = colorInner1; + butCo = uv.x; } - else if (cflag == TOP_RIGHT) { - v = -v; - v += rct.yw; - } - else /* (cflag == TOP_LEFT) */ { - v = vec2(v.y, -v.x); - v += rct.xw; - } - - vec2 uv = faci * (v - recti.xz); - - /* compute uv and color gradient */ - uint color_id = (vflag >> COLOR_OFS) & COLOR_RANGE; - if (color_id == COLOR_INNER) { - float fac = clamp((shadeDir > 0.0) ? uv.y : uv.x, 0.0, 1.0); - - if (doAlphaCheck) { - finalColor = colorInner1; - butCo = uv.x; - } - else { - finalColor = mix(colorInner2, colorInner1, fac); - butCo = -abs(uv.x); - } - } - else if (color_id == COLOR_EDGE) { - finalColor = colorEdge; - butCo = -abs(uv.x); - } - else /* (color_id == COLOR_EMBOSS) */ { - finalColor = colorEmboss; + else { + innerColor = mix(colorInner2, colorInner1, fac); butCo = -abs(uv.x); } - bool is_emboss = (vflag & EMBOSS_FLAG) != 0u; - v.y -= (is_emboss) ? (recti.z - rect.z) : 0.0; + /* We need premultiplied color for transparency. */ + borderColor = colorEdge * vec4(colorEdge.aaa, 1.0); + embossColor = colorEmboss * vec4(colorEmboss.aaa, 1.0); - return v; + return pos; } vec2 do_tria() { - uint vofs = vflag & TRIA_VEC_RANGE; + int vidx = gl_VertexID % 4; + bool tria2 = gl_VertexID > 7; + + vec2 pos; + float size = (tria2) ? -tria2Size : tria1Size; + vec2 center = (tria2) ? tria2Center : tria1Center; + + vec2 arrow_pos[4] = vec2[4](vec2(0.0, 0.6), vec2(0.6, 0.0), vec2(-0.6, 0.0), vec2(0.0, -0.6)); + /* Rotated uv space by 45deg and mirrored. */ + vec2 arrow_uvs[4] = vec2[4](vec2(0.0, 0.85), vec2(0.85, 0.85), vec2(0.0, 0.0), vec2(0.0, 0.85)); + + vec2 point_pos[4] = vec2[4](vec2(-1.0, -1.0), vec2(-1.0, 1.0), vec2(1.0, -1.0), vec2(1.0, 1.0)); + vec2 point_uvs[4] = vec2[4](vec2(0.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 0.0), vec2(1.0, 1.0)); + + /* We reuse the SDF roundbox rendering of widget to render the tria shapes. + * This means we do clever tricks to position the rectangle the way we want using + * the 2 triangles uvs. */ + if (triaType == 0.0) { + /* ROUNDBOX_TRIA_NONE */ + outRectSize = uvInterp = pos = vec2(0); + outRoundCorners = vec4(0.01); + } + else if (triaType == 1.0) { + /* ROUNDBOX_TRIA_ARROWS */ + pos = arrow_pos[vidx]; + uvInterp = arrow_uvs[vidx]; + uvInterp -= vec2(0.05, 0.63); /* Translate */ + outRectSize = vec2(0.74, 0.17); + outRoundCorners = vec4(0.08); + } + else if (triaType == 2.0) { + /* ROUNDBOX_TRIA_SCROLL */ + pos = point_pos[vidx]; + uvInterp = point_uvs[vidx]; + outRectSize = vec2(1.0); + outRoundCorners = vec4(0.5); + } + else if (triaType == 3.0) { + /* ROUNDBOX_TRIA_MENU */ + pos = tria2 ? vec2(0.0) : arrow_pos[vidx]; /* Solo tria */ + pos = vec2(pos.y, -pos.x); /* Rotate */ + pos += vec2(-0.05, 0.0); /* Translate */ + size *= 0.8; /* Scale */ + uvInterp = arrow_uvs[vidx]; + uvInterp -= vec2(0.05, 0.63); /* Translate */ + outRectSize = vec2(0.74, 0.17); + outRoundCorners = vec4(0.01); + } + else if (triaType == 4.0) { + /* ROUNDBOX_TRIA_CHECK */ + /* A bit more hacky: We use the two trias joined together to render + * both sides of the checkmark with different length. */ + pos = arrow_pos[min(vidx, 2)]; /* Only keep 1 triangle. */ + pos.y = tria2 ? -pos.y : pos.y; /* Mirror along X */ + pos = pos.x * vec2(0.0872, -0.996) + pos.y * vec2(0.996, 0.0872); /* Rotate (85deg) */ + pos += vec2(-0.1, 0.2); /* Translate */ + center = tria1Center; + size = tria1Size * 1.7; /* Scale */ + uvInterp = arrow_uvs[vidx]; + uvInterp -= tria2 ? vec2(0.4, 0.65) : vec2(0.08, 0.65); /* Translate */ + outRectSize = vec2(0.74, 0.14); + outRoundCorners = vec4(0.01); + } + else { + /* ROUNDBOX_TRIA_HOLD_ACTION_ARROW */ + /* We use a single triangle to cut the round rect in half. The edge will not be Antialiased. */ + pos = tria2 ? vec2(0.0) : arrow_pos[min(vidx, 2)]; /* Only keep 1 triangle. */ + pos = pos.x * vec2(0.707, 0.707) + pos.y * vec2(-0.707, 0.707); /* Rotate (45deg) */ + pos += vec2(-1.7, 2.4); /* Translate (hardcoded, might want to remove) */ + size *= 0.4; /* Scale */ + uvInterp = arrow_uvs[vidx]; + uvInterp -= vec2(0.05, 0.05); /* Translate */ + outRectSize = vec2(0.75); + outRoundCorners = vec4(0.01); + } - vec2 v = triavec[vofs]; + uvInterp *= abs(size); + outRectSize *= abs(size); + outRoundCorners *= abs(size); - finalColor = colorTria; - butCo = -1.0; + pos = pos * size + center; - bool is_tria_first = (vflag & TRIA_FIRST) != 0u; + innerColor = colorTria * vec4(colorTria.aaa, 1.0); - if (is_tria_first) { - v = v * tria1Size + tria1Center; - } - else { - v = v * tria2Size + tria2Center; - } + lineWidth = 0.0; + borderColor = vec4(0.0); + embossColor = vec4(0.0); - return v; + butCo = -2.0; + + return pos; } void main() { discardFac = discardFactor; - bool is_tria = (vflag & TRIA_FLAG) != 0u; - - vec2 v = (is_tria) ? do_tria() : do_widget(); - - /* Antialiasing offset */ - v += jit[(vflag >> JIT_OFS) & JIT_RANGE]; + bool is_tria = (gl_VertexID > 3); + vec2 pos = (is_tria) ? do_tria() : do_widget(); - gl_Position = ModelViewProjectionMatrix * vec4(v, 0.0, 1.0); + gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0); } diff --git a/source/blender/gpu/shaders/gpu_shader_point_varying_color_varying_outline_aa_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_varying_color_varying_outline_aa_frag.glsl index f30e292154e..6d997ec14cc 100644 --- a/source/blender/gpu/shaders/gpu_shader_point_varying_color_varying_outline_aa_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_point_varying_color_varying_outline_aa_frag.glsl @@ -29,4 +29,6 @@ void main() else { fragColor = mix(fillColor, outlineColor, smoothstep(radii[3], radii[2], dist)); } + + fragColor = blender_srgb_to_framebuffer_space(fragColor); } diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_ambient_occlusion.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_ambient_occlusion.glsl index 8f8ebebb5f1..d6d6fbab971 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_ambient_occlusion.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_ambient_occlusion.glsl @@ -9,5 +9,5 @@ void node_ambient_occlusion( } #else /* Stub ambient occlusion because it is not compatible with volumetrics. */ -# define node_ambient_occlusion +# define node_ambient_occlusion(a, b, c, d, e) (e = CLOSURE_DEFAULT) #endif diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_anisotropic.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_anisotropic.glsl index a8a900b40c6..e1137d9d0e7 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_anisotropic.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_anisotropic.glsl @@ -11,5 +11,5 @@ void node_bsdf_anisotropic(vec4 color, } #else /* Stub anisotropic because it is not compatible with volumetrics. */ -# define node_bsdf_anisotropic +# define node_bsdf_anisotropic(a, b, c, d, e, f, g) (g = CLOSURE_DEFAULT) #endif diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_diffuse.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_diffuse.glsl index 714792489f6..d7b6143d2a1 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_diffuse.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_diffuse.glsl @@ -9,5 +9,5 @@ void node_bsdf_diffuse(vec4 color, float roughness, vec3 N, out Closure result) } #else /* Stub diffuse because it is not compatible with volumetrics. */ -# define node_bsdf_diffuse +# define node_bsdf_diffuse(a, b, c, d) (d = CLOSURE_DEFAULT) #endif diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_eevee_specular.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_eevee_specular.glsl index 747395857ee..443bab7529b 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_eevee_specular.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_eevee_specular.glsl @@ -40,4 +40,7 @@ void node_eevee_specular(vec4 diffuse, closure_load_ssr_data(ssr_spec * alpha, roughness, normal, viewCameraVec, int(ssr_id), result); } +#else +/* Stub specular because it is not compatible with volumetrics. */ +# define node_eevee_specular(a, b, c, d, e, f, g, h, i, j, k, result) (result = CLOSURE_DEFAULT) #endif diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_glass.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_glass.glsl index ece770f0e73..6d782ff18de 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_glass.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_glass.glsl @@ -28,5 +28,5 @@ void node_bsdf_glass( } #else /* Stub glass because it is not compatible with volumetrics. */ -# define node_bsdf_glass +# define node_bsdf_glass(a, b, c, d, e, f) (f = CLOSURE_DEFAULT) #endif diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_glossy.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_glossy.glsl index 7513c3a4edb..5ea22f3e0b4 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_glossy.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_glossy.glsl @@ -12,5 +12,5 @@ void node_bsdf_glossy(vec4 color, float roughness, vec3 N, float ssr_id, out Clo } #else /* Stub glossy because it is not compatible with volumetrics. */ -# define node_bsdf_glossy +# define node_bsdf_glossy(a, b, c, d, e) (e = CLOSURE_DEFAULT) #endif diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl index 3c85dc6456c..80ed4e1ef69 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl @@ -442,11 +442,13 @@ void node_bsdf_principled_glass(vec4 base_color, result.transmittance = vec3(1.0 - alpha); } #else +/* clang-format off */ /* Stub principled because it is not compatible with volumetrics. */ -# define node_bsdf_principled -# define node_bsdf_principled_dielectric -# define node_bsdf_principled_metallic -# define node_bsdf_principled_clearcoat -# define node_bsdf_principled_subsurface -# define node_bsdf_principled_glass +# define node_bsdf_principled(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, result) (result = CLOSURE_DEFAULT) +# define node_bsdf_principled_dielectric(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, result) (result = CLOSURE_DEFAULT) +# define node_bsdf_principled_metallic(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, result) (result = CLOSURE_DEFAULT) +# define node_bsdf_principled_clearcoat(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, result) (result = CLOSURE_DEFAULT) +# define node_bsdf_principled_subsurface(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, result) (result = CLOSURE_DEFAULT) +# define node_bsdf_principled_glass(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, result) (result = CLOSURE_DEFAULT) +/* clang-format on */ #endif diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_refraction.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_refraction.glsl index 4088d6db06a..cd043020a7f 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_refraction.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_refraction.glsl @@ -12,5 +12,5 @@ void node_bsdf_refraction(vec4 color, float roughness, float ior, vec3 N, out Cl } #else /* Stub refraction because it is not compatible with volumetrics. */ -# define node_bsdf_refraction +# define node_bsdf_refraction(a, b, c, d, e) (e = CLOSURE_DEFAULT) #endif diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_subsurface_scattering.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_subsurface_scattering.glsl index 9bbbe71b206..c13b55513da 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_subsurface_scattering.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_subsurface_scattering.glsl @@ -24,5 +24,5 @@ void node_subsurface_scattering(vec4 color, } #else /* Stub subsurface scattering because it is not compatible with volumetrics. */ -# define node_subsurface_scattering +# define node_subsurface_scattering(a, b, c, d, e, f, g, h) (h = CLOSURE_DEFAULT) #endif diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_toon.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_toon.glsl index 02d288d42bf..bbfc99ccc73 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_toon.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_toon.glsl @@ -5,5 +5,5 @@ void node_bsdf_toon(vec4 color, float size, float tsmooth, vec3 N, out Closure r } #else /* Stub toon because it is not compatible with volumetrics. */ -# define node_bsdf_toon +# define node_bsdf_toon(a, b, c, d, e) (e = CLOSURE_DEFAULT) #endif diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_translucent.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_translucent.glsl index 5c3ed81410a..79bfd9b24bb 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_translucent.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_translucent.glsl @@ -9,5 +9,5 @@ void node_bsdf_translucent(vec4 color, vec3 N, out Closure result) } #else /* Stub translucent because it is not compatible with volumetrics. */ -# define node_bsdf_translucent +# define node_bsdf_translucent(a, b, c) (c = CLOSURE_DEFAULT) #endif diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_transparent.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_transparent.glsl index 800d0f81d4a..9040f62bd3f 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_transparent.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_transparent.glsl @@ -7,5 +7,5 @@ void node_bsdf_transparent(vec4 color, out Closure result) } #else /* Stub transparent because it is not compatible with volumetrics. */ -# define node_bsdf_transparent +# define node_bsdf_transparent(a, b) (b = CLOSURE_DEFAULT) #endif diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_velvet.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_velvet.glsl index 9646ffff8ca..989f18b881a 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_velvet.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_velvet.glsl @@ -5,5 +5,5 @@ void node_bsdf_velvet(vec4 color, float sigma, vec3 N, out Closure result) } #else /* Stub velvet because it is not compatible with volumetrics. */ -# define node_bsdf_velvet +# define node_bsdf_velvet(a, b, c, d) (d = CLOSURE_DEFAULT) #endif diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_wireframe.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_wireframe.glsl index 2fcf1b8d914..e2789e046e1 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_wireframe.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_wireframe.glsl @@ -26,6 +26,6 @@ void node_wireframe_screenspace(float size, vec2 barycentric, out float fac) } #else /* Stub wireframe because it is not compatible with volumetrics. */ -# define node_wireframe -# define node_wireframe_screenspace +# define node_wireframe(a, b, c, d) (d = 0.0) +# define node_wireframe_screenspace(a, b, c) (c = 0.0) #endif |