瀏覽代碼

Add desaturation functionality to Unshaded.j3md (#1449)

* Update Unshaded.frag

added a few lines of code for desaturating final color output based on a float value

* Update Unshaded.j3md

added float variable "DesaturationValue" and corresponding define "DESATURATION" to support desaturation of the final output color in Unshaded.frag

* Update Unshaded.frag

fixed alpha value that was previously being set to 0.0 by mistake

* Update Unshaded.frag

* Update Unshaded.frag

added ifdef around variable declaration

* Update Unshaded.j3md
Ryan McDonough 4 年之前
父節點
當前提交
9b401143aa

+ 10 - 1
jme3-core/src/main/resources/Common/MatDefs/Misc/Unshaded.frag

@@ -12,6 +12,10 @@ uniform vec4 m_Color;
 uniform sampler2D m_ColorMap;
 uniform sampler2D m_LightMap;
 
+#ifdef DESATURATION
+    uniform float m_DesaturationValue;
+#endif
+
 varying vec2 texCoord1;
 varying vec2 texCoord2;
 
@@ -45,6 +49,11 @@ void main(){
            discard;
         }
     #endif
+    
+    #ifdef DESATURATION
+        vec3 gray = vec3(dot(vec3(0.2126,0.7152,0.0722), color.rgb));
+        color.rgb = vec3(mix(color.rgb, gray, m_DesaturationValue));       
+    #endif
 
     gl_FragColor = color;
-}
+}

+ 5 - 1
jme3-core/src/main/resources/Common/MatDefs/Misc/Unshaded.j3md

@@ -59,6 +59,9 @@ MaterialDef Unshaded {
         Float ShadowMapSize
 
         Boolean BackfaceShadows: true
+        
+        // 1.0 indicates 100% desaturation
+        Float DesaturationValue
     }
 
     Technique {
@@ -82,7 +85,8 @@ MaterialDef Unshaded {
             NUM_BONES : NumberOfBones
             DISCARD_ALPHA : AlphaDiscardThreshold
             NUM_MORPH_TARGETS: NumberOfMorphTargets
-            NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers
+            NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers            
+            DESATURATION : DesaturationValue
         }
     }