WebGLPhysicalContextNode.js 972 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import ContextNode from '../../nodes/core/ContextNode.js';
  2. import NormalNode from '../../nodes/accessors/NormalNode.js';
  3. import ExpressionNode from '../../nodes/core/ExpressionNode.js';
  4. import FloatNode from '../../nodes/inputs/FloatNode.js';
  5. class WebGLPhysicalContextNode 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 === WebGLPhysicalContextNode.RADIANCE ) {
  16. roughness = new ExpressionNode( 'roughnessFactor', 'float' );
  17. } else if ( scope === WebGLPhysicalContextNode.IRRADIANCE ) {
  18. roughness = new FloatNode( 1.0 ).setConst( true );
  19. this.context.uv = new NormalNode( NormalNode.WORLD );
  20. }
  21. this.context.roughness = roughness;
  22. return super.generate( builder, output );
  23. }
  24. }
  25. export default WebGLPhysicalContextNode;