ToneMappingNode.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. generate( builder ) {
  16. const type = this.getNodeType( builder );
  17. const colorNode = this.color || builder.context.color;
  18. const toneMapping = this.toneMapping;
  19. const toneMappingParams = { exposure: this.exposureNode, color: colorNode };
  20. if ( toneMapping === LinearToneMapping ) {
  21. return LinearToneMappingNode.call( toneMappingParams ).build( builder, type );
  22. } else {
  23. return this.colorNode.build( builder, type );
  24. }
  25. }
  26. }
  27. export default ToneMappingNode;