Our goal is to average four neighboring values in a texture
using ATI_text_fragment_shader. The closest we can get
is to average four neighboring texture coordinates (not actual pixels).
Here is our code. Please Help!
#specify offsets of pixels to read
#texture is 256x256, so .00390625 is offset of 1 pixel
#if texture is 1 wide
StartConstants;
CONSTANT c0 = {0.00390625,0,0,0};
CONSTANT c1 = {0,0.00390625,0,0};
CONSTANT c2 = {-0.00390625,0,0,0};
CONSTANT c3 = {0,-0.00390625,0,0};
EndConstants;
StartPrelimPass;
#read in current texture coordinate
PassTexCoord r5, t0.str;
#specify location of pixels to include in average
ADD r1, r5, c0;
ADD r2, r5, c1;
ADD r3, r5, c2;
ADD r4, r5, c3;
EndPass;
StartOutputPass;
#pass the pixel coordinates
PassTexCoord r1, r1.str;
PassTexCoord r2, r2.str;
PassTexCoord r3, r3.str;
PassTexCoord r4, r4.str;
#how do we sample actual texture values?
#average the values
MOV r0, r1;
ADD r0, r0, r2;
ADD r0, r0, r3;
ADD r0.quarter, r0, r4;
EndPass;