瞎玩—Pete's OGL2 PSX Plugin sha…

2005-12-31 15:16 | mazda

嗯,‘瞎玩系列’还是延续到了这方面,这次玩的不是D3D的HLSL而变成OpenGL的GLSL咯……

使用说明。
一:将下列代码分别存为两个文件:gpuPeteOGL2.slv和gpuPeteOGL2.slf
二:将这两个文件存放到一个目录,比如d:\shader下
三:设置Pete's OGL2 PSX GPU Plugins的full screen filters选项,如下图,重点是红框内的内容,shader effects照图中设置,点击后面的"……"按钮,选择上一步的目录。shader level可以根据需要自由选择,越大,效果越强。

四:点击ok,完毕,运行游戏即可

效果——毛玻璃(frosted Glass)

//----------gpuPeteOGL2.slv--------------------

uniform vec4 OGL2Param;
uniform vec4 OGL2Size;

void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
}

//---------------------------------------------
//-----------gpuPeteOGL2.slf--------------------

uniform vec4 OGL2Param;
uniform vec4 OGL2Size;
uniform sampler2D OGL2Texture;

vec4 colorselect(float k, vec4 v1,vec4 v2,vec4 v3,vec4 v4,vec4 v5,vec4 v6,vec4 v7,vec4 v8)
{
vec4 result;
result = (k >= 0.875 ? v1 :
(k >= 0.75 ? v2 :
(k >= 0.625 ? v3 :
(k >= 0.5 ? v4:
(k >= 0.375 ? v5 :
(k >= 0.25 ? v6 :
(k >= 0.125 ? v7 :
(k >= 0.0 ? v8:v1))))))));
return result;
}
void main()
{


// the bigger the shader level, the bigger the texture fetch distance (0,1,2,3)
float fscale = OGL2Param.z*0.8+0.5;
float fbias_x = fscale/OGL2Size.s;
float fbias_y = fscale/OGL2Size.t;

// fetch the neighbor 8 texels, adjusted by the fetch distance
vec4 tmu0=texture2DProj(OGL2Texture, gl_TexCoord[0] + vec4(-fbias_x,-fbias_y,0.0,0.0));
vec4 tmu1=texture2DProj(OGL2Texture, gl_TexCoord[0] + vec4(0.0,-fbias_y,0.0,0.0));
vec4 tmu2=texture2DProj(OGL2Texture, gl_TexCoord[0] + vec4(fbias_x,-fbias_y,0.0,0.0));
vec4 tmu3=texture2DProj(OGL2Texture, gl_TexCoord[0] + vec4(fbias_x,0.0,0.0,0.0));
vec4 tmu4=texture2DProj(OGL2Texture, gl_TexCoord[0] + vec4(fbias_x,fbias_y,0.0,0.0));
vec4 tmu5=texture2DProj(OGL2Texture, gl_TexCoord[0] + vec4(0.0,fbias_y,0.0,0.0));
vec4 tmu6=texture2DProj(OGL2Texture, gl_TexCoord[0] + vec4(-fbias_x,fbias_y,0.0,0.0));
vec4 tmu7=texture2DProj(OGL2Texture, gl_TexCoord[0] + vec4(-fbias_x,0.0,0.0,0.0));
//generate per-fracgment fake-random value
float frand = fract(gl_TexCoord[1].x*141.141);
frand *= 1431.1431*fract(gl_TexCoord[1].y*131.131);
frand = fract(sqrt(frand+0.3));
// color output
gl_FragColor = colorselect(frand,tmu0,tmu1,tmu2,tmu3,tmu4,tmu5,tmu6,tmu7);

}

//---------------------------------------------
效果如下


以前写的“瞎玩”“瞎写”系列也可以完全移植到这上面。事实上,Pete's的这个plugin的post-processing比MPC要灵活得多啊,呵呵……
-
It's good to be bad~