-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from rsn8887/gtu
add sharp_bilinear_simple (no scanlines, automatic largest integer presc…
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* COMPATIBILITY | ||
- HLSL compilers | ||
- Cg compilers | ||
*/ | ||
|
||
/* | ||
Author: rsn8887 (based on TheMaister) | ||
License: Public domain | ||
|
||
This is an integer prescale filter that should be combined | ||
with a bilinear hardware filtering (GL_BILINEAR filter or some such) to achieve | ||
a smooth scaling result with minimum blur. This is good for pixelgraphics | ||
that are scaled by non-integer factors. | ||
|
||
The prescale factor and texel coordinates are precalculated | ||
in the vertex shader for speed. | ||
*/ | ||
|
||
struct precalc_coord | ||
{ | ||
float2 texel; | ||
float2 prescale; | ||
}; | ||
|
||
struct input | ||
{ | ||
float2 video_size; | ||
float2 texture_size; | ||
float2 output_size; | ||
}; | ||
|
||
float4 main(in precalc_coord co : TEXCOORD2, uniform sampler2D s0 : TEXUNIT0, uniform input IN) : COLOR | ||
{ | ||
//co.texel has already been multiplied by texture_size inside vertex shader | ||
float2 texel_floored = floor(co.texel); | ||
float2 s = frac(co.texel); | ||
//prescale is the largest possible integer scale, calculated in vertex shader | ||
float2 region_range = 0.5 - 0.5 / co.prescale; | ||
|
||
// Figure out where in the texel to sample to get correct pre-scaled bilinear. | ||
// Uses the hardware bilinear interpolator to avoid having to sample 4 times manually. | ||
|
||
float2 center_dist = s - 0.5; | ||
float2 f = (center_dist - clamp(center_dist, -region_range, region_range)) * co.prescale + 0.5; | ||
float2 mod_texel = texel_floored + f; | ||
|
||
return float4(tex2D(s0, mod_texel / IN.texture_size).rgb, 1.0); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* COMPATIBILITY | ||
- HLSL compilers | ||
- Cg compilers | ||
*/ | ||
|
||
/* | ||
Author: rsn8887 (based on TheMaister) | ||
License: Public domain | ||
|
||
This is an integer prescale filter that should be combined | ||
with a bilinear hardware filtering (GL_BILINEAR filter or some such) to achieve | ||
a smooth scaling result with minimum blur. This is good for pixelgraphics | ||
that are scaled by non-integer factors. | ||
|
||
The prescale factor and texel coordinates are precalculated | ||
in the vertex shader for speed. | ||
*/ | ||
|
||
struct precalc_coord | ||
{ | ||
float2 texel; | ||
float2 prescale; | ||
}; | ||
|
||
struct input | ||
{ | ||
float2 video_size; | ||
float2 texture_size; | ||
float2 output_size; | ||
}; | ||
|
||
void main | ||
( | ||
float4 aPosition : POSITION, | ||
out float4 oPosition : POSITION, | ||
uniform float4x4 wvp, | ||
float2 aTexcoord : TEXCOORD, | ||
out float2 oTex : TEXCOORD, | ||
|
||
uniform input IN, | ||
out precalc_coord co: TEXCOORD2 | ||
) | ||
{ | ||
oPosition = mul(aPosition, wvp); | ||
oTex = aTexcoord; | ||
|
||
//precalculate some values to pass to the fragment shader | ||
co.texel = aTexcoord * IN.texture_size; | ||
co.prescale = floor(IN.output_size / IN.texture_size); | ||
} |