Fix T47207: Material shading incorrectly handles colorramp node

The issue was introduced by a fix for T44713 which only made GLSL
consistent with Cycles.

Now we do have conditional averaging or proper luma weighting based
on whether we're new old old shading system. Not totally ideal but
should work for until we re-design viewport possibly breaking how
Blender Internal does implicit conversion.
This commit is contained in:
Sergey Sharybin 2016-02-02 12:48:18 +01:00
parent be10d6d3f0
commit 49247f0fc4
Notes: blender-bot 2023-02-14 10:18:56 +01:00
Referenced by issue #47207, Material shading incorrectly handles colorramp node
6 changed files with 46 additions and 8 deletions

View File

@ -46,6 +46,7 @@ struct GPUTexture;
enum {
GPU_SHADER_FLAGS_NONE = 0,
GPU_SHADER_FLAGS_SPECIAL_OPENSUBDIV = (1 << 0),
GPU_SHADER_FLAGS_NEW_SHADING = (1 << 1),
};
GPUShader *GPU_shader_create(

View File

@ -318,7 +318,9 @@ static void codegen_convert_datatype(DynStr *ds, int from, int to, const char *t
BLI_dynstr_append(ds, name);
}
else if (to == GPU_FLOAT) {
if (from == GPU_VEC4 || from == GPU_VEC3)
if (from == GPU_VEC4)
BLI_dynstr_appendf(ds, "convert_rgba_to_float(%s)", name);
else if (from == GPU_VEC3)
BLI_dynstr_appendf(ds, "(%s.r + %s.g + %s.b) / 3.0", name, name, name);
else if (from == GPU_VEC2)
BLI_dynstr_appendf(ds, "%s.r", name);
@ -1641,7 +1643,9 @@ static void gpu_nodes_prune(ListBase *nodes, GPUNodeLink *outlink)
GPUPass *GPU_generate_pass(
ListBase *nodes, GPUNodeLink *outlink,
GPUVertexAttribs *attribs, int *builtins,
const GPUMatType type, const char *UNUSED(name), const bool use_opensubdiv)
const GPUMatType type, const char *UNUSED(name),
const bool use_opensubdiv,
const bool use_new_shading)
{
GPUShader *shader;
GPUPass *pass;
@ -1664,6 +1668,14 @@ GPUPass *GPU_generate_pass(
fragmentcode = code_generate_fragment(nodes, outlink->output);
vertexcode = code_generate_vertex(nodes, type);
geometrycode = code_generate_geometry(nodes, use_opensubdiv);
int flags = GPU_SHADER_FLAGS_NONE;
if (use_opensubdiv) {
flags |= GPU_SHADER_FLAGS_SPECIAL_OPENSUBDIV;
}
if (use_new_shading) {
flags |= GPU_SHADER_FLAGS_NEW_SHADING;
}
shader = GPU_shader_create_ex(vertexcode,
fragmentcode,
geometrycode,
@ -1672,8 +1684,7 @@ GPUPass *GPU_generate_pass(
0,
0,
0,
use_opensubdiv ? GPU_SHADER_FLAGS_SPECIAL_OPENSUBDIV
: GPU_SHADER_FLAGS_NONE);
flags);
/* failed? */
if (!shader) {

View File

@ -172,7 +172,9 @@ typedef struct GPUPass GPUPass;
GPUPass *GPU_generate_pass(ListBase *nodes, struct GPUNodeLink *outlink,
struct GPUVertexAttribs *attribs, int *builtin,
const GPUMatType type, const char *name, const bool use_opensubdiv);
const GPUMatType type, const char *name,
const bool use_opensubdiv,
const bool use_new_shading);
struct GPUShader *GPU_pass_shader(GPUPass *pass);

View File

@ -226,7 +226,9 @@ static int GPU_material_construct_end(GPUMaterial *material, const char *passnam
GPUNodeLink *outlink = material->outlink;
material->pass = GPU_generate_pass(&material->nodes, outlink,
&material->attribs, &material->builtins, material->type,
passname, material->is_opensubdiv);
passname,
material->is_opensubdiv,
GPU_material_use_new_shading_nodes(material));
if (!material->pass)
return 0;

View File

@ -183,7 +183,9 @@ static void gpu_shader_standard_extensions(char defines[MAX_EXT_DEFINE_LENGTH],
}
}
static void gpu_shader_standard_defines(char defines[MAX_DEFINE_LENGTH], bool use_opensubdiv)
static void gpu_shader_standard_defines(char defines[MAX_DEFINE_LENGTH],
bool use_opensubdiv,
bool use_new_shading)
{
/* some useful defines to detect GPU type */
if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)) {
@ -222,6 +224,10 @@ static void gpu_shader_standard_defines(char defines[MAX_DEFINE_LENGTH], bool us
UNUSED_VARS(use_opensubdiv);
#endif
if (use_new_shading) {
strcat(defines, "#define USE_NEW_SHADING\n");
}
return;
}
@ -296,7 +302,9 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
return NULL;
}
gpu_shader_standard_defines(standard_defines, use_opensubdiv);
gpu_shader_standard_defines(standard_defines,
use_opensubdiv,
(flags & GPU_SHADER_FLAGS_NEW_SHADING) != 0);
gpu_shader_standard_extensions(standard_extensions, geocode != NULL);
if (vertexcode) {

View File

@ -1,3 +1,13 @@
/* Converters */
float convert_rgba_to_float(vec4 color)
{
#ifdef USE_NEW_SHADING
return color.r*0.2126 + color.g*0.7152 + color.b*0.0722;
#else
return (color.r + color.g + color.b) / 3.0;
#endif
}
float exp_blender(float f)
{
@ -743,7 +753,11 @@ void valtorgb(float fac, sampler2D colormap, out vec4 outcol, out float outalpha
void rgbtobw(vec4 color, out float outval)
{
#ifdef USE_NEW_SHADING
outval = color.r*0.2126 + color.g*0.7152 + color.b*0.0722;
#else
outval = color.r*0.35 + color.g*0.45 + color.b*0.2; /* keep these factors in sync with texture.h:RGBTOBW */
#endif
}
void invert(float fac, vec4 col, out vec4 outcol)