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.
This commit is contained in:
Germano Cavalcante 2022-09-05 17:34:10 -03:00
parent 4536de98d1
commit 5763918651
17 changed files with 39 additions and 37 deletions

View File

@ -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);

View File

@ -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,

View File

@ -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);

View File

@ -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,

View File

@ -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,

View File

@ -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);

View File

@ -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,

View File

@ -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,

View File

@ -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);
}

View File

@ -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

View File

@ -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.
*

View File

@ -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",

View File

@ -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);

View File

@ -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);

View File

@ -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,

View File

@ -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);

View File

@ -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);
}