Gizmo: press shift key to scale area lights uniformly #104418

Closed
Weizhen Huang wants to merge 13 commits from weizhen:shift_uniform_scale into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
14 changed files with 73 additions and 72 deletions
Showing only changes of commit d1b830f3eb - Show all commits

View File

@ -106,11 +106,11 @@ GPUShader *BlenderFallbackDisplayShader::bind(int width, int height)
/* Bind shader now to enable uniform assignment. */
GPU_shader_bind(shader_program_);
float slot = 0;
GPU_shader_uniform_vector_int(shader_program_, image_texture_location_, 1, 1, &slot);
GPU_shader_uniform_int_ex(shader_program_, image_texture_location_, 1, 1, &slot);
float size[2];
size[0] = width;
size[1] = height;
GPU_shader_uniform_vector(shader_program_, fullscreen_location_, 2, 1, size);
GPU_shader_uniform_float_ex(shader_program_, fullscreen_location_, 2, 1, size);
return shader_program_;
}

View File

@ -76,16 +76,16 @@ void PushConstant::execute(RecordingState &state) const
}
switch (type) {
case PushConstant::Type::IntValue:
GPU_shader_uniform_vector_int(state.shader, location, comp_len, array_len, int4_value);
GPU_shader_uniform_int_ex(state.shader, location, comp_len, array_len, int4_value);
break;
case PushConstant::Type::IntReference:
GPU_shader_uniform_vector_int(state.shader, location, comp_len, array_len, int_ref);
GPU_shader_uniform_int_ex(state.shader, location, comp_len, array_len, int_ref);
break;
case PushConstant::Type::FloatValue:
GPU_shader_uniform_vector(state.shader, location, comp_len, array_len, float4_value);
GPU_shader_uniform_float_ex(state.shader, location, comp_len, array_len, float4_value);
break;
case PushConstant::Type::FloatReference:
GPU_shader_uniform_vector(state.shader, location, comp_len, array_len, float_ref);
GPU_shader_uniform_float_ex(state.shader, location, comp_len, array_len, float_ref);
break;
}
}

View File

@ -522,10 +522,10 @@ BLI_INLINE void draw_legacy_matrix_update(DRWShadingGroup *shgroup,
/* Still supported for compatibility with gpu_shader_* but should be forbidden. */
DRWObjectMatrix *ob_mats = DRW_memblock_elem_from_handle(DST.vmempool->obmats, handle);
if (obmat_loc != -1) {
GPU_shader_uniform_vector(shgroup->shader, obmat_loc, 16, 1, (float *)ob_mats->model);
GPU_shader_uniform_float_ex(shgroup->shader, obmat_loc, 16, 1, (float *)ob_mats->model);
}
if (obinv_loc != -1) {
GPU_shader_uniform_vector(shgroup->shader, obinv_loc, 16, 1, (float *)ob_mats->modelinverse);
GPU_shader_uniform_float_ex(shgroup->shader, obinv_loc, 16, 1, (float *)ob_mats->modelinverse);
}
}
@ -549,7 +549,7 @@ BLI_INLINE void draw_geometry_execute(DRWShadingGroup *shgroup,
if (baseinst_loc != -1) {
/* Fallback when ARB_shader_draw_parameters is not supported. */
GPU_shader_uniform_vector_int(shgroup->shader, baseinst_loc, 1, 1, (int *)&inst_first);
GPU_shader_uniform_int_ex(shgroup->shader, baseinst_loc, 1, 1, (int *)&inst_first);
/* Avoids VAO reconfiguration on older hardware. (see GPU_batch_draw_advanced) */
inst_first = 0;
}
@ -615,7 +615,7 @@ static void draw_update_uniforms(DRWShadingGroup *shgroup,
memcpy(&mat4_stack[array_index], uni->fvalue, sizeof(float) * uni->length);
/* Flush array data to shader. */
if (array_index <= 0) {
GPU_shader_uniform_vector(shgroup->shader, uni->location, 16, 1, mat4_stack);
GPU_shader_uniform_float_ex(shgroup->shader, uni->location, 16, 1, mat4_stack);
array_uniform_loc = -1;
}
continue;
@ -626,23 +626,23 @@ static void draw_update_uniforms(DRWShadingGroup *shgroup,
case DRW_UNIFORM_INT_COPY:
BLI_assert(uni->arraysize == 1);
if (uni->arraysize == 1) {
GPU_shader_uniform_vector_int(
GPU_shader_uniform_int_ex(
shgroup->shader, uni->location, uni->length, uni->arraysize, uni->ivalue);
}
break;
case DRW_UNIFORM_INT:
GPU_shader_uniform_vector_int(
GPU_shader_uniform_int_ex(
shgroup->shader, uni->location, uni->length, uni->arraysize, uni->pvalue);
break;
case DRW_UNIFORM_FLOAT_COPY:
BLI_assert(uni->arraysize == 1);
if (uni->arraysize == 1) {
GPU_shader_uniform_vector(
GPU_shader_uniform_float_ex(
shgroup->shader, uni->location, uni->length, uni->arraysize, uni->fvalue);
}
break;
case DRW_UNIFORM_FLOAT:
GPU_shader_uniform_vector(
GPU_shader_uniform_float_ex(
shgroup->shader, uni->location, uni->length, uni->arraysize, uni->pvalue);
break;
case DRW_UNIFORM_TEXTURE:
@ -690,7 +690,7 @@ static void draw_update_uniforms(DRWShadingGroup *shgroup,
case DRW_UNIFORM_RESOURCE_CHUNK: {
state->chunkid_loc = uni->location;
int zero = 0;
GPU_shader_uniform_vector_int(shgroup->shader, uni->location, 1, 1, &zero);
GPU_shader_uniform_int_ex(shgroup->shader, uni->location, 1, 1, &zero);
break;
}
case DRW_UNIFORM_RESOURCE_ID:
@ -809,7 +809,7 @@ static void draw_call_resource_bind(DRWCommandsState *state, const DRWResourceHa
int chunk = DRW_handle_chunk_get(handle);
if (state->resource_chunk != chunk) {
if (state->chunkid_loc != -1) {
GPU_shader_uniform_vector_int(DST.shader, state->chunkid_loc, 1, 1, &chunk);
GPU_shader_uniform_int_ex(DST.shader, state->chunkid_loc, 1, 1, &chunk);
}
if (state->obmats_loc != -1) {
GPU_uniformbuf_unbind(DST.vmempool->matrices_ubo[state->resource_chunk]);
@ -829,7 +829,7 @@ static void draw_call_resource_bind(DRWCommandsState *state, const DRWResourceHa
if (state->resourceid_loc != -1) {
int id = DRW_handle_id_get(handle);
if (state->resource_id != id) {
GPU_shader_uniform_vector_int(DST.shader, state->resourceid_loc, 1, 1, &id);
GPU_shader_uniform_int_ex(DST.shader, state->resourceid_loc, 1, 1, &id);
state->resource_id = id;
}
}

View File

@ -1804,18 +1804,18 @@ static void icon_draw_texture(float x,
if (rgb) {
const float color[4] = {rgb[0], rgb[1], rgb[2], alpha};
GPU_shader_uniform_vector(shader, color_loc, 4, 1, color);
GPU_shader_uniform_float_ex(shader, color_loc, 4, 1, color);
}
else {
const float color[4] = {alpha, alpha, alpha, alpha};
GPU_shader_uniform_vector(shader, color_loc, 4, 1, color);
GPU_shader_uniform_float_ex(shader, color_loc, 4, 1, color);
}
const float tex_color[4] = {x1, y1, x2, y2};
const float geom_color[4] = {x, y, x + w, y + h};
GPU_shader_uniform_vector(shader, rect_tex_loc, 4, 1, tex_color);
GPU_shader_uniform_vector(shader, rect_geom_loc, 4, 1, geom_color);
GPU_shader_uniform_float_ex(shader, rect_tex_loc, 4, 1, tex_color);
GPU_shader_uniform_float_ex(shader, rect_geom_loc, 4, 1, geom_color);
GPU_shader_uniform_1f(shader, "text_width", text_width);
GPU_texture_bind_ex(texture, GPU_SAMPLER_ICON, img_binding, false);

View File

@ -722,7 +722,7 @@ void ED_mask_draw_region(
GPU_matrix_mul(stabmat);
}
IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
GPU_shader_uniform_vector(
GPU_shader_uniform_float_ex(
state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, buf_col);
if (overlay_mode == MASK_OVERLAY_COMBINED) {

View File

@ -128,9 +128,9 @@ int GPU_shader_get_uniform(GPUShader *shader, const char *name);
* Sets a generic push constant (a.k.a. uniform).
* \a length and \a array_size should match the create info push_constant declaration.
*/
void GPU_shader_uniform_vector(
void GPU_shader_uniform_float_ex(
GPUShader *shader, int location, int length, int array_size, const float *value);
void GPU_shader_uniform_vector_int(
void GPU_shader_uniform_int_ex(
GPUShader *shader, int location, int length, int array_size, const int *value);
/**

View File

@ -625,7 +625,7 @@ void immUniformColor4f(float r, float g, float b, float a)
int32_t uniform_loc = GPU_shader_get_builtin_uniform(imm->shader, GPU_UNIFORM_COLOR);
BLI_assert(uniform_loc != -1);
float data[4] = {r, g, b, a};
GPU_shader_uniform_vector(imm->shader, uniform_loc, 4, 1, data);
GPU_shader_uniform_float_ex(imm->shader, uniform_loc, 4, 1, data);
/* For wide Line workaround. */
copy_v4_v4(imm->uniform_color, data);
}

View File

@ -623,30 +623,31 @@ void GPU_matrix_bind(GPUShader *shader)
int32_t P_inv = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_PROJECTION_INV);
if (MV != -1) {
GPU_shader_uniform_vector(
GPU_shader_uniform_float_ex(
shader, MV, 16, 1, (const float *)GPU_matrix_model_view_get(nullptr));
}
if (P != -1) {
GPU_shader_uniform_vector(shader, P, 16, 1, (const float *)GPU_matrix_projection_get(nullptr));
GPU_shader_uniform_float_ex(
shader, P, 16, 1, (const float *)GPU_matrix_projection_get(nullptr));
}
if (MVP != -1) {
GPU_shader_uniform_vector(
GPU_shader_uniform_float_ex(
shader, MVP, 16, 1, (const float *)GPU_matrix_model_view_projection_get(nullptr));
}
if (N != -1) {
GPU_shader_uniform_vector(shader, N, 9, 1, (const float *)GPU_matrix_normal_get(nullptr));
GPU_shader_uniform_float_ex(shader, N, 9, 1, (const float *)GPU_matrix_normal_get(nullptr));
}
if (MV_inv != -1) {
Mat4 m;
GPU_matrix_model_view_get(m);
invert_m4(m);
GPU_shader_uniform_vector(shader, MV_inv, 16, 1, (const float *)m);
GPU_shader_uniform_float_ex(shader, MV_inv, 16, 1, (const float *)m);
}
if (P_inv != -1) {
Mat4 m;
GPU_matrix_projection_get(m);
invert_m4(m);
GPU_shader_uniform_vector(shader, P_inv, 16, 1, (const float *)m);
GPU_shader_uniform_float_ex(shader, P_inv, 16, 1, (const float *)m);
}
gpu_matrix_state_active_set_dirty(false);

View File

@ -618,13 +618,13 @@ int GPU_shader_get_program(GPUShader *shader)
/** \name Uniforms setters
* \{ */
void GPU_shader_uniform_vector(
void GPU_shader_uniform_float_ex(
GPUShader *shader, int loc, int len, int array_size, const float *value)
{
unwrap(shader)->uniform_float(loc, len, array_size, value);
}
void GPU_shader_uniform_vector_int(
void GPU_shader_uniform_int_ex(
GPUShader *shader, int loc, int len, int array_size, const int *value)
{
unwrap(shader)->uniform_int(loc, len, array_size, value);
@ -633,7 +633,7 @@ void GPU_shader_uniform_vector_int(
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_vector_int(sh, loc, 1, 1, &value);
GPU_shader_uniform_int_ex(sh, loc, 1, 1, &value);
}
void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value)
@ -662,37 +662,37 @@ void GPU_shader_uniform_4f(GPUShader *sh, const char *name, float x, float y, fl
void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value)
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_vector(sh, loc, 1, 1, &value);
GPU_shader_uniform_float_ex(sh, loc, 1, 1, &value);
}
void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2])
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_vector(sh, loc, 2, 1, data);
GPU_shader_uniform_float_ex(sh, loc, 2, 1, data);
}
void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3])
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_vector(sh, loc, 3, 1, data);
GPU_shader_uniform_float_ex(sh, loc, 3, 1, data);
}
void GPU_shader_uniform_4fv(GPUShader *sh, const char *name, const float data[4])
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_vector(sh, loc, 4, 1, data);
GPU_shader_uniform_float_ex(sh, loc, 4, 1, data);
}
void GPU_shader_uniform_2iv(GPUShader *sh, const char *name, const int data[2])
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_vector_int(sh, loc, 2, 1, data);
GPU_shader_uniform_int_ex(sh, loc, 2, 1, data);
}
void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4])
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_vector(sh, loc, 16, 1, (const float *)data);
GPU_shader_uniform_float_ex(sh, loc, 16, 1, (const float *)data);
}
void GPU_shader_uniform_mat3_as_mat4(GPUShader *sh, const char *name, const float data[3][3])
@ -705,13 +705,13 @@ void GPU_shader_uniform_mat3_as_mat4(GPUShader *sh, const char *name, const floa
void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float (*val)[2])
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_vector(sh, loc, 2, len, (const float *)val);
GPU_shader_uniform_float_ex(sh, loc, 2, len, (const float *)val);
}
void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, const float (*val)[4])
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_vector(sh, loc, 4, len, (const float *)val);
GPU_shader_uniform_float_ex(sh, loc, 4, len, (const float *)val);
}
/** \} */
@ -741,7 +741,7 @@ void Shader::set_srgb_uniform(GPUShader *shader)
{
int32_t loc = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_SRGB_TRANSFORM);
if (loc != -1) {
GPU_shader_uniform_vector_int(shader, loc, 1, 1, &g_shader_builtin_srgb_transform);
GPU_shader_uniform_int_ex(shader, loc, 1, 1, &g_shader_builtin_srgb_transform);
}
g_shader_builtin_srgb_is_dirty = false;
}

View File

@ -530,16 +530,16 @@ id<MTLRenderCommandEncoder> MTLBatch::bind(uint v_first, uint v_count, uint i_fi
/* Set SSBO-fetch-mode status uniforms. */
BLI_assert(active_shader_->uni_ssbo_input_prim_type_loc != -1);
BLI_assert(active_shader_->uni_ssbo_input_vert_count_loc != -1);
GPU_shader_uniform_vector_int(reinterpret_cast<GPUShader *>(wrap(active_shader_)),
active_shader_->uni_ssbo_input_prim_type_loc,
1,
1,
(const int *)(&final_prim_type));
GPU_shader_uniform_vector_int(reinterpret_cast<GPUShader *>(wrap(active_shader_)),
active_shader_->uni_ssbo_input_vert_count_loc,
1,
1,
(const int *)(&v_count));
GPU_shader_uniform_int_ex(reinterpret_cast<GPUShader *>(wrap(active_shader_)),
active_shader_->uni_ssbo_input_prim_type_loc,
1,
1,
(const int *)(&final_prim_type));
GPU_shader_uniform_int_ex(reinterpret_cast<GPUShader *>(wrap(active_shader_)),
active_shader_->uni_ssbo_input_vert_count_loc,
1,
1,
(const int *)(&v_count));
}
/* Ensure Context Render Pipeline State is fully setup and ready to execute the draw.

View File

@ -248,16 +248,16 @@ void MTLImmediate::end()
"ssbo_input_prim_type uniform location invalid!");
BLI_assert_msg(active_mtl_shader->uni_ssbo_input_vert_count_loc != -1,
"ssbo_input_vert_count uniform location invalid!");
GPU_shader_uniform_vector_int(reinterpret_cast<GPUShader *>(wrap(active_mtl_shader)),
active_mtl_shader->uni_ssbo_input_prim_type_loc,
1,
1,
(const int *)(&this->prim_type));
GPU_shader_uniform_vector_int(reinterpret_cast<GPUShader *>(wrap(active_mtl_shader)),
active_mtl_shader->uni_ssbo_input_vert_count_loc,
1,
1,
(const int *)(&this->vertex_idx));
GPU_shader_uniform_int_ex(reinterpret_cast<GPUShader *>(wrap(active_mtl_shader)),
active_mtl_shader->uni_ssbo_input_prim_type_loc,
1,
1,
(const int *)(&this->prim_type));
GPU_shader_uniform_int_ex(reinterpret_cast<GPUShader *>(wrap(active_mtl_shader)),
active_mtl_shader->uni_ssbo_input_vert_count_loc,
1,
1,
(const int *)(&this->vertex_idx));
}
MTLPrimitiveType mtl_prim_type = gpu_prim_type_to_metal(this->prim_type);

View File

@ -269,7 +269,7 @@ static PyObject *pygpu_shader_uniform_vector_float(BPyGPUShader *self, PyObject
}
GPU_shader_bind(self->shader);
GPU_shader_uniform_vector(self->shader, location, length, count, pybuffer.buf);
GPU_shader_uniform_float_ex(self->shader, location, length, count, pybuffer.buf);
PyBuffer_Release(&pybuffer);
@ -292,7 +292,7 @@ static PyObject *pygpu_shader_uniform_vector_int(BPyGPUShader *self, PyObject *a
}
GPU_shader_bind(self->shader);
GPU_shader_uniform_vector_int(self->shader, location, length, count, pybuffer.buf);
GPU_shader_uniform_int_ex(self->shader, location, length, count, pybuffer.buf);
PyBuffer_Release(&pybuffer);
@ -367,7 +367,7 @@ static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args)
}
GPU_shader_bind(self->shader);
GPU_shader_uniform_vector_int(self->shader, location, length, 1, values);
GPU_shader_uniform_int_ex(self->shader, location, length, 1, values);
Py_RETURN_NONE;
}
@ -437,7 +437,7 @@ static PyObject *pygpu_shader_uniform_float(BPyGPUShader *self, PyObject *args)
}
GPU_shader_bind(self->shader);
GPU_shader_uniform_vector(self->shader, location, length, 1, values);
GPU_shader_uniform_float_ex(self->shader, location, length, 1, values);
Py_RETURN_NONE;
}
@ -509,7 +509,7 @@ static PyObject *pygpu_shader_uniform_int(BPyGPUShader *self, PyObject *args)
}
GPU_shader_bind(self->shader);
GPU_shader_uniform_vector_int(self->shader, location, length, 1, values);
GPU_shader_uniform_int_ex(self->shader, location, length, 1, values);
Py_RETURN_NONE;
}

View File

@ -846,9 +846,9 @@ void wm_draw_region_blend(ARegion *region, int view, bool blend)
GPU_texture_bind(texture, texture_bind_loc);
GPU_shader_uniform_vector(shader, rect_tex_loc, 4, 1, rectt);
GPU_shader_uniform_vector(shader, rect_geo_loc, 4, 1, rectg);
GPU_shader_uniform_vector(shader, color_loc, 4, 1, (const float[4]){1, 1, 1, 1});
GPU_shader_uniform_float_ex(shader, rect_tex_loc, 4, 1, rectt);
GPU_shader_uniform_float_ex(shader, rect_geo_loc, 4, 1, rectg);
GPU_shader_uniform_float_ex(shader, color_loc, 4, 1, (const float[4]){1, 1, 1, 1});
GPUBatch *quad = GPU_batch_preset_quad();
GPU_batch_set_shader(quad, shader);

View File

@ -326,7 +326,7 @@ static void draw_filled_lasso(wmGesture *gt)
IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
GPU_shader_bind(state.shader);
GPU_shader_uniform_vector(
GPU_shader_uniform_float_ex(
state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red);
immDrawPixelsTexTiled(