@@ -13,18 +13,19 @@ vec3 colorBlendUniform(vec3 colA, vec3 colB, float h) {
1313 );
1414
1515 // rgb to cone (arg of pow can't be negative)
16- vec3 lmsA = pow (kCONEtoLMS* colA, vec3 (1.0 / 3.0 ));
17- vec3 lmsB = pow (kCONEtoLMS* colB, vec3 (1.0 / 3.0 ));
16+ const vec3 _1_3 = vec3 (1 .0f / 3 .0f);
17+ vec3 lmsA = pow (kCONEtoLMS* colA, _1_3);
18+ vec3 lmsB = pow (kCONEtoLMS* colB, _1_3);
1819 // lerp
1920 vec3 lms = mix (lmsA, lmsB, h);
2021 // gain in the middle (no oaklab anymore, but looks better?)
21- lms *= 1.0 + 0.2 * h * (1.0 - h);
22+ lms *= 1.0 + 0.2 * h * (1.0 - h);
2223 // cone to rgb
23- return kLMStoCONE* (lms* lms* lms);
24+ return kLMStoCONE * (lms * lms * lms);
2425}
2526
2627float weightedRatio(float n, float m) {
27- return 0.5 + 0.5 * (1 - min (n,m)/ max (max (n,m),1.175494e-38 )) * sign (m- n);
28+ return 0.5 + 0.5 * (1 - min (n,m) / max (max (n,m), 1.175494e-38 )) * sign (m- n);
2829}
2930
3031vec4 colorBlendWeightedAverage(vec4 [4 ] colorPoints) {
@@ -44,7 +45,7 @@ vec4 colorBlendWeightedUniform(vec4[4] colorPoints) {
4445 float alphaAvg = (
4546 colorPoints[0 ].a + colorPoints[1 ].a +
4647 colorPoints[2 ].a + colorPoints[3 ].a
47- ) / 4 ;
48+ ) * 0.25 ;
4849
4950 float aMix = weightedRatio(colorPoints[0 ].a, colorPoints[1 ].a);
5051 vec3 a = colorBlendUniform(colorPoints[0 ].rgb, colorPoints[1 ].rgb, aMix);
@@ -62,7 +63,7 @@ vec4 colorBlendAverage(vec4[4] colorPoints) {
6263 colorPoints[1 ] +
6364 colorPoints[2 ] +
6465 colorPoints[3 ]
65- ) / 4 ;
66+ ) * 0.25 ;
6667}
6768
6869vec4 colorBlendUniform(vec4 [4 ] colorPoints) {
@@ -75,23 +76,31 @@ vec4 colorBlendUniform(vec4[4] colorPoints) {
7576
7677#AREA FRAGMENT
7778vec4 [4 ] interpolatePixels(vec2 uv, vec2 uvMin, vec2 uvMax, texture2D tex, sampler sam) {
79+ // Get the size of the texture
7880 vec2 inverseTexSize = textureSize(sampler2D (tex, sam), 0 );
7981 vec2 texSize = 1 / inverseTexSize;
8082
8183 vec2 oldUv = uv;
8284
83- vec2 boxSize = (abs (dFdx (oldUv)) + abs (dFdy (oldUv))) * inverseTexSize * 0.8 ;
85+ // Get the size of the current pixel on the texture
86+ vec2 boxSize = (abs (dFdxCoarse(oldUv)) + abs (dFdyCoarse(oldUv))) * inverseTexSize * 0.8 ;
8487
88+ // Get the functional center for interpolation
8589 vec2 tx = oldUv * inverseTexSize - 0.5 * boxSize;
8690 vec2 tfract = fract (tx);
91+
92+ // Get the offset for the interpolation
8793 vec2 txOffset = smoothstep (1 - boxSize, vec2 (1 ), tfract);
8894
95+ // Get the minimum and maximum coordinates for sampling
8996 vec2 tmin = uvMin + 0.5 * texSize;
9097 vec2 tmax = uvMax - 0.5 * texSize;
9198
99+ // Clamp the texture coordinates and rescale it to the texture
92100 vec2 newUvMin = clamp ((tx - tfract + 0.5 ) * texSize, tmin, tmax);
93101 vec2 newUvMax = clamp ((tx - tfract + 0.5 + txOffset) * texSize, tmin, tmax);
94102
103+ // Sample the colors
95104 vec4 [4 ] sampledColors = {
96105 texture(sampler2D (tex, sam), newUvMin),
97106 texture(sampler2D (tex, sam), newUvMax),
@@ -101,4 +110,4 @@ vec4[4] interpolatePixels(vec2 uv, vec2 uvMin, vec2 uvMax, texture2D tex, sample
101110 return sampledColors;
102111}
103112
104- #END
113+ #END
0 commit comments