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. 50
      jme3-core/src/plugins/java/com/jme3/material/plugins/ShaderNodeLoaderDelegate.java

@ -70,10 +70,10 @@ public class ShaderNodeLoaderDelegate {
protected ShaderNodeDefinition shaderNodeDefinition; protected ShaderNodeDefinition shaderNodeDefinition;
protected ShaderNode shaderNode; protected ShaderNode shaderNode;
protected TechniqueDef techniqueDef; protected TechniqueDef techniqueDef;
protected Map<String, DeclaredVariable> attributes = new HashMap<String, DeclaredVariable>(); protected Map<String, DeclaredVariable> attributes = new HashMap<>();
protected Map<String, DeclaredVariable> vertexDeclaredUniforms = new HashMap<String, DeclaredVariable>(); protected Map<String, DeclaredVariable> vertexDeclaredUniforms = new HashMap<>();
protected Map<String, DeclaredVariable> fragmentDeclaredUniforms = new HashMap<String, DeclaredVariable>(); protected Map<String, DeclaredVariable> fragmentDeclaredUniforms = new HashMap<>();
protected Map<String, DeclaredVariable> varyings = new HashMap<String, DeclaredVariable>(); protected Map<String, DeclaredVariable> varyings = new HashMap<>();
protected MaterialDef materialDef; protected MaterialDef materialDef;
protected String shaderLanguage; protected String shaderLanguage;
protected String shaderName; protected String shaderName;
@ -943,21 +943,33 @@ public class ShaderNodeLoaderDelegate {
*/ */
public void storeVaryings(ShaderNode node, ShaderNodeVariable variable) { public void storeVaryings(ShaderNode node, ShaderNodeVariable variable) {
variable.setShaderOutput(true); 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();
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. if (nodeDefinition.getType() != Shader.ShaderType.Vertex ||
for (VariableMapping variableMapping : node.getInputMapping()) { currentDefinition.getType() != Shader.ShaderType.Fragment) {
final ShaderNodeVariable leftVariable = variableMapping.getLeftVariable(); return;
if (leftVariable.getName().equals(variable.getName())) { }
leftVariable.setShaderOutput(true);
} 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);
} }
} }
} }
@ -1022,7 +1034,7 @@ public class ShaderNodeLoaderDelegate {
private Map<String, ShaderNodeDefinition> getNodeDefinitions() { private Map<String, ShaderNodeDefinition> getNodeDefinitions() {
if (nodeDefinitions == null) { if (nodeDefinitions == null) {
nodeDefinitions = new HashMap<String, ShaderNodeDefinition>(); nodeDefinitions = new HashMap<>();
} }
return nodeDefinitions; return nodeDefinitions;
} }

Loading…
Cancel
Save