-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Sharp Bilinear (Scanlines) post-processing effect.
- Loading branch information
1 parent
a018d3a
commit f721ed5
Showing
4 changed files
with
86 additions
and
25 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
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 |
---|---|---|
@@ -1,20 +1,19 @@ | ||
/* | ||
Author: Gigaherz | ||
License: Public domain | ||
Author: Gigaherz | ||
License: Public domain | ||
*/ | ||
|
||
void main ( | ||
float3 position, | ||
float2 texcoord, | ||
uniform float4x4 wvp, | ||
out float4 vPosition : POSITION, | ||
out float2 vTexcoord : TEXCOORD0, | ||
out float2 omega : TEXCOORD1 | ||
) | ||
float3 position, | ||
float2 texcoord, | ||
uniform float4x4 wvp, | ||
out float4 vPosition : POSITION, | ||
out float2 vTexcoord : TEXCOORD0, | ||
out float2 omega : TEXCOORD1) | ||
{ | ||
float2 texture_size = float2(640.0f, 480.0f); | ||
|
||
vPosition = mul(wvp,float4(position, 1.f)); | ||
vTexcoord = texcoord; | ||
omega = 3.141592654 * 2 * texture_size; | ||
vPosition = mul(wvp,float4(position, 1.f)); | ||
vTexcoord = texcoord; | ||
omega = 3.141592654 * 2 * texture_size; | ||
} |
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,43 @@ | ||
/* | ||
Author: Themaister | ||
License: Public domain | ||
*/ | ||
|
||
#define SCANLINE_BASE_BRIGHTNESS 1.0 | ||
#define SCANLINE_SINE_COMP_A 0.1 | ||
#define SCANLINE_SINE_COMP_B 0.15 | ||
#define SHARP_BILINEAR_PRE_SCALE 1.25 | ||
|
||
float4 main | ||
( | ||
float4 vPosition : POSITION, | ||
float2 vTexcoord : TEXCOORD0, | ||
float2 texel : TEXCOORD1, | ||
uniform sampler2D s0 : TEXUNIT0 | ||
) : COLOR | ||
{ | ||
|
||
float2 texture_size = float2(640.0f, 480.0f); | ||
float2 output_size = float2(960.0f, 544.0f); // TODO: De-hardcode this for different aspect ratios | ||
|
||
float2 texel_floored = floor(texel); | ||
float2 s = frac(texel); | ||
float region_range = 0.5 - 0.5 / SHARP_BILINEAR_PRE_SCALE; | ||
|
||
// 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)) * SHARP_BILINEAR_PRE_SCALE + 0.5; | ||
float2 mod_texel = texel_floored + f; | ||
|
||
float3 res = tex2D(s0, mod_texel / texture_size).rgb; | ||
|
||
float2 sine_comp = float2(SCANLINE_SINE_COMP_A, SCANLINE_SINE_COMP_B); | ||
|
||
float2 omega = float2(2.0 * 3.1415 * texture_size.x, 3.1415 * texture_size.y); | ||
|
||
float3 scanline = res * (SCANLINE_BASE_BRIGHTNESS + dot(sine_comp * sin(vTexcoord * omega), float2(1.0, 1.0))); | ||
|
||
return float4(scanline, 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,20 @@ | ||
/* | ||
Author: Themaister | ||
License: Public domain | ||
*/ | ||
|
||
void main( | ||
float3 position, | ||
float2 texcoord, | ||
uniform float4x4 wvp, | ||
out float4 vPosition : POSITION, | ||
out float2 vTexcoord : TEXCOORD0, | ||
out float2 texel : TEXCOORD1) | ||
{ | ||
float2 texture_size = float2(640.0f, 480.0f); | ||
|
||
vPosition = mul(wvp,float4(position, 1.f)); | ||
vTexcoord = texcoord - float2(0.25 / texture_size.x, 0.0); | ||
|
||
texel = texcoord * texture_size; | ||
} |