MaterialX: `viewdirection` node
Description
MaterialX finally brings back non-photorealistic rendering with a new nprlib; right now it contains a single node, viewdirection with the same possible spaces as position/normal/tangent.
More here: https://github.com/AcademySoftwareFoundation/MaterialX/pull/1631
cc @sunag
Solution
I tried to add support for it but am not sure if the right view direction nodes already exist:
} else if ( element === 'viewdirection' ) {
const space = this.getAttribute( 'space' );
// not sure what to use here for "view direction in world space" and "view direction in object space" – these are wrong
node = space === 'world' ? positionView : positionViewDirection;
}
Alternatives
Emitting transformation nodes that convert between spaces?
Additional context
MaterialX PR including some (unlit) sample materials (would require #27494):
- https://github.com/AcademySoftwareFoundation/MaterialX/pull/1631
I would have to do some more tests to confirm the variations and space, but I don't remember having created these nodes, this would be something like viewDirectionLocal, viewDirectionWorld and the code something like the example below:
const positionSpace = space === 'world' ? positionWorld : positionLocal;
node = positionSpace.sub( cameraPosition ).normalize()