diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2019-01-11 22:50:45 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2019-01-12 02:51:15 +0300 |
commit | 9f6e09bd8c14ca7ae61f6f1a0b71801e06429d8b (patch) | |
tree | a4ea7a8e2240188bac0d0eabe79b5a30e26d1fbc /source/blender | |
parent | 0bd20aa7df2ad7710f92e00d9dc72d826f16762a (diff) |
Drawing API: shgroup_instance and shgroup_instance_alpha clarification
shgroup_instance_alpha was getting a color[4] but would only use the
alpha defined upon creation of the shading group.
This was very limiting since it wouldn't allow for different instances
to have different alpha values.
Patch made with Clément Foucault (he made the code of it, while I fixed
all the parts of the code that were relying on shgroup_instance_alpha.
Diffstat (limited to 'source/blender')
4 files changed, 12 insertions, 16 deletions
diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index 9b969c23ba6..15a8675f55d 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -444,18 +444,18 @@ DRWShadingGroup *shgroup_instance(DRWPass *pass, struct GPUBatch *geom) GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE); DRW_shgroup_instance_format(g_formats.instance_sized, { - {"color", DRW_ATTRIB_FLOAT, 3}, + {"color", DRW_ATTRIB_FLOAT, 4}, {"size", DRW_ATTRIB_FLOAT, 1}, {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16} }); DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_sized); - DRW_shgroup_uniform_float_copy(grp, "alpha", 1.0f); + DRW_shgroup_state_disable(grp, DRW_STATE_BLEND); return grp; } -DRWShadingGroup *shgroup_instance_alpha(DRWPass *pass, struct GPUBatch *geom, float alpha) +DRWShadingGroup *shgroup_instance_alpha(DRWPass *pass, struct GPUBatch *geom) { GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE); @@ -466,7 +466,6 @@ DRWShadingGroup *shgroup_instance_alpha(DRWPass *pass, struct GPUBatch *geom, fl }); DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_sized); - DRW_shgroup_uniform_float_copy(grp, "alpha", alpha); return grp; } diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h index ca4bf967236..b79902bf4e3 100644 --- a/source/blender/draw/intern/draw_common.h +++ b/source/blender/draw/intern/draw_common.h @@ -137,7 +137,7 @@ struct DRWShadingGroup *shgroup_instance_screen_aligned(struct DRWPass *pass, st struct DRWShadingGroup *shgroup_instance_empty_axes(struct DRWPass *pass, struct GPUBatch *geom); struct DRWShadingGroup *shgroup_instance_scaled(struct DRWPass *pass, struct GPUBatch *geom); struct DRWShadingGroup *shgroup_instance(struct DRWPass *pass, struct GPUBatch *geom); -struct DRWShadingGroup *shgroup_instance_alpha(struct DRWPass *pass, struct GPUBatch *geom, float alpha); +struct DRWShadingGroup *shgroup_instance_alpha(struct DRWPass *pass, struct GPUBatch *geom); struct DRWShadingGroup *shgroup_instance_outline(struct DRWPass *pass, struct GPUBatch *geom, int *baseid); struct DRWShadingGroup *shgroup_camera_instance(struct DRWPass *pass, struct GPUBatch *geom); struct DRWShadingGroup *shgroup_distance_lines_instance(struct DRWPass *pass, struct GPUBatch *geom); diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c index 69de0d72fb9..90468658764 100644 --- a/source/blender/draw/modes/object_mode.c +++ b/source/blender/draw/modes/object_mode.c @@ -1368,22 +1368,20 @@ static void OBJECT_cache_init(void *vedata) /* Spot shapes */ state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND | DRW_STATE_CULL_FRONT; sgl->spot_shapes = psl->spot_shapes[i] = DRW_pass_create("Spot Shape Pass", state); - float cone_spot_alpha = 0.5f; geom = DRW_cache_lamp_spot_volume_get(); - sgl->lamp_spot_volume = shgroup_instance_alpha(sgl->spot_shapes, geom, cone_spot_alpha); + sgl->lamp_spot_volume = shgroup_instance_alpha(sgl->spot_shapes, geom); geom = DRW_cache_lamp_spot_square_volume_get(); - sgl->lamp_spot_volume_rect = shgroup_instance_alpha(sgl->spot_shapes, geom, cone_spot_alpha); + sgl->lamp_spot_volume_rect = shgroup_instance_alpha(sgl->spot_shapes, geom); - cone_spot_alpha = 0.3f; geom = DRW_cache_lamp_spot_volume_get(); - sgl->lamp_spot_volume_outside = shgroup_instance_alpha(sgl->spot_shapes, geom, cone_spot_alpha); + sgl->lamp_spot_volume_outside = shgroup_instance_alpha(sgl->spot_shapes, geom); DRW_shgroup_state_disable(sgl->lamp_spot_volume_outside, DRW_STATE_CULL_FRONT); DRW_shgroup_state_enable(sgl->lamp_spot_volume_outside, DRW_STATE_CULL_BACK); geom = DRW_cache_lamp_spot_square_volume_get(); - sgl->lamp_spot_volume_rect_outside = shgroup_instance_alpha(sgl->spot_shapes, geom, cone_spot_alpha); + sgl->lamp_spot_volume_rect_outside = shgroup_instance_alpha(sgl->spot_shapes, geom); DRW_shgroup_state_disable(sgl->lamp_spot_volume_rect_outside, DRW_STATE_CULL_FRONT); DRW_shgroup_state_enable(sgl->lamp_spot_volume_rect_outside, DRW_STATE_CULL_BACK); } @@ -1524,8 +1522,8 @@ static void DRW_shgroup_lamp(OBJECT_ShadingGroupList *sgl, Object *ob, ViewLayer else if (la->type == LA_SPOT) { float size[3], sizemat[4][4]; static float one = 1.0f; - float cone_inside[3] = {0.0f, 0.0f, 0.0f}; - float cone_outside[3] = {1.0f, 1.0f, 1.0f}; + float cone_inside[4] = {0.0f, 0.0f, 0.0f, 0.5f}; + float cone_outside[4] = {1.0f, 1.0f, 1.0f, 0.3f}; float blend = 1.0f - pow2f(la->spotblend); size[0] = size[1] = sinf(la->spotsize * 0.5f) * la->dist; size[2] = cosf(la->spotsize * 0.5f) * la->dist; diff --git a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl index 1ec158ae15c..0d0413fef94 100644 --- a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl @@ -1,13 +1,12 @@ uniform mat4 ViewProjectionMatrix; -uniform float alpha; /* ---- Instantiated Attribs ---- */ in vec3 pos; /* ---- Per instance Attribs ---- */ in mat4 InstanceModelMatrix; -in vec3 color; +in vec4 color; #ifdef UNIFORM_SCALE in float size; #else @@ -19,5 +18,5 @@ flat out vec4 finalColor; void main() { gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pos * size, 1.0); - finalColor = vec4(color, alpha); + finalColor = color; } |