From 375079bfcfea6334732176328b46043940210363 Mon Sep 17 00:00:00 2001 From: Nehon Date: Sat, 3 May 2014 15:03:30 +0200 Subject: [PATCH] The shaderNodesGenerator now properly declare and assign inPosition : inPosition can be a vec4 or Vec3 and will be assign to Global.position accordingly --- .../jme3/shader/Glsl100ShaderGenerator.java | 34 +++++++++++++++++-- .../jme3/shader/Glsl150ShaderGenerator.java | 2 +- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/shader/Glsl100ShaderGenerator.java b/jme3-core/src/main/java/com/jme3/shader/Glsl100ShaderGenerator.java index d7c94c856..ab5d0bb71 100644 --- a/jme3-core/src/main/java/com/jme3/shader/Glsl100ShaderGenerator.java +++ b/jme3-core/src/main/java/com/jme3/shader/Glsl100ShaderGenerator.java @@ -50,6 +50,7 @@ public class Glsl100ShaderGenerator extends ShaderGenerator { * 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 ShaderNodeVariable inPosTmp; /** * creates a Glsl100ShaderGenerator @@ -91,12 +92,16 @@ public class Glsl100ShaderGenerator extends ShaderGenerator { if (var.getName().equals("inPosition")) { inPosition = true; var.setCondition(null); + fixInPositionType(var); + //keep track on the InPosition variable to avoid iterating through attributes again + inPosTmp = var; } declareAttribute(source, var); } - if (!inPosition) { - declareAttribute(source, new ShaderNodeVariable("vec4", "inPosition")); + if (!inPosition) { + inPosTmp = new ShaderNodeVariable("vec3", "inPosition"); + declareAttribute(source, inPosTmp); } } @@ -139,7 +144,7 @@ public class Glsl100ShaderGenerator extends ShaderGenerator { indent(); appendIndent(source); if (type == ShaderType.Vertex) { - declareVariable(source, info.getVertexGlobal(), "inPosition"); + declareGlobalPosition(info, source); } else if (type == ShaderType.Fragment) { for (ShaderNodeVariable global : info.getFragmentGlobals()) { declareVariable(source, global, "vec4(1.0)"); @@ -574,4 +579,27 @@ public class Glsl100ShaderGenerator extends ShaderGenerator { 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)"); + } + } } diff --git a/jme3-core/src/main/java/com/jme3/shader/Glsl150ShaderGenerator.java b/jme3-core/src/main/java/com/jme3/shader/Glsl150ShaderGenerator.java index 8930d6281..0cda27404 100644 --- a/jme3-core/src/main/java/com/jme3/shader/Glsl150ShaderGenerator.java +++ b/jme3-core/src/main/java/com/jme3/shader/Glsl150ShaderGenerator.java @@ -103,7 +103,7 @@ public class Glsl150ShaderGenerator extends Glsl100ShaderGenerator { indent(); if (type == Shader.ShaderType.Vertex) { - declareVariable(source, info.getVertexGlobal(), "inPosition"); + declareGlobalPosition(info, source); } else if (type == Shader.ShaderType.Fragment) { for (ShaderNodeVariable global : info.getFragmentGlobals()) { initVariable(source, global, "vec4(1.0)");