blender/intern/cycles/kernel/osl/shaders/node_raycast.osl
Miguel Pozo 6e7a0eee32 Cycles: Raycast Visibility Toggle
Cycles implementation of #157799.
Allows removing objects from Raycast Node queries.

Adds `PathRayVisibilityFlag::PATH_RAY_VISIBILITY_RAYCAST` .
OSL adds a new `__raycast__` traceset.

Pull Request: https://projects.blender.org/blender/blender/pulls/158816
2026-06-17 20:37:50 +02:00

70 lines
2.5 KiB
Text

/* SPDX-FileCopyrightText: 2011-2025 Blender Foundation
*
* SPDX-License-Identifier: Apache-2.0 */
#include "stdcycles.h"
shader node_raycast(point Position = P,
normal Direction = N,
float Length = 1.0,
int only_local = 0,
float bump_filter_width = 0.0,
string float_attribute_names[] = {},
string alpha_attribute_names[] = {},
string vector_attribute_names[] = {},
output float IsHit = 0.0,
output float SelfHit = 0.0,
output float HitDistance = Length,
output point HitPosition = point(0.0, 0.0, 0.0),
output normal HitNormal = normal(0.0, 0.0, 0.0),
output float float_attributes[32] = {},
output float alpha_attributes[32] = {},
output vector vector_attributes[32] = {})
{
float mindist = 0.0;
if (bump_filter_width > 0.0) {
/* If evaluating for bump mapping at a shifted position, increase min
* distance by slightly more than the shift distance to avoid self
* intersections. */
mindist = bump_filter_width * max(length(Dx(P)), length(Dy(P))) * 1.1;
}
if (trace(Position,
Direction,
"maxdist",
Length,
"mindist",
mindist,
"traceset",
only_local ? "__only_local__" : "__raycast__"))
{
IsHit = 1.0;
getmessage("trace", "hitself", SelfHit);
getmessage("trace", "hitdist", HitDistance);
getmessage("trace", "P", HitPosition);
getmessage("trace", "N", HitNormal);
for (int i = 0; i < arraylength(float_attribute_names); ++i) {
getmessage("trace", float_attribute_names[i], float_attributes[i]);
}
for (int i = 0; i < arraylength(alpha_attribute_names); ++i) {
float data[4] = {0.0, 0.0, 0.0, 0.0};
getmessage("trace", alpha_attribute_names[i], data);
alpha_attributes[i] = data[3];
}
for (int i = 0; i < arraylength(vector_attribute_names); ++i) {
getmessage("trace", vector_attribute_names[i], vector_attributes[i]);
}
}
else {
for (int i = 0; i < arraylength(float_attribute_names); ++i) {
float_attributes[i] = 0.0;
}
for (int i = 0; i < arraylength(alpha_attribute_names); ++i) {
alpha_attributes[i] = 0.0;
}
for (int i = 0; i < arraylength(vector_attribute_names); ++i) {
vector_attributes[i] = point(0.0, 0.0, 0.0);
}
}
}