<ShadX> unregistried
| Created on 04.11.2004 - 13:16 |  |
Hi Pete. I have some questions about your vertex/fragment programs with GLSL. I don't know why you use more then one texture unit for filtering when only one is required, and i don't know why you use vertex and fragment programs together when only fragment program is required. Anyway i can give you a fragment program example:
uniform vec4 OGL2Size; uniform sampler2D OGL2Texture;
void main() { float offsetx = 1.0 / OGL2Size.x; float offsety = 1.0 / OGL2Size.y; vec2 TCoord = gl_TexCoord[0].xy; vec4 c = texture2D(OGL2Texture, TCoord); //center vec4 bl = texture2D(OGL2Texture, TCoord + vec2(-offsetx,-offsety)); //bottom-left vec4 l = texture2D(OGL2Texture, TCoord + vec2(-offsetx, 0.0)); //left vec4 tl = texture2D(OGL2Texture, TCoord + vec2(-offsetx, offsety)); //top-left vec4 t = texture2D(OGL2Texture, TCoord + vec2( 0.0, offsety)); //top vec4 ur = texture2D(OGL2Texture, TCoord + vec2( offsetx, offsety)); //upper-right vec4 r = texture2D(OGL2Texture, TCoord + vec2( offsetx, 0.0)); //right vec4 br = texture2D(OGL2Texture, TCoord + vec2( offsetx, offsety)); //bottom-right vec4 b = texture2D(OGL2Texture, TCoord + vec2( 0.0,-offsety)); //bottom
gl_FragColor = 8.0 * (c + -0.125 * (bl + l + tl + t + ur + r + br + b)); }
This fragment program was derived from "helloGPGPU_GLSL.cpp" v1.0.2 by Mike Weiblen:
sourceforge.net/project/showfiles.php?group_id=104004&package_id=117303&release_id=245080
It demonstrates a simple post-process edge detection filter but you can use whatever you want. Some example:
Simple blur filter gl_FragColor = 0.5 * c + 0.0625 * (l + t + r + b + bl + tl + ur + br)
Gaussian blur filter gl_FragColor = 0.25 * c + 0.125 * (l + t + r + b) + 0.0625 * (bl + tl + ur + br)
Emboss filter (very funny bump mapping emulation) gl_FragColor = 0.5 * (c + r + b) + -0.5 * (l + t) + br - tl
Sharpen filter gl_FragColor = c - (bl + l + tl + t + ur + r + br + b)
bye
|
<ShadX> unregistried
| Created on 05.11.2004 - 12:32 |  |
Hi Guest. you are so touchy... if you have read my post, you can see: "This fragment program was derived from "helloGPGPU_GLSL.cpp" v1.0.2 by Mike Weiblen"...I haven't declared that it's mine... For your request: // //2xSaI scaling filter source code adapted for GLSL (not complete, of course, only for Guest's curiosity... if he will want complete it... //November 05, 2004 //The original source is made available under the terms of the GNU GPL //
uniform vec4 OGL2Size; uniform vec4 OGL2Param; uniform sampler2D OGL2Texture;
void main() { float of1x = 1.0 / OGL2Size.x; float of1y = 1.0 / OGL2Size.y; float of2x = 2.0 / OGL2Size.x; float of2y = 2.0 / OGL2Size.y;
vec4 colorA, colorB; vec4 colorC, colorD; vec4 colorE, colorF, colorG, colorH; vec4 colorI, colorJ, colorK, colorL; vec4 colorM, colorN, colorO, colorP; vec4 product, product1, product2;
// Map of the pixels: // I|E F|J // G|A B|K // H|C D|L // M|N O|P
vec2 TCoord = gl_TexCoord[0].xy; colorA = texture2D(OGL2Texture, TCoord); colorB = texture2D(OGL2Texture, TCoord + vec2( of1x, 0.0)); colorC = texture2D(OGL2Texture, TCoord + vec2( 0.0,-of1y)); colorD = texture2D(OGL2Texture, TCoord + vec2( of1x,-of1y)); colorE = texture2D(OGL2Texture, TCoord + vec2( 0.0,-of1y)); colorF = texture2D(OGL2Texture, TCoord + vec2( of1x, of1y)); colorG = texture2D(OGL2Texture, TCoord + vec2(-of1x, 0.0)); colorH = texture2D(OGL2Texture, TCoord + vec2(-of1x,-of1y)); colorI = texture2D(OGL2Texture, TCoord + vec2(-of1x, of1y)); colorJ = texture2D(OGL2Texture, TCoord + vec2( of2x, of1y)); colorK = texture2D(OGL2Texture, TCoord + vec2( of2x, 0.0)); colorL = texture2D(OGL2Texture, TCoord + vec2( of2x,-of1y)); colorM = texture2D(OGL2Texture, TCoord + vec2(-of1x,-of2y)); colorN = texture2D(OGL2Texture, TCoord + vec2( 0.0,-of2y)); colorO = texture2D(OGL2Texture, TCoord + vec2( of1x,-of2y)); colorP = texture2D(OGL2Texture, TCoord + vec2( of2x,-of2y)); if ((colorA == colorD) && (colorB != colorC)) { if ( ((colorA == colorE) && (colorB == colorL)) || ((colorA == colorC) && (colorA == colorF) && (colorB != colorE) && (colorB == colorJ)) ) { product = colorA; } else { product = 0.5 * (colorA + colorB); }
if (((colorA == colorG) && (colorC == colorO)) || ((colorA == colorB) && (colorA == colorH) && (colorG != colorC) && (colorC == colorM)) ) { product1 = colorA; } else { product1 = 0.5 * (colorA + colorC); } product2 = colorA; } else if ((colorB == colorC) && (colorA != colorD)) { if (((colorB == colorF) && (colorA == colorH)) || ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI)) ) { product = colorB; } else { product = 0.5 * (colorA + colorB); }
if (((colorC == colorH) && (colorA == colorF)) || ((colorC == colorG) && (colorC == colorD) && (colorA != colorH) && (colorA == colorI)) ) { product1 = colorC; } else { product1 = 0.5 * (colorA + colorC); } product2 = colorB; } else if ((colorA == colorD) && (colorB == colorC)) { if (colorA == colorB) { product = colorA; product1 = colorA; product2 = colorA; } else { product1 = 0.5 * (colorA + colorC); product = 0.5 * (colorA + colorB); } ........ Bye p.s.: your customized random number generator or a deceased granny from a friend can be applied to post-process filtering?
|
<ShadX> unregistried
| Created on 05.11.2004 - 16:11 |  |
Ok, waiting for the Pete's answer i have coded a shader like "old way"... if someone want try it... not Guest , isn't supported by its system (7 texture unit used): gpuPeteOGL2.slv // Emboss GLSL vertex program - coded by ShadX free
uniform vec4 OGL2Param; uniform vec4 OGL2Size;
void main() { vec4 offsetx; vec4 offsety; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
offsetx.x = 1.0/OGL2Size.x; offsetx.y = 0.0; offsetx.z = 0.0; offsetx.w = 0.0; offsety.x = 0.0; offsety.y = 1.0/OGL2Size.y; offsety.z = 0.0; offsety.w = 0.0; gl_TexCoord[0] = gl_MultiTexCoord0; //center //gl_TexCoord[x] = gl_TexCoord[0] - offsetx + offsety; //bottom-left gl_TexCoord[1] = gl_TexCoord[0] - offsetx ; //left gl_TexCoord[2] = gl_TexCoord[0] - offsetx - offsety; //top-left gl_TexCoord[3] = gl_TexCoord[0] - offsety ; //top //gl_TexCoord[x] = gl_TexCoord[0] + offsetx -offsety; //top-right gl_TexCoord[4] = gl_TexCoord[0] + offsetx ; //right gl_TexCoord[5] = gl_TexCoord[0] + offsetx + offsety; //bottom-right gl_TexCoord[6] = gl_TexCoord[0] + offsety ; //bottom
}
gpuPeteOGL2.slf // Emboss GLSL shader program - coded by ShadX. Free.
uniform vec4 OGL2Size; uniform vec4 OGL2Param; uniform sampler2D OGL2Texture;
void main() { vec4 c,bl,l,tl,t,tr,r,br,b,col; c = texture2DProj(OGL2Texture, gl_TexCoord[0]); //center //bl = texture2DProj(OGL2Texture, gl_TexCoord[x]); //bottom-left l = texture2DProj(OGL2Texture, gl_TexCoord[1]); //left tl = texture2DProj(OGL2Texture, gl_TexCoord[2]); //top-left t = texture2DProj(OGL2Texture, gl_TexCoord[3]); //top //tr = texture2DProj(OGL2Texture, gl_TexCoord[x]); //top-right r = texture2DProj(OGL2Texture, gl_TexCoord[4]); //right br = texture2DProj(OGL2Texture, gl_TexCoord[5]); //bottom-right b = texture2DProj(OGL2Texture, gl_TexCoord[6]); //bottom
if (OGL2Param.z==1.0) //light emboss col = c + 0.25 * (r + b) + -0.25 * (l + t) + 0.5 * (br - tl); if (OGL2Param.z==2.0) //strong emboss col = c + 0.5 * (r + b) + -0.5 * (l + t) + (br - tl); if (OGL2Param.z==3.0) //light reversed emboss col = c + -0.25 * (r + b) + 0.25 * (l + t) + -0.5 * (br - tl); if (OGL2Param.z==4.0) //strong reversed emboss col = c + -0.5 * (r + b) + 0.5 * (l + t) - (br - tl);
}
Guest, this shader run very well on a 3Dlabs Wildcat Realizm 800... Bye
|