PropertyNode.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import Node, { addNodeClass } from './Node.js';
  2. import { nodeImmutable, nodeObject } from '../shadernode/ShaderNode.js';
  3. class PropertyNode extends Node {
  4. constructor( nodeType, name = null, declare = true ) {
  5. super( nodeType );
  6. this.name = name;
  7. this.declare = declare;
  8. this.isPropertyNode = true;
  9. }
  10. getHash( builder ) {
  11. return this.name || super.getHash( builder );
  12. }
  13. isGlobal( /*builder*/ ) {
  14. return true;
  15. }
  16. generate( builder ) {
  17. if ( this.declare === false ) return this.name;
  18. return builder.getPropertyName( builder.getVarFromNode( this, this.name ) );
  19. }
  20. }
  21. export default PropertyNode;
  22. export const property = ( type, name ) => nodeObject( new PropertyNode( type, name ) );
  23. export const diffuseColor = nodeImmutable( PropertyNode, 'vec4', 'DiffuseColor' );
  24. export const roughness = nodeImmutable( PropertyNode, 'float', 'Roughness' );
  25. export const metalness = nodeImmutable( PropertyNode, 'float', 'Metalness' );
  26. export const clearcoat = nodeImmutable( PropertyNode, 'float', 'Clearcoat' );
  27. export const clearcoatRoughness = nodeImmutable( PropertyNode, 'float', 'ClearcoatRoughness' );
  28. export const sheen = nodeImmutable( PropertyNode, 'vec3', 'Sheen' );
  29. export const sheenRoughness = nodeImmutable( PropertyNode, 'float', 'SheenRoughness' );
  30. export const iridescence = nodeImmutable( PropertyNode, 'float', 'Iridescence' );
  31. export const iridescenceIOR = nodeImmutable( PropertyNode, 'float', 'IridescenceIOR' );
  32. export const iridescenceThickness = nodeImmutable( PropertyNode, 'float', 'IridescenceThickness' );
  33. export const specularColor = nodeImmutable( PropertyNode, 'color', 'SpecularColor' );
  34. export const shininess = nodeImmutable( PropertyNode, 'float', 'Shininess' );
  35. export const output = nodeImmutable( PropertyNode, 'vec4', 'Output' );
  36. export const dashSize = nodeImmutable( PropertyNode, 'float', 'dashSize' );
  37. export const gapSize = nodeImmutable( PropertyNode, 'float', 'gapSize' );
  38. export const pointWidth = nodeImmutable( PropertyNode, 'float', 'pointWidth' );
  39. addNodeClass( 'PropertyNode', PropertyNode );