Skip to content

Instantly share code, notes, and snippets.

@lucasteles
Created May 13, 2025 23:04
Show Gist options
  • Save lucasteles/ba9375e5af2fd4dac327305a662e205a to your computer and use it in GitHub Desktop.
Save lucasteles/ba9375e5af2fd4dac327305a662e205a to your computer and use it in GitHub Desktop.
Godot ArcSys Style Shader
// author: @ijiru_masu
shader_type spatial;
uniform float specularThreshold : hint_range(0,1) = 0.5;
uniform float lightThreshold : hint_range(0,1) = 0.1;
uniform sampler2D BASE: source_color;
uniform sampler2D SSS: source_color;
uniform sampler2D ILM;
uniform sampler2D DETAIL: source_color;
varying vec4 vertexColor;
// Takes the linear texture values and turns them to a float greyscale
float to_greyScale(vec3 Color) {
return (Color.x + Color.y + Color.z) / 3.0;
}
// Blend mode for 'Color Burn'
vec3 colorBurn(vec3 BASE_BLEND, vec3 BLEND) {
vec3 RESULT;
for (int i = 0; i <= 2; i++)
if (BASE_BLEND[i] < .0001) {
RESULT[i] = 0.0;
} else {
RESULT[i] = 1.0 - ((1.0- BASE_BLEND[i])/BLEND[i]);
}
return RESULT;
}
vec3 screen(vec3 BASE_BLEND, vec3 BLEND) {
vec3 RESULT;
for (int i = 0; i <= 2; i++)
RESULT = 1.0 -(BLEND - 1.0) * (BASE_BLEND - 1.0);
return RESULT;
}
vec3 linearDodge(vec3 BASE_BLEND, vec3 BLEND) {
vec3 RESULT;
for (int i = 0; i <= 2; i++)
if (BASE_BLEND[i] + BLEND[i] > 1.0) {
RESULT[i] = 1.0;
} else {
RESULT[i] = BASE_BLEND[i] + BLEND[i];
}
return RESULT;
}
float invert(float color) {
color = 1.0 - color;
return color;
}
// This is a self lit shader, any other lights will influence the shader
void vertex() {
vertexColor = COLOR;
}
void light() {
// initialize textures
vec4 baseColor = texture(BASE, UV);
vec4 sssColor = texture(SSS, UV);
vec4 ILM_Color = texture(ILM, UV);
vec4 DETAIL_Color = texture(DETAIL, UV2);
// The 3 lighting models used in this shader; PHONG, BLINN PHONG, FRESNEL(?)
float NDotL = dot(NORMAL,LIGHT);
float NDotHV = clamp(dot(NORMAL, normalize(VIEW + LIGHT)), 0.0, 1.0);
float NDotV = dot(NORMAL, VIEW);
vec3 shadow2 = sssColor.rgb * sssColor.rgb;
float modifiedVertexColor_R = (vertexColor.r > .75) ? 1.0 : 0.0;
float roundedVertexColor_R = (vertexColor.r > .8) ? 1.0 : 0.0;
float ModifiedNDotL = vertexColor.r * NDotL;
ModifiedNDotL = ModifiedNDotL * modifiedVertexColor_R;
float ModifiedILM_G = (ILM_Color.y > .25) ? 1.0 : 0.0;
ModifiedNDotL = ModifiedNDotL * ModifiedILM_G;
float sunControl = lightThreshold * ILM_Color.y;
float result = (ModifiedNDotL < sunControl) ? 1.0 : 0.0;
vec3 lightMask = vec3(result);
vec3 shadowFresnel = (vec3(sssColor.a) * (1.0 - NDotV));
vec3 lightFresnel = vec3(baseColor.a) * NDotV;
float specularMask = to_greyScale(colorBurn(vec3(NDotHV), vec3(ILM_Color.z)));
specularMask = invert(specularMask);
specularMask = (specularMask < specularThreshold) ? 1.0 : 0.0;
vec3 specularColorCreation = screen(baseColor.rgb,vec3(.5)) * vec3(ILM_Color.x);
vec3 specularResult = linearDodge(baseColor.rgb, specularColorCreation);
vec3 finalLightColor = mix(baseColor.rgb, screen(baseColor.rgb, baseColor.rgb), lightFresnel);
finalLightColor = mix(finalLightColor, specularResult.rgb, specularMask);
vec3 finalShadowColor = mix(sssColor.rgb, shadow2, shadowFresnel);
vec3 finalColor = mix(finalLightColor, finalShadowColor, lightMask);
finalColor = mix(shadow2, finalColor, roundedVertexColor_R);
finalColor = finalColor * ILM_Color.w;
finalColor = finalColor * DETAIL_Color.rgb;
DIFFUSE_LIGHT = finalColor;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment