Skip to content

Commit

Permalink
Add smootheststep shader and fix others.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyllian committed Mar 29, 2016
1 parent ea886a5 commit b698f01
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dithering/shaders/gendither.cg
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ output main_fragment(float2 texCoord : TEXCOORD0, uniform sampler2D decal : TEXU
// Dither
//

int ditdex = int(mod(ditheu.x, 4.0)) * 4 + int(mod(ditheu.y, 4.0)); // 4x4!
int ditdex = int(fmod(ditheu.x, 4.0)) * 4 + int(fmod(ditheu.y, 4.0)); // 4x4!
int3 color;
int3 colord;
color.r = OUT.color.r * 224;
Expand Down
2 changes: 1 addition & 1 deletion retro/shaders/sharp-bilinear.cg
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ float4 main_fragment(float2 texCoord : TEXCOORD0,
{
float2 texel = texCoord * IN.texture_size;
float2 texel_floored = floor(texel);
float2 s = fract(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.
Expand Down
75 changes: 75 additions & 0 deletions retro/shaders/smootheststep.cg
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* COMPATIBILITY
- HLSL compilers
- Cg compilers
*/


/*

Fragment shader based on "Improved texture interpolation" by I�igo Qu�lez
Original description: http://www.iquilezles.org/www/articles/texture/texture.htm

*/

void main_vertex
(
float4 position : POSITION,
float4 color : COLOR,
float2 texCoord : TEXCOORD0,

uniform float4x4 modelViewProj,

out float4 oPosition : POSITION,
out float4 oColor : COLOR,
out float2 otexCoord : TEXCOORD
)
{
oPosition = mul(modelViewProj, position);
oColor = color;
otexCoord = texCoord;
}

struct output
{
float4 color : COLOR;
};

struct input
{
float2 video_size;
float2 texture_size;
float2 output_size;
float frame_count;
float frame_direction;
float frame_rotation;
};


output main_fragment (float2 tex : TEXCOORD0, uniform input IN, uniform sampler2D s_p : TEXUNIT0)
{
float2 p = tex.xy;

p = p * IN.texture_size + float2(0.5, 0.5);

float2 i = floor(p);
float2 f = p - i;

// Smoothstep - amazingly, smoothstep() is slower than calculating directly the expression!
// f = smoothstep(0.0, 1.0, f);
// f = f * f * ( -2.0 * f + 3.0);

// Quilez - This is sharper than smoothstep.
//f = f * f * f * (f * (f * 6.0 - float2(15.0, 15.0)) + float2(10.0, 10.0));

// smootheststep - This is even sharper than Quilez!
f = f * f * f * f * (f * (f * (-20.0 * f + float2(70.0, 70.0)) - float2(84.0, 84.0)) + float2(35.0, 35.0));

p = i + f;

p = (p - float2(0.5, 0.5)) / IN.texture_size;

// final sum and weight normalization
output OUT;
OUT.color = tex2D(s_p, p);
return OUT;
}
5 changes: 5 additions & 0 deletions retro/smootheststep.cgp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
shaders = 1

shader0 = shaders/smootheststep.cg
filter_linear0 = true
scale_type_0 = source
2 changes: 1 addition & 1 deletion retro/smoothstep.cgp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
shaders = 1

shader0 = shaders/pixellate.cg
shader0 = shaders/smoothstep.cg
filter_linear0 = true
scale_type_0 = source

0 comments on commit b698f01

Please sign in to comment.