Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -215,6 +218,7 @@ MaterialDef PBR Lighting {
FOG_LINEAR : LinearFog
FOG_EXP : ExpFog
FOG_EXPSQ : ExpSqFog
HSV_OFFSET : HSVOffset
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -89,6 +92,7 @@ MaterialDef Unshaded {
NUM_MORPH_TARGETS: NumberOfMorphTargets
NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers
DESATURATION : DesaturationValue
HSV_OFFSET : HSVOffset
}
}

Expand Down
30 changes: 30 additions & 0 deletions jme3-core/src/main/resources/Common/ShaderLib/HSVUtils.glsllib
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
Loading