Doodle3D-Core/shaders/matcap_frag.glsl

28 lines
578 B
Plaintext
Raw Normal View History

2017-11-23 17:29:56 +01:00
uniform float opacity;
uniform sampler2D tMatcap;
uniform vec3 color;
varying vec2 vNormal;
2017-11-24 06:11:50 +01:00
vec4 screen(vec4 b, vec4 s) {
return b + s - (b * s);
2017-11-23 17:29:56 +01:00
}
2017-11-24 06:11:50 +01:00
vec4 multiply(vec4 b, vec4 s) {
return b * s;
2017-11-23 17:29:56 +01:00
}
2017-11-24 06:11:50 +01:00
// source https://www.w3.org/TR/compositing-1/#blendingdarken
vec4 hardLight(vec4 b, vec4 s) {
if (length(s) < .5) {
return multiply(b, 2. * s);
} else {
return screen(b, 2. * s - 1.);
}
2017-11-23 17:29:56 +01:00
}
void main() {
vec4 matcap = texture2D(tMatcap, vNormal);
2017-11-24 06:11:50 +01:00
vec4 coloredMatcap = hardLight(matcap, vec4(color, 1.));
gl_FragColor = vec4(coloredMatcap.rgb, opacity);
2017-11-23 17:29:56 +01:00
}