diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag index adf4268810..6927ee398f 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag @@ -10,6 +10,11 @@ #import "Common/ShaderLib/MaterialFog.glsllib" #endif +#ifdef HSV_OFFSET + #import "Common/ShaderLib/HSVUtils.glsllib" + uniform vec3 m_HSVOffset; +#endif + varying vec2 texCoord; #ifdef SEPARATE_TEXCOORD varying vec2 texCoord2; @@ -113,6 +118,10 @@ void main(){ vec4 diffuseColor = vec4(1.0); #endif + #ifdef HSV_OFFSET + diffuseColor.rgb = alterColorWithHsvOffset(diffuseColor.rgb, m_HSVOffset); + #endif + float alpha = DiffuseSum.a * diffuseColor.a; #ifdef ALPHAMAP alpha = alpha * texture2D(m_AlphaMap, newTexCoord).r; diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.j3md b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.j3md index fd32933738..4be679e4d9 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.j3md +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.j3md @@ -22,6 +22,9 @@ MaterialDef Phong Lighting { // Diffuse color Color Diffuse + //Optional vec3 for adjusting the final Color in HSV color space + Vector3 HSVOffset + // Specular color Color Specular @@ -173,12 +176,14 @@ MaterialDef Phong Lighting { NUM_MORPH_TARGETS: NumberOfMorphTargets NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers NORMAL_TYPE: NormalType + HSV_OFFSET : HSVOffset // fog - jayfella USE_FOG : UseFog FOG_LINEAR : LinearFog FOG_EXP : ExpFog FOG_EXPSQ : ExpSqFog + } } diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md index 488c7e565a..2b1a03664d 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md @@ -19,6 +19,9 @@ MaterialDef PBR Lighting { // the emissive intensity Float EmissiveIntensity : 2.0 + //Optional vec3 for adjusting the final BaseColor in HSV color space + Vector3 HSVOffset + // BaseColor map Texture2D BaseColorMap @@ -215,6 +218,7 @@ MaterialDef PBR Lighting { FOG_LINEAR : LinearFog FOG_EXP : ExpFog FOG_EXPSQ : ExpSqFog + HSV_OFFSET : HSVOffset } } diff --git a/jme3-core/src/main/resources/Common/MatDefs/Misc/Unshaded.frag b/jme3-core/src/main/resources/Common/MatDefs/Misc/Unshaded.frag index 0846d22df8..8f698eee02 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Misc/Unshaded.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Misc/Unshaded.frag @@ -16,6 +16,11 @@ uniform sampler2D m_LightMap; uniform float m_DesaturationValue; #endif +#ifdef HSV_OFFSET + #import "Common/ShaderLib/HSVUtils.glsllib" + uniform vec3 m_HSVOffset; +#endif + varying vec2 texCoord1; varying vec2 texCoord2; @@ -49,6 +54,10 @@ void main(){ discard; } #endif + + #ifdef HSV_OFFSET + color.rgb = alterColorWithHsvOffset(color.rgb, m_HSVOffset); + #endif #ifdef DESATURATION vec3 gray = vec3(dot(vec3(0.2126,0.7152,0.0722), color.rgb)); diff --git a/jme3-core/src/main/resources/Common/MatDefs/Misc/Unshaded.j3md b/jme3-core/src/main/resources/Common/MatDefs/Misc/Unshaded.j3md index b5854c2a23..e9e162ad38 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Misc/Unshaded.j3md +++ b/jme3-core/src/main/resources/Common/MatDefs/Misc/Unshaded.j3md @@ -9,6 +9,9 @@ MaterialDef Unshaded { Float PointSize : 1.0 Boolean SeparateTexCoord + //Optional vec3 for adjusting the final Color in HSV color space + Vector3 HSVOffset + // Texture of the glowing parts of the material Texture2D GlowMap // The glow color of the object @@ -89,6 +92,7 @@ MaterialDef Unshaded { NUM_MORPH_TARGETS: NumberOfMorphTargets NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers DESATURATION : DesaturationValue + HSV_OFFSET : HSVOffset } } diff --git a/jme3-core/src/main/resources/Common/ShaderLib/HSVUtils.glsllib b/jme3-core/src/main/resources/Common/ShaderLib/HSVUtils.glsllib new file mode 100644 index 0000000000..ade9f9b554 --- /dev/null +++ b/jme3-core/src/main/resources/Common/ShaderLib/HSVUtils.glsllib @@ -0,0 +1,30 @@ +// Functions for converting between RGB and HSV to allow for adjusting colors in HSV color space + +vec3 rgb2hsv(vec3 c){ + vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); + vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); + + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); +} + +vec3 hsv2rgb(vec3 c){ + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} + +vec3 alterColorWithHsvOffset(vec3 color, vec3 hsvOffset){ + vec3 colorHSV = rgb2hsv(color); + colorHSV += hsvOffset; + + // wrap hue + colorHSV.x = fract(colorHSV.x); + + // clamp saturation and value + colorHSV.yz = clamp(colorHSV.yz, 0.0, 1.0); + + return hsv2rgb(colorHSV); +} diff --git a/jme3-core/src/main/resources/Common/ShaderLib/module/pbrlighting/PBRLightingUtils.glsllib b/jme3-core/src/main/resources/Common/ShaderLib/module/pbrlighting/PBRLightingUtils.glsllib index bf565b61fe..71e235f767 100644 --- a/jme3-core/src/main/resources/Common/ShaderLib/module/pbrlighting/PBRLightingUtils.glsllib +++ b/jme3-core/src/main/resources/Common/ShaderLib/module/pbrlighting/PBRLightingUtils.glsllib @@ -57,6 +57,11 @@ uniform sampler2D m_BaseColorMap; #endif + #ifdef HSV_OFFSET + #import "Common/ShaderLib/HSVUtils.glsllib" + uniform vec3 m_HSVOffset; + #endif + #ifdef USE_PACKED_MR uniform sampler2D m_MetallicRoughnessMap; #else @@ -344,6 +349,10 @@ if( baseColor.a < m_AlphaDiscardThreshold) discard; #endif + #ifdef HSV_OFFSET + baseColor.rgb = alterColorWithHsvOffset(baseColor.rgb, m_HSVOffset); + #endif + surface.albedo = baseColor.rgb; surface.alpha = baseColor.a;