Skip to content

Commit a05270f

Browse files
authored
Auto merge of #414 - pcwalton:radial-gradient-epsilon, r=pcwalton
Allow radial gradients to be evaluated with any nonzero discriminant, not just ones with magnitude above `EPSILON`. Closes #399.
2 parents 536cb4c + 0e82acd commit a05270f

File tree

6 files changed

+79
-87
lines changed

6 files changed

+79
-87
lines changed

resources/shaders/gl3/d3d9/tile.fs.glsl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ precision highp float;
9292

9393

9494

95-
96-
9795

9896

9997

@@ -315,7 +313,7 @@ vec4 filterRadialGradient(vec2 colorTexCoord,
315313
float discrim = b * b - a * c;
316314

317315
vec4 color = vec4(0.0);
318-
if(abs(discrim)>= 0.00001){
316+
if(discrim != 0.0){
319317
vec2 ts = vec2(sqrt(discrim)* vec2(1.0, - 1.0)+ vec2(b))/ vec2(a);
320318
if(ts . x > ts . y)
321319
ts = ts . yx;

resources/shaders/gl4/d3d11/tile.cs.glsl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ layout(local_size_x = 16, local_size_y = 4)in;
9494

9595

9696

97-
98-
9997

10098

10199

@@ -317,7 +315,7 @@ vec4 filterRadialGradient(vec2 colorTexCoord,
317315
float discrim = b * b - a * c;
318316

319317
vec4 color = vec4(0.0);
320-
if(abs(discrim)>= 0.00001){
318+
if(discrim != 0.0){
321319
vec2 ts = vec2(sqrt(discrim)* vec2(1.0, - 1.0)+ vec2(b))/ vec2(a);
322320
if(ts . x > ts . y)
323321
ts = ts . yx;

resources/shaders/gl4/d3d9/tile.fs.glsl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ precision highp float;
9292

9393

9494

95-
96-
9795

9896

9997

@@ -315,7 +313,7 @@ vec4 filterRadialGradient(vec2 colorTexCoord,
315313
float discrim = b * b - a * c;
316314

317315
vec4 color = vec4(0.0);
318-
if(abs(discrim)>= 0.00001){
316+
if(discrim != 0.0){
319317
vec2 ts = vec2(sqrt(discrim)* vec2(1.0, - 1.0)+ vec2(b))/ vec2(a);
320318
if(ts . x > ts . y)
321319
ts = ts . yx;

resources/shaders/metal/d3d11/tile.cs.metal

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct bTiles
1818

1919
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(16u, 4u, 1u);
2020

21-
constant float3 _1151 = {};
21+
constant float3 _1149 = {};
2222

2323
// Implementation of the GLSL mod() function, which is slightly different than Metal fmod()
2424
template<typename Tx, typename Ty>
@@ -126,23 +126,23 @@ float4 filterRadialGradient(thread const float2& colorTexCoord, thread const tex
126126
float c = dot(dP, dP) - (radii.x * radii.x);
127127
float discrim = (b * b) - (a * c);
128128
float4 color = float4(0.0);
129-
if (abs(discrim) >= 9.9999997473787516355514526367188e-06)
129+
if (discrim != 0.0)
130130
{
131131
float2 ts = float2((float2(1.0, -1.0) * sqrt(discrim)) + float2(b)) / float2(a);
132132
if (ts.x > ts.y)
133133
{
134134
ts = ts.yx;
135135
}
136-
float _611;
136+
float _609;
137137
if (ts.x >= 0.0)
138138
{
139-
_611 = ts.x;
139+
_609 = ts.x;
140140
}
141141
else
142142
{
143-
_611 = ts.y;
143+
_609 = ts.y;
144144
}
145-
float t = _611;
145+
float t = _609;
146146
color = colorTexture.sample(colorTextureSmplr, (uvOrigin + float2(t, 0.0)), level(0.0));
147147
}
148148
return color;
@@ -156,19 +156,19 @@ float4 filterBlur(thread const float2& colorTexCoord, thread const texture2d<flo
156156
float3 gaussCoeff = filterParams1.xyz;
157157
float gaussSum = gaussCoeff.x;
158158
float4 color = colorTexture.sample(colorTextureSmplr, colorTexCoord, level(0.0)) * gaussCoeff.x;
159-
float2 _655 = gaussCoeff.xy * gaussCoeff.yz;
160-
gaussCoeff = float3(_655.x, _655.y, gaussCoeff.z);
159+
float2 _653 = gaussCoeff.xy * gaussCoeff.yz;
160+
gaussCoeff = float3(_653.x, _653.y, gaussCoeff.z);
161161
for (int i = 1; i <= support; i += 2)
162162
{
163163
float gaussPartialSum = gaussCoeff.x;
164-
float2 _675 = gaussCoeff.xy * gaussCoeff.yz;
165-
gaussCoeff = float3(_675.x, _675.y, gaussCoeff.z);
164+
float2 _673 = gaussCoeff.xy * gaussCoeff.yz;
165+
gaussCoeff = float3(_673.x, _673.y, gaussCoeff.z);
166166
gaussPartialSum += gaussCoeff.x;
167167
float2 srcOffset = srcOffsetScale * (float(i) + (gaussCoeff.x / gaussPartialSum));
168168
color += ((colorTexture.sample(colorTextureSmplr, (colorTexCoord - srcOffset), level(0.0)) + colorTexture.sample(colorTextureSmplr, (colorTexCoord + srcOffset), level(0.0))) * gaussPartialSum);
169169
gaussSum += (2.0 * gaussPartialSum);
170-
float2 _715 = gaussCoeff.xy * gaussCoeff.yz;
171-
gaussCoeff = float3(_715.x, _715.y, gaussCoeff.z);
170+
float2 _713 = gaussCoeff.xy * gaussCoeff.yz;
171+
gaussCoeff = float3(_713.x, _713.y, gaussCoeff.z);
172172
}
173173
return color / float4(gaussSum);
174174
}
@@ -389,34 +389,34 @@ float3 compositeScreen(thread const float3& destColor, thread const float3& srcC
389389
static inline __attribute__((always_inline))
390390
float3 compositeSelect(thread const bool3& cond, thread const float3& ifTrue, thread const float3& ifFalse)
391391
{
392-
float _835;
392+
float _833;
393393
if (cond.x)
394394
{
395-
_835 = ifTrue.x;
395+
_833 = ifTrue.x;
396396
}
397397
else
398398
{
399-
_835 = ifFalse.x;
399+
_833 = ifFalse.x;
400400
}
401-
float _846;
401+
float _844;
402402
if (cond.y)
403403
{
404-
_846 = ifTrue.y;
404+
_844 = ifTrue.y;
405405
}
406406
else
407407
{
408-
_846 = ifFalse.y;
408+
_844 = ifFalse.y;
409409
}
410-
float _857;
410+
float _855;
411411
if (cond.z)
412412
{
413-
_857 = ifTrue.z;
413+
_855 = ifTrue.z;
414414
}
415415
else
416416
{
417-
_857 = ifFalse.z;
417+
_855 = ifFalse.z;
418418
}
419-
return float3(_835, _846, _857);
419+
return float3(_833, _844, _855);
420420
}
421421

422422
static inline __attribute__((always_inline))
@@ -461,16 +461,16 @@ float3 compositeSoftLight(thread const float3& destColor, thread const float3& s
461461
static inline __attribute__((always_inline))
462462
float compositeDivide(thread const float& num, thread const float& denom)
463463
{
464-
float _871;
464+
float _869;
465465
if (denom != 0.0)
466466
{
467-
_871 = num / denom;
467+
_869 = num / denom;
468468
}
469469
else
470470
{
471-
_871 = 0.0;
471+
_869 = 0.0;
472472
}
473-
return _871;
473+
return _869;
474474
}
475475

476476
static inline __attribute__((always_inline))
@@ -480,25 +480,25 @@ float3 compositeRGBToHSL(thread const float3& rgb)
480480
float xMin = fast::min(fast::min(rgb.x, rgb.y), rgb.z);
481481
float c = v - xMin;
482482
float l = mix(xMin, v, 0.5);
483-
float3 _977;
483+
float3 _975;
484484
if (rgb.x == v)
485485
{
486-
_977 = float3(0.0, rgb.yz);
486+
_975 = float3(0.0, rgb.yz);
487487
}
488488
else
489489
{
490-
float3 _990;
490+
float3 _988;
491491
if (rgb.y == v)
492492
{
493-
_990 = float3(2.0, rgb.zx);
493+
_988 = float3(2.0, rgb.zx);
494494
}
495495
else
496496
{
497-
_990 = float3(4.0, rgb.xy);
497+
_988 = float3(4.0, rgb.xy);
498498
}
499-
_977 = _990;
499+
_975 = _988;
500500
}
501-
float3 terms = _977;
501+
float3 terms = _975;
502502
float param = ((terms.x * c) + terms.y) - terms.z;
503503
float param_1 = c;
504504
float h = 1.0471975803375244140625 * compositeDivide(param, param_1);
@@ -672,17 +672,17 @@ float4 calculateColor(thread const float2& fragCoord, thread const texture2d<flo
672672
float2 param_19 = fragCoord;
673673
int param_20 = compositeOp;
674674
color = composite(param_17, destTexture, destTextureSmplr, param_18, param_19, param_20);
675-
float3 _1437 = color.xyz * color.w;
676-
color = float4(_1437.x, _1437.y, _1437.z, color.w);
675+
float3 _1435 = color.xyz * color.w;
676+
color = float4(_1435.x, _1435.y, _1435.z, color.w);
677677
return color;
678678
}
679679

680-
kernel void main0(constant int2& uFramebufferTileSize [[buffer(3)]], constant int& uLoadAction [[buffer(4)]], constant int2& uTextureMetadataSize [[buffer(7)]], constant float2& uFramebufferSize [[buffer(0)]], constant float2& uTileSize [[buffer(1)]], constant float4& uClearColor [[buffer(5)]], constant float2& uColorTextureSize0 [[buffer(8)]], constant float2& uMaskTextureSize0 [[buffer(9)]], const device bFirstTileMap& _1601 [[buffer(2)]], const device bTiles& _1692 [[buffer(6)]], texture2d<float, access::read_write> uDestImage [[texture(0)]], texture2d<float> uTextureMetadata [[texture(1)]], texture2d<float> uColorTexture0 [[texture(2)]], texture2d<float> uMaskTexture0 [[texture(3)]], texture2d<float> uGammaLUT [[texture(4)]], sampler uTextureMetadataSmplr [[sampler(0)]], sampler uColorTexture0Smplr [[sampler(1)]], sampler uMaskTexture0Smplr [[sampler(2)]], sampler uGammaLUTSmplr [[sampler(3)]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]])
680+
kernel void main0(constant int2& uFramebufferTileSize [[buffer(3)]], constant int& uLoadAction [[buffer(4)]], constant int2& uTextureMetadataSize [[buffer(7)]], constant float2& uFramebufferSize [[buffer(0)]], constant float2& uTileSize [[buffer(1)]], constant float4& uClearColor [[buffer(5)]], constant float2& uColorTextureSize0 [[buffer(8)]], constant float2& uMaskTextureSize0 [[buffer(9)]], const device bFirstTileMap& _1599 [[buffer(2)]], const device bTiles& _1690 [[buffer(6)]], texture2d<float, access::read_write> uDestImage [[texture(0)]], texture2d<float> uTextureMetadata [[texture(1)]], texture2d<float> uColorTexture0 [[texture(2)]], texture2d<float> uMaskTexture0 [[texture(3)]], texture2d<float> uGammaLUT [[texture(4)]], sampler uTextureMetadataSmplr [[sampler(0)]], sampler uColorTexture0Smplr [[sampler(1)]], sampler uMaskTexture0Smplr [[sampler(2)]], sampler uGammaLUTSmplr [[sampler(3)]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]])
681681
{
682682
int2 tileCoord = int2(gl_WorkGroupID.xy);
683683
int2 firstTileSubCoord = int2(gl_LocalInvocationID.xy) * int2(1, 4);
684684
int2 firstFragCoord = (tileCoord * int2(uTileSize)) + firstTileSubCoord;
685-
int tileIndex = _1601.iFirstTileMap[tileCoord.x + (uFramebufferTileSize.x * tileCoord.y)];
685+
int tileIndex = _1599.iFirstTileMap[tileCoord.x + (uFramebufferTileSize.x * tileCoord.y)];
686686
if ((tileIndex < 0) && (uLoadAction != 0))
687687
{
688688
return;
@@ -717,8 +717,8 @@ kernel void main0(constant int2& uFramebufferTileSize [[buffer(3)]], constant in
717717
{
718718
int2 tileSubCoord = firstTileSubCoord + int2(0, subY_1);
719719
float2 fragCoord = float2(firstFragCoord + int2(0, subY_1)) + float2(0.5);
720-
int alphaTileIndex = int(_1692.iTiles[(tileIndex * 4) + 2] << uint(8)) >> 8;
721-
uint tileControlWord = _1692.iTiles[(tileIndex * 4) + 3];
720+
int alphaTileIndex = int(_1690.iTiles[(tileIndex * 4) + 2] << uint(8)) >> 8;
721+
uint tileControlWord = _1690.iTiles[(tileIndex * 4) + 3];
722722
uint colorEntry = tileControlWord & 65535u;
723723
int tileCtrl = int((tileControlWord >> uint(16)) & 255u);
724724
if (alphaTileIndex >= 0)
@@ -762,7 +762,7 @@ kernel void main0(constant int2& uFramebufferTileSize [[buffer(3)]], constant in
762762
float4 srcColor = calculateColor(param_12, uColorTexture0, uColorTexture0Smplr, uMaskTexture0, uMaskTexture0Smplr, uColorTexture0, uColorTexture0Smplr, uGammaLUT, uGammaLUTSmplr, param_13, param_14, param_15, param_16, param_17, param_18, param_19, param_20, param_21, param_22, param_23, param_24, param_25);
763763
destColors[subY_1] = (destColors[subY_1] * (1.0 - srcColor.w)) + srcColor;
764764
}
765-
tileIndex = int(_1692.iTiles[(tileIndex * 4) + 0]);
765+
tileIndex = int(_1690.iTiles[(tileIndex * 4) + 0]);
766766
}
767767
for (int subY_2 = 0; subY_2 < 4; subY_2++)
768768
{

0 commit comments

Comments
 (0)