2
0

ToneMappingNode.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import TempNode from '../core/Node.js';
  2. import ShaderNode from '../shadernode/ShaderNode.js';
  3. import { mul, float } from '../shadernode/ShaderNodeElements.js';
  4. import { LinearToneMapping } from 'three';
  5. // exposure only
  6. export const LinearToneMappingNode = new ShaderNode( ( { color, exposure } ) => {
  7. return mul( color, exposure );
  8. } );
  9. class ToneMappingNode extends TempNode {
  10. constructor( toneMapping, exposureNode = float( 1 ), colorNode = null ) {
  11. super( 'vec3' );
  12. this.toneMapping = toneMapping;
  13. this.exposureNode = exposureNode;
  14. this.colorNode = colorNode;
  15. }
  16. generate( builder ) {
  17. const type = this.getNodeType( builder );
  18. const colorNode = this.color || builder.context.color;
  19. const toneMapping = this.toneMapping;
  20. const toneMappingParams = { exposure: this.exposureNode, color: colorNode };
  21. if ( toneMapping === LinearToneMapping ) {
  22. return LinearToneMappingNode.call( toneMappingParams ).build( builder, type );
  23. } else {
  24. return this.colorNode.build( builder, type );
  25. }
  26. }
  27. }
  28. export default ToneMappingNode;