mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-25 08:51:32 +11:00
Merge pull request #341 from nfp0/handheld-border-lcd-shaders-scaling-parameter
Restricted shader processing to the game screen area, fixing blurry cutoff point
This commit is contained in:
commit
1879db0e5d
|
@ -95,46 +95,53 @@ float intsmear(float x, float dx, float d, float coeffs[7])
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 texelSize = global.SourceSize.zw;
|
if(abs(vTexCoord.x - 0.5) < 0.5 && abs(vTexCoord.y - 0.5) < 0.5)
|
||||||
/* float2 range = IN.video_size / (IN.output_size * IN.texture_size); */
|
{
|
||||||
vec2 range = global.SourceSize.zw / screen_scale;
|
vec2 texelSize = global.SourceSize.zw;
|
||||||
|
/* float2 range = IN.video_size / (IN.output_size * IN.texture_size); */
|
||||||
|
vec2 range = global.SourceSize.zw / screen_scale;
|
||||||
|
|
||||||
vec3 cred = pow(vec3(params.RSUBPIX_R, params.RSUBPIX_G, params.RSUBPIX_B), vec3(outgamma));
|
vec3 cred = pow(vec3(params.RSUBPIX_R, params.RSUBPIX_G, params.RSUBPIX_B), vec3(outgamma));
|
||||||
vec3 cgreen = pow(vec3(params.GSUBPIX_R, params.GSUBPIX_G, params.GSUBPIX_B), vec3(outgamma));
|
vec3 cgreen = pow(vec3(params.GSUBPIX_R, params.GSUBPIX_G, params.GSUBPIX_B), vec3(outgamma));
|
||||||
vec3 cblue = pow(vec3(params.BSUBPIX_R, params.BSUBPIX_G, params.BSUBPIX_B), vec3(outgamma));
|
vec3 cblue = pow(vec3(params.BSUBPIX_R, params.BSUBPIX_G, params.BSUBPIX_B), vec3(outgamma));
|
||||||
|
|
||||||
ivec2 tli = ivec2(floor(vTexCoord/texelSize-vec2(0.4999)));
|
ivec2 tli = ivec2(floor(vTexCoord/texelSize-vec2(0.4999)));
|
||||||
|
|
||||||
vec3 lcol, rcol;
|
vec3 lcol, rcol;
|
||||||
float subpix = (vTexCoord.x/texelSize.x - 0.4999 - float(tli.x))*3.0;
|
float subpix = (vTexCoord.x/texelSize.x - 0.4999 - float(tli.x))*3.0;
|
||||||
float rsubpix = range.x/texelSize.x * 3.0;
|
float rsubpix = range.x/texelSize.x * 3.0;
|
||||||
|
|
||||||
lcol = vec3(intsmear(subpix+1.0, rsubpix, 1.5, coeffs_x),
|
lcol = vec3(intsmear(subpix+1.0, rsubpix, 1.5, coeffs_x),
|
||||||
intsmear(subpix , rsubpix, 1.5, coeffs_x),
|
intsmear(subpix , rsubpix, 1.5, coeffs_x),
|
||||||
intsmear(subpix-1.0, rsubpix, 1.5, coeffs_x));
|
intsmear(subpix-1.0, rsubpix, 1.5, coeffs_x));
|
||||||
rcol = vec3(intsmear(subpix-2.0, rsubpix, 1.5, coeffs_x),
|
rcol = vec3(intsmear(subpix-2.0, rsubpix, 1.5, coeffs_x),
|
||||||
intsmear(subpix-3.0, rsubpix, 1.5, coeffs_x),
|
intsmear(subpix-3.0, rsubpix, 1.5, coeffs_x),
|
||||||
intsmear(subpix-4.0, rsubpix, 1.5, coeffs_x));
|
intsmear(subpix-4.0, rsubpix, 1.5, coeffs_x));
|
||||||
|
|
||||||
if (params.BGR > 0.5) {
|
if (params.BGR > 0.5) {
|
||||||
lcol.rgb = lcol.bgr;
|
lcol.rgb = lcol.bgr;
|
||||||
rcol.rgb = rcol.bgr;
|
rcol.rgb = rcol.bgr;
|
||||||
|
}
|
||||||
|
|
||||||
|
float tcol, bcol;
|
||||||
|
subpix = vTexCoord.y/texelSize.y - 0.4999 - float(tli.y);
|
||||||
|
rsubpix = range.y/texelSize.y;
|
||||||
|
tcol = intsmear(subpix ,rsubpix, 0.63, coeffs_y);
|
||||||
|
bcol = intsmear(subpix-1.0,rsubpix, 0.63, coeffs_y);
|
||||||
|
|
||||||
|
vec3 topLeftColor = fetch_offset(tli, ivec2(0,0)) * lcol * vec3(tcol);
|
||||||
|
vec3 bottomRightColor = fetch_offset(tli, ivec2(1,1)) * rcol * vec3(bcol);
|
||||||
|
vec3 bottomLeftColor = fetch_offset(tli, ivec2(0,1)) * lcol * vec3(bcol);
|
||||||
|
vec3 topRightColor = fetch_offset(tli, ivec2(1,0)) * rcol * vec3(tcol);
|
||||||
|
|
||||||
|
vec3 averageColor = topLeftColor + bottomRightColor + bottomLeftColor + topRightColor;
|
||||||
|
|
||||||
|
averageColor = mat3(cred, cgreen, cblue) * averageColor;
|
||||||
|
|
||||||
|
FragColor = vec4(pow(averageColor, vec3(1.0/outgamma)),0.0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FragColor = vec4(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
float tcol, bcol;
|
|
||||||
subpix = vTexCoord.y/texelSize.y - 0.4999 - float(tli.y);
|
|
||||||
rsubpix = range.y/texelSize.y;
|
|
||||||
tcol = intsmear(subpix ,rsubpix, 0.63, coeffs_y);
|
|
||||||
bcol = intsmear(subpix-1.0,rsubpix, 0.63, coeffs_y);
|
|
||||||
|
|
||||||
vec3 topLeftColor = fetch_offset(tli, ivec2(0,0)) * lcol * vec3(tcol);
|
|
||||||
vec3 bottomRightColor = fetch_offset(tli, ivec2(1,1)) * rcol * vec3(bcol);
|
|
||||||
vec3 bottomLeftColor = fetch_offset(tli, ivec2(0,1)) * lcol * vec3(bcol);
|
|
||||||
vec3 topRightColor = fetch_offset(tli, ivec2(1,0)) * rcol * vec3(tcol);
|
|
||||||
|
|
||||||
vec3 averageColor = topLeftColor + bottomRightColor + bottomLeftColor + topRightColor;
|
|
||||||
|
|
||||||
averageColor = mat3(cred, cgreen, cblue) * averageColor;
|
|
||||||
|
|
||||||
FragColor = vec4(pow(averageColor, vec3(1.0/outgamma)),0.0);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,41 +57,48 @@ float intsmear(float x, float dx)
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 texelSize = global.SourceSize.zw;
|
if(abs(vTexCoord.x - 0.5) < 0.5 && abs(vTexCoord.y - 0.5) < 0.5)
|
||||||
vec2 subtexelSize = texelSize / vec2(3.0,1.0);
|
{
|
||||||
vec2 range;
|
vec2 texelSize = global.SourceSize.zw;
|
||||||
range = global.SourceSize.zw / screen_scale;
|
vec2 subtexelSize = texelSize / vec2(3.0,1.0);
|
||||||
|
vec2 range;
|
||||||
float left = vTexCoord.x - texelSize.x*0.5;
|
range = global.SourceSize.zw / screen_scale;
|
||||||
float top = vTexCoord.y + range.y;
|
|
||||||
float right = vTexCoord.x + texelSize.x*0.5;
|
float left = vTexCoord.x - texelSize.x*0.5;
|
||||||
float bottom = vTexCoord.y - range.y;
|
float top = vTexCoord.y + range.y;
|
||||||
|
float right = vTexCoord.x + texelSize.x*0.5;
|
||||||
vec4 lcol, rcol;
|
float bottom = vTexCoord.y - range.y;
|
||||||
float subpix = mod(vTexCoord.x/subtexelSize.x+1.5,3.0);
|
|
||||||
float rsubpix = range.x/subtexelSize.x;
|
vec4 lcol, rcol;
|
||||||
lcol = vec4(intsmear(subpix+1.0,rsubpix),intsmear(subpix ,rsubpix),
|
float subpix = mod(vTexCoord.x/subtexelSize.x+1.5,3.0);
|
||||||
intsmear(subpix-1.0,rsubpix),0.0);
|
float rsubpix = range.x/subtexelSize.x;
|
||||||
rcol = vec4(intsmear(subpix-2.0,rsubpix),intsmear(subpix-3.0,rsubpix),
|
lcol = vec4(intsmear(subpix+1.0,rsubpix),intsmear(subpix ,rsubpix),
|
||||||
intsmear(subpix-4.0,rsubpix),0.0);
|
intsmear(subpix-1.0,rsubpix),0.0);
|
||||||
|
rcol = vec4(intsmear(subpix-2.0,rsubpix),intsmear(subpix-3.0,rsubpix),
|
||||||
vec4 topLeftColor = TEX2D((floor(vec2(left, top) / texelSize) + 0.5) * texelSize) * lcol;
|
intsmear(subpix-4.0,rsubpix),0.0);
|
||||||
vec4 bottomRightColor = TEX2D((floor(vec2(right, bottom) / texelSize) + 0.5) * texelSize) * rcol;
|
|
||||||
vec4 bottomLeftColor = TEX2D((floor(vec2(left, bottom) / texelSize) + 0.5) * texelSize) * lcol;
|
vec4 topLeftColor = TEX2D((floor(vec2(left, top) / texelSize) + 0.5) * texelSize) * lcol;
|
||||||
vec4 topRightColor = TEX2D((floor(vec2(right, top) / texelSize) + 0.5) * texelSize) * rcol;
|
vec4 bottomRightColor = TEX2D((floor(vec2(right, bottom) / texelSize) + 0.5) * texelSize) * rcol;
|
||||||
|
vec4 bottomLeftColor = TEX2D((floor(vec2(left, bottom) / texelSize) + 0.5) * texelSize) * lcol;
|
||||||
vec2 border = round(vTexCoord.st/subtexelSize);
|
vec4 topRightColor = TEX2D((floor(vec2(right, top) / texelSize) + 0.5) * texelSize) * rcol;
|
||||||
vec2 bordert = clamp((border+vec2(0.0,+global.GRID_STRENGTH)) * subtexelSize,
|
|
||||||
vec2(left, bottom), vec2(right, top));
|
vec2 border = round(vTexCoord.st/subtexelSize);
|
||||||
vec2 borderb = clamp((border+vec2(0.0,-global.GRID_STRENGTH)) * subtexelSize,
|
vec2 bordert = clamp((border+vec2(0.0,+global.GRID_STRENGTH)) * subtexelSize,
|
||||||
vec2(left, bottom), vec2(right, top));
|
vec2(left, bottom), vec2(right, top));
|
||||||
float totalArea = 2.0 * range.y;
|
vec2 borderb = clamp((border+vec2(0.0,-global.GRID_STRENGTH)) * subtexelSize,
|
||||||
|
vec2(left, bottom), vec2(right, top));
|
||||||
|
float totalArea = 2.0 * range.y;
|
||||||
|
|
||||||
vec4 averageColor;
|
vec4 averageColor;
|
||||||
averageColor = ((top - bordert.y) / totalArea) * topLeftColor;
|
averageColor = ((top - bordert.y) / totalArea) * topLeftColor;
|
||||||
averageColor += ((borderb.y - bottom) / totalArea) * bottomRightColor;
|
averageColor += ((borderb.y - bottom) / totalArea) * bottomRightColor;
|
||||||
averageColor += ((borderb.y - bottom) / totalArea) * bottomLeftColor;
|
averageColor += ((borderb.y - bottom) / totalArea) * bottomLeftColor;
|
||||||
averageColor += ((top - bordert.y) / totalArea) * topRightColor;
|
averageColor += ((top - bordert.y) / totalArea) * topRightColor;
|
||||||
|
|
||||||
FragColor = pow(averageColor,vec4(1.0/global.gamma));
|
FragColor = pow(averageColor,vec4(1.0/global.gamma));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FragColor = vec4(0.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue