|
|
// MMJ's 4-in-1 Shader - v1.10
|
//
|
// Shader Level settings will change the "mode" used
|
//
|
// 1 - Pencil Mode
|
// 2 - Chalk & Charcoal mode
|
// 3 - 1/2 Strength Normal mode
|
// 4 - Full Strength Normal mode
|
//
|
// -----------
|
// MegaManJuno
|
|
uniform sampler2D OGL2Texture;
|
uniform vec4 OGL2Param;
|
|
vec3 colorAdjust(in vec3 cRGB, in float L) {
|
// absolute white level cutoff
|
float aw = 0.97; // default: 0.97
|
|
// absolute black level cutoff
|
float ab = 0.03; // default: 0.03
|
|
// number of shading levels (not counting absolute white and black levels)
|
float sl = 7.0; // default: 7.0
|
|
// color range per shading level
|
float cr = 1.0 / sl; // default: 1.0 / sl
|
|
// brightness modifier
|
float ml = mod(L, cr); // default: mod(L, cr)
|
|
float L2 = 0.0;
|
|
float cs = float(int(L / cr)); float cn = cs * cr; float cx = cn + cr;
|
|
// normal modes
|
if(OGL2Param.z > 1.0) {
|
if (L > aw) { L2 = 1.0; }
|
else if(L > ab) { L2 = clamp(L + (((L / cx) * cr) - ml), cn, cx); }
|
else { L2 = 0.0; }
|
cRGB += vec3(L2 - L);
|
|
} else {
|
// Pencil mode
|
if(OGL2Param.z == 0.0) {
|
if (L > aw) { L2 = 1.0; }
|
else if(L > ab) { L2 = clamp(L + ((((L / cx) * cr) - ml)), cn, cx) + 0.1; }
|
else { L2 = 0.1; }
|
|
// Chalk & Charcoal mode
|
} else {
|
if (L > aw) { L2 = 0.9; }
|
else if(L > ab) { L2 = clamp(L + ((((L / cx) * cr) - ml)), cn, cx); }
|
else { L2 = 0.0; }
|
}
|
cRGB = vec3(L2);
|
}
|
return cRGB;
|
}
|
|
void main(void) {
|
vec3 c0 = texture2D(OGL2Texture, gl_TexCoord[3].xy).rgb;
|
vec3 c1 = texture2D(OGL2Texture, gl_TexCoord[2].xy).rgb;
|
vec3 c2 = texture2D(OGL2Texture, gl_TexCoord[3].zy).rgb;
|
vec3 c3 = texture2D(OGL2Texture, gl_TexCoord[1].xy).rgb;
|
vec3 c4 = texture2D(OGL2Texture, gl_TexCoord[0].xy).rgb;
|
vec3 c5 = texture2D(OGL2Texture, gl_TexCoord[1].zw).rgb;
|
vec3 c6 = texture2D(OGL2Texture, gl_TexCoord[3].xw).rgb;
|
vec3 c7 = texture2D(OGL2Texture, gl_TexCoord[2].zw).rgb;
|
vec3 c8 = texture2D(OGL2Texture, gl_TexCoord[3].zw).rgb;
|
vec3 c9 = ((c0 + c2 + c6 + c8) * 0.5 + (c1 + c3 + c5 + c7) * 0.75 + c4) / 6.0;
|
|
float L0 = sqrt(0.241 * pow(c0.r, 2.0) + 0.691 * pow(c0.g, 2.0) + 0.068 * pow(c0.b, 2.0));
|
float L1 = sqrt(0.241 * pow(c1.r, 2.0) + 0.691 * pow(c1.g, 2.0) + 0.068 * pow(c1.b, 2.0));
|
float L2 = sqrt(0.241 * pow(c2.r, 2.0) + 0.691 * pow(c2.g, 2.0) + 0.068 * pow(c2.b, 2.0));
|
float L3 = sqrt(0.241 * pow(c3.r, 2.0) + 0.691 * pow(c3.g, 2.0) + 0.068 * pow(c3.b, 2.0));
|
float L5 = sqrt(0.241 * pow(c5.r, 2.0) + 0.691 * pow(c5.g, 2.0) + 0.068 * pow(c5.b, 2.0));
|
float L6 = sqrt(0.241 * pow(c6.r, 2.0) + 0.691 * pow(c6.g, 2.0) + 0.068 * pow(c6.b, 2.0));
|
float L7 = sqrt(0.241 * pow(c7.r, 2.0) + 0.691 * pow(c7.g, 2.0) + 0.068 * pow(c7.b, 2.0));
|
float L8 = sqrt(0.241 * pow(c8.r, 2.0) + 0.691 * pow(c8.g, 2.0) + 0.068 * pow(c8.b, 2.0));
|
float L9 = sqrt(0.241 * pow(c9.r, 2.0) + 0.691 * pow(c9.g, 2.0) + 0.068 * pow(c9.b, 2.0));
|
|
float LV = 0.0;
|
|
float d1 = abs(L0 - L8); float d2 = abs(L1 - L7);
|
float d3 = abs(L2 - L6); float d4 = abs(L3 - L5);
|
|
float d = (d1 + d2 + d3 + d4) * 0.25;
|
|
if(OGL2Param.z == 1.0) { LV = clamp(L9 + d, 0.0, 1.0); }
|
else { LV = clamp(L9 - d, 0.0, 1.0); }
|
|
c9 = colorAdjust(c9, L9) + vec3(LV - L9);
|
|
if(OGL2Param.z > 1.0) {
|
// 1/2 Normal mode
|
if(OGL2Param.z == 2.0) { gl_FragColor.rgb = mix(c4, c9, 0.5); }
|
|
// Full Normal mode
|
else { gl_FragColor.rgb = c9; }
|
|
} else {
|
// Pencil Mode
|
if(OGL2Param.z == 0.0) { if(c9.g < 0.1) { c9.rgb = vec3(0.1); } gl_FragColor.rgb = c9; }
|
|
// Chalk & Charcoal mode
|
else { if(c9.g > 0.9) { c9.rgb = vec3(0.9); } gl_FragColor.rgb = c9; }
|
}
|
}
|
|