WebGLPhysicalContextNode.js 972 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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;