Better handling of default values for shader nodes input
This commit is contained in:
parent
3ab8466075
commit
514e809326
@ -228,6 +228,7 @@ public class Glsl100ShaderGenerator extends ShaderGenerator {
|
||||
*
|
||||
* 4. mapping outputs to global output if needed<br>
|
||||
*
|
||||
*
|
||||
*<br>
|
||||
* All of this is embed in a #if conditional statement if needed
|
||||
*/
|
||||
@ -241,45 +242,17 @@ public class Glsl100ShaderGenerator extends ShaderGenerator {
|
||||
|
||||
final List<String> declaredInputs = new ArrayList<>();
|
||||
|
||||
for (VariableMapping mapping : shaderNode.getInputMapping()) {
|
||||
|
||||
final ShaderNodeVariable rightVariable = mapping.getRightVariable();
|
||||
final ShaderNodeVariable leftVariable = mapping.getLeftVariable();
|
||||
|
||||
//Variables fed with a sampler matparam or world param are replaced by the matparam itself
|
||||
//It avoids issue with samplers that have to be uniforms.
|
||||
if (rightVariable != null && isWorldOrMaterialParam(rightVariable) && rightVariable.getType().startsWith("sampler")) {
|
||||
nodeSource = replace(nodeSource, leftVariable, rightVariable.getPrefix() + rightVariable.getName());
|
||||
} else {
|
||||
|
||||
if (leftVariable.getType().startsWith("sampler")) {
|
||||
throw new IllegalArgumentException("a Sampler must be a uniform");
|
||||
}
|
||||
|
||||
map(mapping, source);
|
||||
}
|
||||
|
||||
String newName = shaderNode.getName() + "_" + leftVariable.getName();
|
||||
if (!declaredInputs.contains(newName)) {
|
||||
nodeSource = replace(nodeSource, leftVariable, newName);
|
||||
declaredInputs.add(newName);
|
||||
}
|
||||
}
|
||||
|
||||
// Decalring variables with default values first
|
||||
final ShaderNodeDefinition definition = shaderNode.getDefinition();
|
||||
|
||||
for (final ShaderNodeVariable var : definition.getInputs()) {
|
||||
|
||||
if (var.getDefaultValue() == null) {
|
||||
if (var.getType().startsWith("sampler")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final String fullName = shaderNode.getName() + "_" + var.getName();
|
||||
|
||||
if (declaredInputs.contains(fullName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final ShaderNodeVariable variable = new ShaderNodeVariable(var.getType(), shaderNode.getName(),
|
||||
var.getName(), var.getMultiplicity());
|
||||
|
||||
@ -291,6 +264,33 @@ public class Glsl100ShaderGenerator extends ShaderGenerator {
|
||||
declaredInputs.add(fullName);
|
||||
}
|
||||
|
||||
for (VariableMapping mapping : shaderNode.getInputMapping()) {
|
||||
|
||||
final ShaderNodeVariable rightVariable = mapping.getRightVariable();
|
||||
final ShaderNodeVariable leftVariable = mapping.getLeftVariable();
|
||||
|
||||
String newName = shaderNode.getName() + "_" + leftVariable.getName();
|
||||
boolean isDeclared = declaredInputs.contains(newName);
|
||||
//Variables fed with a sampler matparam or world param are replaced by the matparam itself
|
||||
//It avoids issue with samplers that have to be uniforms.
|
||||
if (rightVariable != null && isWorldOrMaterialParam(rightVariable) && rightVariable.getType().startsWith("sampler")) {
|
||||
nodeSource = replace(nodeSource, leftVariable, rightVariable.getPrefix() + rightVariable.getName());
|
||||
} else {
|
||||
|
||||
if (leftVariable.getType().startsWith("sampler")) {
|
||||
throw new IllegalArgumentException("a Sampler must be a uniform");
|
||||
}
|
||||
map(mapping, source, !isDeclared);
|
||||
}
|
||||
|
||||
if (!isDeclared) {
|
||||
nodeSource = replace(nodeSource, leftVariable, newName);
|
||||
declaredInputs.add(newName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (ShaderNodeVariable var : definition.getOutputs()) {
|
||||
ShaderNodeVariable v = new ShaderNodeVariable(var.getType(), shaderNode.getName(), var.getName(), var.getMultiplicity());
|
||||
if (!declaredInputs.contains(shaderNode.getName() + "_" + var.getName())) {
|
||||
@ -304,7 +304,7 @@ public class Glsl100ShaderGenerator extends ShaderGenerator {
|
||||
source.append(nodeSource);
|
||||
|
||||
for (VariableMapping mapping : shaderNode.getOutputMapping()) {
|
||||
map(mapping, source);
|
||||
map(mapping, source, true);
|
||||
}
|
||||
endCondition(shaderNode.getCondition(), source);
|
||||
comment(source, shaderNode, "End");
|
||||
@ -423,7 +423,7 @@ public class Glsl100ShaderGenerator extends ShaderGenerator {
|
||||
* @param mapping the VariableMapping to append
|
||||
* @param source the StringBuilder to use
|
||||
*/
|
||||
protected void map(VariableMapping mapping, StringBuilder source) {
|
||||
protected void map(VariableMapping mapping, StringBuilder source, boolean declare) {
|
||||
|
||||
final ShaderNodeVariable leftVariable = mapping.getLeftVariable();
|
||||
final ShaderNodeVariable rightVariable = mapping.getRightVariable();
|
||||
@ -431,7 +431,7 @@ public class Glsl100ShaderGenerator extends ShaderGenerator {
|
||||
|
||||
startCondition(mapping.getCondition(), source);
|
||||
appendIndent(source);
|
||||
if (!leftVariable.isShaderOutput()) {
|
||||
if (!leftVariable.isShaderOutput() && declare) {
|
||||
source.append(leftVariable.getType());
|
||||
source.append(" ");
|
||||
}
|
||||
|
@ -10,9 +10,9 @@ ShaderNodeDefinitions{
|
||||
@output outColor the mixed color
|
||||
}
|
||||
Input {
|
||||
vec4 color1
|
||||
vec4 color2
|
||||
float factor
|
||||
vec4 color1 vec4(1.0)
|
||||
vec4 color2 vec4(1.0)
|
||||
float factor 0.5
|
||||
}
|
||||
Output {
|
||||
vec4 outColor
|
||||
|
@ -9,8 +9,8 @@ ShaderNodeDefinitions{
|
||||
@output outColor the resulting color
|
||||
}
|
||||
Input {
|
||||
vec4 color1
|
||||
vec4 color2
|
||||
vec4 color1 vec4(1.0)
|
||||
vec4 color2 vec4(1.0)
|
||||
}
|
||||
Output {
|
||||
vec4 outColor
|
||||
|
@ -9,8 +9,8 @@ ShaderNodeDefinitions{
|
||||
@output outFloat the resulting coord
|
||||
}
|
||||
Input {
|
||||
float float1
|
||||
float float2
|
||||
float float1 1.0
|
||||
float float2 1.0
|
||||
}
|
||||
Output {
|
||||
float outFloat
|
||||
|
@ -9,8 +9,8 @@ ShaderNodeDefinitions{
|
||||
@output outCoord the resulting coord
|
||||
}
|
||||
Input {
|
||||
vec2 coord1
|
||||
vec2 coord2
|
||||
vec2 coord1 vec2(1.0)
|
||||
vec2 coord2 vec2(1.0)
|
||||
}
|
||||
Output {
|
||||
vec2 outCoord
|
||||
|
@ -9,8 +9,8 @@ ShaderNodeDefinitions{
|
||||
@output outPos the resulting position
|
||||
}
|
||||
Input {
|
||||
vec2 pos1
|
||||
vec2 pos2
|
||||
vec3 pos1 vec3(1.0)
|
||||
vec3 pos2 vec3(1.0)
|
||||
}
|
||||
Output {
|
||||
vec2 outPos
|
||||
|
Loading…
x
Reference in New Issue
Block a user