From a8630e4ae1e24a0626f0b1b250301fc16fca62fe Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Mon, 16 Mar 2026 23:06:00 -0400 Subject: [PATCH 1/7] Add HSVUtils.glsllib Adds support for converting between RGB and HSV to allow for adjusting colors in HSV color space in shaders. --- .../Common/ShaderLib/HSVUtils.glsllib | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 jme3-core/src/main/resources/Common/ShaderLib/HSVUtils.glsllib 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); +} From 9ed0240ca6182d5e11c039e715be7d415e85c4f7 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Fri, 20 Mar 2026 01:26:26 -0400 Subject: [PATCH 2/7] Update Unshaded.frag --- .../src/main/resources/Common/MatDefs/Misc/Unshaded.frag | 9 +++++++++ 1 file changed, 9 insertions(+) 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)); From 80abdedd6a0eb1f1b5b8f2e270ca1d7454000b94 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Fri, 20 Mar 2026 01:36:27 -0400 Subject: [PATCH 3/7] Update PBRLightingUtils.glsllib --- .../module/pbrlighting/PBRLightingUtils.glsllib | 9 +++++++++ 1 file changed, 9 insertions(+) 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; From 60c137944a4c3f0d235ee715f5f861c43d93be03 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Fri, 20 Mar 2026 01:44:05 -0400 Subject: [PATCH 4/7] Update PBRLighting.j3md --- .../src/main/resources/Common/MatDefs/Light/PBRLighting.j3md | 4 ++++ 1 file changed, 4 insertions(+) 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 } } From 0defd14f6b455f8949f0d40197d9dd602f774998 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Fri, 20 Mar 2026 01:44:09 -0400 Subject: [PATCH 5/7] Update Unshaded.j3md --- .../src/main/resources/Common/MatDefs/Misc/Unshaded.j3md | 4 ++++ 1 file changed, 4 insertions(+) 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 } } From 11a9057d56c75c80d4f9117597d26945af70cc4f Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Sat, 21 Mar 2026 10:23:07 -0400 Subject: [PATCH 6/7] Update Lighting.frag --- .../main/resources/Common/MatDefs/Light/Lighting.frag | 9 +++++++++ 1 file changed, 9 insertions(+) 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; From cc8ccb6302094b4dffa2b1ce3e286e50407e4397 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Sat, 21 Mar 2026 10:24:07 -0400 Subject: [PATCH 7/7] Update Lighting.j3md --- .../src/main/resources/Common/MatDefs/Light/Lighting.j3md | 5 +++++ 1 file changed, 5 insertions(+) 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 + } }