Hello,
I'm trying to write a displacement node in OSL that renders in Arnold (using Gaffer DCC), but I can't get it to work.
My first approach was to reproduce the Arnold Bump2d node, which has the following connections:
inputs:
float bump_map,
float bump_height,
normal normal
output:
normal out
I skipped the "normal" input, which is used to specify the normal to apply displacement to (it reverts to the global variable N if unconnected). Here's my code:
shader RedoBump2d
(
float bump_map = 0,
float bump_height = 1,
output normal out = 0,
)
{
normal Nn = normalize(N);
out = normalize(calculatenormal(P + Nn*bump_map*bump_height));
}
When I connect a noise to bump_map which works in Arnold's Bump2d, it has no effect; the node returns the unchanged incoming N, as evident in both illuminance and the N aov.
I've noticed that it is possible to explicitly set N (even though the Arnold OSL docs specify that "All shader globals are considered to be read-only" https://docs.arnoldrenderer.com/display/A5ARP/OSL+Shaders), although curiously this only seems to work when I used the changed N in an illuminance function, eg. this sets the N aov to (0, 1, 0) (with the illuminance affected accordingly):
surface DiffuseNnUp (
color diffuseColor = color(1.),
output closure color out = 0)
{
N = normal(0, 1, 0);
out += diffuseColor * oren_nayar(N, 1.);
}
and so does this:
surface DiffuseNnUp (
color diffuseColor = color(1.),
output closure color out = 0)
{
N = normal(0, 1, 0);
normal nUp = N;
out += diffuseColor * oren_nayar(nUp, 1.);
}
but if I change "normal nUp = N;" to "normal nUp = (0, 1, 0);", the N aov is unchanged, and the rgb output is black. Also, if I try to apply bump to N before using it for diffuse illumination, the normal remains unchanged:
surface DiffuseBump (
float bump_map = 0, // I connect this to noise
float bump_height = 1,
color diffuse_color = color(1.),
output closure color out = 0)
{
N = normalize(calculatenormal(P + normalize(N)*bump_map*bump_height));
out += diffuse_color * oren_nayar(N, 1.);
}
I've tried various combinations of:
using the shader/surface/displacement object type
using calculatenormal()/bump()/displace()
calculating illuminance using oren_nayar(N) using a modified N and then outputting a color closure vs. just outputting a modified normal
Nothing works, please advise!
All shader globals are considered to be read-only, so I think that's why you don't see anything happening.
Sie finden nicht, was Sie suchen? Fragen Sie die Community oder teilen Sie Ihr Wissen mit anderen.