The shaderNodesGenerator now properly declare and assign inPosition :
inPosition can be a vec4 or Vec3 and will be assign to Global.position accordingly
This commit is contained in:
parent
e898f26cf4
commit
375079bfcf
@ -50,6 +50,7 @@ public class Glsl100ShaderGenerator extends ShaderGenerator {
|
|||||||
* the indentation characters 1à tabulation characters
|
* the indentation characters 1à tabulation characters
|
||||||
*/
|
*/
|
||||||
private final static String INDENTCHAR = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
|
private final static String INDENTCHAR = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
|
||||||
|
private ShaderNodeVariable inPosTmp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a Glsl100ShaderGenerator
|
* creates a Glsl100ShaderGenerator
|
||||||
@ -91,12 +92,16 @@ public class Glsl100ShaderGenerator extends ShaderGenerator {
|
|||||||
if (var.getName().equals("inPosition")) {
|
if (var.getName().equals("inPosition")) {
|
||||||
inPosition = true;
|
inPosition = true;
|
||||||
var.setCondition(null);
|
var.setCondition(null);
|
||||||
|
fixInPositionType(var);
|
||||||
|
//keep track on the InPosition variable to avoid iterating through attributes again
|
||||||
|
inPosTmp = var;
|
||||||
}
|
}
|
||||||
declareAttribute(source, var);
|
declareAttribute(source, var);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (!inPosition) {
|
if (!inPosition) {
|
||||||
declareAttribute(source, new ShaderNodeVariable("vec4", "inPosition"));
|
inPosTmp = new ShaderNodeVariable("vec3", "inPosition");
|
||||||
|
declareAttribute(source, inPosTmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -139,7 +144,7 @@ public class Glsl100ShaderGenerator extends ShaderGenerator {
|
|||||||
indent();
|
indent();
|
||||||
appendIndent(source);
|
appendIndent(source);
|
||||||
if (type == ShaderType.Vertex) {
|
if (type == ShaderType.Vertex) {
|
||||||
declareVariable(source, info.getVertexGlobal(), "inPosition");
|
declareGlobalPosition(info, source);
|
||||||
} else if (type == ShaderType.Fragment) {
|
} else if (type == ShaderType.Fragment) {
|
||||||
for (ShaderNodeVariable global : info.getFragmentGlobals()) {
|
for (ShaderNodeVariable global : info.getFragmentGlobals()) {
|
||||||
declareVariable(source, global, "vec4(1.0)");
|
declareVariable(source, global, "vec4(1.0)");
|
||||||
@ -574,4 +579,27 @@ public class Glsl100ShaderGenerator extends ShaderGenerator {
|
|||||||
indent++;
|
indent++;
|
||||||
indent = Math.min(10, indent);
|
indent = Math.min(10, indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* makes sure inPosition attribut is of type vec or vec4
|
||||||
|
* @param var the inPosition attribute
|
||||||
|
*/
|
||||||
|
private void fixInPositionType(ShaderNodeVariable var) {
|
||||||
|
if(!var.getType().equals("vec3") || !var.getType().equals("vec4")){
|
||||||
|
var.setType("vec3");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* declare and assign the global position in the vertex shader.
|
||||||
|
* @param info the shader generation info
|
||||||
|
* @param source the shader source being generated
|
||||||
|
*/
|
||||||
|
protected void declareGlobalPosition(ShaderGenerationInfo info, StringBuilder source) {
|
||||||
|
if(inPosTmp.getType().equals(info.getVertexGlobal().getType())){
|
||||||
|
declareVariable(source, info.getVertexGlobal(), "inPosition");
|
||||||
|
}else{
|
||||||
|
declareVariable(source, info.getVertexGlobal(), "vec4(inPosition,1.0)");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ public class Glsl150ShaderGenerator extends Glsl100ShaderGenerator {
|
|||||||
indent();
|
indent();
|
||||||
|
|
||||||
if (type == Shader.ShaderType.Vertex) {
|
if (type == Shader.ShaderType.Vertex) {
|
||||||
declareVariable(source, info.getVertexGlobal(), "inPosition");
|
declareGlobalPosition(info, source);
|
||||||
} else if (type == Shader.ShaderType.Fragment) {
|
} else if (type == Shader.ShaderType.Fragment) {
|
||||||
for (ShaderNodeVariable global : info.getFragmentGlobals()) {
|
for (ShaderNodeVariable global : info.getFragmentGlobals()) {
|
||||||
initVariable(source, global, "vec4(1.0)");
|
initVariable(source, global, "vec4(1.0)");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user