- 精华
- 0
- 帖子
- 16
- 威望
- 0 点
- 积分
- 16 点
- 种子
- 10 点
- 注册时间
- 2018-7-24
- 最后登录
- 2024-7-20
|
本帖最后由 堂兄有礼 于 2018-7-28 08:12 编辑
TeamWei 老兄的ePSXe滤镜非常棒!用过的人都应该发现了,这个支持peteopenGL插件的GLSL shader简直让PS一代的画面直接上升了一个台阶!
【原创】ps模拟器最佳画质研究2D+3D更新20180506
这几天我突然发现mGBA也可以挂载GLSL shader,代码书写格式似乎也一样,于是我就按照它的基本格式移植了过去,发现虽然看起来起作用了,但画面其实是错误的,它会随着游戏画面变成纯白色或者纯灰色,我把代码一条条的删减测试,但这些代码似乎都是有关联性,删哪条都会让滤镜失效,所以不得已,只好过来向这里的坛友们求助,是否有人能把这滤镜移植到mGBA?
mGBA的滤镜格式是一个或者若干.fs文件,和一个manifest.ini
我修改使用的manifest.ini如下:- [shader]
- name=GPUPETEOGL2
- author=endrift
- description=A pristine recreation of the illuminated Game Boy Advance SP
- passes=1
- [pass.0]
- fragmentShader=gpuPeteOGL2.fs
- blend=1
- width=-4
- height=-4
- [pass.1]
- fragmentShader=gpuPeteOGL2slv.fs
- width=-4
- height=-4
- [pass.1.uniform.lightBrightness]
- type=float
- default=1
- readableName=Light brightness
- [pass.1.uniform.reflectionBrightness]
- type=float
- default=0.07
- readableName=Reflection brightness
- [pass.1.uniform.reflectionDistance]
- type=float2
- default[0]=0
- default[1]=0.025
- readableName=Reflection distance
复制代码 ---------------------------------------------------分割线------------------------------------------------------------
---------------------------------------------------分割线------------------------------------------------------------
---------------------------------------------------分割线------------------------------------------------------------
---------------------------------------------------分割线------------------------------------------------------------
下面附上滤镜的代码。
第一个是gpuPeteOGL2.slf- /*
- AA & xBR 2D+3D shader, coded by 2016 guest(r)
- Hyllian's xBR Level 2 shader
- Copyright (C) 2011/2014 Hyllian/Jararaca - sergiogdb@gmail.com
- AA + colors shader
- Copyright (C) 2016 guest(r) - guest.r@gmail.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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- /*
- 2017.11.16, by teamwei
- 首先感谢代码的原作者!
- 本人在源代码的基础上增加了CRT电视效果、sRGB效果
- 加强对2D和3D画面的优化,尽可能做到2D+3D完美结合的画面
- 如果对画面不满意,可自行修改代码(部分中文注释)
- */
- // Color variables (please edit them)
- const vec3 c_ch = vec3(1.0,1.0,1.0); // rgb color channel intensity
- const float threshold = 0.05; // xBR algorithm threshold (3D -> 0.0....0.05 -> 2D)
- uniform sampler2D OGL2Texture;
- uniform vec4 OGL2Size;
- uniform vec4 OGL2Param;
- const vec3 dt = vec3(1.0,1.0,1.0);
- //---------------3D画面滤镜效果---------------
- vec3 SoftAA (sampler2D OGL2Texture, vec2 texcoord) {
- float offset = 1;
- if (OGL2Size.x > 4096.0) offset = 0.30;
- float x = offset/2048.0;
- float y = offset/1024.0;
- vec4 yx3 = vec4(1.0/4096,1.0/2048,-1.0/4096,-1.0/2048)*0.8;
- vec3 c11 = texture2D(OGL2Texture, texcoord).xyz;
- vec3 s00 = texture2D(OGL2Texture, texcoord + yx3.zw).xyz;
- vec3 s20 = texture2D(OGL2Texture, texcoord + yx3.xw).xyz;
- vec3 s22 = texture2D(OGL2Texture, texcoord + yx3.xy).xyz;
- vec3 s02 = texture2D(OGL2Texture, texcoord + yx3.zy).xyz;
- vec3 c00 = texture2D(OGL2Texture, texcoord + vec2( -x, -y)).xyz;
- vec3 c22 = texture2D(OGL2Texture, texcoord + vec2( x, y)).xyz;
- vec3 c20 = texture2D(OGL2Texture, texcoord + vec2( x, -y)).xyz;
- vec3 c02 = texture2D(OGL2Texture, texcoord + vec2( -x, y)).xyz;
- vec3 c10 = texture2D(OGL2Texture, texcoord + vec2(0.0, -y)).xyz;
- vec3 c21 = texture2D(OGL2Texture, texcoord + vec2( x,0.0)).xyz;
- vec3 c12 = texture2D(OGL2Texture, texcoord + vec2(0.0, y)).xyz;
- vec3 c01 = texture2D(OGL2Texture, texcoord + vec2( -x,0.0)).xyz;
- float d1=dot(abs(c00-c22),c_ch)+0.001;
- float d2=dot(abs(c20-c02),c_ch)+0.001;
- float hl=dot(abs(c01-c21),c_ch)+0.001;
- float vl=dot(abs(c10-c12),c_ch)+0.001;
- float m1=dot(abs(s00-s22),c_ch)+0.001;
- float m2=dot(abs(s02-s20),c_ch)+0.001;
- vec3 mn1 = min(min(c00,c01),c02);
- vec3 mn2 = min(min(c10,c11),c12);
- vec3 mn3 = min(min(c20,c21),c22);
- vec3 mx1 = max(max(c00,c01),c02);
- vec3 mx2 = max(max(c10,c11),c12);
- vec3 mx3 = max(max(c20,c21),c22);
- mn1 = min(min(mn1,mn2),mn3);
- mx1 = max(max(mx1,mx2),mx3);
- vec3 t1=(hl*(c10+c12)+vl*(c01+c21)+(hl+vl)*c11)/(3.0*(hl+vl));
- vec3 t2=(d1*(c20+c02)+d2*(c00+c22)+(d1+d2)*c11)/(3.0*(d1+d2));
-
- c11 =.25*(t1+t2+(m2*(s00+s22)+m1*(s02+s20))/(m1+m2));
- vec3 dif1 = abs(c11-mn1) + 0.001*c_ch;
- vec3 dif2 = abs(c11-mx1) + 0.001*c_ch;
- float filterparam = 2.8; //3D效果等级
-
- dif1=vec3(pow(dif1.x,filterparam),pow(dif1.y,filterparam),pow(dif1.z,filterparam));
- dif2=vec3(pow(dif2.x,filterparam),pow(dif2.y,filterparam),pow(dif2.z,filterparam));
- c11.r = (dif1.x*mx1.x + dif2.x*mn1.x)/(dif1.x + dif2.x);
- c11.g = (dif1.y*mx1.y + dif2.y*mn1.y)/(dif1.y + dif2.y);
- c11.b = (dif1.z*mx1.z + dif2.z*mn1.z)/(dif1.z + dif2.z);
- return c11;
- }
- //---------------END---------------
- //---------------2D画面滤镜效果---------------
- #define WP1 8
- #define WP2 3
- #define WP3 -1.0
- const vec3 Y = vec3(.2126, .7152, .0722);
- const vec2 OGLSize = vec2( 1024.0, 512.0);
- const vec2 OGLInvSize = vec2( 0.0009765625, 0.001953125);
- const vec2 dx = vec2( 0.0009765625, 0.0);
- const vec2 dy = vec2( 0.0, 0.001953125 );
- float luma(vec3 color)
- {
- return dot(color, Y);
- }
- vec3 bilinear(float p, float q, vec3 A, vec3 B, vec3 C, vec3 D)
- {
- return ((1-p)*(1-q)*A + p*(1-q)*B + (1-p)*q*C + p*q*D);
- }
- vec3 DDTSharp (sampler2D OGL2Texture, vec2 texcoord)
- {
-
- vec2 pos = fract(texcoord*OGLSize)-vec2(0.5, 0.5); // pos = pixel position
- vec2 dir = sign(pos); // dir = pixel direction
- vec2 fp = fract(texcoord*OGLSize);
- vec2 texcoord1 = texcoord-fp*OGLInvSize + 0.5*OGLInvSize;
- vec2 g1 = dir*dx;
- vec2 g2 = dir*dy;
- // A1 B1
- // A0 A B B2
- // C0 C D D2
- // C3 D3
- vec3 A = texture2D(OGL2Texture, texcoord1 ).xyz;
- vec3 B = texture2D(OGL2Texture, texcoord1 +g1 ).xyz;
- vec3 C = texture2D(OGL2Texture, texcoord1 +g2).xyz;
- vec3 D = texture2D(OGL2Texture, texcoord1 +g1+g2).xyz;
- vec3 A1 = texture2D(OGL2Texture, texcoord1 -g2).xyz;
- vec3 B1 = texture2D(OGL2Texture, texcoord1 +g1-g2).xyz;
- vec3 A0 = texture2D(OGL2Texture, texcoord1 -g1 ).xyz;
- vec3 C0 = texture2D(OGL2Texture, texcoord1 -g1+g2).xyz;
- vec3 B2 = texture2D(OGL2Texture, texcoord1 +2*g1 ).xyz;
- vec3 D2 = texture2D(OGL2Texture, texcoord1 +2*g1+ g2).xyz;
- vec3 C3 = texture2D(OGL2Texture, texcoord1 +2*g2).xyz;
- vec3 D3 = texture2D(OGL2Texture, texcoord1 +g1+2*g2).xyz;
- float a = luma(A);
- float b = luma(B);
- float c = luma(C);
- float d = luma(D);
- float a1 = luma(A1);
- float b1 = luma(B1);
- float a0 = luma(A0);
- float c0 = luma(C0);
- float b2 = luma(B2);
- float d2 = luma(D2);
- float c3 = luma(C3);
- float d3 = luma(D3);
- float p = abs(pos.x);
- float q = abs(pos.y);
- float k = distance(pos,g1);
- float l = distance(pos,g2);
- float wd1 = WP1*abs(a-d) + WP2*(abs(b-a1) + abs(b-d2) + abs(c-a0) + abs(c-d3)) + WP3*(abs(a1-d2) + abs(a0-d3));
- float wd2 = WP1*abs(b-c) + WP2*(abs(a-b1) + abs(a-c0) + abs(d-b2) + abs(d-c3)) + WP3*(abs(b1-c0) + abs(b2-c3));
- if ( wd1 < wd2 )
- {
- if (k < l)
- {
- C = A + D - B;
- }
- else
- {
- B = A + D - C;
- }
- }
- else if (wd1 > wd2)
- {
- D = B + C - A;
- }
- vec3 color = clamp (bilinear(p, q, A, B, C, D), 0.0, 1.0);
- return color;
- }
- //---------------END---------------
- //---------------CRT电视效果---------------
- #define shadowMask 5 //效果等级 1, 2, 3, 4 or 5
- #define maskDark 0.92
- #define maskLight 1.20
- // Shadow mask
- vec3 Mask(vec2 pos){
- vec3 mask=vec3(maskDark,maskDark,maskDark);
- // Very compressed TV style shadow mask.
- if (shadowMask == 1) {
- float line=maskLight;
- float odd=0.0;
- if(fract(pos.x/6.0)<0.5)odd=1.0;
- if(fract((pos.y+odd)/2.0)<0.5)line=maskDark;
- pos.x=fract(pos.x/3.0);
-
- if(pos.x<0.333)mask.r=maskLight;
- else if(pos.x<0.666)mask.g=maskLight;
- else mask.b=maskLight;
- mask*=line;
- }
- // Aperture-grille.
- else if (shadowMask == 2) {
- pos.x=fract(pos.x/3.0);
- if(pos.x<0.333)mask.r=maskLight;
- else if(pos.x<0.666)mask.g=maskLight;
- else mask.b=maskLight;
- }
- // Stretched VGA style shadow mask (same as prior shaders).
- else if (shadowMask == 3) {
- pos.x+=pos.y*3.0;
- pos.x=fract(pos.x/6.0);
- if(pos.x<0.333)mask.r=maskLight;
- else if(pos.x<0.666)mask.g=maskLight;
- else mask.b=maskLight;
- }
- // VGA style shadow mask.
- else if (shadowMask == 4) {
- pos.xy=floor(pos.xy*vec2(1.0,0.5));
- pos.x+=pos.y*3.0;
- pos.x=fract(pos.x/6.0);
- if(pos.x<0.333)mask.r=maskLight;
- else if(pos.x<0.666)mask.g=maskLight;
- else mask.b=maskLight;
- }
-
- //2018.05.06, by teamwei
- else if (shadowMask == 5) {
- if(fract(pos.x * 0.5) < 0.5) {
- mask.g *= 1.4;
- } else {
- mask.r *= 1.4;
- mask.b *= 1.4;
- }
- if (mod(pos.y,4.0) > 1.0) {
- mask *= 1;
- } else {
- mask *= 0.72;
- }
-
- if (mod(pos.y,2.0) >1.0) mask *= 0.88;
- }
-
- return mask;
- }
- //---------------END---------------
- //---------------sRGB画面效果---------------
- const float NTSC = 0.25; //效果等级
- vec3 ntscrgb_2_xyz( vec3 c ) {
- //Inverse Companding
- vec3 v = vec3( pow( c.r, 2.2 ), pow( c.g, 2.2 ), pow( c.b, 2.2 ) );
- return v *
- mat3( 0.6068909, 0.1735011, 0.2003480,
- 0.2989164, 0.5865990, 0.1144845,
- 0.0000000, 0.0660957, 1.1162243 );
- }
- // conversion from XYZ to sRGB Reference White D65 ( color space used by windows )
- vec3 xyz_2_srgb( vec3 c ) {
- vec3 v = c *
- mat3( 3.2404542, -1.5371385, -0.4985314,
- -0.9692660, 1.8760108, 0.0415560,
- 0.0556434, -0.2040259, 1.0572252 );
- //Companding
- v.r = ( v.r > 0.0031308 ) ? (( 1.055 * pow( v.r, ( 1.0 / 2.4 ))) - 0.055 ) : 12.92 * v.r;
- v.g = ( v.g > 0.0031308 ) ? (( 1.055 * pow( v.g, ( 1.0 / 2.4 ))) - 0.055 ) : 12.92 * v.g;
- v.b = ( v.b > 0.0031308 ) ? (( 1.055 * pow( v.b, ( 1.0 / 2.4 ))) - 0.055 ) : 12.92 * v.b;
- return v;
- }
- vec3 ntscrgb_2_srgb( vec3 c ) {
- return xyz_2_srgb( ntscrgb_2_xyz( c ) );
- }
- //---------------END---------------
- float diff2D (vec2 coord)
- {
- vec3 c00 = texture2D(OGL2Texture, coord + 0.25*(-dx-dy)).xyz;
- vec3 c20 = texture2D(OGL2Texture, coord + 0.25*( dx-dy)).xyz;
- vec3 c02 = texture2D(OGL2Texture, coord + 0.25*(-dx+dy)).xyz;
- vec3 c22 = texture2D(OGL2Texture, coord + 0.25*( dx+dy)).xyz;
- vec3 mn = min(min(c00,c20),min(c02,c22));
- vec3 mx = max(max(c00,c20),max(c02,c22));
- return dot(mx-mn,dt);
- }
- void main()
- {
- vec2 fp = fract(gl_TexCoord[0].xy*OGLSize);
- vec2 texcoord = gl_TexCoord[0].xy-fp*OGLInvSize + 0.5*OGLInvSize;
- vec2 locator = sign(fp-vec2(0.5000000001,0.5000000001));
- float maxdiff = max(max(diff2D(texcoord+locator*dx),diff2D(texcoord+locator*dy)),diff2D(texcoord));
- vec3 color;
- if (maxdiff <= threshold) { color = DDTSharp(OGL2Texture, gl_TexCoord[0].xy+vec2(0.00000001)).xyz;}
- else color = SoftAA(OGL2Texture, gl_TexCoord[0].xy);;
- color = mix(color, ntscrgb_2_srgb( color ), NTSC); //启用sRGB效果
- color*= Mask(gl_FragCoord.xy); //启动CRT效果
- gl_FragColor.xyz = color;
- }
复制代码 ---------------------------------------------------分割线------------------------------------------------------------
---------------------------------------------------分割线------------------------------------------------------------
---------------------------------------------------分割线------------------------------------------------------------
---------------------------------------------------分割线------------------------------------------------------------
---------------------------------------------------分割线------------------------------------------------------------
第二个是gpuPeteOGL2.slv- /*
- Copyright (C) 2016 guest(r) - guest.r@gmail.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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- uniform vec4 OGL2Param;
- void main()
- {
- gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
- gl_TexCoord[0] = gl_MultiTexCoord0;
- }
复制代码 好了。
|
|