EquirectUVNode.js 592 B

123456789101112131415161718192021222324252627
  1. import TempNode from '../core/TempNode.js';
  2. import { nodeObject, vec2, add, mul, atan2, asin, clamp, positionWorldDirection } from '../shadernode/ShaderNodeElements.js';
  3. class EquirectUVNode extends TempNode {
  4. constructor( dirNode = positionWorldDirection ) {
  5. super( 'vec2' );
  6. this.dirNode = dirNode;
  7. }
  8. construct() {
  9. const dir = nodeObject( this.dirNode );
  10. const u = add( mul( atan2( dir.z, dir.x ), 1 / ( Math.PI * 2 ) ), 0.5 );
  11. const v = add( mul( asin( clamp( dir.y, - 1.0, 1.0 ) ), 1 / Math.PI ), 0.5 );
  12. return vec2( u, v );
  13. }
  14. }
  15. export default EquirectUVNode;