Blender V5.3
gpu_shader_material_normal_map.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8
9[[node]]
11{
12#ifdef MAT_DISPLACEMENT_BUMP
13 out_N = sd.N;
14#else
15 out_N = sd.Ni;
16#endif
17}
18
19[[node]]
21{
22 out_N = sd.Ni;
23}
24
25[[node]]
27 float strength,
28 float3 tex_normal,
29 float3 N,
31 const ShadingData &sd,
32 float3 &out_N)
33{
34 if (all(equal(T, float4(0.0f, 0.0f, 0.0f, 1.0f)))) {
35 out_N = N;
36 return;
37 }
38 T *= (FrontFacing ? 1.0f : -1.0f);
39 float3 B = T.w * cross(N, T.xyz);
40 /* TODO(fclem): EEVEE implementation leaking. */
41 B *= (kg.object_infos_get(sd).flag & OBJECT_NEGATIVE_SCALE) != 0 ? -1.0f : 1.0f;
42
43 /* Apply strength here instead of in node_normal_map_mix for T space. */
44 tex_normal.xy *= strength;
45 tex_normal.z = mix(1.0f, tex_normal.z, saturate(strength));
46
47 out_N = tex_normal.x * T.xyz + tex_normal.y * B + tex_normal.z * N;
48 out_N = normalize(out_N);
49}
50
51[[node]]
53{
54 normal = float3(2.0f) * color - float3(1.0f);
55}
56
57[[node]]
59{
60 normal = float3(2.0f, -2.0f, -2.0f) * color - float3(1.0f);
61}
62
63[[node]]
65{
66 result = float3(color.x, -color.y, color.z);
67}
68
69[[node]]
70void node_normal_map_mix(float strength, float3 new_normal, const ShadingData &sd, float3 &out_N)
71{
72 out_N = normalize(mix(sd.N, new_normal, max(0.0f, strength)));
73}
btScalar max
@ OBJECT_NEGATIVE_SCALE
#define resource_table
VecBase< float, D > normalize(VecOp< float, D >) RET
bool all(VecOp< bool, D >) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
VecBase< bool, D > equal(VecOp< T, D >, VecOp< T, D >) RET
void color_to_normal_new_shading(float3 color, float3 &normal)
void input_normal_displaced(const ShadingData &sd, float3 &out_N)
void node_normal_map(float4 T, float strength, float3 tex_normal, float3 N, KernelGlobals &kg, const ShadingData &sd, float3 &out_N)
void color_to_blender_normal_new_shading(float3 color, float3 &normal)
void color_invert_green_channel(float3 color, float3 &result)
void input_normal_original(const ShadingData &sd, float3 &out_N)
void node_normal_map_mix(float strength, float3 new_normal, const ShadingData &sd, float3 &out_N)
#define N
#define T
#define B
#define mix
#define saturate(a)
Definition smaa.cc:319
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136