[Bf-blender-cvs] [cde0faf4dd4] tmp-workbench-rewrite2: add support for background color
Miguel Pozo
noreply at git.blender.org
Thu Oct 6 20:42:11 CEST 2022
Commit: cde0faf4dd44b8fc71fb9f883affc44cf32a302d
Author: Miguel Pozo
Date: Thu Oct 6 20:09:18 2022 +0200
Branches: tmp-workbench-rewrite2
https://developer.blender.org/rBcde0faf4dd44b8fc71fb9f883affc44cf32a302d
add support for background color
===================================================================
M source/blender/draw/engines/workbench/shaders/workbench_composite_comp.glsl
M source/blender/draw/engines/workbench/workbench_engine.cc
M source/blender/draw/engines/workbench/workbench_shader_shared.h
===================================================================
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_composite_comp.glsl b/source/blender/draw/engines/workbench/shaders/workbench_composite_comp.glsl
index fbfedab7f78..5297559aa60 100644
--- a/source/blender/draw/engines/workbench/shaders/workbench_composite_comp.glsl
+++ b/source/blender/draw/engines/workbench/shaders/workbench_composite_comp.glsl
@@ -21,8 +21,7 @@ void main()
float roughness, metallic;
workbench_float_pair_decode(mat_data.a, roughness, metallic);
- /* TODO(fclem): Pass background color as uniform. */
- vec4 color = vec4(0.0, 0.0, 0.0, 1.0);
+ vec4 color = world_data.background_color;
/* Background pixels. */
if (depth != 1.0) {
diff --git a/source/blender/draw/engines/workbench/workbench_engine.cc b/source/blender/draw/engines/workbench/workbench_engine.cc
index b09949b53a3..147953ee985 100644
--- a/source/blender/draw/engines/workbench/workbench_engine.cc
+++ b/source/blender/draw/engines/workbench/workbench_engine.cc
@@ -263,6 +263,13 @@ struct SceneResources {
StorageVectorBuffer<workbench::Material> material_buf = {"material_buf"};
UniformBuffer<WorldData> world_buf;
+ void init(int2 output_res, float4 background_color)
+ {
+ world_buf.background_color = background_color;
+ matcap_tx.ensure_2d_array(GPU_RGBA16F, int2(1), 1);
+ depth_tx.ensure_2d(GPU_DEPTH24_STENCIL8, output_res);
+ }
+
void world_sync(StudioLight *studio_light)
{
float4x4 rot_matrix = float4x4::identity();
@@ -642,15 +649,12 @@ class Instance {
void init(const int2 &output_res,
const Depsgraph *depsgraph,
const Object * /*camera*/,
- const View3D * /*v3d*/,
- const RegionView3D * /*rv3d*/)
+ const View3D *v3d,
+ const RegionView3D *rv3d)
{
Scene *scene = DEG_get_evaluated_scene(depsgraph);
View3DShading &shading = scene->display.shading;
- resources.matcap_tx.ensure_2d_array(GPU_RGBA16F, int2(1), 1);
- resources.depth_tx.ensure_2d(GPU_DEPTH24_STENCIL8, output_res);
-
cull_state = DRW_STATE_NO_DRAW;
if (shading.flag & V3D_SHADING_BACKFACE_CULLING) {
cull_state |= DRW_STATE_CULL_BACK;
@@ -709,7 +713,24 @@ class Instance {
break;
}
- // TODO(pragma37): Create resources.init() to store the relevant settings;
+ float4 background_color = float4(0.0f);
+
+ /*TODO(pragma37): Replace when Workbench next is complete*/
+ // bool is_workbench_render = BKE_scene_uses_blender_workbench(scene);
+ bool is_workbench_render = std::string(scene->r.engine) ==
+ std::string("BLENDER_WORKBENCH_NEXT");
+
+ /* TODO(pragma37):
+ * Check why Workbench Next exposes OB_MATERIAL, and Workbench exposes OB_RENDER */
+ if (!v3d || (ELEM(v3d->shading.type, OB_RENDER, OB_MATERIAL) && is_workbench_render)) {
+ if (scene->r.alphamode != R_ALPHAPREMUL) {
+ World *w = scene->world;
+ background_color = w ? float4(w->horr, w->horg, w->horb, 1.0f) :
+ float4(0.0f, 0.0f, 0.0f, 1.0f);
+ }
+ }
+
+ resources.init(output_res, background_color);
studio_light = nullptr;
if (shading_type == eShadingType::MATCAP) {
diff --git a/source/blender/draw/engines/workbench/workbench_shader_shared.h b/source/blender/draw/engines/workbench/workbench_shader_shared.h
index b2e8fa30d85..ad06c838846 100644
--- a/source/blender/draw/engines/workbench/workbench_shader_shared.h
+++ b/source/blender/draw/engines/workbench/workbench_shader_shared.h
@@ -24,6 +24,9 @@ struct WorldData {
LightData lights[4];
float4 ambient_color;
+ /* TODO(pragma37): Check why this breaks Workbench rendering*/
+ float4 background_color;
+
int cavity_sample_start;
int cavity_sample_end;
float cavity_sample_count_inv;
More information about the Bf-blender-cvs
mailing list