Skip to content

Instantly share code, notes, and snippets.

@gigaherz
Created November 1, 2012 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gigaherz/3993749 to your computer and use it in GitHub Desktop.
Save gigaherz/3993749 to your computer and use it in GitHub Desktop.
Cg recreation of the Lcd3x scaling algorithm.
/* COMPATIBILITY
- HLSL compilers (untested)
- Cg compilers
*/
/*
Author: Gigaherz
License: Public domain
*/
/* configuration (higher values mean brighter image but reduced effect depth) */
const int brighten_scanlines = 16;
const int brighten_lcd = 4;
struct input
{
float2 video_size;
float2 texture_size;
float2 output_size;
float frame_count;
float frame_direction;
float frame_rotation;
};
void main_vertex (
uniform float4x4 modelViewProj,
uniform input IN,
float4 position : POSITION, out float4 oPosition : POSITION,
float4 color : COLOR, out float4 oColor : COLOR,
float2 tex : TEXCOORD, out float2 oTex : TEXCOORD,
out float2 omega : TEXCOORD2
)
{
oPosition = mul(modelViewProj, position);
oColor = color;
oTex = tex;
omega = 3.141592654 * 2 * IN.texture_size;
}
const float3 offsets = 3.141592654 * float3(1.0/2,1.0/2 - 2.0/3,1.0/2-4.0/3);
float4 main_fragment (
in float2 omega : TEXCOORD2,
float2 tex : TEXCOORD,
uniform sampler2D s0 : TEXUNIT0
) : COLOR
{
float3 res = tex2D(s0, tex).xyz;
float2 angle = tex * omega;
float yfactor = (brighten_scanlines + sin(angle.y)) / (brighten_scanlines + 1);
float3 xfactors = (brighten_lcd + sin(angle.x + offsets)) / (brighten_lcd + 1);
float3 color = yfactor * xfactors * res;
return float4(color.x, color.y, color.z, 1.0);
}
@gigaherz
Copy link
Author

gigaherz commented Nov 1, 2012

Note: the config values are asymptotic. To fully disable the effect they would have to be infinite. a value < 1 is not recommended as it would result in negative numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment