static int node_shader_gpu_oct_tex_float_image(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) {
	int          ret;
    float        rgb[4];
    int          isdata;
	Image        *ima   = (Image*)node->id;
	ImageUser    *iuser = NULL;
	NodeTexImage *tex   = node->storage;
    if(!tex) {
        node_oct_float_image_tex_init(0, node);
        tex   = node->storage;
    }
	isdata = tex->color_space == SHD_COLORSPACE_NONE;

    in[0].type = GPU_VEC3;
	in[0].link = GPU_attribute(CD_MTFACE, "");
    in[1].type = GPU_NONE;

	if(!ima) return GPU_stack_link(mat, "node_tex_image_empty", in, out, GPU_uniform(rgb));
	
	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_uniform(rgb));
	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);
	}
	return ret;
}
예제 #2
0
static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
{
	TexMapping *texmap= node->storage;
	float domin= (texmap->flag & TEXMAP_CLIP_MIN) != 0;
	float domax= (texmap->flag & TEXMAP_CLIP_MAX) != 0;
	GPUNodeLink *tmat = GPU_uniform((float*)texmap->mat);
	GPUNodeLink *tmin = GPU_uniform(texmap->min);
	GPUNodeLink *tmax = GPU_uniform(texmap->max);
	GPUNodeLink *tdomin = GPU_uniform(&domin);
	GPUNodeLink *tdomax = GPU_uniform(&domax);

	return GPU_stack_link(mat, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax);
}
static int node_shader_gpu_tex_wave(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
	if (!in[0].link) {
		in[0].link = GPU_attribute(CD_ORCO, "");
		GPU_link(mat, "generated_from_orco", in[0].link, &in[0].link);
	}

	node_shader_gpu_tex_mapping(mat, node, in, out);

	NodeTexWave *tex = (NodeTexWave *)node->storage;
	float wave_type = tex->wave_type;
	float wave_profile = tex->wave_profile;

	return GPU_stack_link(mat, "node_tex_wave", in, out, GPU_uniform(&wave_type), GPU_uniform(&wave_profile));
}
예제 #4
0
static int gpu_shader_normal(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
{
	bNodeSocket *sock= node->outputs.first;
	GPUNodeLink *vec = GPU_uniform(((bNodeSocketValueVector*)sock->default_value)->value);

	return GPU_stack_link(mat, "normal", in, out, vec);
}
예제 #5
0
/* XXX this is also done as a local static function in gpu_codegen.c,
 * but we need this to hack around the crappy material node.
 */
static GPUNodeLink *gpu_get_input_link(GPUNodeStack *in)
{
	if (in->link)
		return in->link;
	else
		return GPU_uniform(in->vec);
}
예제 #6
0
static int gpu_shader_value(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
{
	bNodeSocket *sock= node->outputs.first;
	GPUNodeLink *vec = GPU_uniform(sock->ns.vec);

	return GPU_stack_link(mat, "set_value", in, out, vec);
}
static int node_shader_gpu_tex_brick(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
	if (!in[0].link) {
		in[0].link = GPU_attribute(CD_ORCO, "");
		GPU_link(mat, "generated_from_orco", in[0].link, &in[0].link);
	}

	node_shader_gpu_tex_mapping(mat, node, in, out);
	NodeTexBrick *tex = (NodeTexBrick *)node->storage;
	float offset_freq = tex->offset_freq;
	float squash_freq = tex->squash_freq;
	return GPU_stack_link(mat, "node_tex_brick",
	                      in, out,
	                      GPU_uniform(&tex->offset), GPU_uniform(&offset_freq),
	                      GPU_uniform(&tex->squash), GPU_uniform(&squash_freq));
}
static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
	Image *ima = (Image *)node->id;
	ImageUser *iuser = NULL;
	NodeTexImage *tex = node->storage;

	GPUNodeLink *norm;

	int isdata = tex->color_space == SHD_COLORSPACE_NONE;
	float blend = tex->projection_blend;

	if (!ima)
		return GPU_stack_link(mat, "node_tex_image_empty", in, out);

	if (!in[0].link)
		in[0].link = GPU_attribute(CD_MTFACE, "");

	node_shader_gpu_tex_mapping(mat, node, in, out);

	switch (tex->projection) {
		case SHD_PROJ_FLAT:
			GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
			break;
		case SHD_PROJ_BOX:
			GPU_link(mat, "direction_transform_m4v3", GPU_builtin(GPU_VIEW_NORMAL),
			                                          GPU_builtin(GPU_INVERSE_VIEW_MATRIX),
			                                          &norm);
			GPU_link(mat, "direction_transform_m4v3", norm,
			                                          GPU_builtin(GPU_INVERSE_OBJECT_MATRIX),
			                                          &norm);
			GPU_link(mat, "node_tex_image_box", in[0].link,
			                                    norm,
			                                    GPU_image(ima, iuser, isdata),
			                                    GPU_uniform(&blend),
			                                    &out[0].link,
			                                    &out[1].link);
			break;
		case SHD_PROJ_SPHERE:
			GPU_link(mat, "point_texco_remap_square", in[0].link, &in[0].link);
			GPU_link(mat, "point_map_to_sphere", in[0].link, &in[0].link);
			GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
			break;
		case SHD_PROJ_TUBE:
			GPU_link(mat, "point_texco_remap_square", in[0].link, &in[0].link);
			GPU_link(mat, "point_map_to_tube", in[0].link, &in[0].link);
			GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
			break;
	}

	ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
	if ((tex->color_space == SHD_COLORSPACE_COLOR) &&
	    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 true;
}
예제 #9
0
static int gpu_shader_rgb(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
{
	bNodeSocket *sock= node->outputs.first;
	float *col= ((bNodeSocketValueRGBA*)sock->default_value)->value;
	GPUNodeLink *vec = GPU_uniform(col);

	return GPU_stack_link(mat, "set_rgba", in, out, vec);
}
void node_shader_gpu_tex_mapping(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *UNUSED(out))
{
	NodeTexBase *base = node->storage;
	TexMapping *texmap = &base->tex_mapping;
	float domin = (texmap->flag & TEXMAP_CLIP_MIN) != 0;
	float domax = (texmap->flag & TEXMAP_CLIP_MAX) != 0;

	if (domin || domax || !(texmap->flag & TEXMAP_UNIT_MATRIX)) {
		GPUNodeLink *tmat = GPU_uniform((float *)texmap->mat);
		GPUNodeLink *tmin = GPU_uniform(texmap->min);
		GPUNodeLink *tmax = GPU_uniform(texmap->max);
		GPUNodeLink *tdomin = GPU_uniform(&domin);
		GPUNodeLink *tdomax = GPU_uniform(&domax);

		GPU_link(mat, "mapping", in[0].link, tmat, tmin, tmax, tdomin, tdomax, &in[0].link);

		if (texmap->type == TEXMAP_TYPE_NORMAL)
			GPU_link(mat, "texco_norm", in[0].link, &in[0].link);
	}
}
static int node_shader_gpu_tex_magic(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
{
	NodeTexMagic *tex = (NodeTexMagic*)node->storage;
	float depth = tex->depth;

	if (!in[0].link)
		in[0].link = GPU_attribute(CD_ORCO, "");

	node_shader_gpu_tex_mapping(mat, node, in, out);

	return GPU_stack_link(mat, "node_tex_magic", in, out, GPU_uniform(&depth));
}
static int gpu_shader_bump(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
	if (!in[3].link)
		in[3].link = GPU_builtin(GPU_VIEW_NORMAL);
	else
		GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link);
	float invert = node->custom1;
	GPU_stack_link(mat, "node_bump", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_uniform(&invert));
	/* Other nodes are applying view matrix if the input Normal has a link.
	 * We don't want normal to have view matrix applied twice, so we cancel it here.
	 *
	 * TODO(sergey): This is an extra multiplication which cancels each other,
	 * better avoid this but that requires bigger refactor.
	 */
	return GPU_link(mat, "direction_transform_m4v3", out[0].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[0].link);
}
예제 #13
0
static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
{
	Image *ima= (Image*)node->id;
	ImageUser *iuser= NULL;

	if (!ima) {
		float black[4] = {0.0f, 0.0f, 0.0f, 1.0f};
		GPUNodeLink *vec = GPU_uniform(black);
		return GPU_stack_link(mat, "set_rgba", out, out, vec);
	}
	
	if (!in[0].link)
		in[0].link = GPU_attribute(CD_MTFACE, "");

	node_shader_gpu_tex_mapping(mat, node, in, out);

	return GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser));
}
예제 #14
0
static int gpu_shader_normal_map(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
	NodeShaderNormalMap *nm = node->storage;
	GPUNodeLink *negnorm;
	GPUNodeLink *realnorm;
	GPUNodeLink *strength;

	float d[4] = {0, 0, 0, 0};

	if (in[0].link)
		strength = in[0].link;
	else
		strength = GPU_uniform(in[0].vec);

	if (in[1].link)
		realnorm = in[1].link;
	else
		realnorm = GPU_uniform(in[1].vec);

	negnorm = GPU_builtin(GPU_VIEW_NORMAL);
	GPU_link(mat, "math_max", strength, GPU_uniform(d), &strength);

	if (GPU_material_use_world_space_shading(mat)) {

		/* ******* CYCLES or BLENDER INTERNAL with world space shading flag ******* */

		const char *color_to_normal_fnc_name = "color_to_normal_new_shading";
		if (nm->space == SHD_SPACE_BLENDER_OBJECT || nm->space == SHD_SPACE_BLENDER_WORLD || !GPU_material_use_new_shading_nodes(mat))
			color_to_normal_fnc_name = "color_to_blender_normal_new_shading";
		switch (nm->space) {
			case SHD_SPACE_TANGENT:
				GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm);
				GPU_link(mat, "node_normal_map", GPU_attribute(CD_TANGENT, nm->uv_map), negnorm, realnorm, &realnorm);
				GPU_link(mat, "vec_math_mix", strength, realnorm, GPU_builtin(GPU_VIEW_NORMAL), &out[0].link);
				/* for uniform scale this is sufficient to match Cycles */
				GPU_link(mat, "direction_transform_m4v3", out[0].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[0].link);
				GPU_link(mat, "vect_normalize", out[0].link, &out[0].link);
				return true;
			case SHD_SPACE_OBJECT:
			case SHD_SPACE_BLENDER_OBJECT:
				GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm);
				GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm);
				GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_OBJECT_MATRIX), &realnorm);
				break;
			case SHD_SPACE_WORLD:
			case SHD_SPACE_BLENDER_WORLD:
				GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm);
				GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm);
				break;
		}

	}
	else {

		/* ************** BLENDER INTERNAL without world space shading flag ******* */

		GPU_link(mat, "color_to_normal", realnorm, &realnorm);
		GPU_link(mat, "mtex_negate_texnormal", realnorm,  &realnorm);
		GPU_link(mat, "vec_math_negate", negnorm, &negnorm);

		switch (nm->space) {
			case SHD_SPACE_TANGENT:
				GPU_link(mat, "node_normal_map", GPU_attribute(CD_TANGENT, nm->uv_map), negnorm, realnorm, &realnorm);
				break;
			case SHD_SPACE_OBJECT:
			case SHD_SPACE_BLENDER_OBJECT:
				GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_LOC_TO_VIEW_MATRIX),  &realnorm);
				break;
			case SHD_SPACE_WORLD:
			case SHD_SPACE_BLENDER_WORLD:
				GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_VIEW_MATRIX),  &realnorm);
				break;
		}
	}

	GPU_link(mat, "vec_math_mix", strength, realnorm, negnorm,  &out[0].link);
	GPU_link(mat, "vect_normalize", out[0].link, &out[0].link);

	return true;
}
예제 #15
0
static int gpu_shader_normal(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
	GPUNodeLink *vec = GPU_uniform(out[0].vec);
	return GPU_stack_link(mat, "normal", in, out, vec);
}
static int node_shader_gpu_oct_portal_mat(struct GPUMaterial *mat, struct bNode *UNUSED(node), struct bNodeExecData *UNUSED(execdata), struct GPUNodeStack *UNUSED(in), struct GPUNodeStack *out) {
    float rgb[4] = {0.1f, 0.1f, 0.1f, 0.5f};
    float roughness[4] = {0};
	return GPU_stack_link(mat, "node_bsdf_diffuse", 0, out, GPU_uniform(rgb), GPU_uniform(roughness), GPU_builtin(GPU_VIEW_NORMAL));
}