FrontFacingNode.js 760 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import Node, { addNodeClass } from '../core/Node.js';
  2. import { nodeImmutable, float } from '../shadernode/ShaderNode.js';
  3. import { BackSide, WebGLCoordinateSystem } from 'three';
  4. class FrontFacingNode extends Node {
  5. constructor() {
  6. super( 'bool' );
  7. this.isFrontFacingNode = true;
  8. }
  9. generate( builder ) {
  10. const { renderer, material } = builder;
  11. if ( renderer.coordinateSystem === WebGLCoordinateSystem ) {
  12. if ( material.side === BackSide ) {
  13. return 'false';
  14. }
  15. }
  16. return builder.getFrontFacing();
  17. }
  18. }
  19. export default FrontFacingNode;
  20. export const frontFacing = nodeImmutable( FrontFacingNode );
  21. export const faceDirection = float( frontFacing ).mul( 2.0 ).sub( 1.0 );
  22. addNodeClass( 'FrontFacingNode', FrontFacingNode );