CheckerNode.js 635 B

123456789101112131415161718192021222324252627282930313233343536
  1. import Node from '../core/Node.js';
  2. import UVNode from '../accessors/UVNode.js';
  3. import { ShaderNode, add, mul, floor, mod, sign } from '../ShaderNode.js';
  4. const checkerShaderNode = new ShaderNode( ( inputs ) => {
  5. const uv = mul( inputs.uv, 2.0 );
  6. const cx = floor( uv.x );
  7. const cy = floor( uv.y );
  8. const result = mod( add( cx, cy ), 2.0 );
  9. return sign( result );
  10. } );
  11. class CheckerNode extends Node {
  12. constructor( uvNode = new UVNode() ) {
  13. super( 'float' );
  14. this.uvNode = uvNode;
  15. }
  16. generate( builder ) {
  17. return checkerShaderNode( { uv: this.uvNode } ).build( builder );
  18. }
  19. }
  20. export default CheckerNode;