From 15d316a51acc72ec4dca51969b4df789eab39377 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 18 Oct 2023 20:09:37 +0200 Subject: [PATCH] Fix #113777: Cycles IES texture not working for sphere lights This was a regression after the sphere light changes, where the normal now is the normal along the geometry of the light and no longer suitable for the IES texture direction. This not only fixes point lights with non-zero radius, but makes the IES texture direction work consistently across light types and meshes, always rotated by the object transform. --- intern/cycles/graph/node_type.h | 13 +++++++------ intern/cycles/scene/shader_graph.cpp | 22 ++++++++++++++++++++-- intern/cycles/scene/shader_nodes.cpp | 2 +- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/intern/cycles/graph/node_type.h b/intern/cycles/graph/node_type.h index 2caf7fcf3f5..7a5f9376e6a 100644 --- a/intern/cycles/graph/node_type.h +++ b/intern/cycles/graph/node_type.h @@ -66,13 +66,14 @@ struct SocketType { LINK_TEXTURE_GENERATED = (1 << 4), LINK_TEXTURE_NORMAL = (1 << 5), LINK_TEXTURE_UV = (1 << 6), - LINK_INCOMING = (1 << 7), - LINK_NORMAL = (1 << 8), - LINK_POSITION = (1 << 9), - LINK_TANGENT = (1 << 10), - LINK_OSL_INITIALIZER = (1 << 11), + LINK_TEXTURE_INCOMING = (1 << 7), + LINK_INCOMING = (1 << 8), + LINK_NORMAL = (1 << 9), + LINK_POSITION = (1 << 10), + LINK_TANGENT = (1 << 11), + LINK_OSL_INITIALIZER = (1 << 12), DEFAULT_LINK_MASK = (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 8) | (1 << 9) | - (1 << 10) | (1 << 11) + (1 << 10) | (1 << 11) | (1 << 12) }; ustring name; diff --git a/intern/cycles/scene/shader_graph.cpp b/intern/cycles/scene/shader_graph.cpp index d97ba779b54..20cf3a38d09 100644 --- a/intern/cycles/scene/shader_graph.cpp +++ b/intern/cycles/scene/shader_graph.cpp @@ -847,8 +847,9 @@ void ShaderGraph::default_inputs(bool do_osl) /* nodes can specify default texture coordinates, for now we give * everything the position by default, except for the sky texture */ - ShaderNode *geom = NULL; - ShaderNode *texco = NULL; + GeometryNode *geom = NULL; + TextureCoordinateNode *texco = NULL; + VectorTransformNode *normal_transform = NULL; foreach (ShaderNode *node, nodes) { foreach (ShaderInput *input, node->inputs) { @@ -874,6 +875,20 @@ void ShaderGraph::default_inputs(bool do_osl) connect(texco->output("UV"), input); } + else if (input->flags() & SocketType::LINK_TEXTURE_INCOMING) { + if (!geom) { + geom = create_node(); + } + if (!normal_transform) { + normal_transform = create_node(); + normal_transform->set_transform_type(NODE_VECTOR_TRANSFORM_TYPE_NORMAL); + normal_transform->set_convert_from(NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD); + normal_transform->set_convert_to(NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT); + connect(geom->output("Incoming"), normal_transform->input("Vector")); + } + + connect(normal_transform->output("Vector"), input); + } else if (input->flags() & SocketType::LINK_INCOMING) { if (!geom) { geom = create_node(); @@ -912,6 +927,9 @@ void ShaderGraph::default_inputs(bool do_osl) if (texco) { add(texco); } + if (normal_transform) { + add(normal_transform); + } } void ShaderGraph::refine_bump_nodes() diff --git a/intern/cycles/scene/shader_nodes.cpp b/intern/cycles/scene/shader_nodes.cpp index 5d2a67cf2f5..a86b1e71da8 100644 --- a/intern/cycles/scene/shader_nodes.cpp +++ b/intern/cycles/scene/shader_nodes.cpp @@ -1336,7 +1336,7 @@ NODE_DEFINE(IESLightNode) SOCKET_STRING(filename, "File Name", ustring()); SOCKET_IN_FLOAT(strength, "Strength", 1.0f); - SOCKET_IN_POINT(vector, "Vector", zero_float3(), SocketType::LINK_TEXTURE_NORMAL); + SOCKET_IN_POINT(vector, "Vector", zero_float3(), SocketType::LINK_TEXTURE_INCOMING); SOCKET_OUT_FLOAT(fac, "Fac");