Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/shader/nodes/node_shader_normal_map.c
| Context not available. | |||||
| for (int 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]; | 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); | interp_v3_v3v3(out[0]->vec, N, out[0]->vec, strength); | ||||
| if (shi->use_world_space_shading) { | |||||
| mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEWINV_MATRIX), out[0]->vec); | |||||
| } | |||||
| break; | break; | ||||
| case SHD_NORMAL_MAP_OBJECT: | case SHD_NORMAL_MAP_OBJECT: | ||||
| case SHD_NORMAL_MAP_BLENDER_OBJECT: | case SHD_NORMAL_MAP_BLENDER_OBJECT: | ||||
| mul_mat3_m4_v3((float (*)[4])RE_object_instance_get_matrix(shi->obi, RE_OBJECT_INSTANCE_MATRIX_LOCALTOVIEW), vecIn); | if (shi->use_world_space_shading) { | ||||
| mul_mat3_m4_v3((float (*)[4])RE_object_instance_get_matrix(shi->obi, RE_OBJECT_INSTANCE_MATRIX_OB), vecIn); | |||||
| mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEWINV_MATRIX), N); | |||||
| } | |||||
| else | |||||
| mul_mat3_m4_v3((float (*)[4])RE_object_instance_get_matrix(shi->obi, RE_OBJECT_INSTANCE_MATRIX_LOCALTOVIEW), vecIn); | |||||
| interp_v3_v3v3(out[0]->vec, N, vecIn, strength); | interp_v3_v3v3(out[0]->vec, N, vecIn, strength); | ||||
| break; | break; | ||||
| case SHD_NORMAL_MAP_WORLD: | case SHD_NORMAL_MAP_WORLD: | ||||
| case SHD_NORMAL_MAP_BLENDER_WORLD: | case SHD_NORMAL_MAP_BLENDER_WORLD: | ||||
| mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEW_MATRIX), vecIn); | if (shi->use_world_space_shading) | ||||
| mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEWINV_MATRIX), N); | |||||
| else | |||||
| mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEW_MATRIX), vecIn); | |||||
| interp_v3_v3v3(out[0]->vec, N, vecIn, strength); | interp_v3_v3v3(out[0]->vec, N, vecIn, strength); | ||||
| break; | break; | ||||
| } | } | ||||
| if (shi->use_world_space_shading) { | |||||
| negate_v3(out[0]->vec); | |||||
| } | |||||
| normalize_v3(out[0]->vec); | normalize_v3(out[0]->vec); | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| negnorm = GPU_builtin(GPU_VIEW_NORMAL); | negnorm = GPU_builtin(GPU_VIEW_NORMAL); | ||||
| GPU_link(mat, "math_max", strength, GPU_uniform(d), &strength); | GPU_link(mat, "math_max", strength, GPU_uniform(d), &strength); | ||||
| if (GPU_material_use_new_shading_nodes(mat)) { | if (GPU_material_use_world_space_shading(mat)) { | ||||
| /* **************** CYCLES ******************** */ | /* ******* CYCLES or BLENDER INTERNAL with world space shading flag ******* */ | ||||
| char *color_to_normal_fnc_name = "color_to_normal_new_shading"; | |||||
| if (nm->space == SHD_NORMAL_MAP_BLENDER_OBJECT || nm->space == SHD_NORMAL_MAP_BLENDER_WORLD || !GPU_material_use_new_shading_nodes(mat)) | |||||
brecht: Not sure why this checks for `GPU_material_use_new_shading_nodes`.
The purpose of this feature… | |||||
a.romanovAuthorUnsubmitted Not Done Inline ActionsI agree. If necessary, this can be done in another patch. a.romanov: I agree. If necessary, this can be done in another patch. | |||||
| color_to_normal_fnc_name = "color_to_blender_normal_new_shading"; | |||||
| switch (nm->space) { | switch (nm->space) { | ||||
| case SHD_NORMAL_MAP_TANGENT: | case SHD_NORMAL_MAP_TANGENT: | ||||
| GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm); | GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm); | ||||
| Context not available. | |||||
| GPU_link(mat, "vect_normalize", out[0].link, &out[0].link); | GPU_link(mat, "vect_normalize", out[0].link, &out[0].link); | ||||
| return true; | return true; | ||||
| case SHD_NORMAL_MAP_OBJECT: | case SHD_NORMAL_MAP_OBJECT: | ||||
| GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm); | |||||
| GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm); | |||||
| GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_OBJECT_MATRIX), &realnorm); | |||||
| break; | |||||
| case SHD_NORMAL_MAP_BLENDER_OBJECT: | case SHD_NORMAL_MAP_BLENDER_OBJECT: | ||||
| GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm); | GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm); | ||||
| GPU_link(mat, "color_to_blender_normal_new_shading", realnorm, &realnorm); | GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm); | ||||
| GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_OBJECT_MATRIX), &realnorm); | GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_OBJECT_MATRIX), &realnorm); | ||||
| break; | break; | ||||
| case SHD_NORMAL_MAP_WORLD: | case SHD_NORMAL_MAP_WORLD: | ||||
| GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm); | |||||
| GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm); | |||||
| break; | |||||
| case SHD_NORMAL_MAP_BLENDER_WORLD: | case SHD_NORMAL_MAP_BLENDER_WORLD: | ||||
| GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm); | GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm); | ||||
| GPU_link(mat, "color_to_blender_normal_new_shading", realnorm, &realnorm); | GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm); | ||||
| break; | break; | ||||
| } | } | ||||
| } else { | } else { | ||||
| /* *********** BLENDER INTERNAL *************** */ | /* ************** BLENDER INTERNAL without world space shading flag ******* */ | ||||
| GPU_link(mat, "color_to_normal", realnorm, &realnorm); | GPU_link(mat, "color_to_normal", realnorm, &realnorm); | ||||
| GPU_link(mat, "mtex_negate_texnormal", realnorm, &realnorm); | GPU_link(mat, "mtex_negate_texnormal", realnorm, &realnorm); | ||||
| Context not available. | |||||
Done Inline ActionsThis code should have been removed I think? brecht: This code should have been removed I think? | |||||
a.romanovAuthorUnsubmitted Not Done Inline ActionsOf cource a.romanov: Of cource | |||||
Not sure why this checks for GPU_material_use_new_shading_nodes.
The purpose of this feature was to support Blender-style normal map encoding and a more standard normal map encoding. I think that feature is useful for both Blender Internal and Cycles?
Though I guess that's not really an issue with this world space stuff specifically and doesn't need to be solved here.