OSDN Git Service

* Fix Lighting.frag compile error
authorshadowislord <shadowislord@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Fri, 18 Mar 2011 23:54:06 +0000 (23:54 +0000)
committershadowislord <shadowislord@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Fri, 18 Mar 2011 23:54:06 +0000 (23:54 +0000)
 * Replaced nondescript NullPointerException in OBJLoader with proper exception for missing material in MTL

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@7026 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

engine/src/core-data/Common/MatDefs/Light/Lighting.frag
engine/src/core-plugins/com/jme3/scene/plugins/OBJLoader.java

index 8d5c785..8b8cc82 100644 (file)
@@ -188,20 +188,22 @@ void main(){
            specularColor.rgb *= texture2D(m_ColorRamp, vec2(light.y, 0.0)).rgb;\r
        #endif\r
 \r
+       // Workaround, since it is not possible to modify varying variables\r
+       vec4 SpecularSum2 = SpecularSum;\r
        #ifdef USE_REFLECTION\r
             vec4 refColor = Optics_GetEnvColor(m_EnvMap, refVec.xyz);\r
 \r
             // Interpolate light specularity toward reflection color\r
             // Multiply result by specular map\r
-            specularColor = mix(SpecularSum * light.y, refColor, refVec.w) * specularColor;\r
+            specularColor = mix(SpecularSum2 * light.y, refColor, refVec.w) * specularColor;\r
 \r
-            SpecularSum = vec4(1.0);\r
+            SpecularSum2 = vec4(1.0);\r
             light.y = 1.0;\r
        #endif\r
 \r
        gl_FragColor =  AmbientSum * diffuseColor +\r
                        DiffuseSum * diffuseColor  * light.x +\r
-                       SpecularSum * specularColor * light.y;\r
+                       SpecularSum2 * specularColor * light.y;\r
     #endif\r
     gl_FragColor.a = alpha;\r
 }\r
index 99202d4..58a13f8 100644 (file)
@@ -332,6 +332,9 @@ public final class OBJLoader implements AssetLoader {
         }else if (cmd.equals("usemtl")){
             // use material from MTL lib for the following faces
             currentMatName = scan.next();
+            if (!matList.containsKey(currentMatName))
+                throw new IOException("Cannot locate material " + currentMatName + " in MTL file!");
+            
         }else if (cmd.equals("mtllib")){
             // specify MTL lib to use for this OBJ file
             String mtllib = scan.nextLine().trim();