Compile error in:ShaderSource[name=Common/MatDefs/Post/bloomExtract15.frag

Hi,



i want to use the Bloom Filter, but i get an error message.

The code i added is this (i got it from the tutorial):

[java]

FilterPostProcessor fpp = new FilterPostProcessor(assetManager);

BloomFilter bf = new BloomFilter(BloomFilter.GlowMode.Objects);

fpp.addFilter(bf);

viewPort.addProcessor(fpp);

[/java]



And the error is this (it kills my application hard):


Jul 5, 2011 9:34:41 PM com.jme3.material.MaterialDef
INFO: Loaded material definition: Bloom
Jul 5, 2011 9:34:41 PM com.jme3.material.MaterialDef
INFO: Loaded material definition: Bloom
Jul 5, 2011 9:34:41 PM com.jme3.material.MaterialDef
INFO: Loaded material definition: Bloom
Jul 5, 2011 9:34:41 PM com.jme3.material.MaterialDef
INFO: Loaded material definition: Bloom Final
Jul 5, 2011 9:34:43 PM com.jme3.renderer.lwjgl.LwjglRenderer updateShaderSourceData
WARNING: Bad compile of:
#define HAS_GLOWMAP 1
#extension GL_ARB_texture_multisample : enable
uniform int m_NumSamples;
uniform int m_NumSamplesDepth;
#ifdef RESOLVE_MS
#define COLORTEXTURE sampler2DMS
#else
#define COLORTEXTURE sampler2D
#endif

#ifdef RESOLVE_DEPTH_MS
#define DEPTHTEXTURE sampler2DMS

#else
#define DEPTHTEXTURE sampler2D
#endif

vec4 textureFetch(in sampler2DMS tex,in vec2 texC, in int numSamples){
ivec2 iTexC = ivec2(texC * textureSize(tex));
vec4 color = vec4(0.0);
for (int i=0;i<numSamples;i++){
color += texelFetch(tex, iTexC, i);
}
return color/numSamples;
}

vec4 fetchTextureSample(in sampler2D tex,in vec2 texC,in int sample){
return texture2D(tex,texC);
}

vec4 fetchTextureSample(in sampler2DMS tex,in vec2 texC,in int sample){
ivec2 iTexC = ivec2(texC * textureSize(tex));
return texelFetch(tex, iTexC, sample);
}

vec4 getColor(in sampler2D tex,in vec2 texC){
return texture2D(tex,texC);
}

vec4 getColor(in sampler2DMS tex,in vec2 texC){
return textureFetch(tex,texC,m_NumSamples);
}

vec4 getDepth(in sampler2D tex,in vec2 texC){
return texture2D(tex,texC);
}

vec4 getDepth(in sampler2DMS tex,in vec2 texC){
return textureFetch(tex,texC,m_NumSamplesDepth);
}


uniform COLORTEXTURE m_Texture;

uniform float m_ExposurePow;
uniform float m_ExposureCutoff;
in vec2 texCoord;


#ifdef HAS_GLOWMAP
uniform sampler2D m_GlowMap;
#endif

void main(void)
{
vec4 color;
#ifdef DO_EXTRACT

color = getColor(m_Texture, texCoord);
if ( (color.r+color.g+color.b)/3.0 < m_ExposureCutoff ) {
color = vec4(0.0);
}else{
color = pow(color,vec4(m_ExposurePow));
}
#endif

#ifdef HAS_GLOWMAP
vec4 glowColor = texture2D( m_GlowMap, texCoord );
glowColor = pow(glowColor,vec4(m_ExposurePow));
color+=glowColor;
#endif

gl_FragColor = color;
}


Jul 5, 2011 9:34:43 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
com.jme3.renderer.RendererException: compile error in:ShaderSource[name=Common/MatDefs/Post/bloomExtract15.frag, defines, type=Fragment] error:Fragment shader failed to compile with the following errors:
ERROR: 0:20: error(#155) Internal error wrong operand type built in unary operator function. Type: in sampler2DMS
ERROR: error(#273) 1 compilation errors. No code generated


I searched for a solution and i found "update your graphics driver - it is fixed already".
I updated my graphics driver (or more precisely the updater told me i am up-to-date already), but problem still remains.

Any solutions?

I’m curious to see if you get this resolved. It looks like the error that one of my users gets since sometime around Alpha 4’s release but it worked before then.



I assume you are running the latest nightly build? Just checking.

Hm, actually i am not … let me check that out!

Ok, i am now running with the latest SVN trunk version of JME3.

This is what is says now (haven’t checked yet if it is identical, but looks at least similar):


Jul 6, 2011 12:46:26 AM com.jme3.material.MaterialDef
INFO: Loaded material definition: Bloom
Jul 6, 2011 12:46:26 AM com.jme3.material.MaterialDef
INFO: Loaded material definition: Bloom
Jul 6, 2011 12:46:26 AM com.jme3.material.MaterialDef
INFO: Loaded material definition: Bloom
Jul 6, 2011 12:46:26 AM com.jme3.material.MaterialDef
INFO: Loaded material definition: Bloom Final
Jul 6, 2011 12:46:27 AM com.jme3.renderer.lwjgl.LwjglRenderer updateShaderSourceData
WARNING: Bad compile of:
#define HAS_GLOWMAP 1
#extension GL_ARB_texture_multisample : enable
uniform int m_NumSamples;
uniform int m_NumSamplesDepth;

#ifdef RESOLVE_MS
#define COLORTEXTURE sampler2DMS
#else
#define COLORTEXTURE sampler2D
#endif

#ifdef RESOLVE_DEPTH_MS
#define DEPTHTEXTURE sampler2DMS
#else
#define DEPTHTEXTURE sampler2D
#endif

vec4 textureFetch(in sampler2DMS tex,in vec2 texC, in int numSamples){
ivec2 iTexC = ivec2(texC * textureSize(tex));
vec4 color = vec4(0.0);
for (int i = 0; i < numSamples; i++){
color += texelFetch(tex, iTexC, i);
}
return color / numSamples;
}

vec4 fetchTextureSample(in sampler2D tex,in vec2 texC,in int sample){
return texture2D(tex,texC);
}

vec4 fetchTextureSample(in sampler2DMS tex,in vec2 texC,in int sample){
ivec2 iTexC = ivec2(texC * textureSize(tex));
return texelFetch(tex, iTexC, sample);
}

vec4 getColor(in sampler2D tex, in vec2 texC){
return texture2D(tex,texC);
}

vec4 getColor(in sampler2DMS tex, in vec2 texC){
return textureFetch(tex, texC, m_NumSamples);
}

vec4 getColorSingle(in sampler2D tex, in vec2 texC){
return texture2D(tex, texC);
}

vec4 getColorSingle(in sampler2DMS tex, in vec2 texC){
ivec2 iTexC = ivec2(texC * textureSize(tex));
return texelFetch(tex, iTexC, 0);
}

vec4 getDepth(in sampler2D tex,in vec2 texC){
return texture2D(tex,texC);
}

vec4 getDepth(in sampler2DMS tex,in vec2 texC){
return textureFetch(tex,texC,m_NumSamplesDepth);
}


uniform COLORTEXTURE m_Texture;

uniform float m_ExposurePow;
uniform float m_ExposureCutoff;

in vec2 texCoord;
out vec4 outFragColor;

#ifdef HAS_GLOWMAP
uniform sampler2D m_GlowMap;
#endif

void main(){
vec4 color = vec4(0.0);
#ifdef DO_EXTRACT
color = getColorSingle(m_Texture, texCoord);
if ( (color.r + color.g + color.b) / 3.0 >= m_ExposureCutoff ) {
color = pow(color, vec4(m_ExposurePow));
}else{
color = vec4(0.0);
}
#endif

#ifdef HAS_GLOWMAP
vec4 glowColor = texture2D( m_GlowMap, texCoord );
glowColor = pow(glowColor, vec4(m_ExposurePow));
color += glowColor;
#endif

outFragColor = color;
}


Jul 6, 2011 12:46:27 AM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
com.jme3.renderer.RendererException: compile error in:ShaderSource[name=Common/MatDefs/Post/bloomExtract15.frag, defines, type=Fragment] error:Fragment shader failed to compile with the following errors:
ERROR: 0:20: error(#155) Internal error wrong operand type built in unary operator function. Type: in sampler2DMS
ERROR: error(#273) 1 compilation errors. No code generated

Actually it has changed!

It is much shorter now.

But I’m still getting an error.



HELP! Please!





The actual error message is this i guess:

ERROR: 0:20: error(#155) Internal error wrong operand type built in unary operator function. Type: in sampler2DMS


Which "unary operator" could it mean?
Maybe the "+=". Let me check that!

I have no idea. I’m also curious as to the solution because the error looked like black magic voodoo when I looked at the source last time. This may be something that @momoko_fan has to comment on.



I have one user who would really like it if this gets fixed but most can run just fine.

That += was not the problem - was just a wild guess anyway.



I don’t understand what the error message means exactly.

Is this 0:20 some kind of location in the fragment?

But 0:20 makes no sense.



But then again the error message mentions “Type: in sampler2DMS”, which shows up a few times in the fragment file.

But still: Which “unary operator” could it mean?



I looked at the code …

i traced it to these parts (i removed unimportant lines):

[java]

glGetShader(id, GL_INFO_LOG_LENGTH, intBuf1);

int length = intBuf1.get(0);

if (length > 3) {

// get infos

ByteBuffer logBuf = BufferUtils.createByteBuffer(length);

glGetShaderInfoLog(id, null, logBuf);

byte logBytes = new byte[length];

logBuf.get(logBytes, 0, length);

// convert to string, etc

infoLog = new String(logBytes);

}

// …

throw new RendererException("compile error in:" + source + " error:" + infoLog);

[/java]

The part inside the “length > 3”-if merely gets the error message from the Shader (org.lwjgl.opengl.GL20).

This is actually LWJGL, which is another more basic OpenGL framework, but i guess you know that ;- )



But that means, that this error message is straight from the Shader / LWJGL:

Fragment shader failed to compile with the following errors:
ERROR: 0:20: error(#155) Internal error wrong operand type built in unary operator function. Type: in sampler2DMS
ERROR: error(#273) 1 compilation errors. No code generated


And this is the "source":
ShaderSource[name=Common/MatDefs/Post/bloomExtract15.frag, defines, type=Fragment]

That part is easy to understand, it tells us which file it is.
That's all i got from looking at it.
The question remains: What does the error message mean, and how can we fix it?

Greetz Fino

p.s. when editing posts, it removes all empty lines. This is annoying. Can somebody fix that please?!

It should be fixed in SVN now.

Essentially the issue was that any GPU that supported GLSL 1.5 but didn’t support multisample textures would quite simply crash.

Cool, thanks!



BUT it does not solve it yet …



I traced it to this:

It seems the flag GL_ARB_texture_multisample is defined, thus it still runs into the same problem.



This was my ultimate test:

[java]

#ifdef GL_ARB_texture_multisample

#define COLORTEXTURE sampler2DMS

#else



[/java]



This errors. If i change it to sampler2D it works.

The point being, it runs into this if-block.

Even though the theory was, that this if-block would prevent a certain part from being included/compiled.



Maybe wrong flag??



Or maybe the thing that is setting the flag is bogus!?



Back to you guys!

HEHE!



Well i don’t understand all of it, but maybe the first line of the file has something to do with it:

[java]#extension GL_ARB_texture_multisample : enable[/java]



Possible?

OK, I GOT IT TO WORK!



This was an adventure!



Here is what i changed:

ORIGINAL - Common/MatDefs/Post/bloomExtract15.frag:

[java]

#import “Common/ShaderLib/MultiSample.glsllib”



uniform COLORTEXTURE m_Texture;



uniform float m_ExposurePow;

uniform float m_ExposureCutoff;



in vec2 texCoord;

out vec4 outFragColor;



#ifdef HAS_GLOWMAP

uniform sampler2D m_GlowMap;

#endif



void main(){

vec4 color = vec4(0.0);

#ifdef DO_EXTRACT

color = getColorSingle(m_Texture, texCoord);

if ( (color.r + color.g + color.b) / 3.0 >= m_ExposureCutoff ) {

color = pow(color, vec4(m_ExposurePow));

}else{

color = vec4(0.0);

}

#endif



#ifdef HAS_GLOWMAP

vec4 glowColor = texture2D( m_GlowMap, texCoord );

glowColor = pow(glowColor, vec4(m_ExposurePow));

color += glowColor;

#endif



outFragColor = color;

}

[/java]



CHANGED TO:

[java]

#extension GL_ARB_texture_multisample : enable



uniform sampler2D m_Texture;



uniform float m_ExposurePow;

uniform float m_ExposureCutoff;



in vec2 texCoord;

out vec4 outFragColor;



#ifdef HAS_GLOWMAP

uniform sampler2D m_GlowMap;

#endif



void main(){

vec4 color = vec4(0.0);

#ifdef DO_EXTRACT

color = texture2D(m_Texture, texCoord);

if ( (color.r + color.g + color.b) / 3.0 >= m_ExposureCutoff ) {

color = pow(color, vec4(m_ExposurePow));

}else{

color = vec4(0.0);

}

#endif



#ifdef HAS_GLOWMAP

vec4 glowColor = texture2D( m_GlowMap, texCoord );

glowColor = pow(glowColor, vec4(m_ExposurePow));

color += glowColor;

#endif



outFragColor = color;

}

[/java]



ORIGINAL - Common/MatDefs/Post/bloomFinal15.frag:

[java]

#import “Common/ShaderLib/MultiSample.glsllib”



uniform COLORTEXTURE m_Texture;



uniform sampler2D m_BloomTex;

uniform float m_BloomIntensity;



in vec2 texCoord;



void main(){

vec4 colorRes = getColor(m_Texture,texCoord);

vec4 bloom = texture2D(m_BloomTex, texCoord);

gl_FragColor = bloom * m_BloomIntensity + colorRes;

}

[/java]



CHANGED TO:

[java]

#extension GL_ARB_texture_multisample : enable



uniform sampler2D m_Texture;



uniform sampler2D m_BloomTex;

uniform float m_BloomIntensity;



in vec2 texCoord;



void main(){

vec4 colorRes = texture2D(m_Texture,texCoord);

vec4 bloom = texture2D(m_BloomTex, texCoord);

gl_FragColor = bloom * m_BloomIntensity + colorRes;

}

[/java]



Basically, something with the type-definition of COLORTEXTURE in conjunction with the option/flag RESOLVE_MS in Common/ShaderLib/MultiSample.glsllib is wrong.



What the error message means (i think) is that a method is being called with a wrong type definition.

So my solution was to hard-wire the type of m_Texture to sampler2D and remove the import of MultiSample.glsllib by copying the relevant parts from there into the 2 affected files (that was “#extension GL_ARB_texture_multisample : enable” and inlining the function calls).



By doing so i REMOVED the RESOLVE_MS option. I have no clue what that is or what it does.



I leave the rest to you guys! For me it works now! It actually works! Like the glow effect … IT WORKS!!!



Greetz Fino ;- )

It shouldn’t expose the define if its not supported by the driver. If its exposed, that means it is supported and thus cannot fail.

I see.

But what is “it”? Maybe that’s exactly where the error comes from.



I also tried changing the above line to disable, but that would cause other errors. So wrong assumption.



But still, it does not work! Can somebody check into this a little bit more please?

“It” is your graphics driver.

If you go to line 20 (considering that #version 150 would be the first line) you will see this:

[java]ivec2 iTexC = ivec2(texC * textureSize(tex));[/java]

The error being generated is:

[java]error(#155) Internal error wrong operand type built in unary operator function. Type: in sampler2DMS[/java]

Looking up this error online I get this:

http://forums.amd.com/forum/messageview.cfm?catid=392&threadid=127469

So its a driver issue after all.



To confirm, I boot up GPU Shader Analyzer from AMD, select driver version 10.3, compile that shader and get the error you get. Then I switch to version 10.4 and the shader compiles successfully.

I just downloaded the latest drivers from AMD.

And the installer then told me that i am up-to-date.

So what can i do, to get the real up-to-date driver?



(For now i am downloading the GPU Shader Analyzer you mentioned and go to sleep … 3 am German time.)



Greets Fino

Check your driver version … Maybe it is the latest