From 0e82acda2bab4c49716c4a86dde024393ee7b552 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 23 Jul 2020 13:45:20 -0700 Subject: [PATCH] Allow radial gradients to be evaluated with any nonzero discriminant, not just ones with magnitude above `EPSILON`. Closes #399. --- resources/shaders/gl3/d3d9/tile.fs.glsl | 4 +- resources/shaders/gl4/d3d11/tile.cs.glsl | 4 +- resources/shaders/gl4/d3d9/tile.fs.glsl | 4 +- resources/shaders/metal/d3d11/tile.cs.metal | 80 ++++++++++----------- resources/shaders/metal/d3d9/tile.fs.metal | 70 +++++++++--------- shaders/tile_fragment.inc.glsl | 4 +- 6 files changed, 79 insertions(+), 87 deletions(-) diff --git a/resources/shaders/gl3/d3d9/tile.fs.glsl b/resources/shaders/gl3/d3d9/tile.fs.glsl index ac4d8e9f..982ecd30 100644 --- a/resources/shaders/gl3/d3d9/tile.fs.glsl +++ b/resources/shaders/gl3/d3d9/tile.fs.glsl @@ -92,8 +92,6 @@ precision highp float; - - @@ -315,7 +313,7 @@ vec4 filterRadialGradient(vec2 colorTexCoord, float discrim = b * b - a * c; vec4 color = vec4(0.0); - if(abs(discrim)>= 0.00001){ + if(discrim != 0.0){ vec2 ts = vec2(sqrt(discrim)* vec2(1.0, - 1.0)+ vec2(b))/ vec2(a); if(ts . x > ts . y) ts = ts . yx; diff --git a/resources/shaders/gl4/d3d11/tile.cs.glsl b/resources/shaders/gl4/d3d11/tile.cs.glsl index c243eb71..09503d60 100644 --- a/resources/shaders/gl4/d3d11/tile.cs.glsl +++ b/resources/shaders/gl4/d3d11/tile.cs.glsl @@ -94,8 +94,6 @@ layout(local_size_x = 16, local_size_y = 4)in; - - @@ -317,7 +315,7 @@ vec4 filterRadialGradient(vec2 colorTexCoord, float discrim = b * b - a * c; vec4 color = vec4(0.0); - if(abs(discrim)>= 0.00001){ + if(discrim != 0.0){ vec2 ts = vec2(sqrt(discrim)* vec2(1.0, - 1.0)+ vec2(b))/ vec2(a); if(ts . x > ts . y) ts = ts . yx; diff --git a/resources/shaders/gl4/d3d9/tile.fs.glsl b/resources/shaders/gl4/d3d9/tile.fs.glsl index ac4d8e9f..982ecd30 100644 --- a/resources/shaders/gl4/d3d9/tile.fs.glsl +++ b/resources/shaders/gl4/d3d9/tile.fs.glsl @@ -92,8 +92,6 @@ precision highp float; - - @@ -315,7 +313,7 @@ vec4 filterRadialGradient(vec2 colorTexCoord, float discrim = b * b - a * c; vec4 color = vec4(0.0); - if(abs(discrim)>= 0.00001){ + if(discrim != 0.0){ vec2 ts = vec2(sqrt(discrim)* vec2(1.0, - 1.0)+ vec2(b))/ vec2(a); if(ts . x > ts . y) ts = ts . yx; diff --git a/resources/shaders/metal/d3d11/tile.cs.metal b/resources/shaders/metal/d3d11/tile.cs.metal index 2ea730e2..6817716b 100644 --- a/resources/shaders/metal/d3d11/tile.cs.metal +++ b/resources/shaders/metal/d3d11/tile.cs.metal @@ -18,7 +18,7 @@ struct bTiles constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(16u, 4u, 1u); -constant float3 _1151 = {}; +constant float3 _1149 = {}; // Implementation of the GLSL mod() function, which is slightly different than Metal fmod() template @@ -126,23 +126,23 @@ float4 filterRadialGradient(thread const float2& colorTexCoord, thread const tex float c = dot(dP, dP) - (radii.x * radii.x); float discrim = (b * b) - (a * c); float4 color = float4(0.0); - if (abs(discrim) >= 9.9999997473787516355514526367188e-06) + if (discrim != 0.0) { float2 ts = float2((float2(1.0, -1.0) * sqrt(discrim)) + float2(b)) / float2(a); if (ts.x > ts.y) { ts = ts.yx; } - float _611; + float _609; if (ts.x >= 0.0) { - _611 = ts.x; + _609 = ts.x; } else { - _611 = ts.y; + _609 = ts.y; } - float t = _611; + float t = _609; color = colorTexture.sample(colorTextureSmplr, (uvOrigin + float2(t, 0.0)), level(0.0)); } return color; @@ -156,19 +156,19 @@ float4 filterBlur(thread const float2& colorTexCoord, thread const texture2d uDestImage [[texture(0)]], texture2d uTextureMetadata [[texture(1)]], texture2d uColorTexture0 [[texture(2)]], texture2d uMaskTexture0 [[texture(3)]], texture2d 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]]) +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 uDestImage [[texture(0)]], texture2d uTextureMetadata [[texture(1)]], texture2d uColorTexture0 [[texture(2)]], texture2d uMaskTexture0 [[texture(3)]], texture2d 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]]) { int2 tileCoord = int2(gl_WorkGroupID.xy); int2 firstTileSubCoord = int2(gl_LocalInvocationID.xy) * int2(1, 4); int2 firstFragCoord = (tileCoord * int2(uTileSize)) + firstTileSubCoord; - int tileIndex = _1601.iFirstTileMap[tileCoord.x + (uFramebufferTileSize.x * tileCoord.y)]; + int tileIndex = _1599.iFirstTileMap[tileCoord.x + (uFramebufferTileSize.x * tileCoord.y)]; if ((tileIndex < 0) && (uLoadAction != 0)) { return; @@ -717,8 +717,8 @@ kernel void main0(constant int2& uFramebufferTileSize [[buffer(3)]], constant in { int2 tileSubCoord = firstTileSubCoord + int2(0, subY_1); float2 fragCoord = float2(firstFragCoord + int2(0, subY_1)) + float2(0.5); - int alphaTileIndex = int(_1692.iTiles[(tileIndex * 4) + 2] << uint(8)) >> 8; - uint tileControlWord = _1692.iTiles[(tileIndex * 4) + 3]; + int alphaTileIndex = int(_1690.iTiles[(tileIndex * 4) + 2] << uint(8)) >> 8; + uint tileControlWord = _1690.iTiles[(tileIndex * 4) + 3]; uint colorEntry = tileControlWord & 65535u; int tileCtrl = int((tileControlWord >> uint(16)) & 255u); if (alphaTileIndex >= 0) @@ -762,7 +762,7 @@ kernel void main0(constant int2& uFramebufferTileSize [[buffer(3)]], constant in 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); destColors[subY_1] = (destColors[subY_1] * (1.0 - srcColor.w)) + srcColor; } - tileIndex = int(_1692.iTiles[(tileIndex * 4) + 0]); + tileIndex = int(_1690.iTiles[(tileIndex * 4) + 0]); } for (int subY_2 = 0; subY_2 < 4; subY_2++) { diff --git a/resources/shaders/metal/d3d9/tile.fs.metal b/resources/shaders/metal/d3d9/tile.fs.metal index 618ddec2..f6fe79de 100644 --- a/resources/shaders/metal/d3d9/tile.fs.metal +++ b/resources/shaders/metal/d3d9/tile.fs.metal @@ -6,7 +6,7 @@ using namespace metal; -constant float3 _1123 = {}; +constant float3 _1121 = {}; struct main0_out { @@ -70,23 +70,23 @@ float4 filterRadialGradient(thread const float2& colorTexCoord, thread const tex float c = dot(dP, dP) - (radii.x * radii.x); float discrim = (b * b) - (a * c); float4 color = float4(0.0); - if (abs(discrim) >= 9.9999997473787516355514526367188e-06) + if (discrim != 0.0) { float2 ts = float2((float2(1.0, -1.0) * sqrt(discrim)) + float2(b)) / float2(a); if (ts.x > ts.y) { ts = ts.yx; } - float _583; + float _581; if (ts.x >= 0.0) { - _583 = ts.x; + _581 = ts.x; } else { - _583 = ts.y; + _581 = ts.y; } - float t = _583; + float t = _581; color = colorTexture.sample(colorTextureSmplr, (uvOrigin + float2(t, 0.0))); } return color; @@ -100,19 +100,19 @@ float4 filterBlur(thread const float2& colorTexCoord, thread const texture2d= EPSILON) { + if (discrim != 0.0) { vec2 ts = vec2(sqrt(discrim) * vec2(1.0, -1.0) + vec2(b)) / vec2(a); if (ts.x > ts.y) ts = ts.yx;