{"size": 2020, "ext": "js", "max_stars_repo_path": "2021-08-05-cubes-and-colors/nodes/Post Processing Component.js", "max_stars_repo_name": "vorg/nodes-stream", "max_stars_repo_stars_event_min_datetime": "2021-08-06T12:15:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-11T14:57:18.000Z", "max_issues_repo_path": "2021-08-05-cubes-and-colors/nodes/Post Processing Component.js", "max_issues_repo_name": "vorg/nodes-stream", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2021-08-05-cubes-and-colors/nodes/Post Processing Component.js", "max_forks_repo_name": "vorg/nodes-stream", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 8, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.8974358974, "max_line_length": 76, "alphanum_fraction": 0.6143564356}
module.exports = (node, graph) => {
  const postProcessingOut = node.out("post processing out", {});

  const fxaa = node.in("fxaa", true);

  const fog = node.in("fog", true);
  const fogColor = node.in("fogColor", [0.5, 0.5, 0.5], { type: "color" });
  const fogStart = node.in("fogStart", 5, { min: 0, max: 100 });
  const fogDensity = node.in("fogDensity", 0.15, { min: 0, max: 10 });

  const ssao = node.in("ssao", true);
  const ssaoIntensity = node.in("ssaoIntensity", 10, { min: 0, max: 100 });
  const ssaoRadius = node.in("ssaoRadius", 5, { min: 0, max: 30 });
  const ssaoBias = node.in("ssaoBias", 0.01, { min: 0, max: 1 });
  const ssaoBlurRadius = node.in("ssaoBlurRadius", 2, { min: 0, max: 5 });
  const ssaoBlurSharpness = node.in("ssaoBlurSharpness", 2, {
    min: 0,
    max: 20,
  });

  const dof = node.in("dof", false);
  const dofFocusDistance = node.in("dofFocusDistance", 10, {
    min: 0,
    max: 100,
  });

  const bloom = node.in("bloom", true);
  const bloomIntensity = node.in("bloomIntensity", 5, { min: 0, max: 100 });
  const bloomThreshold = node.in("bloomThreshold", -1, { min: -1, max: 2 });
  const bloomRadius = node.in("bloomRadius", 0.4, { min: 0, max: 10 });

  const renderer = graph.renderer;

  const ports = [
    fxaa,

    fog,
    fogColor,
    fogStart,
    fogDensity,

    ssao,
    ssaoIntensity,
    ssaoRadius,
    ssaoBias,
    ssaoBlurRadius,
    ssaoBlurSharpness,

    dof,
    dofFocusDistance,

    bloom,
    bloomIntensity,
    bloomThreshold,
    bloomRadius,
  ];

  const initialState = ports.reduce((previousValue, port) => {
    previousValue[port.name] = port.value;
    return previousValue;
  }, {});

  const postProcessingCmp = renderer.postProcessing(initialState);
  postProcessingOut.setValue(postProcessingCmp);

  node.onReady = () => {
    postProcessingOut.setValue(postProcessingCmp);
  };

  ports.forEach((port) => {
    port.onChange = () => {
      postProcessingCmp.set({
        [port.name]: port.value,
      });
    };
  });
};
