Compile error in Shader. Syntax error: ’if’ parse error

Hello all,

I’m getting this error

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,6,main]
com.jme3.renderer.RendererException: compile error in:ShaderSource[name=/assets/shader/ColorFragmentShader.frag, defines, type=Fragment] error:Fragment shader failed to compile with the following errors:
ERROR: 0:602: error(#132) Syntax error: 'if' parse error
ERROR: error(#273) 1 compilation errors. No code generated

For this piece of Fragment Shader:
[java]void main(){

// diffuse calculations
vec4 diffuseColor = calculateTriPlanarDiffuseBlend(wNormal, wVertex, texCoord);

vec4 diffuseColor = calculateDiffuseBlend(texCoord);

vec4 diffuseColor = texture2D(m_DiffuseMap, texCoord);
vec4 diffuseColor = vec4(1.0);

float i;
if(position.y < 63.75){ // blue to cyan
i = interpolate (position.y, 63.75);
else if(position.y < 127.5){ // cyan to yellow
i = interpolate (position.y, 127.5);
else if(position.y < 191.25){ // yellow to red
i = interpolate (position.y, 191.25);
else // red to dark red
i = interpolate (position.y, 128);

As far as i can see I'm doing a perfectly normal if. Anybody knows what is going on?

If I remember right, vars inside main have to be initialized.

ie: float i = 0.0;

Not entirely sure if that’s the problem though.

And no opening brace on the last ‘else’.

Remember that glsl is not java and not that friendly, you probably should initialize your vars.


Good spotting there Sploreg.

It was the opening brace.