MatcapUVNode.js 661 B

12345678910111213141516171819202122232425
  1. import TempNode from '../core/TempNode.js';
  2. import { vec2, vec3, negate, normalize, cross, dot, mul, add, transformedNormalView, positionViewDirection } from '../shadernode/ShaderNodeBaseElements.js';
  3. class MatcapUVNode extends TempNode {
  4. constructor() {
  5. super( 'vec2' );
  6. }
  7. generate( builder ) {
  8. const x = normalize( vec3( positionViewDirection.z, 0, negate( positionViewDirection.x ) ) );
  9. const y = cross( positionViewDirection, x );
  10. const uv = add( mul( vec2( dot( x, transformedNormalView ), dot( y, transformedNormalView ) ), 0.495 ), 0.5 );
  11. return uv.build( builder, this.getNodeType( builder ) );
  12. }
  13. }
  14. export default MatcapUVNode;