Fix part of T102450: Cycles OSL render issues for with normals in shader nodes
Commit c8dd33f5a37b6a6db0b6950d24f9a7cff5ceb799 in OSL changed behavior of parameters that reference each other and are also overwritten with an instance value. This is causing the "NormalIn" parameter of a few OSL nodes in Cycles to be set to zero somehow, which should instead have received the value from a "node_geometry" node Cycles generates and connects automatically. I am not entirely sure why that is happening, but these parameters are superfluous anyway, since OSL already provides the necessary data in the global variable "N". So this patch simply removes those parameters (which mimics SVM, where these parameters do not exist either), which also fixes the rendering artifacts that occured with recent OSL. While this fixes built-in shader nodes, custom OSL scripts can still have this problem. Ref T101222 Differential Revision: https://developer.blender.org/D16470
This commit is contained in:
parent
8fe423a7a9
commit
41a3de878f
Notes:
blender-bot
2023-11-20 12:14:32 +01:00
Referenced by issue #101222, Cycles OSL with OptiX
|
@ -3,8 +3,7 @@
|
|||
|
||||
#include "stdcycles.h"
|
||||
|
||||
shader node_geometry(normal NormalIn = N,
|
||||
string bump_offset = "center",
|
||||
shader node_geometry(string bump_offset = "center",
|
||||
|
||||
output point Position = point(0.0, 0.0, 0.0),
|
||||
output normal Normal = normal(0.0, 0.0, 0.0),
|
||||
|
@ -17,7 +16,7 @@ shader node_geometry(normal NormalIn = N,
|
|||
output float RandomPerIsland = 0.0)
|
||||
{
|
||||
Position = P;
|
||||
Normal = NormalIn;
|
||||
Normal = N;
|
||||
TrueNormal = Ng;
|
||||
Incoming = I;
|
||||
Parametric = point(1.0 - u - v, u, 0.0);
|
||||
|
|
|
@ -3,13 +3,12 @@
|
|||
|
||||
#include "stdcycles.h"
|
||||
|
||||
shader node_normal_map(normal NormalIn = N,
|
||||
float Strength = 1.0,
|
||||
shader node_normal_map(float Strength = 1.0,
|
||||
color Color = color(0.5, 0.5, 1.0),
|
||||
string space = "tangent",
|
||||
string attr_name = "geom:tangent",
|
||||
string attr_sign_name = "geom:tangent_sign",
|
||||
output normal Normal = NormalIn)
|
||||
output normal Normal = N)
|
||||
{
|
||||
color mcolor = 2.0 * color(Color[0] - 0.5, Color[1] - 0.5, Color[2] - 0.5);
|
||||
int is_backfacing = backfacing();
|
||||
|
@ -71,5 +70,5 @@ shader node_normal_map(normal NormalIn = N,
|
|||
}
|
||||
|
||||
if (Strength != 1.0)
|
||||
Normal = normalize(NormalIn + (Normal - NormalIn) * max(Strength, 0.0));
|
||||
Normal = normalize(N + (Normal - N) * max(Strength, 0.0));
|
||||
}
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
|
||||
#include "stdcycles.h"
|
||||
|
||||
shader node_tangent(normal NormalIn = N,
|
||||
string attr_name = "geom:tangent",
|
||||
shader node_tangent(string attr_name = "geom:tangent",
|
||||
string direction_type = "radial",
|
||||
string axis = "z",
|
||||
output normal Tangent = normalize(dPdu))
|
||||
|
@ -29,5 +28,5 @@ shader node_tangent(normal NormalIn = N,
|
|||
}
|
||||
|
||||
T = transform("object", "world", T);
|
||||
Tangent = cross(NormalIn, normalize(cross(T, NormalIn)));
|
||||
Tangent = cross(N, normalize(cross(T, N)));
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include "stdcycles.h"
|
||||
|
||||
shader node_texture_coordinate(
|
||||
normal NormalIn = N,
|
||||
int is_background = 0,
|
||||
int is_volume = 0,
|
||||
int from_dupli = 0,
|
||||
|
@ -27,7 +26,7 @@ shader node_texture_coordinate(
|
|||
point Pcam = transform("camera", "world", point(0, 0, 0));
|
||||
Camera = transform("camera", P + Pcam);
|
||||
getattribute("NDC", Window);
|
||||
Normal = NormalIn;
|
||||
Normal = N;
|
||||
Reflection = I;
|
||||
}
|
||||
else {
|
||||
|
@ -59,8 +58,8 @@ shader node_texture_coordinate(
|
|||
}
|
||||
Camera = transform("camera", P);
|
||||
Window = transform("NDC", P);
|
||||
Normal = transform("world", "object", NormalIn);
|
||||
Reflection = -reflect(I, NormalIn);
|
||||
Normal = transform("world", "object", N);
|
||||
Reflection = -reflect(I, N);
|
||||
}
|
||||
|
||||
if (bump_offset == "dx") {
|
||||
|
|
|
@ -3677,9 +3677,6 @@ NODE_DEFINE(GeometryNode)
|
|||
{
|
||||
NodeType *type = NodeType::add("geometry", create, NodeType::SHADER);
|
||||
|
||||
SOCKET_IN_NORMAL(
|
||||
normal_osl, "NormalIn", zero_float3(), SocketType::LINK_NORMAL | SocketType::OSL_INTERNAL);
|
||||
|
||||
SOCKET_OUT_POINT(position, "Position");
|
||||
SOCKET_OUT_NORMAL(normal, "Normal");
|
||||
SOCKET_OUT_NORMAL(tangent, "Tangent");
|
||||
|
@ -3812,9 +3809,6 @@ NODE_DEFINE(TextureCoordinateNode)
|
|||
SOCKET_BOOLEAN(use_transform, "Use Transform", false);
|
||||
SOCKET_TRANSFORM(ob_tfm, "Object Transform", transform_identity());
|
||||
|
||||
SOCKET_IN_NORMAL(
|
||||
normal_osl, "NormalIn", zero_float3(), SocketType::LINK_NORMAL | SocketType::OSL_INTERNAL);
|
||||
|
||||
SOCKET_OUT_POINT(generated, "Generated");
|
||||
SOCKET_OUT_NORMAL(normal, "Normal");
|
||||
SOCKET_OUT_POINT(UV, "UV");
|
||||
|
@ -7305,8 +7299,6 @@ NODE_DEFINE(NormalMapNode)
|
|||
|
||||
SOCKET_STRING(attribute, "Attribute", ustring());
|
||||
|
||||
SOCKET_IN_NORMAL(
|
||||
normal_osl, "NormalIn", zero_float3(), SocketType::LINK_NORMAL | SocketType::OSL_INTERNAL);
|
||||
SOCKET_IN_FLOAT(strength, "Strength", 1.0f);
|
||||
SOCKET_IN_COLOR(color, "Color", make_float3(0.5f, 0.5f, 1.0f));
|
||||
|
||||
|
@ -7400,8 +7392,6 @@ NODE_DEFINE(TangentNode)
|
|||
|
||||
SOCKET_STRING(attribute, "Attribute", ustring());
|
||||
|
||||
SOCKET_IN_NORMAL(
|
||||
normal_osl, "NormalIn", zero_float3(), SocketType::LINK_NORMAL | SocketType::OSL_INTERNAL);
|
||||
SOCKET_OUT_NORMAL(tangent, "Tangent");
|
||||
|
||||
return type;
|
||||
|
|
|
@ -907,8 +907,6 @@ class GeometryNode : public ShaderNode {
|
|||
return true;
|
||||
}
|
||||
int get_group();
|
||||
|
||||
NODE_SOCKET_API(float3, normal_osl)
|
||||
};
|
||||
|
||||
class TextureCoordinateNode : public ShaderNode {
|
||||
|
@ -924,7 +922,6 @@ class TextureCoordinateNode : public ShaderNode {
|
|||
return true;
|
||||
}
|
||||
|
||||
NODE_SOCKET_API(float3, normal_osl)
|
||||
NODE_SOCKET_API(bool, from_dupli)
|
||||
NODE_SOCKET_API(bool, use_transform)
|
||||
NODE_SOCKET_API(Transform, ob_tfm)
|
||||
|
@ -1569,7 +1566,6 @@ class NormalMapNode : public ShaderNode {
|
|||
NODE_SOCKET_API(ustring, attribute)
|
||||
NODE_SOCKET_API(float, strength)
|
||||
NODE_SOCKET_API(float3, color)
|
||||
NODE_SOCKET_API(float3, normal_osl)
|
||||
};
|
||||
|
||||
class TangentNode : public ShaderNode {
|
||||
|
@ -1588,7 +1584,6 @@ class TangentNode : public ShaderNode {
|
|||
NODE_SOCKET_API(NodeTangentDirectionType, direction_type)
|
||||
NODE_SOCKET_API(NodeTangentAxis, axis)
|
||||
NODE_SOCKET_API(ustring, attribute)
|
||||
NODE_SOCKET_API(float3, normal_osl)
|
||||
};
|
||||
|
||||
class BevelNode : public ShaderNode {
|
||||
|
|
Loading…
Reference in New Issue