Sfoglia il codice sorgente

The shader generator now supports swizzle on the left variable of a mapping :
input mapping vec3 v3.xy = v2
will generate
vec3 v3 = vec3(0.0);
v3.xy = v2;
As this statement can't be done in one line.

Nehon 10 anni fa
parent
commit
5b6b33c8f5

+ 11 - 0
jme3-core/src/main/java/com/jme3/shader/Glsl100ShaderGenerator.java

@@ -396,7 +396,18 @@ public class Glsl100ShaderGenerator extends ShaderGenerator {
         source.append(mapping.getLeftVariable().getNameSpace());
         source.append("_");
         source.append(mapping.getLeftVariable().getName());
+        
+        //left swizzle, the variable can't be declared and assigned on the same line. 
         if (mapping.getLeftSwizzling().length() > 0) {
+            //initialize the declared variable to 0.0
+            source.append(" = ");
+            source.append(mapping.getLeftVariable().getType());
+            source.append("(0.0);\n");
+            appendIndent(source);
+            //assign the value on a new line
+            source.append(mapping.getLeftVariable().getNameSpace());
+            source.append("_");
+            source.append(mapping.getLeftVariable().getName());
             source.append(".");
             source.append(mapping.getLeftSwizzling());
         }

+ 1 - 5
jme3-core/src/main/java/com/jme3/shader/ShaderUtils.java

@@ -120,11 +120,7 @@ public class ShaderUtils {
                 card = Integer.parseInt(type.replaceAll(".*vec", ""));
 
                 if (swizzling.length() > 0) {
-                    //if (card >= swizzling.length()) {
-                        card = swizzling.length();
-//                    } else {
-//                        card = 0;
-//                    }
+                    card = swizzling.length();
                 }
             }
         }