glslify / rollup-plugin-glslify

Import GLSL strings with glslify

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New line should be preserved in certain cases

ajayns opened this issue · comments

commented

Followup to the previous issue I'd mentioned, about cleanup (#8) that included complete stripping of new lines and tab spaces.

Problem

Stripping is super useful in reducing the size and making the shader string concise, but causes problems in certain specific cases where the new line is required to be preserved. For instance: a newline after macros (#define GLSIFY 1).

I've noticed this causing an issue as I attempted to use a Postprocessing effect with a fragment shader. I believe the lack of newlines in the first line is the culprit cause removing that part itself seems to fix the issue.

Solution

Since this is the only place that I'm aware of, maybe the stripping could exclude just this part of the code.

The logic from rollup-plugin-glsl does preserve newlines for anything that starts with a #. I've double-checked the output and there is always a newline with the compress option (#define GLSLIFY 1\n).

Would you be able to provide steps to reproduce?

commented

Yep, please allow me some time, I'll either create a sandbox or let you know about the simplified steps for reproduction.

commented

An instance where I noticed the issue was when I was using a Postprocessing effect:

const { Effect } = POSTPROCESSING;
import fragShader from "../../shaders/shaderPass.frag";

class DistortionEffect extends Effect {
  constructor(texture) {
    super("DistortionEffect", fragShader, {
      uniforms: new Map([["uTexture", new THREE.Uniform(texture)]])
    });
  }
}

This is a shader pass added to the Effect composer after render pass:

const distortionEffect = new DistortionEffect(texture);
const distortionPass = new EffectPass(camera, distortionEffect);

This causes the shader execution to fail unless I remove the #define GLSLIFY 1\n. Now that you mention it though, I have suspicions it could be some other issue.

Ok, if you could close the issue then if it's not newline related. There should also be a newline before the # which is also preserved in the compress output (\n#define GLSLIFY 1\n).

commented

Yes, from what you're saying it's not the newline in particular but I'm not 100% sure the issue is unrelated to the plugin. What could be causing the glslify line to break the shader compilation process? Any insights into that?

Also, I'm closing the issue the bug wasn't what I thought it was.