Luminescent
Veteran
Is it possible to modify the following Ati developed blur smartshader that applies blur to the output frame of a renderer for a depth of field effect? Is there enough information provided by the final frame of rendering to produce such an effect? If it's possible to modify the blur filter below for such an effect, would the change required be trivial?
Anyone familiar with smarshader programming care to give try modyfing the shader or produce a new one for depth of field? If not, at least a hint on how to do it or whether it is even possible would be appreciated? I have no experience in the realm of graphics programming, otherwise I would have tried to write the shader myself. I would really enjoy experiencing the effect on some of my OGL games.shader convolutionPixelShader =
"!!ARBfp1.0
# This is a general purpose 3x3 convolution filter. Unused instructions
# and constants will get culled out by the driver so no need to remove them here.
PARAM texCoord00 = program.local[0];
PARAM texCoord01 = program.local[1];
PARAM texCoord02 = program.local[2];
PARAM texCoord10 = program.local[3];
PARAM texCoord12 = program.local[5];
PARAM texCoord20 = program.local[6];
PARAM texCoord21 = program.local[7];
PARAM texCoord22 = program.local[8];
# These constants are setup to do a blur filter.
PARAM const00 = {0.0769, 0.0769, 0.0769, 0.0};
PARAM const01 = {0.1538, 0.1538, 0.1538, 0.0};
PARAM const02 = {0.0769, 0.0769, 0.0769, 0.0};
PARAM const10 = {0.1538, 0.1538, 0.1538, 0.0};
PARAM const11 = {0.0769, 0.0769, 0.0769, 0.0};
PARAM const12 = {0.1538, 0.1538, 0.1538, 0.0};
PARAM const20 = {0.0769, 0.0769, 0.0769, 0.0};
PARAM const21 = {0.1538, 0.1538, 0.1538, 0.0};
PARAM const22 = {0.0769, 0.0769, 0.0769, 0.0};
TEMP finalPixel;
TEMP coord00;
TEMP coord01;
TEMP coord02;
TEMP coord10;
TEMP coord11;
TEMP coord12;
TEMP coord20;
TEMP coord21;
TEMP coord22;
OUTPUT oColor = result.color;
# Generate all the texture coordinates for the 9 texture lookups
ADD coord00, texCoord00, fragment.texcoord[0];
ADD coord01, texCoord01, fragment.texcoord[0];
ADD coord02, texCoord02, fragment.texcoord[0];
ADD coord10, texCoord10, fragment.texcoord[0];
ADD coord12, texCoord12, fragment.texcoord[0];
ADD coord20, texCoord20, fragment.texcoord[0];
ADD coord21, texCoord21, fragment.texcoord[0];
ADD coord22, texCoord22, fragment.texcoord[0];
# Do the texture lookups for the 3x3 kernel
TEX coord00, coord00, texture[0], 2D;
TEX coord01, coord01, texture[0], 2D;
TEX coord02, coord02, texture[0], 2D;
TEX coord10, coord10, texture[0], 2D;
TEX coord11, fragment.texcoord[0], texture[0], 2D;
TEX coord12, coord12, texture[0], 2D;
TEX coord20, coord20, texture[0], 2D;
TEX coord21, coord21, texture[0], 2D;
TEX coord22, coord22, texture[0], 2D;
# Multiply all texture lookups by their weights and sum them up
MUL finalPixel, coord00, const00;
MAD finalPixel, coord10, const10, finalPixel;
MAD finalPixel, coord20, const20, finalPixel;
MAD finalPixel, coord01, const01, finalPixel;
MAD finalPixel, coord11, const11, finalPixel;
MAD finalPixel, coord21, const21, finalPixel;
MAD finalPixel, coord02, const02, finalPixel;
MAD finalPixel, coord12, const12, finalPixel;
MAD oColor, coord22, const22, finalPixel;
END";
shader copyPixelShader =
"!!ARBfp1.0
OUTPUT oColor = result.color;
TEMP pixel;
TEX pixel, fragment.texcoord[0], texture[0], 2D;
MOV oColor, pixel;
END";
surface temp = allocsurf(width, height);
convolutionPixelShader.constant[0] = {-ds_dx, -dt_dy, 0, 0};
convolutionPixelShader.constant[1] = {0, -dt_dy, 0, 0};
convolutionPixelShader.constant[2] = {ds_dx, -dt_dy, 0, 0};
convolutionPixelShader.constant[3] = {-ds_dx, 0, 0, 0};
convolutionPixelShader.constant[4] = {ds_dx, 0, 0, 0};
convolutionPixelShader.constant[5] = {-ds_dx, dt_dy, 0, 0};
convolutionPixelShader.constant[6] = {0, dt_dy, 0, 0};
convolutionPixelShader.constant[7] = {ds_dx, dt_dy, 0, 0};
texture[0].source = backbuffer;
destination temp;
apply convolutionPixelShader;
texture[0].source = temp;
destination backbuffer;
apply copyPixelShader;
Last edited by a moderator: