My first commit with SVN, let's all hope I don't make some epic stupid mistake…

Add two shaders (if I did this right):
1. nightvision2scanlines - The nightvision2 shader with COD4-style scanlines added as requested in Issue 1. Should we keep the original nightvision2 as well?
2. sepia - An attempt at an old-timey sepia tone like in late 1800's video.
This commit is contained in:
MofoMan2000 2010-06-23 04:53:43 +00:00
parent 78926b6fa6
commit ab1537925f
2 changed files with 68 additions and 0 deletions

56
nightvision2scanlines.txt Normal file
View File

@ -0,0 +1,56 @@
uniform samplerRECT samp0 : register(s0);
void main(out float4 ocol0 : COLOR0, in float2 uv0 : TEXCOORD0)
{
//variables
int internalresolution = 1278;
float4 c0 = texRECT(samp0, uv0).rgba;
//blur
float4 blurtotal = float4(0, 0, 0, 0);
float blursize = 1.5;
blurtotal += texRECT(samp0, uv0 + float2(-blursize, -blursize));
blurtotal += texRECT(samp0, uv0 + float2(-blursize, blursize));
blurtotal += texRECT(samp0, uv0 + float2( blursize, -blursize));
blurtotal += texRECT(samp0, uv0 + float2( blursize, blursize));
blurtotal += texRECT(samp0, uv0 + float2(-blursize, 0));
blurtotal += texRECT(samp0, uv0 + float2( blursize, 0));
blurtotal += texRECT(samp0, uv0 + float2( 0, -blursize));
blurtotal += texRECT(samp0, uv0 + float2( 0, blursize));
blurtotal *= 0.125;
c0 = blurtotal;
//greyscale
float grey = ((0.3 * c0.r) + (0.4 * c0.g) + (0.3 * c0.b));
// brighten and apply horizontal scanlines
// This would have been much simpler if I could get the stupid modulo (%) to work
// If anyone who is more well versed in Cg knows how to do this it'd be slightly more efficient
// float lineIntensity = ((uv0[1] % 9) - 4) / 40;
float vPos = uv0[1] / 9;
float lineIntensity = (((vPos - (int)vPos) * 9) - 4) / 40;
grey = grey * 0.5 + 0.7 + lineIntensity;
// darken edges
float x = uv0[0];
float y = uv0[1];
if (x > internalresolution/2) x = internalresolution-x;
if (y > internalresolution/2) y = internalresolution-y;
if (x > internalresolution/2*0.95) x = internalresolution/2*0.95;
if (y > internalresolution/2*0.95) y = internalresolution/2*0.95;
x = -x+641;
y = -y+641;
/*****inline square root routines*****/
// bit of a performance bottleneck.
// neccessary to make the darkened area rounded
// instead of rhombus-shaped.
float sqrt=x/10;
while((sqrt*sqrt) < x) sqrt+=0.1;
x = sqrt;
sqrt=y/10;
while((sqrt*sqrt) < y) sqrt+=0.1;
y = sqrt;
/*****end of inline square root routines*****/
x *= 2;
y *= 2;
grey -= x/200;
grey -= y/200;
// output
ocol0 = float4(0, grey, 0, 1.0);
}

12
sepia.txt Normal file
View File

@ -0,0 +1,12 @@
uniform samplerRECT samp0 : register(s0);
void main(out float4 ocol0 : COLOR0, in float2 uv0 : TEXCOORD0)
{
float4 c0 = texRECT(samp0, uv0).rgba;
// Same coefficients as grayscale2 at this point
float avg = (0.222 * c0.r) + (0.707 * c0.g) + (0.071 * c0.b);
float red=avg;
float green=avg*.75;
float blue=avg*.5;
ocol0 = float4(red, green, blue, c0.a);
}