<Luigi> unregistried
| Created on 08.11.2004 - 11:51 |  |
I have ported the "Emboss Shader" from ShadX (page 1 of this thread) to ARBvp/ARBfp (this time without errors, I hope ) whit a little modification for color glitch reduction. Tested on NV 6800:
!!ARBvp1.0
OPTION ARB_position_invariant;
# program.env[1].x/y will give the plugin's "effect level" offset
PARAM filterOffset = program.env[1];
ATTRIB sample = vertex.texcoord[ 0 ];
# gl_TexCoord[0] = gl_MultiTexCoord0; //center # 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[4] = gl_TexCoord[0] + offsetx ; //right # gl_TexCoord[5] = gl_TexCoord[0] + offsetx + offsety; //bottom-right # gl_TexCoord[6] = gl_TexCoord[0] + offsety ; //bottom
MOV result.texcoord[ 0 ].x, sample.x; MOV result.texcoord[ 0 ].y, sample.y; ADD result.texcoord[ 1 ].x, sample.x, -filterOffset.x; MOV result.texcoord[ 1 ].y, sample.y; ADD result.texcoord[ 2 ].x, sample.x, -filterOffset.x; ADD result.texcoord[ 2 ].y, sample.y, -filterOffset.y; MOV result.texcoord[ 3 ].x, sample.x; ADD result.texcoord[ 3 ].y, sample.y, -filterOffset.y; ADD result.texcoord[ 4 ].x, sample.x, filterOffset.x; MOV result.texcoord[ 4 ].y, sample.y; ADD result.texcoord[ 5 ].x, sample.x, filterOffset.x; ADD result.texcoord[ 5 ].y, sample.y, filterOffset.y; MOV result.texcoord[ 6 ].x, sample.x; ADD result.texcoord[ 6 ].y, sample.y, filterOffset.y;
END
!!ARBfp1.0
TEMP color0, color1, color2, color3, color4, color5, color6;
PARAM toGray = { 0.3, 0.59, 0.11, 0.0 }; PARAM divtwo = { 0.5, 0.5, 0.5, 0.0 };
# c = texture2DProj(OGL2Texture, gl_TexCoord[0]); //center # l = texture2DProj(OGL2Texture, gl_TexCoord[1]); //left # tl = texture2DProj(OGL2Texture, gl_TexCoord[2]); //top-left # t = texture2DProj(OGL2Texture, gl_TexCoord[3]); //top # r = texture2DProj(OGL2Texture, gl_TexCoord[4]); //right # br = texture2DProj(OGL2Texture, gl_TexCoord[5]); //bottom-right # b = texture2DProj(OGL2Texture, gl_TexCoord[6]); //bottom
TEX color0, fragment.texcoord[ 0 ], texture[ 0 ], 2D; TEX color1, fragment.texcoord[ 1 ], texture[ 0 ], 2D; TEX color2, fragment.texcoord[ 2 ], texture[ 0 ], 2D; TEX color3, fragment.texcoord[ 3 ], texture[ 0 ], 2D; TEX color4, fragment.texcoord[ 4 ], texture[ 0 ], 2D; TEX color5, fragment.texcoord[ 5 ], texture[ 0 ], 2D; TEX color6, fragment.texcoord[ 6 ], texture[ 0 ], 2D;
# calculate emboss
# 0.5 * (r + b) + -0.5 * (l + t) + (br - tl);
ADD color4, color4, color6; ADD color1, color1, color3; ADD color5, color5,-color2; MUL color4, color4, divtwo; MUL color1, color1, divtwo; ADD color1,-color1, color4; ADD color1, color1, color5; DP3 color1, color1, toGray;
# add emboss to color0
ADD result.color, color0, color1;
END
Pete, if ShadX want, you can put it on your site. Please test it, if you can... I am a little careless  Ciao.
|
<ShadX> unregistried
| Created on 09.11.2004 - 18:30 |  |
An example of 2x Hi-Res texture GLSL: Vartex program
// Super Simplified hq2x (SShq2x) GLslang shader - ported ShadX. Comments by Pete Bernert (copied from Scale2x) // // see the .slf file for algorithm/license informations // // How to use the shaders: copy both files into the emu's "shaders" subdirectory, // and rename them to "gpuPeteOGL2.slv" and "gpuPeteOGL2.slf". // Configure the plugin: set "shader effects" to mode "5 - GLslang files". // // Important: to get a real SShq2x effect, your configured window/fullscreen size has // to be at least twice as the internal resolution. That means: // if your internal resolution is "0 - low", than the window/fullscreen size has to be at // least 640x480 with most games. If you are using an internal resolution of "1 - high", // your window/fullscreen size has to be at least 1280x960... it will not crash or // something, if you are using smaller window/fullscreen sizes, but the algorithm will // not work properly on all pixels. Also, the above values may vary, depending on the // psx game's display size. The complete formula to set your window/fullscreen size is: // // "psx game resolution" * "plugin internal resolution mode + 1" * 2 // // So, for a psx game which is using 320x240, and the "1 - high" mode, you would need // 320x240 * (1 + 1) * 2 = 640x480 * 2 = 1280x960... mmmkay? // // Ah, and final note: SShq2X works best on games using clear 2D gfx
uniform vec4 OGL2Param; uniform vec4 OGL2Size;
void main() { vec4 offsetx; vec4 offsety;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
offsetx.x = 1.0/OGL2Size.x; // setup one x/y texel offset offsetx.y = 0.0; offsetx.w = 0.0; offsetx.z = 0.0; offsety.y = 1.0/OGL2Size.y; offsety.x = 0.0; offsety.w = 0.0; offsety.z = 0.0;
gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[1] = gl_TexCoord[0] + offsetx; gl_TexCoord[2] = gl_TexCoord[0] + offsetx + offsety; gl_TexCoord[3] = gl_TexCoord[0] + offsety; }
Fragment program
// Super Simplified hq2x (SShq2x) GLslang shader - ported by ShadX // // hq2x Homepage: http://www.hiend3d.com/hq2x.html // Original license informations: // "Copyright (C) 2003 MaxSt ( maxst@hiend3d.com ) // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later // version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA." // // OGL2Size.x = texture x size (for example "2048" in "high internal resolution" setting) // OGL2Size.y = texture y size (for example "1024" in "high internal resolution" setting) // OGL2Size.z = tex rect width used for current rendering (psx display width) // OGL2Size.w = tex rect height used for current rendering (psx display height) // // B = black C = any color // // [B][B]matrix 1 // [B][C] // // [B][B]matrix 2 // [C][B] // // [C][B]matrix 3 // [B][B] // // [B][C]matrix 4 // [B][B] // // [B][C]matrix 5 // [B][C] // // [B][B]matrix 6 // [C][C] // // [C][B]matrix 7 // [C][B] // // [C][C]matrix 8 // [B][B] // // [B][C]matrix 9 // [C][C] // // [C][B]matrix 10 // [C][C] // // [C][C]matrix 11 // [B][C] // // [C][C]matrix 12 // [C][B] // // [C][C]matrix 13 // [C][C]
uniform vec4 OGL2Param; uniform vec4 OGL2Size; uniform sampler2D OGL2Texture;
void main() { vec4 colA,colB,colC,colD,col; vec3 black;
black.x = 0.0; black.y = 0.0; black.z = 0.0;
colA = texture2DProj(OGL2Texture, gl_TexCoord[0]); // (top-left) colB = texture2DProj(OGL2Texture, gl_TexCoord[1]); // (top-right) colC = texture2DProj(OGL2Texture, gl_TexCoord[2]); // (bottom-left) colD = texture2DProj(OGL2Texture, gl_TexCoord[3]); // (bottom-right) if(colA == colB && colB == colC && colC != colD && colC.xyz == black) // do the SShq2x rule 1 col=colA; else if(colA == colB && colB == colD && colD != colC && colD.xyz == black ) // do the SShq2x rule 2 col=colA; else if(colB == colC && colC == colD && colD != colA && colD.xyz == black ) // do the SShq2x rule 3 col=colB; else if(colA == colC && colC == colD && colD != colA && colD.xyz == black ) // do the SShq2x rule 4 col=colA; else if(colA == colC && colC != colB && colC != colD && colC.xyz == black ) // do the SShq2x rule 5 col=colC; else if(colA == colB && colB != colC && colB != colD && colB.xyz == black ) // do the SShq2x rule 6 col=colB; else if(colB == colD && colD != colC && colD != colA && colD.xyz == black ) // do the SShq2x rule 7 col=(colA+colC)/2.0; else if(colC == colD && colD != colA && colD != colC && colD.xyz == black ) // do the SShq2x rule 8 col=(colA+colB)/2.0; else if(colA != colB && colA != colC && colA != colD && colA.xyz == black ) // do the SShq2x rule 9 col=colA; else if(colB != colA && colB != colC && colB != colD && colB.xyz == black ) // do the SShq2x rule 10 col=(colA+colC+colD)/3.0; else if(colC != colA && colC != colB && colC != colD && colC.xyz == black ) // do the SShq2x rule 11 col=(colA+colB+colD)/3.0; else if(colD != colA && colD != colB && colD != colC && colB.xyz == black ) // do the SShq2x rule 12 col=(colA+colB+colC)/3.0; else if(colA.xyz != black && colB.xyz != black && colC.xyz != black && colD.xyz != black ) // do the SShq2x rule 13 col=(colA+colB+colC+colD)/4.0;
gl_FragColor = col; } Pete, Guest, anyone... optimizations or suggestions are welcome... Bye
|