glsl-optimizer
glsl-optimizer copied to clipboard
Return shader " " after calling optimizer multiple time
I dont know exactly how, but after optimizing multiple shaders, the optimizer return " " without error. you can reproduce the issue with this url http://osgjs.org/examples/pbr/?GLSLOptimizer=1 There are extra info in the console. It happens on some examples on my repo https://github.com/cedricpinson/osgjs but if I extract the shader that does not optimize and put it in your web interface it works. So it looks that after different call, something happens inside the optimizer.
Any clue ?
Hi @cedricpinson, it's been awhile since I've used this so I don't remember why that happens off from my head, although I'm guessing it could be a memory issue or probably some bugs that yield strange behaviour.
Anyways, I tried loading http://osgjs.org/examples/pbr/?GLSLOptimizer=1&log=info but I don't seem to see the error that you're describing?
Hi @zz85, it happens when a shader contains some errors. Instead of showing them (sometimes it shows the error), it returns unreadable or Chinese symbols. My steps to reproduce an error:
- Choose
Fragment shader
&OpenGL ES 3.0
- Copy and paste the source code below.
- Click on the
Optimize!
button. At first time it should show an error. - Correct the error (float x = 1.0;)
- Click on the
Optimize!
button again. It optimizes the code. - Repeat steps 2 and 3 and you will get an unexpected result!
Source code:
uniform sampler2D u_texture;
uniform vec2 u_res;
void main(void)
{
vec2 texCoord = gl_FragCoord.xy / u_res.xy;
float x = 1; //error (must be 1.0)
vec4 sceneColor = texture2D(u_texture, texCoord);
if(sceneColor.r<1. && sceneColor.g<1. && sceneColor.b<1.) discard;
gl_FragColor = sceneColor;
}
Just checking to see if there's been any updates on this in the last few months? Seeing this as well.
Just wanted to note that it's possible to get around this by modifying the minified file a little bit (glsl-optimizer.js).
You should be able to wrap all the code with a function so it gets re-initialized each time you call it. Then you don't need to worry about some kind of internal memory causing this issue on subsequent calls.
For example:
module.exports = () => {
// Paste all the existing code in the file
return Module;
};
Then you'll also need to comment out the existing export. ie, search for module["exports"]=Module
and replace it with /*module["exports"]=Module*/
.
Note that you'll need to use it slightly differently now that it's a function of course.
Is this ideal? Definitely not. But it should work in a pinch if you absolutely need to get around this error.
I'm using a slightly different version of the library so can't promise these exact steps will get it working, but should give you something to go on.