OSL and Tangent vectors (normal mapping in OSL)

Skip to first unread message

Master Zap

Feb 27, 2020, 4:53:15 AM2/27/20
to OSL Developers
So maybe I'm denser than usual, but how can I (or can I) get tangent vectors out of OSL? 

And to this I mean, tangent vectors from a particular uv coordinate space that I might access as a getattriute() ?

The Dx and Dy functions only give me scalar derivatives..... dPdu / dPdv gives me something, but only to whatever "u" and "v" is following.....?

Basically, my problem is this: Assuming I have a texture space in getattribute("UV0") and I want to use pixels from a texture() call and do plain old normal mapping...... how do I actually do that??


Ole Gulbrandsen

Feb 27, 2020, 1:16:35 PM2/27/20
to osl...@googlegroups.com
Are you thinking of something like the PartialDeriv code in this paper: https://graphics.pixar.com/library/BumpRoughness/paper.pdf ?
(swap out Du,Dv with Dx,Dy)

You received this message because you are subscribed to the Google Groups "OSL Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osl-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osl-dev/f24f1b34-35f6-4ebc-b256-53ca5b3663ba%40googlegroups.com.

Brecht Van Lommel

Feb 27, 2020, 2:25:39 PM2/27/20
to osl...@googlegroups.com
I'm pretty sure there isn't enough information available to compute good tangents for normal mapping, they need to be provided by the renderer as another attribute.

There are multiple methods to generate such tangents (mikktspace, Maya tangent space, ..), which for best results need to exactly match the tangent space the normal map was baked with.


Dan Kripac

Feb 27, 2020, 10:34:36 PM2/27/20
to osl...@googlegroups.com
Hey Zap,

Unless I'm misunderstanding the question, in my experience when we've done user supplied uv coordinate normal mapping tangents (or anisotropic specular tangents etc) we used a function similar to the following:

vector compute_tangent( float basis )
float basis_dx = Dx(basis);
float basis_dy = Dy(basis);

if (fabs(basis_dx) < 1.e-6 && fabs(basis_dy) < 1.e-6) {
return Dy(P);
else {
return (basis_dy * Dx(P)) - (basis_dx * Dy(P));

The you supply one of your user coordinates (i.e s or t in oldskool prman parlance) and this will calculate the tangent direction of that coordinate in respect to P.

Apologies I haven't compiled this as yet I don't have an oslc handy. Let me know if it doesn't compile (or work) and I can get one installed and fix it.

Reply all
Reply to author
0 new messages