CheckerNode.js 625 B

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