fixed detecting varyings during loading shader nodes in the case, when we have several output parameters with the same name but with different name spaces.

empirephoenix-patch-1
javasabr 7 years ago committed by Rémy Bouquet
parent 74f2f703b3
commit 8674d8af4b
  1. 42
      jme3-core/src/plugins/java/com/jme3/material/plugins/ShaderNodeLoaderDelegate.java

@ -70,10 +70,10 @@ public class ShaderNodeLoaderDelegate {
protected ShaderNodeDefinition shaderNodeDefinition;
protected ShaderNode shaderNode;
protected TechniqueDef techniqueDef;
protected Map<String, DeclaredVariable> attributes = new HashMap<String, DeclaredVariable>();
protected Map<String, DeclaredVariable> vertexDeclaredUniforms = new HashMap<String, DeclaredVariable>();
protected Map<String, DeclaredVariable> fragmentDeclaredUniforms = new HashMap<String, DeclaredVariable>();
protected Map<String, DeclaredVariable> varyings = new HashMap<String, DeclaredVariable>();
protected Map<String, DeclaredVariable> attributes = new HashMap<>();
protected Map<String, DeclaredVariable> vertexDeclaredUniforms = new HashMap<>();
protected Map<String, DeclaredVariable> fragmentDeclaredUniforms = new HashMap<>();
protected Map<String, DeclaredVariable> varyings = new HashMap<>();
protected MaterialDef materialDef;
protected String shaderLanguage;
protected String shaderName;
@ -943,24 +943,36 @@ public class ShaderNodeLoaderDelegate {
*/
public void storeVaryings(ShaderNode node, ShaderNodeVariable variable) {
variable.setShaderOutput(true);
if (node.getDefinition().getType() == Shader.ShaderType.Vertex && shaderNode.getDefinition().getType() == Shader.ShaderType.Fragment) {
DeclaredVariable dv = varyings.get(variable.getName());
if (dv == null) {
techniqueDef.getShaderGenerationInfo().getVaryings().add(variable);
dv = new DeclaredVariable(variable);
varyings.put(variable.getName(), dv);
final ShaderNodeDefinition nodeDefinition = node.getDefinition();
final ShaderNodeDefinition currentDefinition = shaderNode.getDefinition();
if (nodeDefinition.getType() != Shader.ShaderType.Vertex ||
currentDefinition.getType() != Shader.ShaderType.Fragment) {
return;
}
dv.addNode(shaderNode);
//if a variable is declared with the same name as an input and an output and is a varying, set it as a shader output so it's declared as a varying only once.
for (VariableMapping variableMapping : node.getInputMapping()) {
final String fullName = node.getName() + "." + variable.getName();
DeclaredVariable declaredVar = varyings.get(fullName);
if (declaredVar == null) {
techniqueDef.getShaderGenerationInfo().getVaryings().add(variable);
declaredVar = new DeclaredVariable(variable);
varyings.put(fullName, declaredVar);
}
declaredVar.addNode(shaderNode);
// if a variable is declared with the same name as an input and an output and is a varying,
// set it as a shader output so it's declared as a varying only once.
for (final VariableMapping variableMapping : node.getInputMapping()) {
final ShaderNodeVariable leftVariable = variableMapping.getLeftVariable();
if (leftVariable.getName().equals(variable.getName())) {
leftVariable.setShaderOutput(true);
}
}
}
}
/**
* merges 2 condition with the given operator
@ -1022,7 +1034,7 @@ public class ShaderNodeLoaderDelegate {
private Map<String, ShaderNodeDefinition> getNodeDefinitions() {
if (nodeDefinitions == null) {
nodeDefinitions = new HashMap<String, ShaderNodeDefinition>();
nodeDefinitions = new HashMap<>();
}
return nodeDefinitions;
}

Loading…
Cancel
Save