blender/intern/cycles/kernel/osl/shaders/node_attribute.osl
Weizhen Huang 3a1fbe17b9 Fix: OSL: Attribute "generated" not available for World and Point Cloud
When "generated" is required via Attribute Node, it is not available for
World and Point Cloud.

Make OSL match the SVM behavior to use the object coordinates
(see `svm/attribute.h`),

Pull Request: https://projects.blender.org/blender/blender/pulls/143198
2025-07-25 15:39:06 +02:00

44 lines
1.3 KiB
Text

/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
*
* SPDX-License-Identifier: Apache-2.0 */
#include "node_math.h"
#include "stdcycles.h"
shader node_attribute(string bump_offset = "center",
float bump_filter_width = BUMP_FILTER_WIDTH,
string name = "",
output point Vector = point(0.0, 0.0, 0.0),
output color Color = 0.0,
output float Fac = 0.0,
output float Alpha = 0.0)
{
float data[4] = {0.0, 0.0, 0.0, 0.0};
int success = getattribute(name, data);
if (!success && (name == "geom:generated")) {
/* No generated attribute, fall back to object coordinates. */
Color = transform("object", P);
Fac = average(Color);
data[3] = 1.0;
}
else {
getattribute(name, Fac);
Color = color(data[0], data[1], data[2]);
}
Vector = point(Color);
Alpha = data[3];
if (bump_offset == "dx") {
Color += Dx(Color) * bump_filter_width;
Vector += Dx(Vector) * bump_filter_width;
Fac += Dx(Fac) * bump_filter_width;
Alpha += Dx(Alpha) * bump_filter_width;
}
else if (bump_offset == "dy") {
Color += Dy(Color) * bump_filter_width;
Vector += Dy(Vector) * bump_filter_width;
Fac += Dy(Fac) * bump_filter_width;
Alpha += Dy(Alpha) * bump_filter_width;
}
}