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.
pspeed
April 28, 2018, 10:39pm
2
I think we’d probably like to be sure.
Didn’t it also dump the shader source?
nehon
April 29, 2018, 7:02am
3
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.
nehon
April 29, 2018, 9:38am
5
the error seems to occur when parsing the j3md
nehon
April 29, 2018, 9:55am
6
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
nehon
April 29, 2018, 10:03am
7
ho ok… I found the issue… it’s here
if (varName.contains("[")) {
//we have an array
String[] arr = splitVar[1].split("\\[");
varName = arr[0].trim();
multiplicity = arr[1].replaceAll("\\]", "").trim();
}
if (varNames.contains(varName)) {
throw new MatParseException("Duplicate variable name " + varName, statement);
}
varNames.add(varName);
final ShaderNodeVariable variable = new ShaderNodeVariable(varType, "", varName, multiplicity);
variable.setDefaultValue(defaultValue);
return variable;
}
/**
* reads the VertexShaderNodes{} block
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