From 57639186514079d3fce590006616c543628fe1d8 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Mon, 5 Sep 2022 17:34:10 -0300 Subject: GPU: convert 'GPU_SHADER_2D_IMAGE_COLOR' to 3D 3D shaders work in both 2D and 3D viewports. This shader is a good candidate to be exposed in Python. --- source/blender/draw/intern/draw_color_management.cc | 2 +- source/blender/editors/interface/interface_draw.c | 4 ++-- source/blender/editors/interface/interface_icons.c | 2 +- source/blender/editors/render/render_preview.cc | 2 +- source/blender/editors/screen/glutil.c | 2 +- source/blender/editors/sculpt_paint/paint_cursor.c | 4 ++-- source/blender/editors/space_file/file_draw.c | 2 +- source/blender/editors/space_node/node_draw.cc | 2 +- source/blender/editors/space_sequencer/sequencer_draw.c | 2 +- source/blender/gpu/CMakeLists.txt | 1 - source/blender/gpu/GPU_shader.h | 10 +++++++++- source/blender/gpu/intern/gpu_shader_builtin.c | 10 +++++----- .../gpu/shaders/infos/gpu_shader_2D_image_color_info.hh | 14 -------------- .../blender/gpu/shaders/infos/gpu_shader_3D_image_info.hh | 13 +++++++++++-- source/blender/windowmanager/intern/wm_dragdrop.cc | 2 +- source/blender/windowmanager/intern/wm_operators.c | 2 +- source/blender/windowmanager/intern/wm_playanim.c | 2 +- 17 files changed, 39 insertions(+), 37 deletions(-) delete mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_image_color_info.hh diff --git a/source/blender/draw/intern/draw_color_management.cc b/source/blender/draw/intern/draw_color_management.cc index bb11f1ab3ad..eab86226be5 100644 --- a/source/blender/draw/intern/draw_color_management.cc +++ b/source/blender/draw/intern/draw_color_management.cc @@ -169,7 +169,7 @@ void DRW_transform_none(GPUTexture *tex) /* Draw as texture for final render (without immediate mode). */ GPUBatch *geom = DRW_cache_fullscreen_quad_get(); - GPU_batch_program_set_builtin(geom, GPU_SHADER_2D_IMAGE_COLOR); + GPU_batch_program_set_builtin(geom, GPU_SHADER_3D_IMAGE_COLOR); GPU_batch_uniform_4f(geom, "color", 1.0f, 1.0f, 1.0f, 1.0f); GPU_batch_texture_bind(geom, "image", tex); diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 02325920e6d..fb30cfb86ff 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -309,7 +309,7 @@ void ui_draw_but_IMAGE(ARegion *UNUSED(region), rgba_uchar_to_float(col, but->col); } - IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR); + IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_3D_IMAGE_COLOR); immDrawPixelsTexTiled(&state, (float)rect->xmin, (float)rect->ymin, @@ -2132,7 +2132,7 @@ void ui_draw_but_TRACKPREVIEW(ARegion *UNUSED(region), color); } - IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR); + IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_3D_IMAGE_COLOR); immDrawPixelsTexTiled(&state, rect.xmin, rect.ymin + 1, diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index a3d95fa3a49..ad2c08194aa 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -1546,7 +1546,7 @@ static void icon_draw_rect(float x, shader = GPU_SHADER_2D_IMAGE_DESATURATE_COLOR; } else { - shader = GPU_SHADER_2D_IMAGE_COLOR; + shader = GPU_SHADER_3D_IMAGE_COLOR; } IMMDrawPixelsTexState state = immDrawPixelsTexSetup(shader); diff --git a/source/blender/editors/render/render_preview.cc b/source/blender/editors/render/render_preview.cc index cd0a05f02bc..5e23458e8bb 100644 --- a/source/blender/editors/render/render_preview.cc +++ b/source/blender/editors/render/render_preview.cc @@ -679,7 +679,7 @@ static bool ed_preview_draw_rect(ScrArea *area, int split, int first, rcti *rect /* material preview only needs monoscopy (view 0) */ RE_AcquiredResultGet32(re, &rres, (uint *)rect_byte, 0); - IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR); + IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_3D_IMAGE_COLOR); immDrawPixelsTexTiled(&state, fx, fy, diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index cb3510615cc..4382fd3d1c2 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -515,7 +515,7 @@ void ED_draw_imbuf_clipping(ImBuf *ibuf, ibuf, view_settings, display_settings, &cache_handle); if (display_buffer) { - IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR); + IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_3D_IMAGE_COLOR); immDrawPixelsTexTiled_clipping(&state, x, y, diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index 6241119c01e..164e13ac3c9 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -628,7 +628,7 @@ static bool paint_draw_tex_overlay(UnifiedPaintSettings *ups, /* Premultiplied alpha blending. */ GPU_blend(GPU_BLEND_ALPHA_PREMULT); - immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_IMAGE_COLOR); float final_color[4] = {1.0f, 1.0f, 1.0f, 1.0f}; if (!col) { @@ -720,7 +720,7 @@ static bool paint_draw_cursor_overlay( GPU_blend(GPU_BLEND_ALPHA_PREMULT); - immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_IMAGE_COLOR); float final_color[4] = {UNPACK3(U.sculpt_paint_overlay_col), 1.0f}; mul_v4_fl(final_color, brush->cursor_overlay_alpha * 0.01f); diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 8ebda7ef98e..93eb5938301 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -378,7 +378,7 @@ static void file_draw_preview(const SpaceFile *sfile, GPU_blend(GPU_BLEND_ALPHA_PREMULT); } - IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR); + IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_3D_IMAGE_COLOR); immDrawPixelsTexTiled_scaling(&state, (float)xco, (float)yco, diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 84860d7073a..507748e68bc 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -1288,7 +1288,7 @@ static void node_draw_preview(bNodePreview *preview, rctf *prv) /* Premul graphics. */ GPU_blend(GPU_BLEND_ALPHA); - IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR); + IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_3D_IMAGE_COLOR); immDrawPixelsTexTiled(&state, draw_rect.xmin, draw_rect.ymin, diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 929217fa10e..d90b4b3ecfc 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -1920,7 +1920,7 @@ static void sequencer_draw_display_buffer(const bContext *C, GPU_texture_bind(texture, 0); if (!glsl_used) { - immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_IMAGE_COLOR); immUniformColor3f(1.0f, 1.0f, 1.0f); } diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 2eceeedf845..152df8cb592 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -574,7 +574,6 @@ set(SRC_SHADER_CREATE_INFOS shaders/infos/gpu_shader_2D_area_borders_info.hh shaders/infos/gpu_shader_2D_checker_info.hh shaders/infos/gpu_shader_2D_diag_stripes_info.hh - shaders/infos/gpu_shader_2D_image_color_info.hh shaders/infos/gpu_shader_2D_image_desaturate_color_info.hh shaders/infos/gpu_shader_2D_image_info.hh shaders/infos/gpu_shader_2D_image_multi_rect_color_info.hh diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index d694fcf4da1..0db61bedc2c 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -212,7 +212,6 @@ typedef enum eGPUBuiltinShader { * \param color: in vec4 * \param pos: in vec2 */ - GPU_SHADER_2D_IMAGE_COLOR, GPU_SHADER_2D_IMAGE_DESATURATE_COLOR, GPU_SHADER_2D_IMAGE_RECT_COLOR, GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR, @@ -287,6 +286,15 @@ typedef enum eGPUBuiltinShader { * \param pos: in vec3 */ GPU_SHADER_3D_IMAGE, + /** + * Take a 3D position and color for each vertex with linear interpolation in window space. + * + * \param color: uniform vec4 + * \param image: uniform sampler2D + * \param texCoord: in vec2 + * \param pos: in vec3 + */ + GPU_SHADER_3D_IMAGE_COLOR, /** * Draw texture with alpha. Take a 3D position and a 2D texture coordinate for each vertex. * diff --git a/source/blender/gpu/intern/gpu_shader_builtin.c b/source/blender/gpu/intern/gpu_shader_builtin.c index d255084609e..7973c635cb8 100644 --- a/source/blender/gpu/intern/gpu_shader_builtin.c +++ b/source/blender/gpu/intern/gpu_shader_builtin.c @@ -136,6 +136,11 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = { .name = "GPU_SHADER_3D_IMAGE", .create_info = "gpu_shader_3D_image", }, + [GPU_SHADER_3D_IMAGE_COLOR] = + { + .name = "GPU_SHADER_3D_IMAGE_COLOR", + .create_info = "gpu_shader_3D_image_color", + }, [GPU_SHADER_3D_IMAGE_MODULATE_ALPHA] = { .name = "GPU_SHADER_3D_IMAGE_MODULATE_ALPHA", @@ -163,11 +168,6 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = { .name = "GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE", .create_info = "gpu_shader_2D_image_overlays_stereo_merge", }, - [GPU_SHADER_2D_IMAGE_COLOR] = - { - .name = "GPU_SHADER_2D_IMAGE_COLOR", - .create_info = "gpu_shader_2D_image_color", - }, [GPU_SHADER_2D_IMAGE_DESATURATE_COLOR] = { .name = "GPU_SHADER_2D_IMAGE_DESATURATE_COLOR", diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_image_color_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_color_info.hh deleted file mode 100644 index 021bd9ebb95..00000000000 --- a/source/blender/gpu/shaders/infos/gpu_shader_2D_image_color_info.hh +++ /dev/null @@ -1,14 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later - * Copyright 2022 Blender Foundation. All rights reserved. */ - -/** \file - * \ingroup gpu - */ - -#include "gpu_shader_create_info.hh" - -GPU_SHADER_CREATE_INFO(gpu_shader_2D_image_color) - .additional_info("gpu_shader_2D_image_common") - .push_constant(Type::VEC4, "color") - .fragment_source("gpu_shader_image_color_frag.glsl") - .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_3D_image_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_3D_image_info.hh index 94cf58933af..8abd140397f 100644 --- a/source/blender/gpu/shaders/infos/gpu_shader_3D_image_info.hh +++ b/source/blender/gpu/shaders/infos/gpu_shader_3D_image_info.hh @@ -8,13 +8,22 @@ #include "gpu_interface_info.hh" #include "gpu_shader_create_info.hh" -GPU_SHADER_CREATE_INFO(gpu_shader_3D_image) +GPU_SHADER_CREATE_INFO(gpu_shader_3D_image_common) .vertex_in(0, Type::VEC3, "pos") .vertex_in(1, Type::VEC2, "texCoord") .vertex_out(smooth_tex_coord_interp_iface) .fragment_out(0, Type::VEC4, "fragColor") .push_constant(Type::MAT4, "ModelViewProjectionMatrix") .sampler(0, ImageType::FLOAT_2D, "image") - .vertex_source("gpu_shader_3D_image_vert.glsl") + .vertex_source("gpu_shader_3D_image_vert.glsl"); + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_image) + .additional_info("gpu_shader_3D_image_common") .fragment_source("gpu_shader_image_frag.glsl") .do_static_compilation(true); + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_image_color) + .additional_info("gpu_shader_3D_image_common") + .push_constant(Type::VEC4, "color") + .fragment_source("gpu_shader_image_color_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/windowmanager/intern/wm_dragdrop.cc b/source/blender/windowmanager/intern/wm_dragdrop.cc index fa8cc842037..94bd33a9765 100644 --- a/source/blender/windowmanager/intern/wm_dragdrop.cc +++ b/source/blender/windowmanager/intern/wm_dragdrop.cc @@ -837,7 +837,7 @@ static void wm_drag_draw_icon(bContext *UNUSED(C), y = xy[1] - (wm_drag_imbuf_icon_height_get(drag) / 2); const float col[4] = {1.0f, 1.0f, 1.0f, 0.65f}; /* this blends texture */ - IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR); + IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_3D_IMAGE_COLOR); immDrawPixelsTexTiled_scaling(&state, x, y, diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 54c3cc3342c..f37fc6ec483 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -2328,7 +2328,7 @@ static void radial_control_paint_tex(RadialControl *rc, float radius, float alph GPU_matrix_rotate_2d(RAD2DEGF(rot)); } - immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_IMAGE_COLOR); immUniformColor3fvAlpha(col, alpha); immBindTexture("image", rc->texture); diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c index 08987af46ca..60f3842bc7c 100644 --- a/source/blender/windowmanager/intern/wm_playanim.c +++ b/source/blender/windowmanager/intern/wm_playanim.c @@ -482,7 +482,7 @@ static void draw_display_buffer(PlayState *ps, ImBuf *ibuf) GPU_texture_bind(texture, 0); if (!glsl_used) { - immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_IMAGE_COLOR); immUniformColor3f(1.0f, 1.0f, 1.0f); } -- cgit v1.2.3