mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
101.74k stars 35.3k forks source link

MaterialX: `viewdirection` node #27496

Open hybridherbst opened 8 months ago

hybridherbst commented 8 months ago

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):

sunag commented 8 months ago

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()