Page 1 of 1

OSL UV Displacement with Bitmap

Posted: Fri May 05, 2023 7:18 pm
by andrewprousalis
Is there a trick to make octane displace using OSL to sample a bitmap? I have tried it a few different ways and it seems to work fine with triplanar, built-in uvs, other projections, etc. it also works fine with procedural noise, etc generated within the OSL shader. As soon as I instruct OSL to sample a bitmap using supplied uv values, displacement stops working. and ideas? here's my osl test shader:

#include <octane-oslintrin.h>
shader customuv
(
color img = color(0.0, 0.0, 0.0),
color uv = color(0.0, 0.0, 0.0),
output color result = color(0.0, 0.0, 0.0)
)
{
result = _evaluateDelayed(img, uv[0], uv[1]);
}

Re: OSL UV Displacement with Bitmap

Posted: Sat May 06, 2023 11:39 pm
by WoutTgh
I assume you're trying this on the old displacement node ? That one is quite limited and I'm pretty sure anything but a simple texture input won't work unfortunately.

Another thing to try, which will only work with the vertex displacement node, is setting your uv in an osl projection shader. ( u and v are given variables in an osl projection shader, and the output is a point type, not color )
uv.jpg

Re: OSL UV Displacement with Bitmap

Posted: Mon May 08, 2023 5:04 pm
by andrewprousalis
Hi! Thanks for the response. Yes, I'm using the vertex displacement. I can get good results when referencing the internal U and V OSL variables, but when I use arbitrary attributes to set my UV coordinates, all displacement goes flat.

shader proj
(
color pos = color(0, 0, 0),
output point uvw = 0
)
{
uvw = point(pos[0],pos[1], 0);
}

Re: OSL UV Displacement with Bitmap

Posted: Mon May 08, 2023 5:18 pm
by WoutTgh
Can you show me the shader tree ? Perhaps you're using that in the wrong type of osl shader ? It also looks like you're using the components of a color input to use as uvw coordinates so my first try would be to import the uvs as point also

shader proj
(
color pos = color(0, 0, 0),
output point uvw = 0
)
{
uvw = point(pos[0],pos[1], 0);
}


shader proj
(
point pos = 0,
output point uvw = 0
)
{
uvw = point(pos[0],pos[1], 0);
}

Re: OSL UV Displacement with Bitmap

Posted: Mon May 08, 2023 6:13 pm
by andrewprousalis
Thanks again for the reply. Importing the attribute as Point type doesn't work correctly, but it does work fine as Color - and works as expected when the output is fed into BaseColor. It just fails as a displacement. Oddly enough, if Auto Bump is enabled, then I get the artifacts of the bump map, just no displacement. The only way I have been able to use a texture as a displacement source is if it is using the standard UVs (1-3) or it is manipulating those standard UVs through OSL. If provided and an entirely fresh set of UVs from and attribute, they work just fine everywhere but displacement.
Image

Re: OSL UV Displacement with Bitmap

Posted: Mon May 08, 2023 6:31 pm
by WoutTgh
ooh, interesting, perhaps it's a bug or limitation.

I discovered a new trick btw : Using a procedural noise as uv coordinates gives really nice results, and no seams of course :p
It also work swith vertex displacement
noise_as_uvs.jpg

Out of curiosity : why do you need to import uvs from an attribute ?

Re: OSL UV Displacement with Bitmap

Posted: Mon May 08, 2023 6:45 pm
by andrewprousalis
Yeah, I think it might be a bug as well. Arbitrarily limiting usable UVs to 3 hardly seems like a good design decision. More UVs are needed when building complex materials for dual-rest setups with changing topology (texturing a fluid sim, that kinda thing). Thanks for the assistance! Hopefully someone from otoy will weigh in on what's going on here.

Re: OSL UV Displacement with Bitmap

Posted: Mon May 08, 2023 7:25 pm
by WoutTgh
you're welcome :)