I am working on a shader that needs an array of floats that hold definitions to calculate the vertices per instance. So I gave it a FloatArray uniform to pass this data. But it gives me the following error:
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
com.jme3.renderer.RendererException: Shader failed to link, shader:Shader[numSources=2, numUniforms=5, numBufferBlocks=0, shaderSources=[ShaderSource[name=MatDefs/guiTBTBackground.frag, defines, type=Fragment, language=GLSL150], ShaderSource[name=MatDefs/guiTBTBackground.vert, defines, type=Vertex, language=GLSL150]]]
error: Too many vertex shader default uniform block components
Here I define the parameters:
MaterialParameters {
Int BoundDrawBuffer
Texture2D atlasTexture
FloatArray atlasDefinition
// For instancing
//Boolean UseInstancing
// Alpha threshold for fragment discarding
Float AlphaDiscardThreshold (AlphaTestFallOff)
Float time //ToDo find out built in timer
}
And this is the vertex shader part where I define the uniforms:
Got it… 20000 is too many floats for this array. Tuning it down to 5120 works. I did not bother to find out why and what the upper limit would be. If someone can provide the theory behind this, that would be great.
I tuned the number down, like I wrote before, the error message was gone. But somehow the data does not get to the shader.
I fed the material the definition array (of floats) and attached the material to the geometry:
void loadMaterial(String _materialName){
material = atlas.gui.assetMgr.loadMaterial(_materialName);
material.setTexture("atlasTexture", atlas.atlasImg);
material.setParam("atlasDefinition", VarType.FloatArray, atlas.definitionArray);
geometry.setMaterial(material);
Utils.LOG("Def test pos#4:"+atlas.definitionArray[4]);
}
To be sure, I had the app spit out a value to see if the array was filled. At position #4, the value in the array is 9.0
In the shader however, the value is 0.0
Even when I sized the uniform down to just 16 floats - a number mentioned in another post on this topic - the array was still empty in the shader.
MaterialParameters {
Int BoundDrawBuffer
Texture2D atlasTexture
FloatArray atlasDefinition
// For instancing
//Boolean UseInstancing
// Alpha threshold for fragment discarding
Float AlphaDiscardThreshold (AlphaTestFallOff)
Float time //ToDo find out built in timer
}
In the frag shader I directly throw testColor into the gl_FragColor, so I should see a purple rectangle since I know m_AtlasDefinition[4] should be holding a 9.0 value. But the rectangle I get is pure blue;
Yeah, me too. But it occurs to me that I was only making assumptions about which version of JME is being used… and perhaps even then there is a regression or something.
Only way to know for sure for sure is to put an intentional error in the shader so JME dumps the full source with the #version line at the top.
Tested that right away, when I change it to value/12.0 it still gives 0, and multiply with 0.1 does that too.
And in most cases on this laptop forgetting the decimal point does result in errors. Just not in that specific case. I do a lot of int math in other shaders because it is needed for indexes. And in most cases it will complain about it.
If it were me… I’d confirm every other weird thing my fingers might have gotten wrong…
…starting by changing the parameter to a float and seeing if even one value gets through. Or change the parameter name so that code breaks if you are running the wrong things, etc…
“Kilroy debugging”… making sure the code you think is running is even what’s running, etc… because I also agree that setting an array “should” work.