Code cleanup: minor cleanups for GPU_link return values, normal map node.
This commit is contained in:
@@ -1496,7 +1496,7 @@ bool GPU_link(GPUMaterial *mat, const char *name, ...)
|
||||
function = gpu_lookup_function(name);
|
||||
if (!function) {
|
||||
fprintf(stderr, "GPU failed to find function %s\n", name);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
node = GPU_node_begin(name);
|
||||
@@ -1516,7 +1516,7 @@ bool GPU_link(GPUMaterial *mat, const char *name, ...)
|
||||
|
||||
gpu_material_add_node(mat, node);
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNodeStack *out, ...)
|
||||
@@ -1530,7 +1530,7 @@ bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNod
|
||||
function = gpu_lookup_function(name);
|
||||
if (!function) {
|
||||
fprintf(stderr, "GPU failed to find function %s\n", name);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
node = GPU_node_begin(name);
|
||||
@@ -1577,7 +1577,7 @@ bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNod
|
||||
|
||||
gpu_material_add_node(mat, node);
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int GPU_link_changed(GPUNodeLink *link)
|
||||
|
@@ -69,7 +69,7 @@ static int gpu_shader_lamp(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
|
||||
return GPU_stack_link(mat, "lamp", in, out, col, energy, lv, dist, shadow, visifac);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
void register_node_type_sh_lamp(void)
|
||||
|
@@ -85,12 +85,12 @@ static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS
|
||||
GPUNodeLink *tdomin = GPU_uniform(&domin);
|
||||
GPUNodeLink *tdomax = GPU_uniform(&domax);
|
||||
|
||||
int result = GPU_stack_link(mat, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax);
|
||||
GPU_stack_link(mat, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax);
|
||||
|
||||
if (result && texmap->type == TEXMAP_TYPE_NORMAL)
|
||||
if (texmap->type == TEXMAP_TYPE_NORMAL)
|
||||
GPU_link(mat, "texco_norm", out[0].link, &out[0].link);
|
||||
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
void register_node_type_sh_mapping(void)
|
||||
|
@@ -48,18 +48,12 @@ static void node_shader_init_normal_map(bNodeTree *UNUSED(ntree), bNode *node)
|
||||
|
||||
static void node_shader_exec_normal_map(void *data, int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out)
|
||||
{
|
||||
float vecIn[3];
|
||||
float strength;
|
||||
float B[4];
|
||||
float *T;
|
||||
float *N;
|
||||
int j;
|
||||
|
||||
if (data) {
|
||||
ShadeInput *shi = ((ShaderCallData *)data)->shi;
|
||||
|
||||
NodeShaderNormalMap *nm = node->storage;
|
||||
|
||||
float strength, vecIn[3];
|
||||
nodestack_get_vec(&strength, SOCK_FLOAT, in[0]);
|
||||
nodestack_get_vec(vecIn, SOCK_VECTOR, in[1]);
|
||||
|
||||
@@ -69,7 +63,7 @@ static void node_shader_exec_normal_map(void *data, int UNUSED(thread), bNode *n
|
||||
|
||||
CLAMP_MIN(strength, 0.0f);
|
||||
|
||||
N = shi->vno;
|
||||
float *N = shi->vno;
|
||||
int uv_index = 0;
|
||||
switch (nm->space) {
|
||||
case SHD_NORMAL_MAP_TANGENT:
|
||||
@@ -86,12 +80,13 @@ static void node_shader_exec_normal_map(void *data, int UNUSED(thread), bNode *n
|
||||
uv_index = shi->actuv;
|
||||
}
|
||||
|
||||
T = shi->tangents[uv_index];
|
||||
float *T = shi->tangents[uv_index];
|
||||
|
||||
float B[3];
|
||||
cross_v3_v3v3(B, N, T);
|
||||
mul_v3_fl(B, T[3]);
|
||||
|
||||
for (j = 0; j < 3; j++)
|
||||
for (int j = 0; j < 3; j++)
|
||||
out[0]->vec[j] = vecIn[0] * T[j] + vecIn[1] * B[j] + vecIn[2] * N[j];
|
||||
interp_v3_v3v3(out[0]->vec, N, out[0]->vec, strength);
|
||||
break;
|
||||
@@ -114,7 +109,6 @@ static void node_shader_exec_normal_map(void *data, int UNUSED(thread), bNode *n
|
||||
|
||||
static int gpu_shader_normal_map(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
|
||||
{
|
||||
int r;
|
||||
NodeShaderNormalMap *nm = node->storage;
|
||||
GPUNodeLink *negnorm;
|
||||
GPUNodeLink *realnorm;
|
||||
@@ -128,45 +122,35 @@ static int gpu_shader_normal_map(GPUMaterial *mat, bNode *node, bNodeExecData *U
|
||||
strength = GPU_uniform(in[0].vec);
|
||||
|
||||
if (in[1].link) {
|
||||
r = GPU_link(mat, "color_to_normal", in[1].link, &realnorm);
|
||||
if (!r) return r;
|
||||
r = GPU_link(mat, "mtex_negate_texnormal", realnorm, &realnorm);
|
||||
GPU_link(mat, "color_to_normal", in[1].link, &realnorm);
|
||||
GPU_link(mat, "mtex_negate_texnormal", realnorm, &realnorm);
|
||||
}
|
||||
else
|
||||
r = 1;
|
||||
|
||||
GPU_link(mat, "math_max", strength, GPU_uniform(d), &strength);
|
||||
GPU_link(mat, "vec_math_negate", GPU_builtin(GPU_VIEW_NORMAL), &negnorm);
|
||||
switch (nm->space) {
|
||||
case SHD_NORMAL_MAP_TANGENT:
|
||||
if (in[1].link) {
|
||||
r = GPU_link(mat, "node_normal_map", GPU_attribute(CD_TANGENT, nm->uv_map), negnorm, realnorm, &out[0].link);
|
||||
if (!r) return r;
|
||||
}
|
||||
break;
|
||||
case SHD_NORMAL_MAP_OBJECT:
|
||||
case SHD_NORMAL_MAP_BLENDER_OBJECT:
|
||||
if (in[1].link) {
|
||||
r = GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_LOC_TO_VIEW_MATRIX), &out[0].link);
|
||||
if (!r) return r;
|
||||
}
|
||||
break;
|
||||
case SHD_NORMAL_MAP_WORLD:
|
||||
case SHD_NORMAL_MAP_BLENDER_WORLD:
|
||||
if (in[1].link) {
|
||||
r = GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_VIEW_MATRIX), &out[0].link);
|
||||
if (!r) return r;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (out[0].link) {
|
||||
r = GPU_link(mat, "vec_math_mix", strength, out[0].link, negnorm, &out[0].link);
|
||||
if (!r) return r;
|
||||
|
||||
r = GPU_link(mat, "vect_normalize", out[0].link, &out[0].link);
|
||||
if (!r) return r;
|
||||
if (in[1].link) {
|
||||
switch (nm->space) {
|
||||
case SHD_NORMAL_MAP_TANGENT:
|
||||
GPU_link(mat, "node_normal_map", GPU_attribute(CD_TANGENT, nm->uv_map), negnorm, realnorm, &out[0].link);
|
||||
break;
|
||||
case SHD_NORMAL_MAP_OBJECT:
|
||||
case SHD_NORMAL_MAP_BLENDER_OBJECT:
|
||||
GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_LOC_TO_VIEW_MATRIX), &out[0].link);
|
||||
break;
|
||||
case SHD_NORMAL_MAP_WORLD:
|
||||
case SHD_NORMAL_MAP_BLENDER_WORLD:
|
||||
GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_VIEW_MATRIX), &out[0].link);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
|
||||
if (out[0].link) {
|
||||
GPU_link(mat, "vec_math_mix", strength, out[0].link, negnorm, &out[0].link);
|
||||
GPU_link(mat, "vect_normalize", out[0].link, &out[0].link);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* node type definition */
|
||||
|
@@ -43,7 +43,7 @@ static int node_shader_gpu_output_material(GPUMaterial *mat, bNode *UNUSED(node)
|
||||
GPU_stack_link(mat, "node_output_material", in, out, &outlink);
|
||||
GPU_material_output_link(mat, outlink);
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -42,7 +42,7 @@ static int node_shader_gpu_output_world(GPUMaterial *mat, bNode *UNUSED(node), b
|
||||
GPU_stack_link(mat, "node_output_world", in, out, &outlink);
|
||||
GPU_material_output_link(mat, outlink);
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* node type definition */
|
||||
|
@@ -60,7 +60,6 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, bNodeE
|
||||
ImageUser *iuser = NULL;
|
||||
NodeTexImage *tex = node->storage;
|
||||
int isdata = tex->color_space == SHD_COLORSPACE_NONE;
|
||||
int ret;
|
||||
|
||||
if (!ima)
|
||||
return GPU_stack_link(mat, "node_tex_environment_empty", in, out);
|
||||
@@ -77,21 +76,19 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, bNodeE
|
||||
node_shader_gpu_tex_mapping(mat, node, in, out);
|
||||
|
||||
if (tex->projection == SHD_PROJ_EQUIRECTANGULAR)
|
||||
ret = GPU_stack_link(mat, "node_tex_environment_equirectangular", in, out, GPU_image(ima, iuser, isdata));
|
||||
GPU_stack_link(mat, "node_tex_environment_equirectangular", in, out, GPU_image(ima, iuser, isdata));
|
||||
else
|
||||
ret = GPU_stack_link(mat, "node_tex_environment_mirror_ball", in, out, GPU_image(ima, iuser, isdata));
|
||||
GPU_stack_link(mat, "node_tex_environment_mirror_ball", in, out, GPU_image(ima, iuser, isdata));
|
||||
|
||||
if (ret) {
|
||||
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
|
||||
if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&
|
||||
GPU_material_do_color_management(mat))
|
||||
{
|
||||
GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link);
|
||||
}
|
||||
BKE_image_release_ibuf(ima, ibuf, NULL);
|
||||
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
|
||||
if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&
|
||||
GPU_material_do_color_management(mat))
|
||||
{
|
||||
GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link);
|
||||
}
|
||||
BKE_image_release_ibuf(ima, ibuf, NULL);
|
||||
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* node type definition */
|
||||
|
@@ -60,7 +60,6 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, bNodeExecDat
|
||||
ImageUser *iuser = NULL;
|
||||
NodeTexImage *tex = node->storage;
|
||||
int isdata = tex->color_space == SHD_COLORSPACE_NONE;
|
||||
int ret;
|
||||
|
||||
if (!ima)
|
||||
return GPU_stack_link(mat, "node_tex_image_empty", in, out);
|
||||
@@ -70,19 +69,17 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, bNodeExecDat
|
||||
|
||||
node_shader_gpu_tex_mapping(mat, node, in, out);
|
||||
|
||||
ret = GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
|
||||
GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
|
||||
|
||||
if (ret) {
|
||||
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
|
||||
if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&
|
||||
GPU_material_do_color_management(mat))
|
||||
{
|
||||
GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link);
|
||||
}
|
||||
BKE_image_release_ibuf(ima, ibuf, NULL);
|
||||
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
|
||||
if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&
|
||||
GPU_material_do_color_management(mat))
|
||||
{
|
||||
GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link);
|
||||
}
|
||||
BKE_image_release_ibuf(ima, ibuf, NULL);
|
||||
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* node type definition */
|
||||
|
@@ -123,22 +123,20 @@ static int gpu_shader_texture(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS
|
||||
|
||||
if (tex && tex->type == TEX_IMAGE && tex->ima) {
|
||||
GPUNodeLink *texlink = GPU_image(tex->ima, &tex->iuser, false);
|
||||
int ret = GPU_stack_link(mat, "texture_image", in, out, texlink);
|
||||
GPU_stack_link(mat, "texture_image", in, out, texlink);
|
||||
|
||||
if (ret) {
|
||||
ImBuf *ibuf = BKE_image_acquire_ibuf(tex->ima, &tex->iuser, NULL);
|
||||
if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&
|
||||
GPU_material_do_color_management(mat))
|
||||
{
|
||||
GPU_link(mat, "srgb_to_linearrgb", out[1].link, &out[1].link);
|
||||
}
|
||||
BKE_image_release_ibuf(tex->ima, ibuf, NULL);
|
||||
ImBuf *ibuf = BKE_image_acquire_ibuf(tex->ima, &tex->iuser, NULL);
|
||||
if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&
|
||||
GPU_material_do_color_management(mat))
|
||||
{
|
||||
GPU_link(mat, "srgb_to_linearrgb", out[1].link, &out[1].link);
|
||||
}
|
||||
BKE_image_release_ibuf(tex->ima, ibuf, NULL);
|
||||
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void register_node_type_sh_texture(void)
|
||||
|
@@ -130,10 +130,10 @@ static int gpu_shader_vect_math(GPUMaterial *mat, bNode *node, bNodeExecData *UN
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void register_node_type_sh_vect_math(void)
|
||||
|
@@ -157,8 +157,6 @@ static int gpu_shader_vect_transform(GPUMaterial *mat, bNode *node, bNodeExecDat
|
||||
struct GPUNodeLink *inputlink;
|
||||
struct GPUNodeLink *fromto;
|
||||
|
||||
int ret = 0;
|
||||
|
||||
const char *vtransform = "direction_transform_m4v3";
|
||||
const char *ptransform = "point_transform_m4v3";
|
||||
const char *func_name = 0;
|
||||
@@ -180,24 +178,24 @@ static int gpu_shader_vect_transform(GPUMaterial *mat, bNode *node, bNodeExecDat
|
||||
/* For cycles we have inverted Z */
|
||||
/* TODO: pass here the correct matrices */
|
||||
if (nodeprop->convert_from == SHD_VECT_TRANSFORM_SPACE_CAMERA && nodeprop->convert_to != SHD_VECT_TRANSFORM_SPACE_CAMERA) {
|
||||
ret = GPU_link(mat, "invert_z", inputlink, &inputlink);
|
||||
GPU_link(mat, "invert_z", inputlink, &inputlink);
|
||||
}
|
||||
ret = GPU_link(mat, func_name, inputlink, fromto, &out[0].link);
|
||||
GPU_link(mat, func_name, inputlink, fromto, &out[0].link);
|
||||
if (nodeprop->convert_to == SHD_VECT_TRANSFORM_SPACE_CAMERA && nodeprop->convert_from != SHD_VECT_TRANSFORM_SPACE_CAMERA) {
|
||||
ret = GPU_link(mat, "invert_z", out[0].link, &out[0].link);
|
||||
GPU_link(mat, "invert_z", out[0].link, &out[0].link);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ret = GPU_link(mat, func_name, inputlink, fromto, &out[0].link);
|
||||
GPU_link(mat, func_name, inputlink, fromto, &out[0].link);
|
||||
}
|
||||
}
|
||||
else
|
||||
ret = GPU_link(mat, "set_rgb", inputlink, &out[0].link);
|
||||
GPU_link(mat, "set_rgb", inputlink, &out[0].link);
|
||||
|
||||
if (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_NORMAL)
|
||||
return GPU_link(mat, "vect_normalize", out[0].link, &out[0].link);
|
||||
GPU_link(mat, "vect_normalize", out[0].link, &out[0].link);
|
||||
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
void register_node_type_sh_vect_transform(void)
|
||||
|
@@ -42,7 +42,7 @@ static bNodeSocketTemplate sh_node_volume_absorption_out[] = {
|
||||
|
||||
static int node_shader_gpu_volume_absorption(GPUMaterial *UNUSED(mat), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *UNUSED(in), GPUNodeStack *UNUSED(out))
|
||||
{
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* node type definition */
|
||||
|
@@ -43,7 +43,7 @@ static bNodeSocketTemplate sh_node_volume_scatter_out[] = {
|
||||
|
||||
static int node_shader_gpu_volume_scatter(GPUMaterial *UNUSED(mat), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *UNUSED(in), GPUNodeStack *UNUSED(out))
|
||||
{
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* node type definition */
|
||||
|
Reference in New Issue
Block a user