Jelajahi Sumber

Introduced a new Enum ColorSpace.
One can now mark a texture param in a material definition as linear by using -Linear at the end of the parameter declaration (case insensitive).
An Image bound to a material texture param in a linear color space will have its ColorSpace set to linear when bound to the material by mat.setTexture("name", texture);
Added the -LINEAR flag to all texture param that needed it in stock materials (lighting.j3md, terrainLighting.j3md, different Filter materials).

Nehon 11 tahun lalu
induk
melakukan
8ff6f8df24
28 mengubah file dengan 576 tambahan dan 459 penghapusan
  1. 26 0
      jme3-core/src/main/java/com/jme3/material/MatParamTexture.java
  2. 8 0
      jme3-core/src/main/java/com/jme3/material/Material.java
  3. 15 0
      jme3-core/src/main/java/com/jme3/material/MaterialDef.java
  4. 33 36
      jme3-core/src/main/java/com/jme3/texture/Image.java
  5. 3 2
      jme3-core/src/main/java/com/jme3/texture/Texture2D.java
  6. 3 2
      jme3-core/src/main/java/com/jme3/texture/Texture3D.java
  7. 3 2
      jme3-core/src/main/java/com/jme3/texture/TextureArray.java
  8. 2 1
      jme3-core/src/main/java/com/jme3/texture/TextureCubeMap.java
  9. 40 0
      jme3-core/src/main/java/com/jme3/texture/image/ColorSpace.java
  10. 2 1
      jme3-core/src/main/java/com/jme3/util/PlaceholderAssets.java
  11. 1 1
      jme3-core/src/main/java/com/jme3/util/SkyFactory.java
  12. 352 352
      jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.j3md
  13. 17 3
      jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java
  14. 3 2
      jme3-core/src/plugins/java/com/jme3/texture/plugins/DDSLoader.java
  15. 2 1
      jme3-core/src/plugins/java/com/jme3/texture/plugins/HDRLoader.java
  16. 2 1
      jme3-core/src/plugins/java/com/jme3/texture/plugins/PFMLoader.java
  17. 4 2
      jme3-core/src/tools/java/jme3tools/optimize/TextureAtlas.java
  18. 6 6
      jme3-desktop/src/main/java/com/jme3/texture/plugins/AWTLoader.java
  19. 1 1
      jme3-effects/src/main/resources/Common/MatDefs/SSAO/ssao.j3md
  20. 2 2
      jme3-effects/src/main/resources/Common/MatDefs/Water/SimpleWater.j3md
  21. 2 2
      jme3-effects/src/main/resources/Common/MatDefs/Water/Water.j3md
  22. 3 2
      jme3-examples/src/main/java/jme3test/texture/TestImageRaster.java
  23. 2 1
      jme3-examples/src/main/java/jme3test/texture/TestTexture3D.java
  24. 22 19
      jme3-examples/src/main/java/jme3test/water/TestPostWater.java
  25. 3 2
      jme3-jogl/src/main/java/com/jme3/renderer/jogl/TextureUtil.java
  26. 3 2
      jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/TextureUtil.java
  27. 1 1
      jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Terrain.j3md
  28. 15 15
      jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.j3md

+ 26 - 0
jme3-core/src/main/java/com/jme3/material/MatParamTexture.java

@@ -38,18 +38,27 @@ import com.jme3.export.OutputCapsule;
 import com.jme3.renderer.Renderer;
 import com.jme3.shader.VarType;
 import com.jme3.texture.Texture;
+import com.jme3.texture.image.ColorSpace;
 import java.io.IOException;
 
 public class MatParamTexture extends MatParam {
 
     private Texture texture;
     private int unit;
+    private ColorSpace colorSpace;
 
     public MatParamTexture(VarType type, String name, Texture texture, int unit) {
         super(type, name, texture, null);
         this.texture = texture;
         this.unit = unit;
     }
+    
+    public MatParamTexture(VarType type, String name, Texture texture, int unit, ColorSpace colorSpace) {
+        super(type, name, texture, null);
+        this.texture = texture;
+        this.unit = unit;
+        this.colorSpace = colorSpace;
+    }
 
     public MatParamTexture() {
     }
@@ -72,6 +81,23 @@ public class MatParamTexture extends MatParam {
         this.texture = (Texture) value;
     }
 
+    /**
+     * 
+     * @return the color space required by this texture param
+     */
+    public ColorSpace getColorSpace() {
+        return colorSpace;
+    }
+
+    /**
+     * Set to {@link ColorSpace#Linear} if the texture color space has to be forced to linear 
+     * instead of sRGB
+     * @param colorSpace @see ColorSpace
+     */
+    public void setColorSpace(ColorSpace colorSpace) {
+        this.colorSpace = colorSpace;
+    }
+
     public void setUnit(int unit) {
         this.unit = unit;
     }

+ 8 - 0
jme3-core/src/main/java/com/jme3/material/Material.java

@@ -52,6 +52,7 @@ import com.jme3.shader.Uniform;
 import com.jme3.shader.UniformBindingManager;
 import com.jme3.shader.VarType;
 import com.jme3.texture.Texture;
+import com.jme3.texture.image.ColorSpace;
 import com.jme3.util.ListMap;
 import com.jme3.util.TempVars;
 import java.io.IOException;
@@ -536,6 +537,13 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
         checkSetParam(type, name);
         MatParamTexture val = getTextureParam(name);
         if (val == null) {
+            MatParamTexture paramDef = (MatParamTexture)def.getMaterialParam(name);
+            if(paramDef.getColorSpace() != null && paramDef.getColorSpace() != value.getImage().getColorSpace()){
+                value.getImage().setColorSpace(paramDef.getColorSpace());
+                logger.log(Level.FINE, "Material parameter {0} needs a {1} texture, texture {2} was switched to {3} color space.", new Object[]{name, paramDef.getColorSpace().toString(), value.getName(), value.getImage().getColorSpace().name()});
+            }else if(paramDef.getColorSpace() == null &&  value.getName() != null && value.getImage().getColorSpace() == ColorSpace.Linear){
+                logger.log(Level.WARNING, "texture {0} has a {1} color space, but material parameter {2} has no color space requirement, this may lead to unexpected behavior.\n Cheack wether the image was not set to another material parameter with a linear color space, or that you did not set the ColorSpace to Linear using texture.getImage.setColorSpace().", new Object[]{value.getName(), value.getImage().getColorSpace().name(),name});                
+            }
             paramValues.put(name, new MatParamTexture(type, name, value, nextTexUnit++));
         } else {
             val.setTextureValue(value);

+ 15 - 0
jme3-core/src/main/java/com/jme3/material/MaterialDef.java

@@ -33,6 +33,7 @@ package com.jme3.material;
 
 import com.jme3.asset.AssetManager;
 import com.jme3.shader.VarType;
+import com.jme3.texture.image.ColorSpace;
 import java.util.*;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -124,6 +125,20 @@ public class MaterialDef {
         matParams.put(name, new MatParam(type, name, value, ffBinding));
     }
     
+    /**
+     * Adds a new material parameter.
+     * 
+     * @param type Type of the parameter
+     * @param name Name of the parameter
+     * @param value Default value of the parameter
+     * @param ffBinding Fixed function binding for the parameter
+     * @param colorSpace the color space of the texture required by thiis texture param
+     * @see ColorSpace
+     */
+    public void addMaterialParamTexture(VarType type, String name, ColorSpace colorSpace) {
+        matParams.put(name, new MatParamTexture(type, name, null , 0, colorSpace));
+    }
+    
     /**
      * Returns the material parameter with the given name.
      * 

+ 33 - 36
jme3-core/src/main/java/com/jme3/texture/Image.java

@@ -34,6 +34,7 @@ package com.jme3.texture;
 import com.jme3.export.*;
 import com.jme3.renderer.Caps;
 import com.jme3.renderer.Renderer;
+import com.jme3.texture.image.ColorSpace;
 import com.jme3.util.BufferUtils;
 import com.jme3.util.NativeObject;
 import java.io.IOException;
@@ -334,7 +335,7 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
     protected ArrayList<ByteBuffer> data;
     protected transient Object efficientData;
     protected int multiSamples = 1;
-    protected boolean srgb;
+    protected ColorSpace colorSpace = null;
 //    protected int mipOffset = 0;
     
     // attributes relating to GL object
@@ -448,12 +449,11 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
      *            the image data.
      * @param mipMapSizes
      *            the array of mipmap sizes, or null for no mipmaps.
-     * @param isSrgb 
-     *            true if the image in is sRGB color space false for linear 
-     *color space
+     * @param colorSpace 
+     *            @see ColorSpace the colorSpace of the image      
      */
     public Image(Format format, int width, int height, int depth, ArrayList<ByteBuffer> data,
-            int[] mipMapSizes, boolean isSrgb) {
+            int[] mipMapSizes, ColorSpace colorSpace) {
         
         this();
 
@@ -470,7 +470,7 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
         this.data = data;
         this.depth = depth;
         this.mipMapSizes = mipMapSizes;
-        this.srgb = isSrgb;
+        this.colorSpace = colorSpace;
     }
 
     /**
@@ -486,7 +486,7 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
      @Deprecated
      public Image(Format format, int width, int height, int depth, ArrayList<ByteBuffer> data,
             int[] mipMapSizes) {
-         this(format, width, height, depth, data, mipMapSizes, false);
+         this(format, width, height, depth, data, mipMapSizes, ColorSpace.Linear);
      }
     
     /**
@@ -503,12 +503,11 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
      *            the image data.
      * @param mipMapSizes
      *            the array of mipmap sizes, or null for no mipmaps.
-     * @param isSrgb 
-     *            true if the image in is sRGB color space false for linear 
-     *  color space
+     * @param colorSpace 
+     *            @see ColorSpace the colorSpace of the image    
      */
     public Image(Format format, int width, int height, ByteBuffer data,
-            int[] mipMapSizes, boolean isSrgb) {
+            int[] mipMapSizes, ColorSpace colorSpace) {
 
         this();
 
@@ -527,7 +526,7 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
             this.data.add(data);
         }
         this.mipMapSizes = mipMapSizes;
-        this.srgb = isSrgb;
+        this.colorSpace = colorSpace;
     }
     
     /**
@@ -542,7 +541,7 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
     @Deprecated
     public Image(Format format, int width, int height, ByteBuffer data,
             int[] mipMapSizes) {
-        this(format, width, height, data, mipMapSizes, false);
+        this(format, width, height, data, mipMapSizes, ColorSpace.Linear);
     }
        
     /**
@@ -557,12 +556,11 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
      *            the height of the image.
      * @param data
      *            the image data.
-     * @param isSrgb 
-     *            true if the image in is sRGB color space false for linear 
-     * color space
+     * @param colorSpace 
+     *            @see ColorSpace the colorSpace of the image  
      */
-    public Image(Format format, int width, int height, int depth, ArrayList<ByteBuffer> data, boolean isSrgb) {
-        this(format, width, height, depth, data, null, isSrgb);
+    public Image(Format format, int width, int height, int depth, ArrayList<ByteBuffer> data, ColorSpace colorSpace) {
+        this(format, width, height, depth, data, null, colorSpace);
     }
     
     /**
@@ -576,7 +574,7 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
      */
     @Deprecated
     public Image(Format format, int width, int height, int depth, ArrayList<ByteBuffer> data) {
-        this(format, width, height, depth, data, false);
+        this(format, width, height, depth, data, ColorSpace.Linear);
     }
 
     /**
@@ -591,12 +589,11 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
      *            the height of the image.
      * @param data
      *            the image data.
-     * @param isSrgb 
-     *            true if the image in is sRGB color space false for linear 
-     * color space
+     * @param colorSpace 
+     *            @see ColorSpace the colorSpace of the image  
      */
-    public Image(Format format, int width, int height, ByteBuffer data, boolean isSrgb) {
-        this(format, width, height, data, null, isSrgb);
+    public Image(Format format, int width, int height, ByteBuffer data, ColorSpace colorSpace) {
+        this(format, width, height, data, null, colorSpace);
     }
     
     
@@ -610,7 +607,7 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
      */
     @Deprecated
     public Image(Format format, int width, int height, ByteBuffer data) {
-        this(format, width, height, data, null, false);
+        this(format, width, height, data, null, ColorSpace.Linear);
     }
 
 
@@ -865,24 +862,24 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
     }
    
     /**
-     * image loader is responsible for setting this flag based on the color
+     * image loader is responsible for setting this attribute based on the color
      * space in which the image has been encoded with. In the majority of cases,
-     * this flag will be on by default since many image formats do not contain
-     * any color space information.
+     * this flag will be set to sRGB by default since many image formats do not 
+     * contain any color space information and the most frequently used colors 
+     * space is sRGB
      *
-     * The material loader may override this flag to false if it determines that
+     * The material loader may override this attribute to Lineat if it determines that
      * such conversion must not be performed, for example, when loading normal
      * maps.
      *
-     * @param srgb True to enable SRGB -> linear conversion, false otherwise.
+     * @param colorSpace @see ColorSpace. Set to sRGB to enable srgb -> linear 
+     * conversion, Linear otherwise.
      *
      * @seealso Renderer#setLinearizeSrgbImages(boolean)
      *
-     * @throws InvalidStateException If the image format does not support SRGB
-     * -> linear conversion.
      */
-    public void setSrgb(boolean srgb) {
-        this.srgb = srgb;
+    public void setColorSpace(ColorSpace colorSpace) {
+        this.colorSpace = colorSpace;
     }
 
     /**
@@ -898,8 +895,8 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
      *
      * @seealso Renderer#setLinearizeSrgbImages(boolean)
      */
-    public boolean isSrgb() {
-        return srgb;
+    public ColorSpace getColorSpace() {
+        return colorSpace;
     }
 
     @Override

+ 3 - 2
jme3-core/src/main/java/com/jme3/texture/Texture2D.java

@@ -35,6 +35,7 @@ import com.jme3.export.InputCapsule;
 import com.jme3.export.JmeExporter;
 import com.jme3.export.JmeImporter;
 import com.jme3.export.OutputCapsule;
+import com.jme3.texture.image.ColorSpace;
 import java.io.IOException;
 
 /**
@@ -76,7 +77,7 @@ public class Texture2D extends Texture {
      * @param format
      */
     public Texture2D(int width, int height, Image.Format format){
-        this(new Image(format, width, height, null, false));
+        this(new Image(format, width, height, null, ColorSpace.Linear));
     }
 
     /**
@@ -91,7 +92,7 @@ public class Texture2D extends Texture {
      * @param numSamples
      */
     public Texture2D(int width, int height, int numSamples, Image.Format format){
-        this(new Image(format, width, height, null, false));
+        this(new Image(format, width, height, null, ColorSpace.Linear));
         getImage().setMultiSamples(numSamples);
     }
 

+ 3 - 2
jme3-core/src/main/java/com/jme3/texture/Texture3D.java

@@ -35,6 +35,7 @@ import com.jme3.export.InputCapsule;
 import com.jme3.export.JmeExporter;
 import com.jme3.export.JmeImporter;
 import com.jme3.export.OutputCapsule;
+import com.jme3.texture.image.ColorSpace;
 import java.io.IOException;
 
 /**
@@ -78,7 +79,7 @@ public class Texture3D extends Texture {
      * @param format
      */
     public Texture3D(int width, int height, int depth, Image.Format format) {
-        this(new Image(format, width, height, depth, null, false));
+        this(new Image(format, width, height, depth, null, ColorSpace.Linear));
     }
 
     /**
@@ -93,7 +94,7 @@ public class Texture3D extends Texture {
      * @param numSamples
      */
     public Texture3D(int width, int height, int depth, int numSamples, Image.Format format) {
-        this(new Image(format, width, height, depth, null, false));
+        this(new Image(format, width, height, depth, null, ColorSpace.Linear));
         getImage().setMultiSamples(numSamples);
     }
 

+ 3 - 2
jme3-core/src/main/java/com/jme3/texture/TextureArray.java

@@ -32,6 +32,7 @@
 package com.jme3.texture;
 
 import com.jme3.texture.Image.Format;
+import com.jme3.texture.image.ColorSpace;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -70,8 +71,8 @@ public class TextureArray extends Texture {
         int width = images.get(0).getWidth();
         int height = images.get(0).getHeight();
         Format format = images.get(0).getFormat();
-        boolean isSRGB = images.get(0).isSrgb();
-        Image arrayImage = new Image(format, width, height, null, isSRGB);
+        ColorSpace colorSpace = images.get(0).getColorSpace();
+        Image arrayImage = new Image(format, width, height, null, colorSpace);
 
         for (Image img : images) {
             if (img.getHeight() != height || img.getWidth() != width) {

+ 2 - 1
jme3-core/src/main/java/com/jme3/texture/TextureCubeMap.java

@@ -35,6 +35,7 @@ import com.jme3.export.InputCapsule;
 import com.jme3.export.JmeExporter;
 import com.jme3.export.JmeImporter;
 import com.jme3.export.OutputCapsule;
+import com.jme3.texture.image.ColorSpace;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
@@ -88,7 +89,7 @@ public class TextureCubeMap extends Texture {
         for(int i = 0; i < layerCount; i++) {
             layers.add(null);
         }
-        Image image = new Image(format, width, height, 0, layers, false);
+        Image image = new Image(format, width, height, 0, layers, ColorSpace.Linear);
         return image;
     }
 

+ 40 - 0
jme3-core/src/main/java/com/jme3/texture/image/ColorSpace.java

@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2009-2012 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.texture.image;
+
+
+public enum ColorSpace{
+    
+    sRGB,
+    Linear
+    
+}

+ 2 - 1
jme3-core/src/main/java/com/jme3/util/PlaceholderAssets.java

@@ -41,6 +41,7 @@ import com.jme3.scene.Spatial;
 import com.jme3.scene.shape.Box;
 import com.jme3.texture.Image;
 import com.jme3.texture.Image.Format;
+import com.jme3.texture.image.ColorSpace;
 import java.nio.ByteBuffer;
 
 public class PlaceholderAssets {
@@ -73,7 +74,7 @@ public class PlaceholderAssets {
     public static Image getPlaceholderImage(){
         ByteBuffer tempData = BufferUtils.createByteBuffer(3 * 4 * 4);
         tempData.put(imageData).flip();
-        return new Image(Format.RGB8, 4, 4, tempData, null, false);
+        return new Image(Format.RGB8, 4, 4, tempData, null, ColorSpace.Linear);
     }
     
     public static Material getPlaceholderMaterial(AssetManager assetManager){

+ 1 - 1
jme3-core/src/main/java/com/jme3/util/SkyFactory.java

@@ -243,7 +243,7 @@ public class SkyFactory {
 
         checkImagesForCubeMap(westImg, eastImg, northImg, southImg, upImg, downImg);
 
-        Image cubeImage = new Image(westImg.getFormat(), westImg.getWidth(), westImg.getHeight(), null, westImg.isSrgb());
+        Image cubeImage = new Image(westImg.getFormat(), westImg.getWidth(), westImg.getHeight(), null, westImg.getColorSpace());
 
         cubeImage.addData(westImg.getData(0));
         cubeImage.addData(eastImg.getData(0));

+ 352 - 352
jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.j3md

@@ -1,353 +1,353 @@
-MaterialDef Phong Lighting {
-
-    MaterialParameters {
-
-        // Compute vertex lighting in the shader
-        // For better performance
-        Boolean VertexLighting
-
-        // Use more efficent algorithms to improve performance
-        Boolean LowQuality
-
-        // Improve quality at the cost of performance
-        Boolean HighQuality
-
-        // Output alpha from the diffuse map
-        Boolean UseAlpha
-
-        // Alpha threshold for fragment discarding
-        Float AlphaDiscardThreshold (AlphaTestFallOff)
-
-        // Normal map is in BC5/ATI2n/LATC/3Dc compression format
-        Boolean LATC
-
-        // Use the provided ambient, diffuse, and specular colors
-        Boolean UseMaterialColors
-
-        // Activate shading along the tangent, instead of the normal
-        // Requires tangent data to be available on the model.
-        Boolean VTangent
-
-        // Use minnaert diffuse instead of lambert
-        Boolean Minnaert
-
-        // Use ward specular instead of phong
-        Boolean WardIso
-
-        // Use vertex color as an additional diffuse color.
-        Boolean UseVertexColor
-
-        // Ambient color
-        Color Ambient (MaterialAmbient)
-
-        // Diffuse color
-        Color Diffuse (MaterialDiffuse)
-
-        // Specular color
-        Color Specular (MaterialSpecular)
-
-        // Specular power/shininess
-        Float Shininess (MaterialShininess) : 1
-
-        // Diffuse map
-        Texture2D DiffuseMap
-
-        // Normal map
-        Texture2D NormalMap
-
-        // Specular/gloss map
-        Texture2D SpecularMap
-
-        // Parallax/height map
-        Texture2D ParallaxMap
-
-        //Set to true is parallax map is stored in the alpha channel of the normal map
-        Boolean PackedNormalParallax   
-
-        //Sets the relief height for parallax mapping
-        Float ParallaxHeight : 0.05       
-
-        //Set to true to activate Steep Parallax mapping
-        Boolean SteepParallax
-
-        // Texture that specifies alpha values
-        Texture2D AlphaMap
-
-        // Color ramp, will map diffuse and specular values through it.
-        Texture2D ColorRamp
-
-        // Texture of the glowing parts of the material
-        Texture2D GlowMap
-
-        // Set to Use Lightmap
-        Texture2D LightMap
-
-        // Set to use TexCoord2 for the lightmap sampling
-        Boolean SeparateTexCoord
-
-        // The glow color of the object
-        Color GlowColor
-
-        // Parameters for fresnel
-        // X = bias
-        // Y = scale
-        // Z = power
-        Vector3 FresnelParams
-
-        // Env Map for reflection
-        TextureCubeMap EnvMap
-
-        // the env map is a spheremap and not a cube map
-        Boolean EnvMapAsSphereMap
-
-        //shadows
-         Int FilterMode
-        Boolean HardwareShadows
-
-        Texture2D ShadowMap0
-        Texture2D ShadowMap1
-        Texture2D ShadowMap2
-        Texture2D ShadowMap3
-        //pointLights
-        Texture2D ShadowMap4
-        Texture2D ShadowMap5
-        
-        Float ShadowIntensity
-        Vector4 Splits
-        Vector2 FadeInfo
-
-        Matrix4 LightViewProjectionMatrix0
-        Matrix4 LightViewProjectionMatrix1
-        Matrix4 LightViewProjectionMatrix2
-        Matrix4 LightViewProjectionMatrix3
-        //pointLight
-        Matrix4 LightViewProjectionMatrix4
-        Matrix4 LightViewProjectionMatrix5   
-        Vector3 LightPos
-        Vector3 LightDir
-
-        Float PCFEdge
-        Float ShadowMapSize
-
-        // For hardware skinning
-        Int NumberOfBones
-        Matrix4Array BoneMatrices
-    }
-
-    Technique {
-
-        LightMode MultiPass
-
-        VertexShader GLSL100:   Common/MatDefs/Light/Lighting.vert
-        FragmentShader GLSL100: Common/MatDefs/Light/Lighting.frag
-
-        WorldParameters {
-            WorldViewProjectionMatrix
-            NormalMatrix
-            WorldViewMatrix
-            ViewMatrix
-            CameraPosition
-            WorldMatrix
-        }
-
-        Defines {
-            LATC : LATC
-            VERTEX_COLOR : UseVertexColor
-            VERTEX_LIGHTING : VertexLighting
-            ATTENUATION : Attenuation
-            MATERIAL_COLORS : UseMaterialColors
-            V_TANGENT : VTangent
-            MINNAERT  : Minnaert
-            WARDISO   : WardIso
-            LOW_QUALITY : LowQuality
-            HQ_ATTENUATION : HighQuality
-
-            DIFFUSEMAP : DiffuseMap
-            NORMALMAP : NormalMap
-            SPECULARMAP : SpecularMap
-            PARALLAXMAP : ParallaxMap
-            NORMALMAP_PARALLAX : PackedNormalParallax
-            STEEP_PARALLAX : SteepParallax
-            ALPHAMAP : AlphaMap
-            COLORRAMP : ColorRamp
-            LIGHTMAP : LightMap
-            SEPARATE_TEXCOORD : SeparateTexCoord
-
-            USE_REFLECTION : EnvMap
-            SPHERE_MAP : SphereMap  
-
-            NUM_BONES : NumberOfBones
-        }
-    }
-
-    Technique PreShadow {
-
-        VertexShader GLSL100 :   Common/MatDefs/Shadow/PreShadow.vert
-        FragmentShader GLSL100 : Common/MatDefs/Shadow/PreShadow.frag
-
-        WorldParameters {
-            WorldViewProjectionMatrix
-            WorldViewMatrix
-        }
-
-        Defines {
-            COLOR_MAP : ColorMap
-            DISCARD_ALPHA : AlphaDiscardThreshold
-            NUM_BONES : NumberOfBones
-        }
-
-        ForcedRenderState {
-            FaceCull Off
-            DepthTest On
-            DepthWrite On
-            PolyOffset 5 3
-            ColorWrite Off
-        }
-
-    }
-
-
-    Technique PostShadow15{
-        VertexShader GLSL150:   Common/MatDefs/Shadow/PostShadow15.vert
-        FragmentShader GLSL150: Common/MatDefs/Shadow/PostShadow15.frag
-
-        WorldParameters {
-            WorldViewProjectionMatrix
-            WorldMatrix
-        }
-
-        Defines {
-            HARDWARE_SHADOWS : HardwareShadows
-            FILTER_MODE : FilterMode
-            PCFEDGE : PCFEdge
-            DISCARD_ALPHA : AlphaDiscardThreshold           
-            COLOR_MAP : ColorMap
-            SHADOWMAP_SIZE : ShadowMapSize
-            FADE : FadeInfo
-            PSSM : Splits
-            POINTLIGHT : LightViewProjectionMatrix5
-            NUM_BONES : NumberOfBones
-        }
-
-        ForcedRenderState {
-            Blend Modulate
-            DepthWrite Off                 
-            PolyOffset -0.1 0
-        }
-    }
-
-    Technique PostShadow{
-        VertexShader GLSL100:   Common/MatDefs/Shadow/PostShadow.vert
-        FragmentShader GLSL100: Common/MatDefs/Shadow/PostShadow.frag
-
-        WorldParameters {
-            WorldViewProjectionMatrix
-            WorldMatrix
-        }
-
-        Defines {
-            HARDWARE_SHADOWS : HardwareShadows
-            FILTER_MODE : FilterMode
-            PCFEDGE : PCFEdge
-            DISCARD_ALPHA : AlphaDiscardThreshold           
-            COLOR_MAP : ColorMap
-            SHADOWMAP_SIZE : ShadowMapSize
-            FADE : FadeInfo
-            PSSM : Splits
-            POINTLIGHT : LightViewProjectionMatrix5
-            NUM_BONES : NumberOfBones
-        }
-
-        ForcedRenderState {
-            Blend Modulate
-            DepthWrite Off   
-            PolyOffset -0.1 0  
-        }
-    }
-
-  Technique PreNormalPass {
-
-        VertexShader GLSL100 :   Common/MatDefs/SSAO/normal.vert
-        FragmentShader GLSL100 : Common/MatDefs/SSAO/normal.frag
-
-        WorldParameters {
-            WorldViewProjectionMatrix
-            WorldViewMatrix
-            NormalMatrix
-        }
-
-        Defines {
-            DIFFUSEMAP_ALPHA : DiffuseMap
-            NUM_BONES : NumberOfBones
-        }
-
-    }
-
-
-    Technique PreNormalPassDerivative {
-
-        VertexShader GLSL100 :   Common/MatDefs/MSSAO/normal.vert
-        FragmentShader GLSL100 : Common/MatDefs/MSSAO/normal.frag
-
-        WorldParameters {
-            WorldViewProjectionMatrix
-            WorldViewMatrix
-            NormalMatrix
-        }
-
-        Defines {
-            DIFFUSEMAP_ALPHA : DiffuseMap
-            NUM_BONES : NumberOfBones
-        }
-
-    }
-
-    Technique GBuf {
-
-        VertexShader GLSL100:   Common/MatDefs/Light/GBuf.vert
-        FragmentShader GLSL100: Common/MatDefs/Light/GBuf.frag
-
-        WorldParameters {
-            WorldViewProjectionMatrix
-            NormalMatrix
-            WorldViewMatrix
-            WorldMatrix
-        }
-
-        Defines {
-            VERTEX_COLOR : UseVertexColor
-            MATERIAL_COLORS : UseMaterialColors
-            V_TANGENT : VTangent
-            MINNAERT  : Minnaert
-            WARDISO   : WardIso
-
-            DIFFUSEMAP : DiffuseMap
-            NORMALMAP : NormalMap
-            SPECULARMAP : SpecularMap
-            PARALLAXMAP : ParallaxMap
-        }
-    }
-
-    Technique {
-        LightMode FixedPipeline
-    }
-
-    Technique Glow {
-
-        VertexShader GLSL100:   Common/MatDefs/Misc/Unshaded.vert
-        FragmentShader GLSL100: Common/MatDefs/Light/Glow.frag
-
-        WorldParameters {
-            WorldViewProjectionMatrix
-        }
-
-        Defines {
-            NEED_TEXCOORD1
-            HAS_GLOWMAP : GlowMap
-            HAS_GLOWCOLOR : GlowColor
-
-            NUM_BONES : NumberOfBones
-        }
-    }
-
+MaterialDef Phong Lighting {
+
+    MaterialParameters {
+
+        // Compute vertex lighting in the shader
+        // For better performance
+        Boolean VertexLighting
+
+        // Use more efficent algorithms to improve performance
+        Boolean LowQuality
+
+        // Improve quality at the cost of performance
+        Boolean HighQuality
+
+        // Output alpha from the diffuse map
+        Boolean UseAlpha
+
+        // Alpha threshold for fragment discarding
+        Float AlphaDiscardThreshold (AlphaTestFallOff)
+
+        // Normal map is in BC5/ATI2n/LATC/3Dc compression format
+        Boolean LATC
+
+        // Use the provided ambient, diffuse, and specular colors
+        Boolean UseMaterialColors
+
+        // Activate shading along the tangent, instead of the normal
+        // Requires tangent data to be available on the model.
+        Boolean VTangent
+
+        // Use minnaert diffuse instead of lambert
+        Boolean Minnaert
+
+        // Use ward specular instead of phong
+        Boolean WardIso
+
+        // Use vertex color as an additional diffuse color.
+        Boolean UseVertexColor
+
+        // Ambient color
+        Color Ambient (MaterialAmbient)
+
+        // Diffuse color
+        Color Diffuse (MaterialDiffuse)
+
+        // Specular color
+        Color Specular (MaterialSpecular)
+
+        // Specular power/shininess
+        Float Shininess (MaterialShininess) : 1
+
+        // Diffuse map
+        Texture2D DiffuseMap
+
+        // Normal map
+        Texture2D NormalMap -LINEAR
+
+        // Specular/gloss map
+        Texture2D SpecularMap
+
+        // Parallax/height map
+        Texture2D ParallaxMap -LINEAR
+
+        //Set to true is parallax map is stored in the alpha channel of the normal map
+        Boolean PackedNormalParallax   
+
+        //Sets the relief height for parallax mapping
+        Float ParallaxHeight : 0.05       
+
+        //Set to true to activate Steep Parallax mapping
+        Boolean SteepParallax
+
+        // Texture that specifies alpha values
+        Texture2D AlphaMap -LINEAR
+
+        // Color ramp, will map diffuse and specular values through it.
+        Texture2D ColorRamp
+
+        // Texture of the glowing parts of the material
+        Texture2D GlowMap
+
+        // Set to Use Lightmap
+        Texture2D LightMap
+
+        // Set to use TexCoord2 for the lightmap sampling
+        Boolean SeparateTexCoord
+
+        // The glow color of the object
+        Color GlowColor
+
+        // Parameters for fresnel
+        // X = bias
+        // Y = scale
+        // Z = power
+        Vector3 FresnelParams
+
+        // Env Map for reflection
+        TextureCubeMap EnvMap
+
+        // the env map is a spheremap and not a cube map
+        Boolean EnvMapAsSphereMap
+
+        //shadows
+         Int FilterMode
+        Boolean HardwareShadows
+
+        Texture2D ShadowMap0
+        Texture2D ShadowMap1
+        Texture2D ShadowMap2
+        Texture2D ShadowMap3
+        //pointLights
+        Texture2D ShadowMap4
+        Texture2D ShadowMap5
+        
+        Float ShadowIntensity
+        Vector4 Splits
+        Vector2 FadeInfo
+
+        Matrix4 LightViewProjectionMatrix0
+        Matrix4 LightViewProjectionMatrix1
+        Matrix4 LightViewProjectionMatrix2
+        Matrix4 LightViewProjectionMatrix3
+        //pointLight
+        Matrix4 LightViewProjectionMatrix4
+        Matrix4 LightViewProjectionMatrix5   
+        Vector3 LightPos
+        Vector3 LightDir
+
+        Float PCFEdge
+        Float ShadowMapSize
+
+        // For hardware skinning
+        Int NumberOfBones
+        Matrix4Array BoneMatrices
+    }
+
+    Technique {
+
+        LightMode MultiPass
+
+        VertexShader GLSL100:   Common/MatDefs/Light/Lighting.vert
+        FragmentShader GLSL100: Common/MatDefs/Light/Lighting.frag
+
+        WorldParameters {
+            WorldViewProjectionMatrix
+            NormalMatrix
+            WorldViewMatrix
+            ViewMatrix
+            CameraPosition
+            WorldMatrix
+        }
+
+        Defines {
+            LATC : LATC
+            VERTEX_COLOR : UseVertexColor
+            VERTEX_LIGHTING : VertexLighting
+            ATTENUATION : Attenuation
+            MATERIAL_COLORS : UseMaterialColors
+            V_TANGENT : VTangent
+            MINNAERT  : Minnaert
+            WARDISO   : WardIso
+            LOW_QUALITY : LowQuality
+            HQ_ATTENUATION : HighQuality
+
+            DIFFUSEMAP : DiffuseMap
+            NORMALMAP : NormalMap
+            SPECULARMAP : SpecularMap
+            PARALLAXMAP : ParallaxMap
+            NORMALMAP_PARALLAX : PackedNormalParallax
+            STEEP_PARALLAX : SteepParallax
+            ALPHAMAP : AlphaMap
+            COLORRAMP : ColorRamp
+            LIGHTMAP : LightMap
+            SEPARATE_TEXCOORD : SeparateTexCoord
+
+            USE_REFLECTION : EnvMap
+            SPHERE_MAP : SphereMap  
+
+            NUM_BONES : NumberOfBones
+        }
+    }
+
+    Technique PreShadow {
+
+        VertexShader GLSL100 :   Common/MatDefs/Shadow/PreShadow.vert
+        FragmentShader GLSL100 : Common/MatDefs/Shadow/PreShadow.frag
+
+        WorldParameters {
+            WorldViewProjectionMatrix
+            WorldViewMatrix
+        }
+
+        Defines {
+            COLOR_MAP : ColorMap
+            DISCARD_ALPHA : AlphaDiscardThreshold
+            NUM_BONES : NumberOfBones
+        }
+
+        ForcedRenderState {
+            FaceCull Off
+            DepthTest On
+            DepthWrite On
+            PolyOffset 5 3
+            ColorWrite Off
+        }
+
+    }
+
+
+    Technique PostShadow15{
+        VertexShader GLSL150:   Common/MatDefs/Shadow/PostShadow15.vert
+        FragmentShader GLSL150: Common/MatDefs/Shadow/PostShadow15.frag
+
+        WorldParameters {
+            WorldViewProjectionMatrix
+            WorldMatrix
+        }
+
+        Defines {
+            HARDWARE_SHADOWS : HardwareShadows
+            FILTER_MODE : FilterMode
+            PCFEDGE : PCFEdge
+            DISCARD_ALPHA : AlphaDiscardThreshold           
+            COLOR_MAP : ColorMap
+            SHADOWMAP_SIZE : ShadowMapSize
+            FADE : FadeInfo
+            PSSM : Splits
+            POINTLIGHT : LightViewProjectionMatrix5
+            NUM_BONES : NumberOfBones
+        }
+
+        ForcedRenderState {
+            Blend Modulate
+            DepthWrite Off                 
+            PolyOffset -0.1 0
+        }
+    }
+
+    Technique PostShadow{
+        VertexShader GLSL100:   Common/MatDefs/Shadow/PostShadow.vert
+        FragmentShader GLSL100: Common/MatDefs/Shadow/PostShadow.frag
+
+        WorldParameters {
+            WorldViewProjectionMatrix
+            WorldMatrix
+        }
+
+        Defines {
+            HARDWARE_SHADOWS : HardwareShadows
+            FILTER_MODE : FilterMode
+            PCFEDGE : PCFEdge
+            DISCARD_ALPHA : AlphaDiscardThreshold           
+            COLOR_MAP : ColorMap
+            SHADOWMAP_SIZE : ShadowMapSize
+            FADE : FadeInfo
+            PSSM : Splits
+            POINTLIGHT : LightViewProjectionMatrix5
+            NUM_BONES : NumberOfBones
+        }
+
+        ForcedRenderState {
+            Blend Modulate
+            DepthWrite Off   
+            PolyOffset -0.1 0  
+        }
+    }
+
+  Technique PreNormalPass {
+
+        VertexShader GLSL100 :   Common/MatDefs/SSAO/normal.vert
+        FragmentShader GLSL100 : Common/MatDefs/SSAO/normal.frag
+
+        WorldParameters {
+            WorldViewProjectionMatrix
+            WorldViewMatrix
+            NormalMatrix
+        }
+
+        Defines {
+            DIFFUSEMAP_ALPHA : DiffuseMap
+            NUM_BONES : NumberOfBones
+        }
+
+    }
+
+
+    Technique PreNormalPassDerivative {
+
+        VertexShader GLSL100 :   Common/MatDefs/MSSAO/normal.vert
+        FragmentShader GLSL100 : Common/MatDefs/MSSAO/normal.frag
+
+        WorldParameters {
+            WorldViewProjectionMatrix
+            WorldViewMatrix
+            NormalMatrix
+        }
+
+        Defines {
+            DIFFUSEMAP_ALPHA : DiffuseMap
+            NUM_BONES : NumberOfBones
+        }
+
+    }
+
+    Technique GBuf {
+
+        VertexShader GLSL100:   Common/MatDefs/Light/GBuf.vert
+        FragmentShader GLSL100: Common/MatDefs/Light/GBuf.frag
+
+        WorldParameters {
+            WorldViewProjectionMatrix
+            NormalMatrix
+            WorldViewMatrix
+            WorldMatrix
+        }
+
+        Defines {
+            VERTEX_COLOR : UseVertexColor
+            MATERIAL_COLORS : UseMaterialColors
+            V_TANGENT : VTangent
+            MINNAERT  : Minnaert
+            WARDISO   : WardIso
+
+            DIFFUSEMAP : DiffuseMap
+            NORMALMAP : NormalMap
+            SPECULARMAP : SpecularMap
+            PARALLAXMAP : ParallaxMap
+        }
+    }
+
+    Technique {
+        LightMode FixedPipeline
+    }
+
+    Technique Glow {
+
+        VertexShader GLSL100:   Common/MatDefs/Misc/Unshaded.vert
+        FragmentShader GLSL100: Common/MatDefs/Light/Glow.frag
+
+        WorldParameters {
+            WorldViewProjectionMatrix
+        }
+
+        Defines {
+            NEED_TEXCOORD1
+            HAS_GLOWMAP : GlowMap
+            HAS_GLOWCOLOR : GlowColor
+
+            NUM_BONES : NumberOfBones
+        }
+    }
+
 }

+ 17 - 3
jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java

@@ -44,6 +44,7 @@ import com.jme3.shader.VarType;
 import com.jme3.texture.Texture;
 import com.jme3.texture.Texture.WrapMode;
 import com.jme3.texture.Texture2D;
+import com.jme3.texture.image.ColorSpace;
 import com.jme3.util.PlaceholderAssets;
 import com.jme3.util.blockparser.BlockLanguageParser;
 import com.jme3.util.blockparser.Statement;
@@ -206,13 +207,22 @@ public class J3MLoader implements AssetLoader {
         }
     }
     
-    // <TYPE> <NAME> [ "(" <FFBINDING> ")" ] [ ":" <DEFAULTVAL> ]
+    // <TYPE> <NAME> [ "(" <FFBINDING> ")" ] [ ":" <DEFAULTVAL> ] [-LINEAR]
     private void readParam(String statement) throws IOException{
         String name;
         String defaultVal = null;
         FixedFuncBinding ffBinding = null;
+        ColorSpace colorSpace = null;
         
-        String[] split = statement.split(":");
+        String[] split = statement.split("-");
+        if(split.length>1){
+            if(split[1].equalsIgnoreCase("LINEAR")){
+                colorSpace = ColorSpace.Linear;
+            }
+            statement = split[0].trim();
+        }
+        
+        split = statement.split(":");
         
         // Parse default val
         if (split.length == 1){
@@ -259,8 +269,12 @@ public class J3MLoader implements AssetLoader {
         if (defaultVal != null){ 
             defaultValObj = readValue(type, defaultVal);
         }
+        if(type.isTextureType()){
+            materialDef.addMaterialParamTexture(type, name, colorSpace);    
+        }else{
+            materialDef.addMaterialParam(type, name, defaultValObj, ffBinding);
+        }
         
-        materialDef.addMaterialParam(type, name, defaultValObj, ffBinding);
     }
 
     private void readValueParam(String statement) throws IOException{

+ 3 - 2
jme3-core/src/plugins/java/com/jme3/texture/plugins/DDSLoader.java

@@ -37,6 +37,7 @@ import com.jme3.asset.TextureKey;
 import com.jme3.texture.Image;
 import com.jme3.texture.Image.Format;
 import com.jme3.texture.Texture.Type;
+import com.jme3.texture.image.ColorSpace;
 import com.jme3.util.BufferUtils;
 import com.jme3.util.LittleEndien;
 import java.io.DataInput;
@@ -132,7 +133,7 @@ public class DDSLoader implements AssetLoader {
                 ((TextureKey) info.getKey()).setTextureTypeHint(Type.CubeMap);
             }
             ArrayList<ByteBuffer> data = readData(((TextureKey) info.getKey()).isFlipY());
-            return new Image(pixelFormat, width, height, depth, data, sizes, true);
+            return new Image(pixelFormat, width, height, depth, data, sizes, ColorSpace.sRGB);
         } finally {
             if (stream != null){
                 stream.close();
@@ -144,7 +145,7 @@ public class DDSLoader implements AssetLoader {
         in = new LittleEndien(stream);
         loadHeader();
         ArrayList<ByteBuffer> data = readData(false);
-        return new Image(pixelFormat, width, height, depth, data, sizes, true);
+        return new Image(pixelFormat, width, height, depth, data, sizes, ColorSpace.sRGB);
     }
 
     private void loadDX10Header() throws IOException {

+ 2 - 1
jme3-core/src/plugins/java/com/jme3/texture/plugins/HDRLoader.java

@@ -37,6 +37,7 @@ import com.jme3.asset.TextureKey;
 import com.jme3.math.FastMath;
 import com.jme3.texture.Image;
 import com.jme3.texture.Image.Format;
+import com.jme3.texture.image.ColorSpace;
 import com.jme3.util.BufferUtils;
 import java.io.IOException;
 import java.io.InputStream;
@@ -309,7 +310,7 @@ public class HDRLoader implements AssetLoader {
 
         dataStore.rewind();
         //TODO, HDR color space? considered linear here
-        return new Image(pixelFormat, width, height, dataStore, false);
+        return new Image(pixelFormat, width, height, dataStore, ColorSpace.Linear);
     }
 
     public Object load(AssetInfo info) throws IOException {

+ 2 - 1
jme3-core/src/plugins/java/com/jme3/texture/plugins/PFMLoader.java

@@ -36,6 +36,7 @@ import com.jme3.asset.AssetLoader;
 import com.jme3.asset.TextureKey;
 import com.jme3.texture.Image;
 import com.jme3.texture.Image.Format;
+import com.jme3.texture.image.ColorSpace;
 import com.jme3.util.BufferUtils;
 import java.io.IOException;
 import java.io.InputStream;
@@ -129,7 +130,7 @@ public class PFMLoader implements AssetLoader {
         }
         imageData.rewind();
 
-        return new Image(format, width, height, imageData, null, false);
+        return new Image(format, width, height, imageData, null, ColorSpace.Linear);
     }
 
     public Object load(AssetInfo info) throws IOException {

+ 4 - 2
jme3-core/src/tools/java/jme3tools/optimize/TextureAtlas.java

@@ -45,6 +45,7 @@ import com.jme3.texture.Image;
 import com.jme3.texture.Image.Format;
 import com.jme3.texture.Texture;
 import com.jme3.texture.Texture2D;
+import com.jme3.texture.image.ColorSpace;
 import com.jme3.util.BufferUtils;
 import java.lang.reflect.InvocationTargetException;
 import java.nio.ByteBuffer;
@@ -354,7 +355,7 @@ public class TextureAtlas {
             if (clazz == null) {
                 return null;
             }
-            Image newImage = new Image(format, source.getWidth(), source.getHeight(), BufferUtils.createByteBuffer(source.getWidth() * source.getHeight() * 4), null, false);
+            Image newImage = new Image(format, source.getWidth(), source.getHeight(), BufferUtils.createByteBuffer(source.getWidth() * source.getHeight() * 4), null, ColorSpace.Linear);
             clazz.getMethod("convert", Image.class, Image.class).invoke(clazz.newInstance(), source, newImage);
             return newImage;
         } catch (InstantiationException ex) {
@@ -401,7 +402,8 @@ public class TextureAtlas {
         }
         byte[] image = images.get(mapName);
         if (image != null) {
-            Texture2D tex = new Texture2D(new Image(format, atlasWidth, atlasHeight, BufferUtils.createByteBuffer(image), null, true));
+            //TODO check if color space shouldn't be sRGB
+            Texture2D tex = new Texture2D(new Image(format, atlasWidth, atlasHeight, BufferUtils.createByteBuffer(image), null, ColorSpace.Linear));
             tex.setMagFilter(Texture.MagFilter.Bilinear);
             tex.setMinFilter(Texture.MinFilter.BilinearNearestMipMap);
             tex.setWrap(Texture.WrapMode.Clamp);

+ 6 - 6
jme3-desktop/src/main/java/com/jme3/texture/plugins/AWTLoader.java

@@ -112,7 +112,7 @@ public class AWTLoader implements AssetLoader {
                 
                ByteBuffer data1 = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight()*4);
                data1.put(dataBuf1);
-               return new Image(Format.ABGR8, width, height, data1, null, true);
+               return new Image(Format.ABGR8, width, height, data1, null, com.jme3.texture.image.ColorSpace.sRGB);
             case BufferedImage.TYPE_3BYTE_BGR: // most common in JPEG images
                byte[] dataBuf2 = (byte[]) extractImageData(img);
                if (flipY)
@@ -120,14 +120,14 @@ public class AWTLoader implements AssetLoader {
                
                ByteBuffer data2 = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight()*3);
                data2.put(dataBuf2);
-               return new Image(Format.BGR8, width, height, data2, null, true);
+               return new Image(Format.BGR8, width, height, data2, null, com.jme3.texture.image.ColorSpace.sRGB);
             case BufferedImage.TYPE_BYTE_GRAY: // grayscale fonts
                 byte[] dataBuf3 = (byte[]) extractImageData(img);
                 if (flipY)
                     flipImage(dataBuf3, width, height, 8);
                 ByteBuffer data3 = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight());
                 data3.put(dataBuf3);
-                return new Image(Format.Luminance8, width, height, data3, null, true);
+                return new Image(Format.Luminance8, width, height, data3, null, com.jme3.texture.image.ColorSpace.sRGB);
             case BufferedImage.TYPE_USHORT_GRAY: // grayscale heightmap
                 short[] dataBuf4 = (short[]) extractImageData(img);
                 if (flipY)
@@ -135,7 +135,7 @@ public class AWTLoader implements AssetLoader {
                 
                 ByteBuffer data4 = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight()*2);
                 data4.asShortBuffer().put(dataBuf4);
-                return new Image(Format.Luminance16, width, height, data4, null, true);
+                return new Image(Format.Luminance16, width, height, data4, null, com.jme3.texture.image.ColorSpace.sRGB);
             default:
                 break;
         }
@@ -158,7 +158,7 @@ public class AWTLoader implements AssetLoader {
                 }
             }
             data.flip();
-            return new Image(Format.RGB8, width, height, data, null, true);
+            return new Image(Format.RGB8, width, height, data, null, com.jme3.texture.image.ColorSpace.sRGB);
         }else{
             ByteBuffer data = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight()*4);
             // alpha
@@ -178,7 +178,7 @@ public class AWTLoader implements AssetLoader {
                 }
             }
             data.flip();
-            return new Image(Format.RGBA8, width, height, data, null, true);
+            return new Image(Format.RGBA8, width, height, data, null, com.jme3.texture.image.ColorSpace.sRGB);
         }
     }
 

+ 1 - 1
jme3-effects/src/main/resources/Common/MatDefs/SSAO/ssao.j3md

@@ -4,7 +4,7 @@ MaterialDef SSAO {
         Int NumSamples
         Int NumSamplesDepth
         Texture2D Texture
-        Texture2D RandomMap
+        Texture2D RandomMap -LINEAR
         Texture2D Normals
         Texture2D DepthTexture
         Vector3 FrustumCorner

+ 2 - 2
jme3-effects/src/main/resources/Common/MatDefs/Water/SimpleWater.j3md

@@ -4,8 +4,8 @@ MaterialDef Simple Water {
         Texture2D water_reflection
         Texture2D water_refraction
         Texture2D water_depthmap
-        Texture2D water_normalmap
-        Texture2D water_dudvmap
+        Texture2D water_normalmap -LINEAR
+        Texture2D water_dudvmap -LINEAR
         Vector4 waterColor
         Vector3 lightPos
         Float time

+ 2 - 2
jme3-effects/src/main/resources/Common/MatDefs/Water/Water.j3md

@@ -5,9 +5,9 @@ MaterialDef Advanced Water {
         Int NumSamplesDepth
         Texture2D FoamMap
         Texture2D CausticsMap
-        Texture2D NormalMap
+        Texture2D NormalMap -LINEAR
         Texture2D ReflectionMap
-        Texture2D HeightMap
+        Texture2D HeightMap -LINEAR
         Texture2D Texture
         Texture2D DepthTexture        
         Vector3 CameraPosition

+ 3 - 2
jme3-examples/src/main/java/jme3test/texture/TestImageRaster.java

@@ -17,6 +17,7 @@ import com.jme3.texture.Texture;
 import com.jme3.texture.Texture.MagFilter;
 import com.jme3.texture.Texture.MinFilter;
 import com.jme3.texture.Texture2D;
+import com.jme3.texture.image.ColorSpace;
 import com.jme3.texture.image.ImageRaster;
 import com.jme3.util.BufferUtils;
 import java.nio.ByteBuffer;
@@ -27,7 +28,7 @@ public class TestImageRaster extends SimpleApplication {
         int width = image.getWidth();
         int height = image.getHeight();
         ByteBuffer data = BufferUtils.createByteBuffer( (int)Math.ceil(newFormat.getBitsPerPixel() / 8.0) * width * height);
-        Image convertedImage = new Image(newFormat, width, height, data,null, image.isSrgb());
+        Image convertedImage = new Image(newFormat, width, height, data,null, image.getColorSpace());
         
         ImageRaster sourceReader = ImageRaster.create(image);
         ImageRaster targetWriter = ImageRaster.create(convertedImage);
@@ -66,7 +67,7 @@ public class TestImageRaster extends SimpleApplication {
     }
     
     private Image createTestImage() {
-        Image testImage = new Image(Format.BGR8, 4, 3, BufferUtils.createByteBuffer(4 * 4 * 3), null, false);
+        Image testImage = new Image(Format.BGR8, 4, 3, BufferUtils.createByteBuffer(4 * 4 * 3), null, ColorSpace.Linear);
         
         ImageRaster io = ImageRaster.create(testImage);
         io.setPixel(0, 0, ColorRGBA.Black);

+ 2 - 1
jme3-examples/src/main/java/jme3test/texture/TestTexture3D.java

@@ -46,6 +46,7 @@ import com.jme3.texture.Image;
 import com.jme3.texture.Image.Format;
 import com.jme3.texture.Texture;
 import com.jme3.texture.Texture3D;
+import com.jme3.texture.image.ColorSpace;
 import com.jme3.util.BufferUtils;
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -125,6 +126,6 @@ public class TestTexture3D extends SimpleApplication {
         }
         bb.rewind();
         data.add(bb);
-        return new Texture3D(new Image(Format.RGB8, 10, 10, 10, data, null, false));
+        return new Texture3D(new Image(Format.RGB8, 10, 10, 10, data, null, ColorSpace.Linear));
     }
 }

+ 22 - 19
jme3-examples/src/main/java/jme3test/water/TestPostWater.java

@@ -82,11 +82,14 @@ public class TestPostWater extends SimpleApplication {
 
         //cam.setLocation(new Vector3f(-700, 100, 300));
         //cam.setRotation(new Quaternion().fromAngleAxis(0.5f, Vector3f.UNIT_Z));
-        cam.setLocation(new Vector3f(-327.21957f, 61.6459f, 126.884346f));
-        cam.setRotation(new Quaternion(0.052168474f, 0.9443102f, -0.18395276f, 0.2678024f));
+//        cam.setLocation(new Vector3f(-327.21957f, 61.6459f, 126.884346f));
+//        cam.setRotation(new Quaternion(0.052168474f, 0.9443102f, -0.18395276f, 0.2678024f));
+
+
+        cam.setLocation(new Vector3f(-370.31592f, 182.04016f, 196.81192f));
+        cam.setRotation(new Quaternion(0.015302252f, 0.9304095f, -0.039101653f, 0.3641086f));
 
 
-        cam.setRotation(new Quaternion().fromAngles(new float[]{FastMath.PI * 0.06f, FastMath.PI * 0.65f, 0}));
 
 
         Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false);
@@ -293,21 +296,21 @@ public class TestPostWater extends SimpleApplication {
     @Override
     public void simpleUpdate(float tpf) {
         super.simpleUpdate(tpf);
-        //     box.updateGeometricState();
-        time += tpf;
-        waterHeight = (float) Math.cos(((time * 0.6f) % FastMath.TWO_PI)) * 1.5f;
-        water.setWaterHeight(initialWaterHeight + waterHeight);
-        if (water.isUnderWater() && !uw) {
-
-            waves.setDryFilter(new LowPassFilter(0.5f, 0.1f));
-            uw = true;
-        }
-        if (!water.isUnderWater() && uw) {
-            uw = false;
-            //waves.setReverbEnabled(false);
-            waves.setDryFilter(new LowPassFilter(1, 1f));
-            //waves.setDryFilter(new LowPassFilter(1,1f));
-
-        }
+//        //     box.updateGeometricState();
+//        time += tpf;
+//        waterHeight = (float) Math.cos(((time * 0.6f) % FastMath.TWO_PI)) * 1.5f;
+//        water.setWaterHeight(initialWaterHeight + waterHeight);
+//        if (water.isUnderWater() && !uw) {
+//
+//            waves.setDryFilter(new LowPassFilter(0.5f, 0.1f));
+//            uw = true;
+//        }
+//        if (!water.isUnderWater() && uw) {
+//            uw = false;
+//            //waves.setReverbEnabled(false);
+//            waves.setDryFilter(new LowPassFilter(1, 1f));
+//            //waves.setDryFilter(new LowPassFilter(1,1f));
+//
+//        }
     }
 }

+ 3 - 2
jme3-jogl/src/main/java/com/jme3/renderer/jogl/TextureUtil.java

@@ -35,6 +35,7 @@ package com.jme3.renderer.jogl;
 import com.jme3.renderer.RendererException;
 import com.jme3.texture.Image;
 import com.jme3.texture.Image.Format;
+import com.jme3.texture.image.ColorSpace;
 import java.nio.ByteBuffer;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -291,7 +292,7 @@ public class TextureUtil {
                                      boolean linearizeSrgb){
         GL gl = GLContext.getCurrentGL();
         Image.Format fmt = image.getFormat();
-        GLImageFormat glFmt = getImageFormatWithError(fmt, image.isSrgb() && linearizeSrgb);
+        GLImageFormat glFmt = getImageFormatWithError(fmt, image.getColorSpace() == ColorSpace.sRGB  && linearizeSrgb);
 
         ByteBuffer data;
         if (index >= 0 && image.getData() != null && image.getData().size() > 0){
@@ -474,7 +475,7 @@ public class TextureUtil {
         boolean linearizeSrgb) {
       GL gl = GLContext.getCurrentGL();
       Image.Format fmt = image.getFormat();
-      GLImageFormat glFmt = getImageFormatWithError(fmt, image.isSrgb() && linearizeSrgb);
+      GLImageFormat glFmt = getImageFormatWithError(fmt, image.getColorSpace() == ColorSpace.sRGB  && linearizeSrgb);
 
       ByteBuffer data = null;
       if (index >= 0 && image.getData() != null && image.getData().size() > 0) {

+ 3 - 2
jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/TextureUtil.java

@@ -56,6 +56,7 @@ import com.jme3.renderer.RendererException;
 import com.jme3.texture.Image;
 import com.jme3.texture.Image.Format;
 import static com.jme3.texture.Image.Format.RGB8;
+import com.jme3.texture.image.ColorSpace;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.lwjgl.opengl.EXTTextureSRGB;
@@ -268,7 +269,7 @@ class TextureUtil {
                                      boolean linearizeSrgb){
         
         Image.Format fmt = image.getFormat();
-        GLImageFormat glFmt = getImageFormatWithError(fmt, image.isSrgb() && linearizeSrgb);
+        GLImageFormat glFmt = getImageFormatWithError(fmt, image.getColorSpace() == ColorSpace.sRGB && linearizeSrgb);
 
         ByteBuffer data;
         if (index >= 0 && image.getData() != null && image.getData().size() > 0){
@@ -425,7 +426,7 @@ class TextureUtil {
         int y,
         boolean linearizeSrgb) {
       Image.Format fmt = image.getFormat();
-      GLImageFormat glFmt = getImageFormatWithError(fmt, image.isSrgb() && linearizeSrgb);
+      GLImageFormat glFmt = getImageFormatWithError(fmt, image.getColorSpace() == ColorSpace.sRGB  && linearizeSrgb);
 
       ByteBuffer data = null;
       if (index >= 0 && image.getData() != null && image.getData().size() > 0) {

+ 1 - 1
jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Terrain.j3md

@@ -5,7 +5,7 @@ MaterialDef Terrain {
         // use tri-planar mapping
         Boolean useTriPlanarMapping
 
-		Texture2D Alpha
+		Texture2D Alpha -LINEAR
 		Texture2D Tex1
 		Texture2D Tex2
 		Texture2D Tex3

+ 15 - 15
jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.j3md

@@ -27,62 +27,62 @@ MaterialDef Terrain Lighting {
         // Texture map #0
         Texture2D DiffuseMap
         Float DiffuseMap_0_scale
-        Texture2D NormalMap
+        Texture2D NormalMap -LINEAR
 
         // Texture map #1
         Texture2D DiffuseMap_1
         Float DiffuseMap_1_scale
-        Texture2D NormalMap_1
+        Texture2D NormalMap_1 -LINEAR
 
         // Texture map #2
         Texture2D DiffuseMap_2
         Float DiffuseMap_2_scale
-        Texture2D NormalMap_2
+        Texture2D NormalMap_2 -LINEAR
 
         // Texture map #3
         Texture2D DiffuseMap_3
         Float DiffuseMap_3_scale
-        Texture2D NormalMap_3
+        Texture2D NormalMap_3 -LINEAR
 
         // Texture map #4
         Texture2D DiffuseMap_4
         Float DiffuseMap_4_scale
-        Texture2D NormalMap_4
+        Texture2D NormalMap_4 -LINEAR
 
         // Texture map #5
         Texture2D DiffuseMap_5
         Float DiffuseMap_5_scale
-        Texture2D NormalMap_5
+        Texture2D NormalMap_5 -LINEAR
 
         // Texture map #6
         Texture2D DiffuseMap_6
         Float DiffuseMap_6_scale
-        Texture2D NormalMap_6
+        Texture2D NormalMap_6 -LINEAR
 
         // Texture map #7
         Texture2D DiffuseMap_7
         Float DiffuseMap_7_scale
-        Texture2D NormalMap_7
+        Texture2D NormalMap_7 -LINEAR
 
         // Texture map #8
         Texture2D DiffuseMap_8
         Float DiffuseMap_8_scale
-        Texture2D NormalMap_8
+        Texture2D NormalMap_8 -LINEAR
 
         // Texture map #9
         Texture2D DiffuseMap_9
         Float DiffuseMap_9_scale
-        Texture2D NormalMap_9
+        Texture2D NormalMap_9 -LINEAR
 
         // Texture map #10
         Texture2D DiffuseMap_10
         Float DiffuseMap_10_scale
-        Texture2D NormalMap_10
+        Texture2D NormalMap_10 -LINEAR
 
         // Texture map #11
         Texture2D DiffuseMap_11
         Float DiffuseMap_11_scale
-        Texture2D NormalMap_11
+        Texture2D NormalMap_11 -LINEAR
 
 
         // Specular/gloss map
@@ -90,9 +90,9 @@ MaterialDef Terrain Lighting {
 
 
         // Texture that specifies alpha values
-        Texture2D AlphaMap
-        Texture2D AlphaMap_1
-        Texture2D AlphaMap_2
+        Texture2D AlphaMap -LINEAR
+        Texture2D AlphaMap_1 -LINEAR
+        Texture2D AlphaMap_2 -LINEAR
 
         // Texture of the glowing parts of the material
         Texture2D GlowMap