12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import ContextNode from '../core/ContextNode.js';
- import StructNode from '../core/StructNode.js';
- import { PhysicalLightingModel } from '../functions/BSDFs.js';
- const reflectedLightStruct = new StructNode( {
- directDiffuse: 'vec3',
- directSpecular: 'vec3'
- }, 'ReflectedLight' );
- class LightContextNode extends ContextNode {
- constructor( node ) {
- super( node, 'vec3' );
- }
- generate( builder, output ) {
- const type = this.getType( builder );
- const material = builder.material;
- let lightingModel = null;
- if ( material.isMeshStandardMaterial === true ) {
- lightingModel = PhysicalLightingModel;
- }
- const reflectedLightNode = reflectedLightStruct.create();
- const reflectedLight = reflectedLightNode.build( builder, 'var' );
- this.setContextValue( 'reflectedLight', reflectedLightNode );
- if ( lightingModel !== null ) {
- this.setContextValue( 'lightingModel', lightingModel );
- }
- const totalLightSnippet = `( ${reflectedLight}.directDiffuse + ${reflectedLight}.directSpecular )`;
- // add code
- super.generate( builder, output );
- return builder.format( totalLightSnippet, type, output );
- }
- }
- export default LightContextNode;
|