Shader node "duplicate variable name"

TerrainFactor.j3sn

   ShaderNodeDefinitions {
         ShaderNodeDefinition TerrainFactor {
            Type: Fragment
            Shader GLSL100: MatDefs/PBRTerrain/ShaderNodes/TerrainFactor.frag

            Documentation { 
                Terrain Fragment shader node

                @input HillMinHeight HillMinHeight
                @input HillMaxHeight HillMaxHeight

                @input MountainMinHeight MountainMinHeight
            }

            Input {
                vec3 vVertex;

                float PrevLayerMaxHeight;

                float LayerMinHeight;
                float LayerMaxHeight;

                float NextLayerMinHeight;
            }

            Output {
                float factor;
            }
        }
    }

TerrainFactor.frag:

void main(){
    factor = 1.0
    if(vVertex.y >= NextLayerMinHeight) {
        factor -= ((vVertex.y - NextLayerMinHeight) / (LayerMaxHeight - NextLayerMinHeight));
    }
}

If i try to compile this shader I get this error:

Caused by: com.jme3.material.plugins.MatParseException: Error On line 21 : float LayerMaxHeight
->Duplicate variable name LayerMaxHeight

What does it mean? I don’t have any other variable with the same name in this node or in the entire shader either.

I think we’d probably like to be sure.

Didn’t it also dump the shader source?

Yeah the source of the terrainFactor.frag could help too.

Why should variables from different shader nodes have to be named differently? They could still be dereferenced by theirs node name.

No, it doesn’t dump shader source.

However, I added TerrainFactor.frag source code.

the error seems to occur when parsing the j3md

btw there is a missing semi colon after factor = 1.0
It’s probably not the issue, but it will eventually becomes one.

Could you also provide the j3md? or a test case

ho ok… I found the issue… it’s here

Maybe not the best way to check for already existing variables. here contains returns true for “LayerMaxHeight” because there is a “PrevLayerMaxHeight” variable defined…
That’s dumb, I’m gonna fix it.
Meanwhile you can declare “PrevLayerMaxHeight” after “LayerMaxHeight” and it should work.

1 Like

I may fix it if you want, I’d like to contribute to the Shader Nodes system and I have other ideas I’d like to implement on it.

EDIT: I made a pull request about this issue.

2 Likes