Workbench: Removed MaterialData UBO
Most of the times the materials differ due to the object_id. This was an overhead and resulted in instabilities on Intel graphical cards. This commit will revert the Material Data UBO and replace it with normal uniform.
This commit is contained in:
parent
9bd0c63382
commit
d34b0faa65
|
@ -15,9 +15,3 @@ struct WorldData {
|
|||
float background_alpha;
|
||||
int pad[1];
|
||||
};
|
||||
|
||||
struct MaterialData {
|
||||
vec4 diffuse_color;
|
||||
vec4 specular_color;
|
||||
float roughness;
|
||||
};
|
||||
|
|
|
@ -7,6 +7,10 @@ uniform float alpha = 0.5;
|
|||
uniform vec2 invertedViewportSize;
|
||||
uniform vec4 viewvecs[3];
|
||||
|
||||
uniform vec4 materialDiffuseColor;
|
||||
uniform vec4 materialSpecularColor;
|
||||
uniform float materialRoughness;
|
||||
|
||||
#ifdef NORMAL_VIEWPORT_PASS_ENABLED
|
||||
in vec3 normal_viewport;
|
||||
#endif /* NORMAL_VIEWPORT_PASS_ENABLED */
|
||||
|
@ -21,10 +25,6 @@ layout(std140) uniform world_block {
|
|||
WorldData world_data;
|
||||
};
|
||||
|
||||
layout(std140) uniform material_block {
|
||||
MaterialData material_data;
|
||||
};
|
||||
|
||||
layout(location=0) out vec4 transparentAccum;
|
||||
layout(location=1) out float revealageAccum; /* revealage actually stored in transparentAccum.a */
|
||||
|
||||
|
@ -36,7 +36,7 @@ void main()
|
|||
#ifdef V3D_SHADING_TEXTURE_COLOR
|
||||
diffuse_color = texture(image, uv_interp);
|
||||
#else
|
||||
diffuse_color = material_data.diffuse_color;
|
||||
diffuse_color = materialDiffuseColor;
|
||||
#endif /* V3D_SHADING_TEXTURE_COLOR */
|
||||
|
||||
vec2 uv_viewport = gl_FragCoord.xy * invertedViewportSize;
|
||||
|
@ -53,7 +53,7 @@ void main()
|
|||
#endif
|
||||
|
||||
#ifdef V3D_SHADING_SPECULAR_HIGHLIGHT
|
||||
vec3 specular_color = get_world_specular_lights(world_data, vec4(material_data.specular_color.rgb, material_data.roughness), nor, I_vs);
|
||||
vec3 specular_color = get_world_specular_lights(world_data, vec4(materialSpecularColor.rgb, materialRoughness), nor, I_vs);
|
||||
#else
|
||||
vec3 specular_color = vec3(0.0);
|
||||
#endif
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
uniform int object_id = 0;
|
||||
|
||||
layout(std140) uniform material_block {
|
||||
MaterialData material_data;
|
||||
};
|
||||
uniform vec4 materialDiffuseColor;
|
||||
uniform vec4 materialSpecularColor;
|
||||
uniform float materialRoughness;
|
||||
|
||||
#ifdef V3D_SHADING_TEXTURE_COLOR
|
||||
uniform sampler2D image;
|
||||
|
@ -43,9 +43,9 @@ void main()
|
|||
#ifdef V3D_SHADING_TEXTURE_COLOR
|
||||
diffuseColor = texture(image, uv_interp);
|
||||
#else
|
||||
diffuseColor = vec4(material_data.diffuse_color.rgb, 0.0);
|
||||
diffuseColor = vec4(materialDiffuseColor.rgb, 0.0);
|
||||
# ifdef STUDIOLIGHT_ORIENTATION_VIEWNORMAL
|
||||
specularColor = vec4(material_data.diffuse_color.rgb, 0.0);
|
||||
specularColor = vec4(materialDiffuseColor.rgb, 0.0);
|
||||
|
||||
# endif
|
||||
#endif /* V3D_SHADING_TEXTURE_COLOR */
|
||||
|
@ -56,7 +56,7 @@ void main()
|
|||
#endif
|
||||
|
||||
#ifdef V3D_SHADING_SPECULAR_HIGHLIGHT
|
||||
specularColor = vec4(material_data.specular_color.rgb, material_data.roughness);
|
||||
specularColor = vec4(materialSpecularColor.rgb, materialRoughness);
|
||||
# ifdef HAIR_SHADER
|
||||
specularColor.rgb = clamp(specularColor.rgb - hair_color_variation, 0.0, 1.0);
|
||||
# endif
|
||||
|
|
|
@ -159,15 +159,8 @@ void workbench_private_data_get_light_direction(WORKBENCH_PrivateData *wpd, floa
|
|||
DRW_uniformbuffer_update(wpd->world_ubo, wd);
|
||||
}
|
||||
|
||||
static void workbench_private_material_free(void *data)
|
||||
{
|
||||
WORKBENCH_MaterialData *material_data = data;
|
||||
DRW_UBO_FREE_SAFE(material_data->material_ubo);
|
||||
MEM_freeN(material_data);
|
||||
}
|
||||
|
||||
void workbench_private_data_free(WORKBENCH_PrivateData *wpd)
|
||||
{
|
||||
BLI_ghash_free(wpd->material_hash, NULL, workbench_private_material_free);
|
||||
BLI_ghash_free(wpd->material_hash, NULL, MEM_freeN);
|
||||
DRW_UBO_FREE_SAFE(wpd->world_ubo);
|
||||
}
|
||||
|
|
|
@ -580,18 +580,14 @@ static WORKBENCH_MaterialData *get_or_create_material_data(
|
|||
material = MEM_mallocN(sizeof(WORKBENCH_MaterialData), __func__);
|
||||
material->shgrp = DRW_shgroup_create(
|
||||
color_type == V3D_SHADING_TEXTURE_COLOR ? wpd->prepass_texture_sh: wpd->prepass_solid_sh, psl->prepass_pass);
|
||||
workbench_material_copy(material, &material_template);
|
||||
DRW_shgroup_stencil_mask(material->shgrp, 0xFF);
|
||||
material->object_id = material_template.object_id;
|
||||
copy_v4_v4(material->material_data.diffuse_color, material_template.material_data.diffuse_color);
|
||||
copy_v4_v4(material->material_data.specular_color, material_template.material_data.specular_color);
|
||||
material->material_data.roughness = material_template.material_data.roughness;
|
||||
DRW_shgroup_uniform_int(material->shgrp, "object_id", &material->object_id, 1);
|
||||
workbench_material_shgroup_uniform(material->shgrp, material);
|
||||
if (color_type == V3D_SHADING_TEXTURE_COLOR) {
|
||||
GPUTexture *tex = GPU_texture_from_blender(ima, NULL, GL_TEXTURE_2D, false, 0.0);
|
||||
DRW_shgroup_uniform_texture(material->shgrp, "image", tex);
|
||||
}
|
||||
DRW_shgroup_uniform_int(material->shgrp, "object_id", &material->object_id, 1);
|
||||
material->material_ubo = DRW_uniformbuffer_create(sizeof(WORKBENCH_UBO_Material), &material->material_data);
|
||||
DRW_shgroup_uniform_block(material->shgrp, "material_block", material->material_ubo);
|
||||
|
||||
BLI_ghash_insert(wpd->material_hash, SET_UINT_IN_POINTER(hash), material);
|
||||
}
|
||||
|
@ -637,7 +633,7 @@ static void workbench_cache_populate_particles(WORKBENCH_Data *vedata, Object *o
|
|||
shader);
|
||||
DRW_shgroup_stencil_mask(shgrp, 0xFF);
|
||||
DRW_shgroup_uniform_int(shgrp, "object_id", &material->object_id, 1);
|
||||
DRW_shgroup_uniform_block(shgrp, "material_block", material->material_ubo);
|
||||
workbench_material_shgroup_uniform(shgrp, material);
|
||||
if (image) {
|
||||
GPUTexture *tex = GPU_texture_from_blender(image, NULL, GL_TEXTURE_2D, false, 0.0f);
|
||||
DRW_shgroup_uniform_texture(shgrp, "image", tex);
|
||||
|
|
|
@ -177,11 +177,7 @@ static WORKBENCH_MaterialData *get_or_create_material_data(
|
|||
DRW_shgroup_uniform_float(grp, "alpha", &wpd->shading.xray_alpha, 1);
|
||||
DRW_shgroup_uniform_vec4(grp, "viewvecs[0]", (float *)wpd->viewvecs, 3);
|
||||
workbench_material_set_normal_world_matrix(grp, wpd, e_data.normal_world_matrix);
|
||||
material->object_id = engine_object_data->object_id;
|
||||
copy_v4_v4(material->material_data.diffuse_color, material_template.material_data.diffuse_color);
|
||||
copy_v4_v4(material->material_data.specular_color, material_template.material_data.specular_color);
|
||||
material->material_data.roughness = material_template.material_data.roughness;
|
||||
|
||||
workbench_material_copy(material, &material_template);
|
||||
if (color_type == V3D_SHADING_TEXTURE_COLOR) {
|
||||
GPUTexture *tex = GPU_texture_from_blender(ima, NULL, GL_TEXTURE_2D, false, 0.0f);
|
||||
DRW_shgroup_uniform_texture(grp, "image", tex);
|
||||
|
@ -194,8 +190,7 @@ static WORKBENCH_MaterialData *get_or_create_material_data(
|
|||
DRW_shgroup_uniform_vec2(grp, "invertedViewportSize", DRW_viewport_invert_size_get(), 1);
|
||||
}
|
||||
|
||||
material->material_ubo = DRW_uniformbuffer_create(sizeof(WORKBENCH_UBO_Material), &material->material_data);
|
||||
DRW_shgroup_uniform_block(grp, "material_block", material->material_ubo);
|
||||
workbench_material_shgroup_uniform(grp, material);
|
||||
material->shgrp = grp;
|
||||
|
||||
/* Depth */
|
||||
|
@ -431,7 +426,7 @@ static void workbench_forward_cache_populate_particles(WORKBENCH_Data *vedata, O
|
|||
shader);
|
||||
workbench_material_set_normal_world_matrix(shgrp, wpd, e_data.normal_world_matrix);
|
||||
DRW_shgroup_uniform_block(shgrp, "world_block", wpd->world_ubo);
|
||||
DRW_shgroup_uniform_block(shgrp, "material_block", material->material_ubo);
|
||||
workbench_material_shgroup_uniform(shgrp, material);
|
||||
DRW_shgroup_uniform_vec4(shgrp, "viewvecs[0]", (float *)wpd->viewvecs, 3);
|
||||
/* Hairs have lots of layer and can rapidly become the most prominent surface.
|
||||
* So lower their alpha artificially. */
|
||||
|
|
|
@ -13,12 +13,12 @@ void workbench_material_update_data(WORKBENCH_PrivateData *wpd, Object *ob, Mate
|
|||
int color_type = wpd->shading.color_type == V3D_SHADING_TEXTURE_COLOR ? V3D_SHADING_MATERIAL_COLOR : wpd->shading.color_type;
|
||||
static float default_diffuse_color[] = {0.8f, 0.8f, 0.8f, 1.0f};
|
||||
static float default_specular_color[] = {0.5f, 0.5f, 0.5f, 0.5f};
|
||||
copy_v4_v4(data->material_data.diffuse_color, default_diffuse_color);
|
||||
copy_v4_v4(data->material_data.specular_color, default_specular_color);
|
||||
data->material_data.roughness = 0.5f;
|
||||
copy_v4_v4(data->diffuse_color, default_diffuse_color);
|
||||
copy_v4_v4(data->specular_color, default_specular_color);
|
||||
data->roughness = 0.5f;
|
||||
|
||||
if (color_type == V3D_SHADING_SINGLE_COLOR) {
|
||||
copy_v3_v3(data->material_data.diffuse_color, wpd->shading.single_color);
|
||||
copy_v3_v3(data->diffuse_color, wpd->shading.single_color);
|
||||
}
|
||||
else if (color_type == V3D_SHADING_RANDOM_COLOR) {
|
||||
uint hash = BLI_ghashutil_strhash_p_murmur(ob->id.name);
|
||||
|
@ -28,14 +28,14 @@ void workbench_material_update_data(WORKBENCH_PrivateData *wpd, Object *ob, Mate
|
|||
float offset = fmodf((hash / 100000.0) * M_GOLDEN_RATION_CONJUGATE, 1.0);
|
||||
|
||||
float hsv[3] = {offset, HSV_SATURATION, HSV_VALUE};
|
||||
hsv_to_rgb_v(hsv, data->material_data.diffuse_color);
|
||||
hsv_to_rgb_v(hsv, data->diffuse_color);
|
||||
}
|
||||
else {
|
||||
/* V3D_SHADING_MATERIAL_COLOR */
|
||||
if (mat) {
|
||||
copy_v3_v3(data->material_data.diffuse_color, &mat->r);
|
||||
copy_v3_v3(data->material_data.specular_color, &mat->specr);
|
||||
data->material_data.roughness = mat->roughness;
|
||||
copy_v3_v3(data->diffuse_color, &mat->r);
|
||||
copy_v3_v3(data->specular_color, &mat->specr);
|
||||
data->roughness = mat->roughness;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,18 +109,18 @@ uint workbench_material_get_hash(WORKBENCH_MaterialData *material_template)
|
|||
{
|
||||
uint input[4];
|
||||
uint result;
|
||||
float *color = material_template->material_data.diffuse_color;
|
||||
float *color = material_template->diffuse_color;
|
||||
input[0] = (uint)(color[0] * 512);
|
||||
input[1] = (uint)(color[1] * 512);
|
||||
input[2] = (uint)(color[2] * 512);
|
||||
input[3] = material_template->object_id;
|
||||
result = BLI_ghashutil_uinthash_v4_murmur(input);
|
||||
|
||||
color = material_template->material_data.specular_color;
|
||||
color = material_template->specular_color;
|
||||
input[0] = (uint)(color[0] * 512);
|
||||
input[1] = (uint)(color[1] * 512);
|
||||
input[2] = (uint)(color[2] * 512);
|
||||
input[3] = (uint)(material_template->material_data.roughness * 512);
|
||||
input[3] = (uint)(material_template->roughness * 512);
|
||||
result += BLI_ghashutil_uinthash_v4_murmur(input);
|
||||
|
||||
/* add texture reference */
|
||||
|
@ -176,3 +176,19 @@ int workbench_material_determine_color_type(WORKBENCH_PrivateData *wpd, Image *i
|
|||
}
|
||||
return color_type;
|
||||
}
|
||||
|
||||
void workbench_material_shgroup_uniform(DRWShadingGroup *grp, WORKBENCH_MaterialData *material)
|
||||
{
|
||||
DRW_shgroup_uniform_vec4(grp, "materialDiffuseColor", material->diffuse_color, 1);
|
||||
DRW_shgroup_uniform_vec4(grp, "materialSpecularColor", material->specular_color, 1);
|
||||
DRW_shgroup_uniform_float(grp, "materialRoughness", &material->roughness, 1);
|
||||
}
|
||||
|
||||
void workbench_material_copy(WORKBENCH_MaterialData *dest_material, const WORKBENCH_MaterialData *source_material)
|
||||
{
|
||||
dest_material->object_id = source_material->object_id;
|
||||
copy_v4_v4(dest_material->diffuse_color, source_material->diffuse_color);
|
||||
copy_v4_v4(dest_material->specular_color, source_material->specular_color);
|
||||
dest_material->roughness = source_material->roughness;
|
||||
dest_material->ima = source_material->ima;
|
||||
}
|
|
@ -138,13 +138,6 @@ typedef struct WORKBENCH_UBO_World {
|
|||
} WORKBENCH_UBO_World;
|
||||
BLI_STATIC_ASSERT_ALIGN(WORKBENCH_UBO_World, 16)
|
||||
|
||||
typedef struct WORKBENCH_UBO_Material {
|
||||
float diffuse_color[4];
|
||||
float specular_color[4];
|
||||
float roughness;
|
||||
float pad[3];
|
||||
} WORKBENCH_UBO_Material;
|
||||
BLI_STATIC_ASSERT_ALIGN(WORKBENCH_UBO_Material, 16)
|
||||
|
||||
typedef struct WORKBENCH_PrivateData {
|
||||
struct GHash *material_hash;
|
||||
|
@ -196,10 +189,9 @@ typedef struct WORKBENCH_EffectInfo {
|
|||
} WORKBENCH_EffectInfo;
|
||||
|
||||
typedef struct WORKBENCH_MaterialData {
|
||||
/* Solid color */
|
||||
WORKBENCH_UBO_Material material_data;
|
||||
struct GPUUniformBuffer *material_ubo;
|
||||
|
||||
float diffuse_color[4];
|
||||
float specular_color[4];
|
||||
float roughness;
|
||||
int object_id;
|
||||
int color_type;
|
||||
Image *ima;
|
||||
|
@ -279,6 +271,8 @@ uint workbench_material_get_hash(WORKBENCH_MaterialData *material_template);
|
|||
int workbench_material_get_shader_index(WORKBENCH_PrivateData *wpd, bool use_textures, bool is_hair);
|
||||
void workbench_material_set_normal_world_matrix(
|
||||
DRWShadingGroup *grp, WORKBENCH_PrivateData *wpd, float persistent_matrix[3][3]);
|
||||
void workbench_material_shgroup_uniform(DRWShadingGroup *grp, WORKBENCH_MaterialData *material);
|
||||
void workbench_material_copy(WORKBENCH_MaterialData *dest_material, const WORKBENCH_MaterialData *source_material);
|
||||
|
||||
/* workbench_studiolight.c */
|
||||
void studiolight_update_world(StudioLight *sl, WORKBENCH_UBO_World *wd);
|
||||
|
|
Loading…
Reference in New Issue