|
楼主 |
发表于 2012-4-6 11:45:28
|
显示全部楼层
array 发表于 2012-4-6 10:14
谨慎怀疑是您的显卡本身不能完全支持这种FBO纹理的mipmap;事实上的确有相当一部分显卡是不能直接对FBO纹理 ...
谢谢。 你说的这种情况确实很有可能。
我的显卡支持 GL_ARB_Framebuffer_object 和 GL_EXT_FrameBuffer_object. 但很有可能支持mipmap。
我做过一些后处理操作,但是效果不是太好。
用的是 FXAA算法。相关代码如下:
m_strVertShader =
"uniform float subPixelShift = 1.0/4.0;\n"
"uniform float winWidth;\n"
"uniform float winHeight;\n"
"varying vec4 fxaaUV;\n"
"void main(void)\n"
"{\n"
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
" gl_Position = ftransform();\n"
" vec2 rcpFrame = vec2(1.0/winWidth, 1.0/winHeight);\n"
" fxaaUV.xy = gl_MultiTexCoord0.xy;\n"
" fxaaUV.zw = gl_MultiTexCoord0.xy - (rcpFrame * (0.5 + subPixelShift));\n"
"}\n";
m_strFragShader =
"uniform float winWidth;\n"
"uniform float winHeight;\n"
"uniform float spanMax = 8.0;\n"
"uniform float reduceMul = 1.0/8.0;\n"
"varying vec4 fxaaUV;\n"
"uniform sampler2D BufferTexture;\n"
"#define FxaaInt2 ivec2\n"
"#define FxaaFloat2 vec2\n"
"#define FxaaTexLod0(t, p) texture2DLod(t, p, 0.0)\n"
"#define FxaaTexOff(t, p, o, r) texture2DLodOffset(t, p, 0.0, o)\n"
"const float reduceMin = (1.0/128.0);\n"
"vec3 fxaaPixelShader(sampler2D tex, vec2 rcpFrame)\n"
"{\n"
" vec3 rgbNW = FxaaTexLod0(tex, fxaaUV.zw).xyz;\n"
" vec3 rgbNE = FxaaTexOff(tex, fxaaUV.zw, FxaaInt2(1,0), rcpFrame.xy).xyz;\n"
//" vec3 rgbNE = FxaaTexLod0(tex, fxaaUV.zw + (FxaaInt2(1,0) * rcpFrame.xy)).xyz;\n"
" vec3 rgbSW = FxaaTexOff(tex, fxaaUV.zw, FxaaInt2(0,1), rcpFrame.xy).xyz;\n"
//" vec3 rgbSW = FxaaTexLod0(tex, fxaaUV.zw + (FxaaInt2(0,1) * rcpFrame.xy)).xyz;\n"
" vec3 rgbSE = FxaaTexOff(tex, fxaaUV.zw, FxaaInt2(1,1), rcpFrame.xy).xyz;\n"
//" vec3 rgbSE = FxaaTexLod0(tex, fxaaUV.zw + (FxaaInt2(1,1) * rcpFrame.xy)).xyz;\n"
" vec3 rgbM = FxaaTexLod0(tex, fxaaUV.xy).xyz;\n"
" vec3 luma = vec3(0.299, 0.587, 0.114);\n"
" float lumaNW = dot(rgbNW, luma);\n"
" float lumaNE = dot(rgbNE, luma);\n"
" float lumaSW = dot(rgbSW, luma);\n"
" float lumaSE = dot(rgbSE, luma);\n"
" float lumaM = dot(rgbM, luma);\n"
" float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n"
" float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n"
" vec2 dir = vec2(-((lumaNW + lumaNE) - (lumaSW + lumaSE)), (lumaNW + lumaSW) - (lumaNE + lumaSE));\n"
" float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * reduceMul), reduceMin);\n"
" float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce);\n"
" dir = min(FxaaFloat2(spanMax, spanMax), max(FxaaFloat2(-spanMax,-spanMax), dir * rcpDirMin)) * rcpFrame.xy;\n"
" vec3 rgbA = (1.0/2.0) * (FxaaTexLod0(tex, fxaaUV.xy + dir * (1.0/3.0 - 0.5)).xyz + FxaaTexLod0(tex, fxaaUV.xy + dir * (2.0/3.0 - 0.5)).xyz);\n"
" vec3 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (FxaaTexLod0(tex, fxaaUV.xy + dir * (0.0/3.0 - 0.5)).xyz + FxaaTexLod0(tex, fxaaUV.xy + dir * (3.0/3.0 - 0.5)).xyz);\n"
" float lumaB = dot(rgbB, luma);\n"
" if ((lumaB < lumaMin) || (lumaB > lumaMax)) return rgbA;\n"
" return rgbB;\n"
"}\n"
"vec4 computeColor(sampler2D tex, vec2 uv, float time)\n"
"{\n"
" vec4 c = vec4(0.0);\n"
" vec2 rcpFrame = vec2(1.0/winWidth, 1.0/winHeight);\n"
" c.rgb = fxaaPixelShader(tex, rcpFrame);\n"
" c.a = 1.0;\n"
" return c;\n"
"}\n"
"void main(void)\n"
"{\n"
" gl_FragColor = computeColor(BufferTexture, gl_TexCoord[0].st, 0.0);\n"
"}\n"; |
|