-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update normalmap node to 1.39 (#1911)
- I have added the null-check from GLSL and MSL to the OSL and MDL backends for consistency. As an alternative, it could be removed from all implementations. - Tangent vector renormalization in OSL seems like a concern that should be handled by the implementation providing the geometry streams. I removed it.
- Loading branch information
Showing
12 changed files
with
57 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,13 @@ | ||
void mx_normalmap_vector2(vec3 value, int map_space, vec2 normal_scale, vec3 N, vec3 T, out vec3 result) | ||
void mx_normalmap_vector2(vec3 value, vec2 normal_scale, vec3 N, vec3 T, vec3 B, out vec3 result) | ||
{ | ||
// Decode the normal map. | ||
value = (value == vec3(0.0f)) ? vec3(0.0, 0.0, 1.0) : value * 2.0 - 1.0; | ||
value = (value == vec3(0.0)) ? vec3(0.0, 0.0, 1.0) : value * 2.0 - 1.0; | ||
|
||
// Transform from tangent space if needed. | ||
if (map_space == 0) | ||
{ | ||
vec3 B = normalize(cross(N, T)); | ||
value.xy *= normal_scale; | ||
value = T * value.x + B * value.y + N * value.z; | ||
} | ||
value = T * value.x * normal_scale.x + B * value.y * normal_scale.y + N * value.z; | ||
|
||
// Normalize the result. | ||
result = normalize(value); | ||
} | ||
|
||
void mx_normalmap_float(vec3 value, int map_space, float normal_scale, vec3 N, vec3 T, out vec3 result) | ||
void mx_normalmap_float(vec3 value, float normal_scale, vec3 N, vec3 T, vec3 B, out vec3 result) | ||
{ | ||
mx_normalmap_vector2(value, map_space, vec2(normal_scale), N, T, result); | ||
mx_normalmap_vector2(value, vec2(normal_scale), N, T, B, result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,13 @@ | ||
void mx_normalmap_vector2(vec3 value, int map_space, vec2 normal_scale, vec3 N, vec3 T, out vec3 result) | ||
void mx_normalmap_vector2(vec3 value, vec2 normal_scale, vec3 N, vec3 T, vec3 B, out vec3 result) | ||
{ | ||
// Decode the normal map. | ||
value = all(value == vec3(0.0f)) ? vec3(0.0, 0.0, 1.0) : value * 2.0 - 1.0; | ||
value = all(value == vec3(0.0)) ? vec3(0.0, 0.0, 1.0) : value * 2.0 - 1.0; | ||
|
||
// Transform from tangent space if needed. | ||
if (map_space == 0) | ||
{ | ||
vec3 B = normalize(cross(N, T)); | ||
value.xy *= normal_scale; | ||
value = T * value.x + B * value.y + N * value.z; | ||
} | ||
value = T * value.x * normal_scale.x + B * value.y * normal_scale.y + N * value.z; | ||
|
||
// Normalize the result. | ||
result = normalize(value); | ||
} | ||
|
||
void mx_normalmap_float(vec3 value, int map_space, float normal_scale, vec3 N, vec3 T, out vec3 result) | ||
void mx_normalmap_float(vec3 value, float normal_scale, vec3 N, vec3 T, vec3 B, out vec3 result) | ||
{ | ||
mx_normalmap_vector2(value, map_space, vec2(normal_scale), N, T, result); | ||
mx_normalmap_vector2(value, vec2(normal_scale), N, T, B, result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
void mx_normalmap_vector2(vector value, string map_space, vector2 normal_scale, vector N, vector U, output vector result) | ||
void mx_normalmap_vector2(vector value, vector2 normal_scale, vector N, vector T, vector B, output vector result) | ||
{ | ||
// Tangent space | ||
if (map_space == "tangent") | ||
vector decodedValue; | ||
if (value == vector(0.0)) | ||
{ | ||
vector v = value * 2.0 - 1.0; | ||
vector T = normalize(U - dot(U, N) * N); | ||
vector B = normalize(cross(N, T)); | ||
result = normalize(T * v[0] * normal_scale.x + B * v[1] * normal_scale.y + N * v[2]); | ||
decodedValue = vector(0.0, 0.0, 1.0); | ||
} | ||
// Object space | ||
else | ||
{ | ||
vector n = value * 2.0 - 1.0; | ||
result = normalize(n); | ||
decodedValue = value * 2.0 - 1.0; | ||
} | ||
|
||
result = normalize(T * decodedValue[0] * normal_scale.x + B * decodedValue[1] * normal_scale.y + N * decodedValue[2]); | ||
} | ||
|
||
void mx_normalmap_float(vector value, string map_space, float normal_scale, vector N, vector U, output vector result) | ||
void mx_normalmap_float(vector value, float normal_scale, vector N, vector T, vector B, output vector result) | ||
{ | ||
mx_normalmap_vector2(value, map_space, vector2(normal_scale, normal_scale), N, U, result); | ||
mx_normalmap_vector2(value, vector2(normal_scale, normal_scale), N, T, B, result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters