diff options
author | Julian Eisel <julian@blender.org> | 2020-08-07 14:04:31 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2020-08-07 14:04:31 +0300 |
commit | 0d2d4a6d4a75ac38c41f872c88255eab70e88ab7 (patch) | |
tree | b7a7518af86dddba48e05a98b3c2be55e8804721 /source/blender/draw/engines/workbench | |
parent | 9b416c66fb714bdfd15a481489dbf650d0f389ea (diff) | |
parent | cfc6f9eb18e701f5be601b95c45004e8cf7fbc81 (diff) |
Merge branch 'master' into temp-ui-button-type-refactortemp-ui-button-type-refactor
Diffstat (limited to 'source/blender/draw/engines/workbench')
22 files changed, 245 insertions, 247 deletions
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_cavity_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_cavity_lib.glsl index d8cb4f86f7b..d0d52c8485b 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_cavity_lib.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_cavity_lib.glsl @@ -28,7 +28,7 @@ void cavity_compute(vec2 screenco, return; } - vec3 position = view_position_from_depth(screenco, depth, world_data.viewvecs, ProjectionMatrix); + vec3 position = get_view_space_from_depth(screenco, depth); vec3 normal = workbench_normal_decode(texture(normalBuffer, screenco)); vec2 jitter_co = (screenco * world_data.viewport_size.xy) * world_data.cavity_jitter_scale; @@ -68,8 +68,7 @@ void cavity_compute(vec2 screenco, bool is_background = (s_depth == 1.0); /* This trick provide good edge effect even if no neighbor is found. */ s_depth = (is_background) ? depth : s_depth; - vec3 s_pos = view_position_from_depth( - uvcoords, s_depth, world_data.viewvecs, ProjectionMatrix); + vec3 s_pos = get_view_space_from_depth(uvcoords, s_depth); if (is_background) { s_pos.z -= world_data.cavity_distance; diff --git a/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl index 25eaf003e07..eb61edca6c7 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl @@ -48,7 +48,7 @@ float workbench_float_pair_encode(float v1, float v2) { // const uint v1_mask = ~(0xFFFFFFFFu << ROUGHNESS_BITS); // const uint v2_mask = ~(0xFFFFFFFFu << METALLIC_BITS); - /* Same as above because some compiler are dumb af. and think we use mediump int. */ + /* Same as above because some compiler are very dumb and think we use medium int. */ const int v1_mask = 0x1F; const int v2_mask = 0x7; int iv1 = int(v1 * float(v1_mask)); @@ -60,38 +60,10 @@ void workbench_float_pair_decode(float data, out float v1, out float v2) { // const uint v1_mask = ~(0xFFFFFFFFu << ROUGHNESS_BITS); // const uint v2_mask = ~(0xFFFFFFFFu << METALLIC_BITS); - /* Same as above because some compiler are dumb af. and think we use mediump int. */ + /* Same as above because some compiler are very dumb and think we use medium int. */ const int v1_mask = 0x1F; const int v2_mask = 0x7; int idata = int(data); v1 = float(idata & v1_mask) * (1.0 / float(v1_mask)); v2 = float(idata >> int(ROUGHNESS_BITS)) * (1.0 / float(v2_mask)); } - -vec3 view_vector_from_screen_uv(vec2 uv, vec4 viewvecs[3], mat4 proj_mat) -{ - if (proj_mat[3][3] == 0.0) { - return normalize(viewvecs[0].xyz + vec3(uv, 0.0) * viewvecs[1].xyz); - } - else { - return vec3(0.0, 0.0, 1.0); - } -} - -vec3 view_position_from_depth(vec2 uvcoords, float depth, vec4 viewvecs[3], mat4 proj_mat) -{ - if (proj_mat[3][3] == 0.0) { - /* Perspective */ - float d = 2.0 * depth - 1.0; - - float zview = -proj_mat[3][2] / (d + proj_mat[2][2]); - - return zview * (viewvecs[0].xyz + vec3(uvcoords, 0.0) * viewvecs[1].xyz); - } - else { - /* Orthographic */ - vec3 offset = vec3(uvcoords, depth); - - return viewvecs[0].xyz + offset * viewvecs[1].xyz; - } -} diff --git a/source/blender/draw/engines/workbench/shaders/workbench_composite_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_composite_frag.glsl index cdb9823096c..6e10a656fc1 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_composite_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_composite_frag.glsl @@ -14,7 +14,7 @@ out vec4 fragColor; void main() { /* Normal and Incident vector are in viewspace. Lighting is evaluated in viewspace. */ - vec3 I = view_vector_from_screen_uv(uvcoordsvar.st, world_data.viewvecs, ProjectionMatrix); + vec3 I = get_view_vector_from_screen_uv(uvcoordsvar.st); vec3 N = workbench_normal_decode(texture(normalBuffer, uvcoordsvar.st)); vec4 mat_data = texture(materialBuffer, uvcoordsvar.st); diff --git a/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl index 5f3283e1643..a76a14fa750 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl @@ -5,7 +5,6 @@ struct LightData { }; struct WorldData { - vec4 viewvecs[3]; vec4 viewport_size; vec4 object_outline_color; vec4 shadow_direction_vs; diff --git a/source/blender/draw/engines/workbench/shaders/workbench_effect_dof_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_effect_dof_frag.glsl index 51007a9f246..71816f6ff6e 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_effect_dof_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_effect_dof_frag.glsl @@ -1,3 +1,6 @@ + +#pragma BLENDER_REQUIRE(common_math_lib.glsl) + /** * Separable Hexagonal Bokeh Blur by Colin Barré-Brisebois * https://colinbarrebrisebois.com/2017/04/18/hexagonal-bokeh-blur-revisited-part-1-basic-3-pass-version/ @@ -21,13 +24,6 @@ uniform sampler2D noiseTex; #define dof_distance dofParams.y #define dof_invsensorsize dofParams.z -#define M_PI 3.1415926535897932 /* pi */ - -float max_v4(vec4 v) -{ - return max(max(v.x, v.y), max(v.z, v.w)); -} - #define weighted_sum(a, b, c, d, e, e_sum) \ ((a)*e.x + (b)*e.y + (c)*e.z + (d)*e.w) / max(1e-6, e_sum); diff --git a/source/blender/draw/engines/workbench/shaders/workbench_prepass_hair_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_prepass_hair_vert.glsl index 6a7bc185fe9..3e1ea14f47c 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_prepass_hair_vert.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_prepass_hair_vert.glsl @@ -90,5 +90,5 @@ void main() packed_rough_metal = workbench_float_pair_encode(roughness, metallic); #endif - object_id = int((uint(resource_id) + 1u) & 0xFFu); + object_id = int(uint(resource_handle) & 0xFFFFu) + 1; } diff --git a/source/blender/draw/engines/workbench/shaders/workbench_prepass_pointcloud_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_prepass_pointcloud_vert.glsl new file mode 100644 index 00000000000..6f61874b8f5 --- /dev/null +++ b/source/blender/draw/engines/workbench/shaders/workbench_prepass_pointcloud_vert.glsl @@ -0,0 +1,38 @@ + +#pragma BLENDER_REQUIRE(common_view_lib.glsl) +#pragma BLENDER_REQUIRE(common_pointcloud_lib.glsl) +#pragma BLENDER_REQUIRE(workbench_shader_interface_lib.glsl) +#pragma BLENDER_REQUIRE(workbench_common_lib.glsl) +#pragma BLENDER_REQUIRE(workbench_material_lib.glsl) +#pragma BLENDER_REQUIRE(workbench_image_lib.glsl) + +void main() +{ + vec3 world_pos; + pointcloud_get_pos_and_nor(world_pos, normal_interp); + + normal_interp = normalize(normal_world_to_view(normal_interp)); + + gl_Position = point_world_to_ndc(world_pos); + +#ifdef USE_WORLD_CLIP_PLANES + world_clip_planes_calc_clip_distance(world_pos); +#endif + + uv_interp = vec2(0.0); + +#ifdef OPAQUE_MATERIAL + float metallic, roughness; +#endif + workbench_material_data_get(resource_handle, color_interp, alpha_interp, roughness, metallic); + + if (materialIndex == 0) { + color_interp = vec3(1.0); + } + +#ifdef OPAQUE_MATERIAL + packed_rough_metal = workbench_float_pair_encode(roughness, metallic); +#endif + + object_id = int(uint(resource_handle) & 0xFFFFu) + 1; +} diff --git a/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl index 31e298d1540..1192081caf1 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl @@ -36,5 +36,5 @@ void main() packed_rough_metal = workbench_float_pair_encode(roughness, metallic); #endif - object_id = int((uint(resource_id) + 1u) & 0xFFu); + object_id = int(uint(resource_handle) & 0xFFFFu) + 1; } diff --git a/source/blender/draw/engines/workbench/shaders/workbench_shader_interface_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_shader_interface_lib.glsl index 8e2f7ba4735..6bfa351aeb0 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_shader_interface_lib.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_shader_interface_lib.glsl @@ -1,10 +1,4 @@ -#ifdef GPU_VERTEX_SHADER -# define IN_OUT out -#else -# define IN_OUT in -#endif - IN_OUT ShaderStageInterface { vec3 normal_interp; diff --git a/source/blender/draw/engines/workbench/shaders/workbench_transparent_accum_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_transparent_accum_frag.glsl index 3c2d1a9c0c7..fd4d00d96dd 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_transparent_accum_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_transparent_accum_frag.glsl @@ -15,7 +15,7 @@ layout(location = 1) out vec4 revealageAccum; layout(location = 2) out uint objectId; /* Special function only to be used with calculate_transparent_weight(). */ -float linear_zdepth(float depth, vec4 viewvecs[3], mat4 proj_mat) +float linear_zdepth(float depth, vec4 viewvecs[2], mat4 proj_mat) { if (proj_mat[3][3] == 0.0) { float d = 2.0 * depth - 1.0; @@ -33,7 +33,7 @@ float linear_zdepth(float depth, vec4 viewvecs[3], mat4 proj_mat) */ float calculate_transparent_weight(void) { - float z = linear_zdepth(gl_FragCoord.z, world_data.viewvecs, ProjectionMatrix); + float z = linear_zdepth(gl_FragCoord.z, ViewVecs, ProjectionMatrix); #if 0 /* Eq 10 : Good for surfaces with varying opacity (like particles) */ float a = min(1.0, alpha * 10.0) + 0.01; @@ -57,7 +57,7 @@ void main() { /* Normal and Incident vector are in viewspace. Lighting is evaluated in viewspace. */ vec2 uv_viewport = gl_FragCoord.xy * world_data.viewport_size_inv; - vec3 I = view_vector_from_screen_uv(uv_viewport, world_data.viewvecs, ProjectionMatrix); + vec3 I = get_view_vector_from_screen_uv(uv_viewport); vec3 N = normalize(normal_interp); vec3 color = color_interp; diff --git a/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl index 2920a504062..aa938d80fa3 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl @@ -1,4 +1,5 @@ +#pragma BLENDER_REQUIRE(common_math_lib.glsl) #pragma BLENDER_REQUIRE(common_view_lib.glsl) #pragma BLENDER_REQUIRE(gpu_shader_common_obinfos_lib.glsl) #pragma BLENDER_REQUIRE(workbench_data_lib.glsl) @@ -33,11 +34,6 @@ float phase_function_isotropic() return 1.0 / (4.0 * M_PI); } -float max_v3(vec3 v) -{ - return max(v.x, max(v.y, v.z)); -} - float line_unit_box_intersect_dist(vec3 lineorigin, vec3 linedirection) { /* https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/ @@ -194,10 +190,8 @@ void main() float depth = texelFetch(depthBuffer, ivec2(gl_FragCoord.xy), 0).r; float depth_end = min(depth, gl_FragCoord.z); - vec3 vs_ray_end = view_position_from_depth( - screen_uv, depth_end, world_data.viewvecs, ProjectionMatrix); - vec3 vs_ray_ori = view_position_from_depth( - screen_uv, 0.0, world_data.viewvecs, ProjectionMatrix); + vec3 vs_ray_end = get_view_space_from_depth(screen_uv, depth_end); + vec3 vs_ray_ori = get_view_space_from_depth(screen_uv, 0.0); vec3 vs_ray_dir = (is_persp) ? (vs_ray_end - vs_ray_ori) : vec3(0.0, 0.0, -1.0); vs_ray_dir /= abs(vs_ray_dir.z); diff --git a/source/blender/draw/engines/workbench/workbench_data.c b/source/blender/draw/engines/workbench/workbench_data.c index 7b08e97ac31..0d7f4ee660b 100644 --- a/source/blender/draw/engines/workbench/workbench_data.c +++ b/source/blender/draw/engines/workbench/workbench_data.c @@ -86,43 +86,6 @@ static WORKBENCH_ViewLayerData *workbench_view_layer_data_ensure_ex(struct ViewL /* \} */ -static void workbench_viewvecs_update(float r_viewvecs[3][4]) -{ - float invproj[4][4]; - const bool is_persp = DRW_view_is_persp_get(NULL); - DRW_view_winmat_get(NULL, invproj, true); - - /* view vectors for the corners of the view frustum. - * Can be used to recreate the world space position easily */ - copy_v4_fl4(r_viewvecs[0], -1.0f, -1.0f, -1.0f, 1.0f); - copy_v4_fl4(r_viewvecs[1], 1.0f, -1.0f, -1.0f, 1.0f); - copy_v4_fl4(r_viewvecs[2], -1.0f, 1.0f, -1.0f, 1.0f); - - /* convert the view vectors to view space */ - for (int i = 0; i < 3; i++) { - mul_m4_v4(invproj, r_viewvecs[i]); - /* normalized trick see: - * http://www.derschmale.com/2014/01/26/reconstructing-positions-from-the-depth-buffer */ - mul_v3_fl(r_viewvecs[i], 1.0f / r_viewvecs[i][3]); - if (is_persp) { - mul_v3_fl(r_viewvecs[i], 1.0f / r_viewvecs[i][2]); - } - r_viewvecs[i][3] = 1.0; - } - - /* we need to store the differences */ - r_viewvecs[1][0] -= r_viewvecs[0][0]; - r_viewvecs[1][1] = r_viewvecs[2][1] - r_viewvecs[0][1]; - - /* calculate a depth offset as well */ - if (!is_persp) { - float vec_far[] = {-1.0f, -1.0f, 1.0f, 1.0f}; - mul_m4_v4(invproj, vec_far); - mul_v3_fl(vec_far, 1.0f / vec_far[3]); - r_viewvecs[1][2] = vec_far[2] - r_viewvecs[0][2]; - } -} - static void workbench_studiolight_data_update(WORKBENCH_PrivateData *wpd, WORKBENCH_UBO_World *wd) { StudioLight *studiolight = wpd->studio_light; @@ -256,6 +219,8 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd) } else if (XRAY_ENABLED(v3d)) { wpd->shading.xray_alpha = XRAY_ALPHA(v3d); + /* Disable shading options that aren't supported in transparency mode. */ + wpd->shading.flag &= ~(V3D_SHADING_SHADOW | V3D_SHADING_CAVITY | V3D_SHADING_DEPTH_OF_FIELD); } else { wpd->shading.xray_alpha = 1.0f; @@ -309,7 +274,6 @@ void workbench_update_world_ubo(WORKBENCH_PrivateData *wpd) workbench_studiolight_data_update(wpd, &wd); workbench_shadow_data_update(wpd, &wd); workbench_cavity_data_update(wpd, &wd); - workbench_viewvecs_update(wd.viewvecs); DRW_uniformbuffer_update(wpd->world_ubo, &wd); } diff --git a/source/blender/draw/engines/workbench/workbench_effect_antialiasing.c b/source/blender/draw/engines/workbench/workbench_effect_antialiasing.c index 0e896c4b7bb..faf64b55c2d 100644 --- a/source/blender/draw/engines/workbench/workbench_effect_antialiasing.c +++ b/source/blender/draw/engines/workbench/workbench_effect_antialiasing.c @@ -112,17 +112,15 @@ int workbench_antialiasing_sample_count_get(WORKBENCH_PrivateData *wpd) /* Only draw using SMAA or no AA when navigating. */ return min_ii(wpd->preferences->viewport_aa, 1); } - else if (DRW_state_is_image_render()) { + if (DRW_state_is_image_render()) { if (draw_ctx->v3d) { return scene->display.viewport_aa; } - else { - return scene->display.render_aa; - } - } - else { - return wpd->preferences->viewport_aa; + + return scene->display.render_aa; } + + return wpd->preferences->viewport_aa; } void workbench_antialiasing_view_updated(WORKBENCH_Data *vedata) @@ -361,53 +359,52 @@ bool workbench_antialiasing_setup(WORKBENCH_Data *vedata) /* TAA accumulation has finish. Just copy the result back */ return false; } - else { - const float *viewport_size = DRW_viewport_size_get(); - const DRWView *default_view = DRW_view_default_get(); - float *transform_offset; - - switch (wpd->taa_sample_len) { - default: - case 5: - transform_offset = e_data.jitter_5[min_ii(wpd->taa_sample, 5)]; - break; - case 8: - transform_offset = e_data.jitter_8[min_ii(wpd->taa_sample, 8)]; - break; - case 11: - transform_offset = e_data.jitter_11[min_ii(wpd->taa_sample, 11)]; - break; - case 16: - transform_offset = e_data.jitter_16[min_ii(wpd->taa_sample, 16)]; - break; - case 32: - transform_offset = e_data.jitter_32[min_ii(wpd->taa_sample, 32)]; - break; - } - - /* construct new matrices from transform delta */ - float winmat[4][4], viewmat[4][4], persmat[4][4]; - DRW_view_winmat_get(default_view, winmat, false); - DRW_view_viewmat_get(default_view, viewmat, false); - DRW_view_persmat_get(default_view, persmat, false); - window_translate_m4(winmat, - persmat, - transform_offset[0] / viewport_size[0], - transform_offset[1] / viewport_size[1]); - - if (wpd->view) { - /* When rendering just update the view. This avoids recomputing the culling. */ - DRW_view_update_sub(wpd->view, viewmat, winmat); - } - else { - /* TAA is not making a big change to the matrices. - * Reuse the main view culling by creating a sub-view. */ - wpd->view = DRW_view_create_sub(default_view, viewmat, winmat); - } - DRW_view_set_active(wpd->view); - return true; + const float *viewport_size = DRW_viewport_size_get(); + const DRWView *default_view = DRW_view_default_get(); + float *transform_offset; + + switch (wpd->taa_sample_len) { + default: + case 5: + transform_offset = e_data.jitter_5[min_ii(wpd->taa_sample, 5)]; + break; + case 8: + transform_offset = e_data.jitter_8[min_ii(wpd->taa_sample, 8)]; + break; + case 11: + transform_offset = e_data.jitter_11[min_ii(wpd->taa_sample, 11)]; + break; + case 16: + transform_offset = e_data.jitter_16[min_ii(wpd->taa_sample, 16)]; + break; + case 32: + transform_offset = e_data.jitter_32[min_ii(wpd->taa_sample, 32)]; + break; + } + + /* construct new matrices from transform delta */ + float winmat[4][4], viewmat[4][4], persmat[4][4]; + DRW_view_winmat_get(default_view, winmat, false); + DRW_view_viewmat_get(default_view, viewmat, false); + DRW_view_persmat_get(default_view, persmat, false); + + window_translate_m4(winmat, + persmat, + transform_offset[0] / viewport_size[0], + transform_offset[1] / viewport_size[1]); + + if (wpd->view) { + /* When rendering just update the view. This avoids recomputing the culling. */ + DRW_view_update_sub(wpd->view, viewmat, winmat); + } + else { + /* TAA is not making a big change to the matrices. + * Reuse the main view culling by creating a sub-view. */ + wpd->view = DRW_view_create_sub(default_view, viewmat, winmat); } + DRW_view_set_active(wpd->view); + return true; } void workbench_antialiasing_draw_pass(WORKBENCH_Data *vedata) diff --git a/source/blender/draw/engines/workbench/workbench_engine.c b/source/blender/draw/engines/workbench/workbench_engine.c index c8dde4d513b..53119723fab 100644 --- a/source/blender/draw/engines/workbench/workbench_engine.c +++ b/source/blender/draw/engines/workbench/workbench_engine.c @@ -130,6 +130,17 @@ static void workbench_cache_sculpt_populate(WORKBENCH_PrivateData *wpd, } } +BLI_INLINE void workbench_object_drawcall(DRWShadingGroup *grp, struct GPUBatch *geom, Object *ob) +{ + if (ob->type == OB_POINTCLOUD) { + /* Draw range to avoid drawcall batching messing up the instance attrib. */ + DRW_shgroup_call_instance_range(grp, ob, geom, 0, 0); + } + else { + DRW_shgroup_call(grp, geom, ob); + } +} + static void workbench_cache_texpaint_populate(WORKBENCH_PrivateData *wpd, Object *ob) { const DRWContextState *draw_ctx = DRW_context_state_get(); @@ -145,7 +156,7 @@ static void workbench_cache_texpaint_populate(WORKBENCH_PrivateData *wpd, Object SET_FLAG_FROM_TEST(state, imapaint->interp == IMAGEPAINT_INTERP_LINEAR, GPU_SAMPLER_FILTER); DRWShadingGroup *grp = workbench_image_setup(wpd, ob, 0, ima, NULL, state); - DRW_shgroup_call(grp, geom, ob); + workbench_object_drawcall(grp, geom, ob); } } else { @@ -157,7 +168,7 @@ static void workbench_cache_texpaint_populate(WORKBENCH_PrivateData *wpd, Object continue; } DRWShadingGroup *grp = workbench_image_setup(wpd, ob, i + 1, NULL, NULL, 0); - DRW_shgroup_call(grp, geoms[i], ob); + workbench_object_drawcall(grp, geoms[i], ob); } } } @@ -180,7 +191,12 @@ static void workbench_cache_common_populate(WORKBENCH_PrivateData *wpd, geom = DRW_cache_mesh_surface_vertpaint_get(ob); } else { - geom = DRW_cache_mesh_surface_sculptcolors_get(ob); + if (U.experimental.use_sculpt_vertex_colors) { + geom = DRW_cache_mesh_surface_sculptcolors_get(ob); + } + else { + geom = DRW_cache_mesh_surface_vertpaint_get(ob); + } } } else { @@ -189,7 +205,7 @@ static void workbench_cache_common_populate(WORKBENCH_PrivateData *wpd, if (geom) { DRWShadingGroup *grp = workbench_material_setup(wpd, ob, 0, color_type, r_transp); - DRW_shgroup_call(grp, geom, ob); + workbench_object_drawcall(grp, geom, ob); } } else { @@ -202,7 +218,7 @@ static void workbench_cache_common_populate(WORKBENCH_PrivateData *wpd, continue; } DRWShadingGroup *grp = workbench_material_setup(wpd, ob, i + 1, color_type, r_transp); - DRW_shgroup_call(grp, geoms[i], ob); + workbench_object_drawcall(grp, geoms[i], ob); } } } @@ -261,8 +277,15 @@ static eV3DShadingColorType workbench_color_type_get(WORKBENCH_PrivateData *wpd, } } else if (color_type == V3D_SHADING_VERTEX_COLOR) { - if ((me == NULL) || !CustomData_has_layer(&me->vdata, CD_PROP_COLOR)) { - color_type = V3D_SHADING_OBJECT_COLOR; + if (U.experimental.use_sculpt_vertex_colors) { + if ((me == NULL) || !CustomData_has_layer(&me->vdata, CD_PROP_COLOR)) { + color_type = V3D_SHADING_OBJECT_COLOR; + } + } + else { + if ((me == NULL) || !CustomData_has_layer(&me->ldata, CD_MLOOPCOL)) { + color_type = V3D_SHADING_OBJECT_COLOR; + } } } @@ -438,7 +461,7 @@ void workbench_cache_finish(void *ved) /* TODO don't free reuse next redraw. */ for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { - for (int k = 0; k < 2; k++) { + for (int k = 0; k < WORKBENCH_DATATYPE_MAX; k++) { if (wpd->prepass[i][j][k].material_hash) { BLI_ghash_free(wpd->prepass[i][j][k].material_hash, NULL, NULL); wpd->prepass[i][j][k].material_hash = NULL; @@ -618,7 +641,7 @@ RenderEngineType DRW_engine_viewport_workbench_type = { NULL, WORKBENCH_ENGINE, N_("Workbench"), - RE_INTERNAL | RE_USE_STEREO_VIEWPORT, + RE_INTERNAL | RE_USE_STEREO_VIEWPORT | RE_USE_GPU_CONTEXT, NULL, &DRW_render_to_image, NULL, diff --git a/source/blender/draw/engines/workbench/workbench_engine.h b/source/blender/draw/engines/workbench/workbench_engine.h index eee53fcde07..8fd427c2683 100644 --- a/source/blender/draw/engines/workbench/workbench_engine.h +++ b/source/blender/draw/engines/workbench/workbench_engine.h @@ -20,9 +20,6 @@ * \ingroup draw_engine */ -#ifndef __WORKBENCH_ENGINE_H__ -#define __WORKBENCH_ENGINE_H__ +#pragma once extern RenderEngineType DRW_engine_viewport_workbench_type; - -#endif /* __WORKBENCH_ENGINE_H__ */ diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c index d6d3ff8610b..2ed63bac853 100644 --- a/source/blender/draw/engines/workbench/workbench_materials.c +++ b/source/blender/draw/engines/workbench/workbench_materials.c @@ -162,13 +162,13 @@ DRWShadingGroup *workbench_material_setup_ex(WORKBENCH_PrivateData *wpd, Object *ob, int mat_nr, eV3DShadingColorType color_type, - bool hair, + eWORKBENCH_DataType datatype, bool *r_transp) { Image *ima = NULL; ImageUser *iuser = NULL; eGPUSamplerState sampler; - const bool infront = (ob->dtx & OB_DRAWXRAY) != 0; + const bool infront = (ob->dtx & OB_DRAW_IN_FRONT) != 0; if (color_type == V3D_SHADING_TEXTURE_COLOR) { workbench_material_get_image(ob, mat_nr, &ima, &iuser, &sampler); @@ -180,7 +180,7 @@ DRWShadingGroup *workbench_material_setup_ex(WORKBENCH_PrivateData *wpd, switch (color_type) { case V3D_SHADING_TEXTURE_COLOR: { - return workbench_image_setup_ex(wpd, ob, mat_nr, ima, iuser, sampler, hair); + return workbench_image_setup_ex(wpd, ob, mat_nr, ima, iuser, sampler, datatype); } case V3D_SHADING_MATERIAL_COLOR: { /* For now, we use the same ubo for material and object coloring but with different indices. @@ -191,7 +191,7 @@ DRWShadingGroup *workbench_material_setup_ex(WORKBENCH_PrivateData *wpd, Material *ma = workbench_object_material_get(ob, mat_nr); const bool transp = wpd->shading.xray_alpha < 1.0f || ma->a < 1.0f; - WORKBENCH_Prepass *prepass = &wpd->prepass[transp][infront][hair]; + WORKBENCH_Prepass *prepass = &wpd->prepass[transp][infront][datatype]; if (r_transp && transp) { *r_transp = true; @@ -216,7 +216,7 @@ DRWShadingGroup *workbench_material_setup_ex(WORKBENCH_PrivateData *wpd, } case V3D_SHADING_VERTEX_COLOR: { const bool transp = wpd->shading.xray_alpha < 1.0f; - DRWShadingGroup *grp = wpd->prepass[transp][infront][hair].vcol_shgrp; + DRWShadingGroup *grp = wpd->prepass[transp][infront][datatype].vcol_shgrp; return grp; } default: { @@ -231,15 +231,15 @@ DRWShadingGroup *workbench_material_setup_ex(WORKBENCH_PrivateData *wpd, workbench_material_ubo_data(wpd, ob, NULL, &wpd->material_ubo_data_curr[mat_id], color_type); const bool transp = wpd->shading.xray_alpha < 1.0f || ob->color[3] < 1.0f; - DRWShadingGroup *grp = wpd->prepass[transp][infront][hair].common_shgrp; + DRWShadingGroup **grp = &wpd->prepass[transp][infront][datatype].common_shgrp; if (resource_changed) { - grp = DRW_shgroup_create_sub(grp); - DRW_shgroup_uniform_block(grp, "material_block", wpd->material_ubo_curr); + *grp = DRW_shgroup_create_sub(*grp); + DRW_shgroup_uniform_block(*grp, "material_block", wpd->material_ubo_curr); } if (r_transp && transp) { *r_transp = true; } - return grp; + return *grp; } } } @@ -251,7 +251,7 @@ DRWShadingGroup *workbench_image_setup_ex(WORKBENCH_PrivateData *wpd, Image *ima, ImageUser *iuser, eGPUSamplerState sampler, - bool hair) + eWORKBENCH_DataType datatype) { GPUTexture *tex = NULL, *tex_tile_data = NULL; @@ -261,11 +261,11 @@ DRWShadingGroup *workbench_image_setup_ex(WORKBENCH_PrivateData *wpd, if (ima) { if (ima->source == IMA_SRC_TILED) { - tex = GPU_texture_from_blender(ima, iuser, NULL, GL_TEXTURE_2D_ARRAY); - tex_tile_data = GPU_texture_from_blender(ima, iuser, NULL, GL_TEXTURE_1D_ARRAY); + tex = BKE_image_get_gpu_tiles(ima, iuser, NULL); + tex_tile_data = BKE_image_get_gpu_tilemap(ima, iuser, NULL); } else { - tex = GPU_texture_from_blender(ima, iuser, NULL, GL_TEXTURE_2D); + tex = BKE_image_get_gpu_texture(ima, iuser, NULL); } } @@ -273,9 +273,9 @@ DRWShadingGroup *workbench_image_setup_ex(WORKBENCH_PrivateData *wpd, tex = wpd->dummy_image_tx; } - const bool infront = (ob->dtx & OB_DRAWXRAY) != 0; + const bool infront = (ob->dtx & OB_DRAW_IN_FRONT) != 0; const bool transp = wpd->shading.xray_alpha < 1.0f; - WORKBENCH_Prepass *prepass = &wpd->prepass[transp][infront][hair]; + WORKBENCH_Prepass *prepass = &wpd->prepass[transp][infront][datatype]; DRWShadingGroup **grp_tex = NULL; /* A hashmap stores image shgroups to pack all similar drawcalls together. */ diff --git a/source/blender/draw/engines/workbench/workbench_opaque.c b/source/blender/draw/engines/workbench/workbench_opaque.c index 27d5b71f35c..738f4a67471 100644 --- a/source/blender/draw/engines/workbench/workbench_opaque.c +++ b/source/blender/draw/engines/workbench/workbench_opaque.c @@ -59,10 +59,10 @@ void workbench_opaque_engine_init(WORKBENCH_Data *data) }); } -void workbench_opaque_cache_init(WORKBENCH_Data *data) +void workbench_opaque_cache_init(WORKBENCH_Data *vedata) { - WORKBENCH_PassList *psl = data->psl; - WORKBENCH_PrivateData *wpd = data->stl->wpd; + WORKBENCH_PassList *psl = vedata->psl; + WORKBENCH_PrivateData *wpd = vedata->stl->wpd; DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); struct GPUShader *sh; DRWShadingGroup *grp; @@ -84,31 +84,31 @@ void workbench_opaque_cache_init(WORKBENCH_Data *data) pass = psl->opaque_ps; } - for (int hair = 0; hair < 2; hair++) { - wpd->prepass[opaque][infront][hair].material_hash = BLI_ghash_ptr_new(__func__); + for (eWORKBENCH_DataType data = 0; data < WORKBENCH_DATATYPE_MAX; data++) { + wpd->prepass[opaque][infront][data].material_hash = BLI_ghash_ptr_new(__func__); - sh = workbench_shader_opaque_get(wpd, hair); + sh = workbench_shader_opaque_get(wpd, data); - wpd->prepass[opaque][infront][hair].common_shgrp = grp = DRW_shgroup_create(sh, pass); + wpd->prepass[opaque][infront][data].common_shgrp = grp = DRW_shgroup_create(sh, pass); DRW_shgroup_uniform_block(grp, "material_block", wpd->material_ubo_curr); DRW_shgroup_uniform_int_copy(grp, "materialIndex", -1); DRW_shgroup_uniform_bool_copy(grp, "useMatcap", use_matcap); - wpd->prepass[opaque][infront][hair].vcol_shgrp = grp = DRW_shgroup_create(sh, pass); + wpd->prepass[opaque][infront][data].vcol_shgrp = grp = DRW_shgroup_create(sh, pass); DRW_shgroup_uniform_block(grp, "material_block", wpd->material_ubo_curr); DRW_shgroup_uniform_int_copy(grp, "materialIndex", 0); /* Default material. (uses vcol) */ DRW_shgroup_uniform_bool_copy(grp, "useMatcap", use_matcap); - sh = workbench_shader_opaque_image_get(wpd, hair, false); + sh = workbench_shader_opaque_image_get(wpd, data, false); - wpd->prepass[opaque][infront][hair].image_shgrp = grp = DRW_shgroup_create(sh, pass); + wpd->prepass[opaque][infront][data].image_shgrp = grp = DRW_shgroup_create(sh, pass); DRW_shgroup_uniform_block(grp, "material_block", wpd->material_ubo_curr); DRW_shgroup_uniform_int_copy(grp, "materialIndex", 0); /* Default material. */ DRW_shgroup_uniform_bool_copy(grp, "useMatcap", use_matcap); - sh = workbench_shader_opaque_image_get(wpd, hair, true); + sh = workbench_shader_opaque_image_get(wpd, data, true); - wpd->prepass[opaque][infront][hair].image_tiled_shgrp = grp = DRW_shgroup_create(sh, pass); + wpd->prepass[opaque][infront][data].image_tiled_shgrp = grp = DRW_shgroup_create(sh, pass); DRW_shgroup_uniform_block(grp, "material_block", wpd->material_ubo_curr); DRW_shgroup_uniform_int_copy(grp, "materialIndex", 0); /* Default material. */ DRW_shgroup_uniform_bool_copy(grp, "useMatcap", use_matcap); diff --git a/source/blender/draw/engines/workbench/workbench_private.h b/source/blender/draw/engines/workbench/workbench_private.h index ee9960ea0ef..4a6dadc32fd 100644 --- a/source/blender/draw/engines/workbench/workbench_private.h +++ b/source/blender/draw/engines/workbench/workbench_private.h @@ -20,8 +20,7 @@ * \ingroup draw_engine */ -#ifndef __WORKBENCH_PRIVATE_H__ -#define __WORKBENCH_PRIVATE_H__ +#pragma once #include "BKE_studiolight.h" @@ -71,6 +70,14 @@ struct RenderEngine; struct RenderLayer; struct rcti; +typedef enum eWORKBENCH_DataType { + WORKBENCH_DATATYPE_MESH = 0, + WORKBENCH_DATATYPE_HAIR, + WORKBENCH_DATATYPE_POINTCLOUD, + + WORKBENCH_DATATYPE_MAX, +} eWORKBENCH_DataType; + typedef struct WORKBENCH_FramebufferList { struct GPUFrameBuffer *opaque_fb; struct GPUFrameBuffer *opaque_infront_fb; @@ -168,7 +175,6 @@ typedef struct WORKBENCH_UBO_Material { } WORKBENCH_UBO_Material; typedef struct WORKBENCH_UBO_World { - float viewvecs[3][4]; float viewport_size[2], viewport_size_inv[2]; float object_outline_color[4]; float shadow_direction_vs[4]; @@ -293,8 +299,8 @@ typedef struct WORKBENCH_PrivateData { /** Object IDs buffer for curvature & outline. */ struct GPUTexture *object_id_tx; - /** Pre-pass information for each draw types [transparent][infront][hair]. */ - WORKBENCH_Prepass prepass[2][2][2]; + /** Pre-pass information for each draw types [transparent][infront][datatype]. */ + WORKBENCH_Prepass prepass[2][2][WORKBENCH_DATATYPE_MAX]; /* Materials */ /** Copy of vldata->material_ubo for faster access. */ @@ -393,14 +399,16 @@ void workbench_shadow_cache_init(WORKBENCH_Data *data); void workbench_shadow_cache_populate(WORKBENCH_Data *data, Object *ob, const bool has_transp_mat); /* workbench_shader.c */ -GPUShader *workbench_shader_opaque_get(WORKBENCH_PrivateData *wpd, bool hair); -GPUShader *workbench_shader_opaque_image_get(WORKBENCH_PrivateData *wpd, bool hair, bool tiled); +GPUShader *workbench_shader_opaque_get(WORKBENCH_PrivateData *wpd, eWORKBENCH_DataType data); +GPUShader *workbench_shader_opaque_image_get(WORKBENCH_PrivateData *wpd, + eWORKBENCH_DataType data, + bool tiled); GPUShader *workbench_shader_composite_get(WORKBENCH_PrivateData *wpd); GPUShader *workbench_shader_merge_infront_get(WORKBENCH_PrivateData *wpd); -GPUShader *workbench_shader_transparent_get(WORKBENCH_PrivateData *wpd, bool hair); +GPUShader *workbench_shader_transparent_get(WORKBENCH_PrivateData *wpd, eWORKBENCH_DataType data); GPUShader *workbench_shader_transparent_image_get(WORKBENCH_PrivateData *wpd, - bool hair, + eWORKBENCH_DataType data, bool tiled); GPUShader *workbench_shader_transparent_resolve_get(WORKBENCH_PrivateData *wpd); @@ -455,7 +463,7 @@ DRWShadingGroup *workbench_material_setup_ex(WORKBENCH_PrivateData *wpd, Object *ob, int mat_nr, eV3DShadingColorType color_type, - bool hair, + eWORKBENCH_DataType datatype, bool *r_transp); DRWShadingGroup *workbench_image_setup_ex(WORKBENCH_PrivateData *wpd, Object *ob, @@ -463,17 +471,20 @@ DRWShadingGroup *workbench_image_setup_ex(WORKBENCH_PrivateData *wpd, Image *ima, ImageUser *iuser, eGPUSamplerState sampler, - bool hair); + eWORKBENCH_DataType datatype); + +#define WORKBENCH_OBJECT_DATATYPE(ob) \ + ((ob->type == OB_POINTCLOUD) ? WORKBENCH_DATATYPE_POINTCLOUD : WORKBENCH_DATATYPE_MESH) #define workbench_material_setup(wpd, ob, mat_nr, color_type, r_transp) \ - workbench_material_setup_ex(wpd, ob, mat_nr, color_type, false, r_transp) + workbench_material_setup_ex(wpd, ob, mat_nr, color_type, WORKBENCH_OBJECT_DATATYPE(ob), r_transp) #define workbench_image_setup(wpd, ob, mat_nr, ima, iuser, interp) \ - workbench_image_setup_ex(wpd, ob, mat_nr, ima, iuser, interp, false) + workbench_image_setup_ex(wpd, ob, mat_nr, ima, iuser, interp, WORKBENCH_OBJECT_DATATYPE(ob)) #define workbench_material_hair_setup(wpd, ob, mat_nr, color_type) \ - workbench_material_setup_ex(wpd, ob, mat_nr, color_type, true, 0) + workbench_material_setup_ex(wpd, ob, mat_nr, color_type, WORKBENCH_DATATYPE_HAIR, 0) #define workbench_image_hair_setup(wpd, ob, mat_nr, ima, iuser, interp) \ - workbench_image_setup_ex(wpd, ob, mat_nr, ima, iuser, interp, true) + workbench_image_setup_ex(wpd, ob, mat_nr, ima, iuser, interp, WORKBENCH_DATATYPE_HAIR) /* workbench_data.c */ void workbench_private_data_init(WORKBENCH_PrivateData *wpd); @@ -508,5 +519,3 @@ void workbench_render(void *ved, void workbench_render_update_passes(struct RenderEngine *engine, struct Scene *scene, struct ViewLayer *view_layer); - -#endif diff --git a/source/blender/draw/engines/workbench/workbench_render.c b/source/blender/draw/engines/workbench/workbench_render.c index 9e66bcb07f4..77e16327a43 100644 --- a/source/blender/draw/engines/workbench/workbench_render.c +++ b/source/blender/draw/engines/workbench/workbench_render.c @@ -212,6 +212,7 @@ void workbench_render(void *ved, RenderEngine *engine, RenderLayer *render_layer BLI_rcti_size_y(rect), 4, 0, + GPU_DATA_FLOAT, rp->rect); workbench_render_result_z(render_layer, viewname, rect); diff --git a/source/blender/draw/engines/workbench/workbench_shader.c b/source/blender/draw/engines/workbench/workbench_shader.c index 99366779b22..aab3cef00e6 100644 --- a/source/blender/draw/engines/workbench/workbench_shader.c +++ b/source/blender/draw/engines/workbench/workbench_shader.c @@ -28,12 +28,16 @@ #include "workbench_engine.h" #include "workbench_private.h" +extern char datatoc_common_math_lib_glsl[]; +extern char datatoc_common_math_geom_lib_glsl[]; extern char datatoc_common_hair_lib_glsl[]; +extern char datatoc_common_pointcloud_lib_glsl[]; extern char datatoc_common_view_lib_glsl[]; extern char datatoc_common_smaa_lib_glsl[]; extern char datatoc_workbench_prepass_vert_glsl[]; extern char datatoc_workbench_prepass_hair_vert_glsl[]; +extern char datatoc_workbench_prepass_pointcloud_vert_glsl[]; extern char datatoc_workbench_prepass_frag_glsl[]; extern char datatoc_workbench_effect_cavity_frag_glsl[]; @@ -74,7 +78,6 @@ extern char datatoc_gpu_shader_common_obinfos_lib_glsl[]; /* Maximum number of variations. */ #define MAX_LIGHTING 3 #define MAX_COLOR 3 -#define MAX_GEOM 2 enum { VOLUME_SH_SLICE = 0, @@ -85,8 +88,9 @@ enum { #define VOLUME_SH_MAX (1 << (VOLUME_SH_CUBIC + 1)) static struct { - struct GPUShader *opaque_prepass_sh_cache[GPU_SHADER_CFG_LEN][MAX_GEOM][MAX_COLOR]; - struct GPUShader *transp_prepass_sh_cache[GPU_SHADER_CFG_LEN][MAX_GEOM][MAX_LIGHTING][MAX_COLOR]; + struct GPUShader *opaque_prepass_sh_cache[GPU_SHADER_CFG_LEN][WORKBENCH_DATATYPE_MAX][MAX_COLOR]; + struct GPUShader *transp_prepass_sh_cache[GPU_SHADER_CFG_LEN][WORKBENCH_DATATYPE_MAX] + [MAX_LIGHTING][MAX_COLOR]; struct GPUShader *opaque_composite_sh[MAX_LIGHTING]; struct GPUShader *oit_resolve_sh; @@ -117,8 +121,11 @@ void workbench_shader_library_ensure(void) if (e_data.lib == NULL) { e_data.lib = DRW_shader_library_create(); /* NOTE: Theses needs to be ordered by dependencies. */ + DRW_SHADER_LIB_ADD(e_data.lib, common_math_lib); + DRW_SHADER_LIB_ADD(e_data.lib, common_math_geom_lib); DRW_SHADER_LIB_ADD(e_data.lib, common_hair_lib); DRW_SHADER_LIB_ADD(e_data.lib, common_view_lib); + DRW_SHADER_LIB_ADD(e_data.lib, common_pointcloud_lib); DRW_SHADER_LIB_ADD(e_data.lib, gpu_shader_common_obinfos_lib); DRW_SHADER_LIB_ADD(e_data.lib, workbench_shader_interface_lib); DRW_SHADER_LIB_ADD(e_data.lib, workbench_common_lib); @@ -177,15 +184,18 @@ static int workbench_color_index(WORKBENCH_PrivateData *UNUSED(wpd), bool textur return (textured) ? (tiled ? 2 : 1) : 0; } -static GPUShader *workbench_shader_get_ex( - WORKBENCH_PrivateData *wpd, bool transp, bool hair, bool textured, bool tiled) +static GPUShader *workbench_shader_get_ex(WORKBENCH_PrivateData *wpd, + bool transp, + eWORKBENCH_DataType datatype, + bool textured, + bool tiled) { int color = workbench_color_index(wpd, textured, tiled); int light = wpd->shading.light; BLI_assert(light < MAX_LIGHTING); struct GPUShader **shader = - (transp) ? &e_data.transp_prepass_sh_cache[wpd->sh_cfg][hair][light][color] : - &e_data.opaque_prepass_sh_cache[wpd->sh_cfg][hair][color]; + (transp) ? &e_data.transp_prepass_sh_cache[wpd->sh_cfg][datatype][light][color] : + &e_data.opaque_prepass_sh_cache[wpd->sh_cfg][datatype][color]; if (*shader == NULL) { char *defines = workbench_build_defines(wpd, textured, tiled, false, false); @@ -194,8 +204,11 @@ static GPUShader *workbench_shader_get_ex( datatoc_workbench_prepass_frag_glsl; char *frag_src = DRW_shader_library_create_shader_string(e_data.lib, frag_file); - char *vert_file = hair ? datatoc_workbench_prepass_hair_vert_glsl : - datatoc_workbench_prepass_vert_glsl; + char *vert_file = (datatype == WORKBENCH_DATATYPE_HAIR) ? + datatoc_workbench_prepass_hair_vert_glsl : + ((datatype == WORKBENCH_DATATYPE_POINTCLOUD) ? + datatoc_workbench_prepass_pointcloud_vert_glsl : + datatoc_workbench_prepass_vert_glsl); char *vert_src = DRW_shader_library_create_shader_string(e_data.lib, vert_file); const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[wpd->sh_cfg]; @@ -207,6 +220,10 @@ static GPUShader *workbench_shader_get_ex( defines, transp ? "#define TRANSPARENT_MATERIAL\n" : "#define OPAQUE_MATERIAL\n", + (datatype == WORKBENCH_DATATYPE_POINTCLOUD) ? + "#define UNIFORM_RESOURCE_ID\n" + "#define INSTANCED_ATTR\n" : + NULL, NULL}, }); @@ -217,26 +234,29 @@ static GPUShader *workbench_shader_get_ex( return *shader; } -GPUShader *workbench_shader_opaque_get(WORKBENCH_PrivateData *wpd, bool hair) +GPUShader *workbench_shader_opaque_get(WORKBENCH_PrivateData *wpd, eWORKBENCH_DataType datatype) { - return workbench_shader_get_ex(wpd, false, hair, false, false); + return workbench_shader_get_ex(wpd, false, datatype, false, false); } -GPUShader *workbench_shader_opaque_image_get(WORKBENCH_PrivateData *wpd, bool hair, bool tiled) +GPUShader *workbench_shader_opaque_image_get(WORKBENCH_PrivateData *wpd, + eWORKBENCH_DataType datatype, + bool tiled) { - return workbench_shader_get_ex(wpd, false, hair, true, tiled); + return workbench_shader_get_ex(wpd, false, datatype, true, tiled); } -GPUShader *workbench_shader_transparent_get(WORKBENCH_PrivateData *wpd, bool hair) +GPUShader *workbench_shader_transparent_get(WORKBENCH_PrivateData *wpd, + eWORKBENCH_DataType datatype) { - return workbench_shader_get_ex(wpd, true, hair, false, false); + return workbench_shader_get_ex(wpd, true, datatype, false, false); } GPUShader *workbench_shader_transparent_image_get(WORKBENCH_PrivateData *wpd, - bool hair, + eWORKBENCH_DataType datatype, bool tiled) { - return workbench_shader_get_ex(wpd, true, hair, true, tiled); + return workbench_shader_get_ex(wpd, true, datatype, true, tiled); } GPUShader *workbench_shader_composite_get(WORKBENCH_PrivateData *wpd) diff --git a/source/blender/draw/engines/workbench/workbench_transparent.c b/source/blender/draw/engines/workbench/workbench_transparent.c index 1c40a350300..5eff056846c 100644 --- a/source/blender/draw/engines/workbench/workbench_transparent.c +++ b/source/blender/draw/engines/workbench/workbench_transparent.c @@ -83,10 +83,10 @@ static void workbench_transparent_lighting_uniforms(WORKBENCH_PrivateData *wpd, } } -void workbench_transparent_cache_init(WORKBENCH_Data *data) +void workbench_transparent_cache_init(WORKBENCH_Data *vedata) { - WORKBENCH_PassList *psl = data->psl; - WORKBENCH_PrivateData *wpd = data->stl->wpd; + WORKBENCH_PassList *psl = vedata->psl; + WORKBENCH_PrivateData *wpd = vedata->stl->wpd; struct GPUShader *sh; DRWShadingGroup *grp; @@ -105,30 +105,30 @@ void workbench_transparent_cache_init(WORKBENCH_Data *data) pass = psl->transp_accum_ps; } - for (int hair = 0; hair < 2; hair++) { - wpd->prepass[transp][infront][hair].material_hash = BLI_ghash_ptr_new(__func__); + for (eWORKBENCH_DataType data = 0; data < WORKBENCH_DATATYPE_MAX; data++) { + wpd->prepass[transp][infront][data].material_hash = BLI_ghash_ptr_new(__func__); - sh = workbench_shader_transparent_get(wpd, hair); + sh = workbench_shader_transparent_get(wpd, data); - wpd->prepass[transp][infront][hair].common_shgrp = grp = DRW_shgroup_create(sh, pass); + wpd->prepass[transp][infront][data].common_shgrp = grp = DRW_shgroup_create(sh, pass); DRW_shgroup_uniform_block(grp, "material_block", wpd->material_ubo_curr); DRW_shgroup_uniform_int_copy(grp, "materialIndex", -1); workbench_transparent_lighting_uniforms(wpd, grp); - wpd->prepass[transp][infront][hair].vcol_shgrp = grp = DRW_shgroup_create(sh, pass); + wpd->prepass[transp][infront][data].vcol_shgrp = grp = DRW_shgroup_create(sh, pass); DRW_shgroup_uniform_block(grp, "material_block", wpd->material_ubo_curr); DRW_shgroup_uniform_int_copy(grp, "materialIndex", 0); /* Default material. (uses vcol) */ - sh = workbench_shader_transparent_image_get(wpd, hair, false); + sh = workbench_shader_transparent_image_get(wpd, data, false); - wpd->prepass[transp][infront][hair].image_shgrp = grp = DRW_shgroup_create(sh, pass); + wpd->prepass[transp][infront][data].image_shgrp = grp = DRW_shgroup_create(sh, pass); DRW_shgroup_uniform_block(grp, "material_block", wpd->material_ubo_curr); DRW_shgroup_uniform_int_copy(grp, "materialIndex", 0); /* Default material. */ workbench_transparent_lighting_uniforms(wpd, grp); - sh = workbench_shader_transparent_image_get(wpd, hair, true); + sh = workbench_shader_transparent_image_get(wpd, data, true); - wpd->prepass[transp][infront][hair].image_tiled_shgrp = grp = DRW_shgroup_create(sh, pass); + wpd->prepass[transp][infront][data].image_tiled_shgrp = grp = DRW_shgroup_create(sh, pass); DRW_shgroup_uniform_block(grp, "material_block", wpd->material_ubo_curr); DRW_shgroup_uniform_int_copy(grp, "materialIndex", 0); /* Default material. */ workbench_transparent_lighting_uniforms(wpd, grp); diff --git a/source/blender/draw/engines/workbench/workbench_volume.c b/source/blender/draw/engines/workbench/workbench_volume.c index 8e345f8275b..d3c4d51dbd4 100644 --- a/source/blender/draw/engines/workbench/workbench_volume.c +++ b/source/blender/draw/engines/workbench/workbench_volume.c @@ -38,8 +38,6 @@ #include "BKE_volume.h" #include "BKE_volume_render.h" -#include "GPU_draw.h" - void workbench_volume_engine_init(WORKBENCH_Data *vedata) { WORKBENCH_TextureList *txl = vedata->txl; @@ -79,13 +77,10 @@ static void workbench_volume_modifier_cache_populate(WORKBENCH_Data *vedata, wpd->volumes_do = true; if (fds->use_coba) { - GPU_create_smoke_coba_field(fmd); - } - else if (!(fds->flags & FLUID_DOMAIN_USE_NOISE)) { - GPU_create_smoke(fmd, 0); + DRW_smoke_ensure_coba_field(fmd); } - else if (fds->flags & FLUID_DOMAIN_USE_NOISE) { - GPU_create_smoke(fmd, 1); + else { + DRW_smoke_ensure(fmd, fds->flags & FLUID_DOMAIN_USE_NOISE); } if ((!fds->use_coba && (fds->tex_density == NULL && fds->tex_color == NULL)) || @@ -293,7 +288,7 @@ void workbench_volume_draw_finish(WORKBENCH_Data *vedata) * all viewport in a redraw at least. */ LISTBASE_FOREACH (LinkData *, link, &wpd->smoke_domains) { FluidModifierData *fmd = (FluidModifierData *)link->data; - GPU_free_smoke(fmd); + DRW_smoke_free(fmd); } BLI_freelistN(&wpd->smoke_domains); } |