| 1 |
void main() |
| 2 |
{ |
| 3 |
//variables |
| 4 |
float internalresolution = 1278.0; |
| 5 |
float4 c0 = Sample(); |
| 6 |
|
| 7 |
//blur |
| 8 |
float4 blurtotal = float4(0.0, 0.0, 0.0, 0.0); |
| 9 |
float blursize = 1.5; |
| 10 |
blurtotal += SampleLocation(GetCoordinates() + float2(-blursize, -blursize)*GetInvResolution()); |
| 11 |
blurtotal += SampleLocation(GetCoordinates() + float2(-blursize, blursize)*GetInvResolution()); |
| 12 |
blurtotal += SampleLocation(GetCoordinates() + float2( blursize, -blursize)*GetInvResolution()); |
| 13 |
blurtotal += SampleLocation(GetCoordinates() + float2( blursize, blursize)*GetInvResolution()); |
| 14 |
blurtotal += SampleLocation(GetCoordinates() + float2(-blursize, 0.0)*GetInvResolution()); |
| 15 |
blurtotal += SampleLocation(GetCoordinates() + float2( blursize, 0.0)*GetInvResolution()); |
| 16 |
blurtotal += SampleLocation(GetCoordinates() + float2( 0.0, -blursize)*GetInvResolution()); |
| 17 |
blurtotal += SampleLocation(GetCoordinates() + float2( 0.0, blursize)*GetInvResolution()); |
| 18 |
blurtotal *= 0.125; |
| 19 |
c0 = blurtotal; |
| 20 |
|
| 21 |
//greyscale |
| 22 |
float grey = ((0.3 * c0.r) + (0.4 * c0.g) + (0.3 * c0.b)); |
| 23 |
|
| 24 |
// brighten and apply horizontal scanlines |
| 25 |
// This would have been much simpler if I could get the stupid modulo (%) to work |
| 26 |
// If anyone who is more well versed in Cg knows how to do this it'd be slightly more efficient |
| 27 |
// float lineIntensity = ((GetCoordinates()[1] % 9) - 4) / 40; |
| 28 |
float vPos = GetCoordinates().y*GetResolution().y / 9.0; |
| 29 |
float lineIntensity = (((vPos - floor(vPos)) * 9.0) - 4.0) / 40.0; |
| 30 |
grey = grey * 0.5 + 0.7 + lineIntensity; |
| 31 |
|
| 32 |
// darken edges |
| 33 |
float x = GetCoordinates().x * GetResolution().x; |
| 34 |
float y = GetCoordinates().y * GetResolution().y; |
| 35 |
|
| 36 |
if (x > internalresolution/2.0) |
| 37 |
x = internalresolution-x; |
| 38 |
|
| 39 |
if (y > internalresolution/2.0) |
| 40 |
y = internalresolution-y; |
| 41 |
|
| 42 |
if (x > internalresolution/2.0*0.95) |
| 43 |
x = internalresolution/2.0*0.95; |
| 44 |
|
| 45 |
if (y > internalresolution/2.0*0.95) |
| 46 |
y = internalresolution/2.0*0.95; |
| 47 |
|
| 48 |
x = -x + 641.0; |
| 49 |
y = -y + 641.0; |
| 50 |
|
| 51 |
//****inline square root routines*****/ |
| 52 |
// bit of a performance bottleneck. |
| 53 |
// necessary to make the darkened area rounded |
| 54 |
// instead of rhombus-shaped. |
| 55 |
float sqrt = x / 10.0; |
| 56 |
while ((sqrt*sqrt) < x) |
| 57 |
sqrt+=0.1; |
| 58 |
x = sqrt; |
| 59 |
sqrt = y / 10.0; |
| 60 |
while ((sqrt*sqrt) < y) |
| 61 |
sqrt+=0.1; |
| 62 |
y = sqrt; |
| 63 |
|
| 64 |
x *= 2.0; |
| 65 |
y *= 2.0; |
| 66 |
grey -= x / 200.0; |
| 67 |
grey -= y / 200.0; |
| 68 |
|
| 69 |
// output |
| 70 |
SetOutput(float4(0.0, grey, 0.0, 1.0)); |
| 71 |
} |