mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2024-12-22 02:53:50 +01:00
use different blending technique
This commit is contained in:
parent
fe39018b2c
commit
a5dcb91cf5
@ -3,27 +3,25 @@ uniform sampler2D tMatcap;
|
||||
uniform vec3 color;
|
||||
varying vec2 vNormal;
|
||||
|
||||
// color blending from https://www.w3.org/TR/compositing-1/#blendingcolor
|
||||
float lum(vec3 c) {
|
||||
return c.r * .3 + c.g * .59 + c.b * .11;
|
||||
vec4 screen(vec4 b, vec4 s) {
|
||||
return b + s - (b * s);
|
||||
}
|
||||
|
||||
vec3 clipColor(vec3 c) {
|
||||
float l = lum(c);
|
||||
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;
|
||||
vec4 multiply(vec4 b, vec4 s) {
|
||||
return b * s;
|
||||
}
|
||||
|
||||
vec3 setLum(vec3 c, float l) {
|
||||
float d = l - lum(c);
|
||||
return clipColor(c + d);
|
||||
// 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.);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 matcap = texture2D(tMatcap, vNormal);
|
||||
vec3 coloredMatcap = setLum(color, lum(matcap.rgb));
|
||||
gl_FragColor = vec4(coloredMatcap, opacity);
|
||||
vec4 coloredMatcap = hardLight(matcap, vec4(color, 1.));
|
||||
gl_FragColor = vec4(coloredMatcap.rgb, opacity);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user