ToneMappingNode.js 1002 B

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