Skip to content

Instantly share code, notes, and snippets.

@PLyczkowski
Created March 31, 2018 14:32
Show Gist options
  • Save PLyczkowski/f3cebca38c1184c9a56d9d06a0e6597c to your computer and use it in GitHub Desktop.
Save PLyczkowski/f3cebca38c1184c9a56d9d06a0e6597c to your computer and use it in GitHub Desktop.
shader_type spatial;
uniform vec4 tint : hint_color = vec4(1, 1, 1, 1);
uniform float specularity = 0;
uniform float metallic = 0;
uniform float roughness = 0;
uniform vec4 transmission : hint_color;
uniform sampler2D texture_1 : hint_albedo;
uniform float tex_1_opacity = 1;
uniform float tex_1_hue = 1;
uniform float tex_1_saturation = 1;
uniform float tex_1_light = 1;
uniform sampler2D texture_2 : hint_albedo;
uniform vec4 tex_2_tint : hint_color = vec4(1, 1, 1, 1);
uniform float tex_2_opacity = 1;
uniform float tex_2_hue = 1;
uniform float tex_2_saturation = 1;
uniform float tex_2_light = 1;
uniform sampler2D texture_3 : hint_albedo;
uniform float tex_3_opacity = 1;
uniform float tex_3_hue = 1;
uniform float tex_3_saturation = 1;
uniform float tex_3_light = 1;
uniform sampler2D texture_4 : hint_albedo;
uniform float tex_4_opacity = 1;
uniform float tex_4_hue = 1;
uniform float tex_4_saturation = 1;
uniform float tex_4_light = 1;
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);
}
void fragment() {
vec4 tex_1_appl = texture(texture_1, UV);
vec3 hsv = rgb2hsv(vec3(tex_1_appl.r, tex_1_appl.g, tex_1_appl.b));
hsv = vec3(hsv.x + tex_1_hue - 1.0, hsv.y + tex_1_saturation - 1.0 , hsv.z);
vec3 rgb = hsv2rgb(hsv);
tex_1_appl = vec4(rgb.r * tex_1_light, rgb.g * tex_1_light, rgb.b * tex_1_light, tex_1_appl.a);
vec4 tex_2_appl = texture(texture_2, UV);
tex_2_appl.rgb = tex_2_appl.rgb * tex_2_tint.rgb;
hsv = rgb2hsv(vec3(tex_2_appl.r, tex_2_appl.g, tex_2_appl.b));
hsv = vec3(hsv.x + tex_2_hue - 1.0, hsv.y + tex_2_saturation - 1.0 , hsv.z);
rgb = hsv2rgb(hsv);
tex_2_appl = vec4(rgb.r * tex_2_light, rgb.g * tex_2_light, rgb.b * tex_2_light, tex_2_appl.a);
vec4 tex_3_appl = texture(texture_3, UV);
hsv = rgb2hsv(vec3(tex_3_appl.r, tex_3_appl.g, tex_3_appl.b));
hsv = vec3(hsv.x + tex_3_hue - 1.0, hsv.y + tex_3_saturation - 1.0 , hsv.z);
rgb = hsv2rgb(hsv);
tex_3_appl = vec4(rgb.r * tex_3_light, rgb.g * tex_3_light, rgb.b * tex_3_light, tex_3_appl.a);
vec4 tex_4_appl = texture(texture_4, UV);
hsv = rgb2hsv(vec3(tex_4_appl.r, tex_4_appl.g, tex_4_appl.b));
hsv = vec3(hsv.x + tex_4_hue - 1.0, hsv.y + tex_4_saturation - 1.0 , hsv.z);
rgb = hsv2rgb(hsv);
tex_4_appl = vec4(rgb.r * tex_4_light, rgb.g * tex_4_light, rgb.b * tex_4_light, tex_4_appl.a);
vec4 textures = tex_1_appl;
textures = mix(textures, tex_2_appl, tex_2_appl.a * tex_2_opacity);
textures = mix(textures, tex_3_appl, tex_3_appl.a * tex_3_opacity);
textures = mix(textures, tex_4_appl, tex_4_appl.a * tex_4_opacity);
textures.rgb = textures.rgb * tint.rgb;
ALBEDO = textures.rgb;
ROUGHNESS = roughness;
METALLIC = metallic;
TRANSMISSION = transmission.rgb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment