PhysicalMaterialContextNode.js 972 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import ContextNode from '../core/ContextNode.js';
  2. import NormalNode from '../accessors/NormalNode.js';
  3. import ExpressionNode from '../core/ExpressionNode.js';
  4. import FloatNode from '../inputs/FloatNode.js';
  5. class PhysicalMaterialContextNode extends ContextNode {
  6. static RADIANCE = 'radiance';
  7. static IRRADIANCE = 'irradiance';
  8. constructor( scope, node ) {
  9. super( node, 'vec3' );
  10. this.scope = scope;
  11. }
  12. generate( builder, output ) {
  13. const scope = this.scope;
  14. let roughness = null;
  15. if ( scope === PhysicalMaterialContextNode.RADIANCE ) {
  16. roughness = new ExpressionNode( 'roughnessFactor', 'float' );
  17. } else if ( scope === PhysicalMaterialContextNode.IRRADIANCE ) {
  18. roughness = new FloatNode( 1.0 ).setConst( true );
  19. this.setContextValue( 'uv', new NormalNode( NormalNode.WORLD ) );
  20. }
  21. this.setContextValue( 'roughness', roughness );
  22. return super.generate( builder, output );
  23. }
  24. }
  25. export default PhysicalMaterialContextNode;