use different blending technique

This commit is contained in:
casperlamboo 2017-11-24 06:11:50 +01:00
parent fe39018b2c
commit a5dcb91cf5

View File

@ -3,27 +3,25 @@ uniform sampler2D tMatcap;
uniform vec3 color; uniform vec3 color;
varying vec2 vNormal; varying vec2 vNormal;
// color blending from https://www.w3.org/TR/compositing-1/#blendingcolor vec4 screen(vec4 b, vec4 s) {
float lum(vec3 c) { return b + s - (b * s);
return c.r * .3 + c.g * .59 + c.b * .11;
} }
vec3 clipColor(vec3 c) { vec4 multiply(vec4 b, vec4 s) {
float l = lum(c); return b * s;
float n = min(min(c.r, c.g), c.b);
float x = max(max(c.r, c.g), c.b);
if (n < 0.) c = l + (((c - l) * l) / (l - n));
if (x > 1.) c = l + (((c - l) * (1. - l)) / (x - l));
return c;
} }
vec3 setLum(vec3 c, float l) { // source https://www.w3.org/TR/compositing-1/#blendingdarken
float d = l - lum(c); vec4 hardLight(vec4 b, vec4 s) {
return clipColor(c + d); if (length(s) < .5) {
return multiply(b, 2. * s);
} else {
return screen(b, 2. * s - 1.);
}
} }
void main() { void main() {
vec4 matcap = texture2D(tMatcap, vNormal); vec4 matcap = texture2D(tMatcap, vNormal);
vec3 coloredMatcap = setLum(color, lum(matcap.rgb)); vec4 coloredMatcap = hardLight(matcap, vec4(color, 1.));
gl_FragColor = vec4(coloredMatcap, opacity); gl_FragColor = vec4(coloredMatcap.rgb, opacity);
} }