Pete´s Messageboard... No ISO/BIOS requests!

Homepage Members Register Login Search Old board


Neuer Thread ...
More : [1] [2]


AuthorTopics » Book an abo for this threadClose Thread Move Thread Fix the thread Print view Delete this thread

guest ...
Real addict
.........

...

Status:Offline
Date registered: 30.07.2004
Post:854
Send Message
...   Created on 01.07.2009 - 15:18Jump to top Quote this post Report this post Edit Delete


You can grab Dosbox from: http://code.google.com/p/emugameshader/downloads/list

It's a 2 pass shader, not easily merged into one pass. I hope it can be put to some good use.

The Gs2xSmartFilter shader:

Code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
 

/*

   Copyright (C) 2009 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.

*/

/*

   The Gs2xSmartFilter shader is well used to scale a gfx. buffer to a custom size.

   Note: set scaler to normal2x or any other 2x scaler.

   If playing a hi-res game, add the word: forced (example scaler = normal2x forced)

*/



#include "shader.code"

float  scaling   : SCALING = 0.1;
float3 dtt = float3(0.001,0.001,0.001);


string preprocessTechique : PREPROCESSTECHNIQUE = "Gs2x";
string combineTechique : COMBINETECHNIQUE =  "SmartFilter";



// **VS**

VERTEX_STUFF0 S_VERTEX (float3 p : POSITION, float2 tc : TEXCOORD0)
{
  VERTEX_STUFF0 OUT = (VERTEX_STUFF0)0;
  
  float dx = ps.x;
  float dy = ps.y;

  OUT.coord = mul(float4(p,1),WorldViewProjection);
  OUT.CT = tc;
  OUT.t1.xy = tc + float2(-dx, 0);
  OUT.t2.xy = tc + float2( dx, 0);
  OUT.t3.xy = tc + float2( 0,-dy);
  OUT.t4.xy = tc + float2( 0, dy);
  OUT.t1.zw = tc + float2(-dx,-dy);
  OUT.t2.zw = tc + float2(-dx, dy);
  OUT.t3.zw = tc + float2( dx,-dy);
  OUT.t4.zw = tc + float2( dx, dy);

  return OUT;
}

// **PS**

float4 S_FRAGMENT ( in VERTEX_STUFF0 VAR ) : COLOR
{
   half3 c00 = tex2D(s_p, VAR.t1.zw).xyz; 
   half3 c10 = tex2D(s_p, VAR.t3.xy).xyz; 
   half3 c20 = tex2D(s_p, VAR.t3.zw).xyz; 
   half3 c01 = tex2D(s_p, VAR.t1.xy).xyz; 
   half3 c11 = tex2D(s_p, VAR.CT).xyz; 
   half3 c21 = tex2D(s_p, VAR.t2.xy).xyz; 
   half3 c02 = tex2D(s_p, VAR.t2.zw).xyz; 
   half3 c12 = tex2D(s_p, VAR.t4.xy).xyz; 
   half3 c22 = tex2D(s_p, VAR.t4.zw).xyz;

   float d1=dot(abs(c00-c22),dt)+0.001;
   float d2=dot(abs(c20-c02),dt)+0.001;
   float hl=dot(abs(c01-c21),dt)+0.001;
   float vl=dot(abs(c10-c12),dt)+0.001;

   float3 t1=(hl*(c10+c12)+vl*(c01+c21)+(hl+vl)*c11)/(6.0*(hl+vl));
   float3 t2=(d1*(c20+c02)+d2*(c00+c22)+(d1+d2)*c11)/(6.0*(d1+d2));

   return float4 (t1+t2,1);

}

VERTEX_STUFF0 S_VERTEX0 (float3 p : POSITION, float2 tc : TEXCOORD0)
{
  VERTEX_STUFF0 OUT = (VERTEX_STUFF0)0;
  
  float dx = ps.x*0.5;
  float dy = ps.y*0.5;

  OUT.coord = mul(float4(p,1),WorldViewProjection);
  OUT.CT = tc;
  OUT.t1.xy = tc + float2(-dx, 0);
  OUT.t2.xy = tc + float2( dx, 0);
  OUT.t3.xy = tc + float2( 0,-dy);
  OUT.t4.xy = tc + float2( 0, dy);
  OUT.t1.zw = tc + float2(-dx,-dy);
  OUT.t2.zw = tc + float2(-dx, dy);
  OUT.t3.zw = tc + float2( dx,-dy);
  OUT.t4.zw = tc + float2( dx, dy);

  return OUT;
}

// **PS**

float4 S_FRAGMENT0 ( in VERTEX_STUFF0 VAR ) : COLOR
{
   half3 c00 = tex2D(w_l, VAR.t1.zw).xyz; 
   half3 c10 = tex2D(w_l, VAR.t3.xy).xyz; 
   half3 c20 = tex2D(w_l, VAR.t3.zw).xyz; 
   half3 c01 = tex2D(w_l, VAR.t1.xy).xyz; 
   half3 c11 = tex2D(w_l, VAR.CT).xyz; 
   half3 c21 = tex2D(w_l, VAR.t2.xy).xyz; 
   half3 c02 = tex2D(w_l, VAR.t2.zw).xyz; 
   half3 c12 = tex2D(w_l, VAR.t4.xy).xyz; 
   half3 c22 = tex2D(w_l, VAR.t4.zw).xyz;

   float3 mn1 = min(min(c00,c01),c02);
   float3 mn2 = min(min(c10,c11),c12);
   float3 mn3 = min(min(c20,c21),c22);
   float3 mx1 = max(max(c00,c01),c02);
   float3 mx2 = max(max(c10,c11),c12);
   float3 mx3 = max(max(c20,c21),c22);

   mn1 = min(min(mn1,mn2),mn3);
   mx1 = max(max(mx1,mx2),mx3);

   float3 dif1 = abs(c11-mn1) + dtt;
   float3 dif2 = abs(c11-mx1) + dtt;

   float filterparam = 5.0; 
// float filterparam = 2*length(mn1-mx1) + 0.75; 
// float filterparam = length(mx1-mn1) + dot(mx1-mn1,mx1-mn1) + dot(abs(mx1-mn1),float3(2,2,2)) + 0.5;
// float filterparam = pow(dot(abs(mn1-mx1),float3(2,2,2)),sqrt(dot(abs(mn1-mx1),float3(1,1,1)))+0.5) + 0.75;
// float filterparam = 2.75*dot(abs(mn1-mx1),dt)/(dot(c11,dt)+0.1) + 0.5;

   dif1=float3(pow(dif1.x,filterparam),pow(dif1.y,filterparam),pow(dif1.z,filterparam));
   dif2=float3(pow(dif2.x,filterparam),pow(dif2.y,filterparam),pow(dif2.z,filterparam));

   return float4( (dif1.x*mx1.x + dif2.x*mn1.x)/(dif1.x + dif2.x),
                  (dif1.y*mx1.y + dif2.y*mn1.y)/(dif1.y + dif2.y),
                  (dif1.z*mx1.z + dif2.z*mn1.z)/(dif1.z + dif2.z),1);
}


technique Gs2x
{
   pass P0
   {
     VertexShader = compile vs_2_0 S_VERTEX();
     PixelShader  = compile ps_2_0 S_FRAGMENT();
   }  
}


technique SmartFilter
{
   pass P0
   {
     VertexShader = compile vs_3_0 S_VERTEX0();
     PixelShader  = compile ps_3_0 S_FRAGMENT0();
   }  
}


[Dieser Beitrag wurde am 10.07.2009 - 18:40 von guest aktualisiert]




guest ...
Real addict
.........

...

Status:Offline
Date registered: 30.07.2004
Post:854
Send Message
...   Created on 02.07.2009 - 16:10Jump to top Quote this post Report this post Edit Delete


OK the algorithm is not easily 1 passed, but the end effect can be achieved 'close to original' with little more trust 'on guesswork. :P

With the OGL2 plugin it's best to set internal resolutions to low (0,0), use fullscreen smothing and max shader effect level.

The GLSmartTexMag filter:

Fragment file:

Code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
 

/*
   The GLSmartTexMag filter shader
   
   Copyright (C) 2009 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 sampler2D OGL2Texture;

float hd(float x)

  float y = x*1.1547-1.0;
  float z = x*0.8660254;
  y = (sin(y*1.5707)+1.0)*0.866025;
  return ((1.0-z)*x+z*y);
}

void main()
{
    vec3 c11 = texture2D(OGL2Texture, gl_TexCoord[0].xy).xyz;
    vec3 s00 = texture2D(OGL2Texture, gl_TexCoord[1].xy).xyz; 
    vec3 s20 = texture2D(OGL2Texture, gl_TexCoord[2].xy).xyz; 
    vec3 s22 = texture2D(OGL2Texture, gl_TexCoord[3].xy).xyz; 
    vec3 s02 = texture2D(OGL2Texture, gl_TexCoord[4].xy).xyz; 
    vec3 c00 = texture2D(OGL2Texture, gl_TexCoord[5].xy).xyz; 
    vec3 c22 = texture2D(OGL2Texture, gl_TexCoord[6].xy).xyz; 
    vec3 c20 = texture2D(OGL2Texture, gl_TexCoord[5].zw).xyz;
    vec3 c02 = texture2D(OGL2Texture, gl_TexCoord[6].zw).xyz;
    vec3 c01 = texture2D(OGL2Texture, gl_TexCoord[1].zw).xyz; 
    vec3 c21 = texture2D(OGL2Texture, gl_TexCoord[2].zw).xyz; 
    vec3 c10 = texture2D(OGL2Texture, gl_TexCoord[3].zw).xyz; 
    vec3 c12 = texture2D(OGL2Texture, gl_TexCoord[4].zw).xyz;  
    vec3 dt = vec3(1.0,1.0,1.0);

    float d1=dot(abs(c00-c22),dt)+0.001;
    float d2=dot(abs(c20-c02),dt)+0.001;
    float hl=dot(abs(c01-c21),dt)+0.001;
    float vl=dot(abs(c10-c12),dt)+0.001;
    float m1=dot(abs(s00-s22),dt)+0.001;
    float m2=dot(abs(s02-s20),dt)+0.001;

    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 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);

    float filterparam = 3.0; 
    // float filterparam = 2.0*length(mn1-mx1) + 0.75; 
      // float filterparam = length(mx1-mn1) + dot(mx1-mn1,mx1-mn1) + dot(abs(mx1-mn1),vec3(2.0)) + 0.5;

    vec3 dif1 = abs(c11-mn1) + 0.001*dt;
    vec3 dif2 = abs(c11-mx1) + 0.001*dt;

    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);

    d1 = length(c11);
    c11= vec3(pow(c11,vec3(1.2)));

        gl_FragColor.xyz=hd(d1)*normalize(c11);
}




Vertex file:

Code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
 

/*
   
   Copyright (C) 2005 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;
uniform vec4 OGL2Size;

void main()
{
float x = (OGL2Size.x/2048.0)*OGL2Param.x;
float y = (OGL2Size.y/1024.0)*OGL2Param.y;
vec2 dg1 = vec2( x,y);  vec2 dg2 = vec2(-x,y);
vec2 sd1 = dg1*0.5;     vec2 sd2 = dg2*0.5;
vec2 ddx = vec2(x,0.0); vec2 ddy = vec2(0.0,y);

gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1].xy = gl_TexCoord[0].xy - sd1;
gl_TexCoord[2].xy = gl_TexCoord[0].xy - sd2;
gl_TexCoord[3].xy = gl_TexCoord[0].xy + sd1;
gl_TexCoord[4].xy = gl_TexCoord[0].xy + sd2;
gl_TexCoord[5].xy = gl_TexCoord[0].xy - dg1;
gl_TexCoord[6].xy = gl_TexCoord[0].xy + dg1;
gl_TexCoord[5].zw = gl_TexCoord[0].xy - dg2;
gl_TexCoord[6].zw = gl_TexCoord[0].xy + dg2;
gl_TexCoord[1].zw = gl_TexCoord[0].xy - ddy;
gl_TexCoord[2].zw = gl_TexCoord[0].xy + ddx;
gl_TexCoord[3].zw = gl_TexCoord[0].xy + ddy;
gl_TexCoord[4].zw = gl_TexCoord[0].xy - ddx;
}


[Dieser Beitrag wurde am 05.08.2009 - 12:20 von guest aktualisiert]




zaykho 



...

Status:Offline
Date registered: 25.06.2009
Post:5
Send Message
...   Created on 02.07.2009 - 21:15Jump to top Quote this post Report this post Edit Delete


W - O - W !!!!!

That's A W E S O M E !!! o_O


It is very close to what I search, a very nice shader what smooth and improve the color of the game.

Very nice ;p

But what is DOSbox ??? I dont understand ?


Here it's a screen "comporator" ;o











(ps: yes guest as right, be carefull if you use the maximum internal resolution (x,y) with this shader, because your system will be very slow!)




KrossX 
Strong supporter
......

...

Status:Offline
Date registered: 16.06.2008
Post:94
Send Message
...   Created on 03.07.2009 - 09:13Jump to top Quote this post Report this post Edit Delete


It's very nice indeed. O_O

Here are some shots running Castlevania: SotN

Pete's OGL2, Internal (0,0):
No shader | Shader level 4

For comparison, with PEOpS:
Scale3x | HQ3x

And yes, the shader is quite demanding. It went from 250+ FPS with the shader disabled, to ~30 FPS when enabled... no difference from level 1 to 4.
Of course, this just with me'old low end piece of... hardware. XD

PS: O_O ... the character looks a bit, fat.. on OGL2.

#EDIT:
More Pete's OGL2 tests.

Same resolution, 1280x960
Internal (2,2)... FPS ~28

Resolution, 640x480
Internal (0,0)... FPS ~106
Internal (2,2)... FPS ~75

Resolution, 800x600
Internal (0,0)... FPS ~70
Internal (2,2)... FPS ~55

I guess it depends a lot more on the normal resolution,
than on the internal resolution. Also, no noticeable
difference in speed between shader levels.




[Dieser Beitrag wurde am 03.07.2009 - 09:27 von KrossX aktualisiert]





Signature

guest ...
Real addict
.........

...

Status:Offline
Date registered: 30.07.2004
Post:854
Send Message
...   Created on 03.07.2009 - 19:19Jump to top Quote this post Report this post Edit Delete


I changed the code a bit, should work a bit better now, especially with other formula for the 'filterparam' variable.

It still works like 1-x to n-x filter, or more like 1-x to n-x HQ filter due the better compare value.

The DosBOX version has a 1-x to 2-x, 2-x to n-x implementation (2 pass).

I mention this because in the OGL2 case only the (0,0) res. interpolates the big pixels in a suitable way. (1,1) can be used - for example - with texture filtering or 2xsai hi-res textures...

It was found out as it seems that 4x scale, AA, smart-mag-filter would do a very nice job, but 3 passes are needed for this, or at least 2 for a LQ implementation.

... and shader power got cheap, available, The HD4770, HD4850...are even cheaper now then my 9600 Atlantis was when i bought it. :D




KrossX 
Strong supporter
......

...

Status:Offline
Date registered: 16.06.2008
Post:94
Send Message
...   Created on 03.07.2009 - 21:11Jump to top Quote this post Report this post Edit Delete


Yay! More to try~~

I see why is better to try it at native internal resolution.
Quite the limitation having to do all that on one pass.

Anyhow, here are some screens:
OGL2, 1280x960, Internal (0,0), Shader level 4
With FS filter | Without FS filter

There are some artifacts now, those white and yellow... dots?
About speed, no change. XD

And yes, considering what I payed for my low end Series 7, I could buy a 9800GTX+ now. T_T

[Dieser Beitrag wurde am 03.07.2009 - 21:11 von KrossX aktualisiert]





Signature

guest ...
Real addict
.........

...

Status:Offline
Date registered: 30.07.2004
Post:854
Send Message
...   Created on 04.07.2009 - 06:57Jump to top Quote this post Report this post Edit Delete


Kk, i rather reposted the previous version, since it seem to be a little more 'dot resistant'.
It's my humble guess only that there is some degree of risk involved when calculating the base values in a broad manner. It could be done more accurate in a single pass, gaining like 25% on quality, but much slower.

-----------------------------------------------------------

Another interesting discovery. Since DOS games use less colors compared with PSX games (texturing, transparence, dithering, filtering...), the classic scaling algorithms do a much better job there.
If smart filter is used with like advmame2x instead of normal 2x, then the end image can turn out even nicer...

Example1: KQ5 - advmame2x + smart filter, 1024x768

Example2: X-Wing - 2xSai + smart filter, 900x700

Fun fun fun...


[Dieser Beitrag wurde am 23.07.2009 - 15:27 von guest aktualisiert]




KrossX 
Strong supporter
......

...

Status:Offline
Date registered: 16.06.2008
Post:94
Send Message
...   Created on 14.07.2009 - 07:56Jump to top Quote this post Report this post Edit Delete


O_O .. update and screenies, yay!
Those DOS games look quite nice. XD

I was going to post this screenies, using the shader that had filterparam = 4.0

640x480(0,0): No Shader | Shader lv4
640x480(1,1): No Shader | Shader lv4 <= Looks very nice to me. =D
1280x960(1,1): No Shader | Shader lv4

Now to update the shader files with the new ones. ^_^

#EDIT: With new version~~
640x480(1,1): No Shader | Shader lv4
I notice abolutely, no difference. XD
Imma keep it.

[Dieser Beitrag wurde am 14.07.2009 - 08:12 von KrossX aktualisiert]





Signature

guest ...
Real addict
.........

...

Status:Offline
Date registered: 30.07.2004
Post:854
Send Message
...   Created on 23.07.2009 - 15:40Jump to top Quote this post Report this post Edit Delete


An improoved version. For DosBox only atm.

Code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
 

/* ############################################################################################

   Copyright (C) 2009 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.

   ############################################################################################

   The Gs2xSmartFilter shader is well used to scale a gfx. buffer to a custom size.

   Note: set scaler to normal2x or advmame2x...

   Note: If playing a hi-res game set scaler to forced mode (i.e. scaler = normal2x forced)

   ############################################################################################*/



#include "shader.code"

float scaling   : SCALING = 0.1;
float3 dtt = float3(0.005,0.005,0.005);

string preprocessTechique : PREPROCESSTECHNIQUE = "Gs2x";
string combineTechique : COMBINETECHNIQUE =  "SmartFilter";




VERTEX_STUFF0 S_VERTEX (float3 p : POSITION, float2 tc : TEXCOORD0)
{
  VERTEX_STUFF0 OUT = (VERTEX_STUFF0)0;
  
  float dx = ps.x;
  float dy = ps.y;

  OUT.coord = mul(float4(p,1),WorldViewProjection);
  OUT.CT = tc;
  OUT.t1.xy = tc + float2(-dx, 0);
  OUT.t2.xy = tc + float2( dx, 0);
  OUT.t3.xy = tc + float2( 0,-dy);
  OUT.t4.xy = tc + float2( 0, dy);
  OUT.t1.zw = tc + float2(-dx,-dy);
  OUT.t2.zw = tc + float2(-dx, dy);
  OUT.t3.zw = tc + float2( dx,-dy);
  OUT.t4.zw = tc + float2( dx, dy);

  return OUT;
}

// **PS**

float4 S_FRAGMENT ( in VERTEX_STUFF0 VAR ) : COLOR
{
   half3 c00 = tex2D(s_l, VAR.t1.zw).xyz; 
   half3 c10 = tex2D(s_l, VAR.t3.xy).xyz; 
   half3 c20 = tex2D(s_l, VAR.t3.zw).xyz; 
   half3 c01 = tex2D(s_l, VAR.t1.xy).xyz; 
   half3 c11 = tex2D(s_l, VAR.CT).xyz; 
   half3 c21 = tex2D(s_l, VAR.t2.xy).xyz; 
   half3 c02 = tex2D(s_l, VAR.t2.zw).xyz; 
   half3 c12 = tex2D(s_l, VAR.t4.xy).xyz; 
   half3 c22 = tex2D(s_l, VAR.t4.zw).xyz;

   float d1 = dot(abs(c00-c22),dt)+0.001;
   float d2 = dot(abs(c20-c02),dt)+0.001;
   float hl = dot(abs(c01-c21),dt)+0.001;
   float vl = dot(abs(c10-c12),dt)+0.001;

   float k1=hl+vl;
   float k2=d1+d2;
    
   float3 t1=(hl*(c10+c12)+vl*(c01+c21)+k1*c11)/(3.0*(hl+vl));
   float3 t2=(d1*(c20+c02)+d2*(c00+c22)+k2*c11)/(3.0*(d1+d2));

   k1=dot(abs(t1-c11),dt)+0.001;
   k2=dot(abs(t2-0.5*(c11+t1)),dt)+0.001;

   return float4((k1*t2+k2*t1)/(k1+k2),1);
}


VERTEX_STUFF4 S_VERTEX0 (float3 p : POSITION, float2 tc : TEXCOORD0)
{
  VERTEX_STUFF4 OUT = (VERTEX_STUFF4)0;
  
  float dx = ps.x*0.5;
  float dy = ps.y*0.5;

  OUT.coord = mul(float4(p,1),WorldViewProjection);
  OUT.CT = tc;

  OUT.t1 = float4(tc,tc) + float4(-dx,-dy, dx,-dy); // outer diag. texels
  OUT.t2 = float4(tc,tc) + float4( dx, dy,-dx, dy);
  OUT.t5 = float4(tc,tc) + float4(-dx,  0, dx,  0); // inner hor/vert texels
  OUT.t6 = float4(tc,tc) + float4(  0,-dy,  0, dy);

return OUT;
}


// **PS**

float4 S_FRAGMENT0 ( in VERTEX_STUFF4 VAR ) : COLOR

{
  half3 c11 = tex2D(w_l, VAR.CT   ).xyz;
  half3 c00 = tex2D(w_l, VAR.t1.xy).xyz;
  half3 c20 = tex2D(w_l, VAR.t1.zw).xyz;
  half3 c22 = tex2D(w_l, VAR.t2.xy).xyz;
  half3 c02 = tex2D(w_l, VAR.t2.zw).xyz;
  half3 c01 = tex2D(w_l, VAR.t5.xy).xyz;
  half3 c21 = tex2D(w_l, VAR.t5.zw).xyz;
  half3 c10 = tex2D(w_l, VAR.t6.xy).xyz;
  half3 c12 = tex2D(w_l, VAR.t6.zw).xyz;

  float d1 = dot(abs(c00-c22),dt)+0.001;
  float d2 = dot(abs(c20-c02),dt)+0.001;
  float hl = dot(abs(c01-c21),dt)+0.001;
  float vl = dot(abs(c10-c12),dt)+0.001;

  float3 mn1 = min (min (c00,c01), c02);
  float3 mn2 = min (min (c10,c11), c12);
  float3 mn3 = min (min (c20,c21), c22);
  float3 mx1 = max (max (c00,c01), c02);
  float3 mx2 = max (max (c10,c11), c12);
  float3 mx3 = max (max (c20,c21), c22);

  mn1 = min(min(mn1,mn2),mn3);
  mx1 = max(max(mx1,mx2),mx3);

  c11=(hl*(c10+c12)+vl*(c01+c21)+(hl+vl)*c11)/(6.0*(hl+vl))+
      (d1*(c20+c02)+d2*(c00+c22)+(d1+d2)*c11)/(6.0*(d1+d2));

  float3 dif1 = abs(c11-mn1) + dtt;
  float3 dif2 = abs(c11-mx1) + dtt;

  float filterparam = 5.5;

// Filterparam variable can be calculated by different formula, for nicer smoothing for example

  // float filterparam = clamp(5*length(mn1-mx1)+ 5*dot(abs(mn1-mx1),dt)+0.90,1,6);

  dif1=float3(pow(dif1.x,filterparam),pow(dif1.y,filterparam),pow(dif1.z,filterparam));
  dif2=float3(pow(dif2.x,filterparam),pow(dif2.y,filterparam),pow(dif2.z,filterparam));

  c11 = float3((dif1.x*mx1.x + dif2.x*mn1.x)/(dif1.x + dif2.x),
               (dif1.y*mx1.y + dif2.y*mn1.y)/(dif1.y + dif2.y),
               (dif1.z*mx1.z + dif2.z*mn1.z)/(dif1.z + dif2.z));

   return float4(c11,1);
}


technique Gs2x
{
   pass P0
   {
     VertexShader = compile vs_2_0 S_VERTEX();
     PixelShader  = compile ps_2_0 S_FRAGMENT();
   }  
}


technique SmartFilter
{
   pass P0
   {
     VertexShader = compile vs_3_0 S_VERTEX0();
     PixelShader  = compile ps_3_0 S_FRAGMENT0();
   }  
}



[Dieser Beitrag wurde am 05.08.2009 - 12:21 von guest aktualisiert]




KrossX 
Strong supporter
......

...

Status:Offline
Date registered: 16.06.2008
Post:94
Send Message
...   Created on 14.11.2009 - 12:40Jump to top Quote this post Report this post Edit Delete


Cheap (or LQ) version of your OGL2 Smart Shader. Now is not so smart. >_<

Basicly, I just tried to get a better performance with this IGP I'm now using. It needed to reach stable 120FPS with vsync for a "smooth" image and was giving around 95FPS. Now is able to have stable 120FPS most of the time.

Screenies for comparison, without color correction.
SmartShader | NotSmartOne

gpuPeteOGL2.slf

Code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
 
/*
   The GLSmartTexMag filter shader
   
   Copyright (C) 2009 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 sampler2D OGL2Texture;

void main()
{
    vec3 c11 = texture(OGL2Texture, gl_TexCoord[0].xy).xyz;
    vec3 s00 = texture(OGL2Texture, gl_TexCoord[1].xy).xyz; 
    vec3 s20 = texture(OGL2Texture, gl_TexCoord[2].xy).xyz; 
    vec3 s22 = texture(OGL2Texture, gl_TexCoord[3].xy).xyz; 
    vec3 s02 = texture(OGL2Texture, gl_TexCoord[4].xy).xyz;     
    vec3 c01 = texture(OGL2Texture, gl_TexCoord[1].zw).xyz; 
    vec3 c21 = texture(OGL2Texture, gl_TexCoord[2].zw).xyz; 
    vec3 c10 = texture(OGL2Texture, gl_TexCoord[3].zw).xyz; 
    vec3 c12 = texture(OGL2Texture, gl_TexCoord[4].zw).xyz;  
    vec3 dt = vec3(1.0,1.0,1.0);

    float hl=dot(abs(c01-c21),dt)+0.0001;
    float vl=dot(abs(c10-c12),dt)+0.0001;
    float m1=dot(abs(s00-s22),dt)+0.0001;
    float m2=dot(abs(s02-s20),dt)+0.0001;            
    
    vec3 temp1 = m2*(s00 + s22) + m1*(s02 + s20);
    vec3 temp2 = hl*(c10 + c12) + vl*(c01 + c21);
    
    c11 = (temp2/(hl+vl) + c11 + c11) * 0.083333 + (temp1/(m1+m2)) * 0.333333;

    vec3 mn1 = min(min(s00,c01),s02);
    vec3 mn2 = min(min(c10,c11),c12);
    vec3 mn3 = min(min(s20,c21),s22);

    vec3 mx1 = max(max(s00,c01),s02);
    vec3 mx2 = max(max(c10,c11),c12);
    vec3 mx3 = max(max(s20,c21),s22);

    mn1 = min(min(mn1,mn2),mn3);
    mx1 = max(max(mx1,mx2),mx3);

    // float filterparam = 3.0;     

    vec3 dif1 = 0.0001*dt + abs(c11-mn1);
    vec3 dif2 = 0.0001*dt + abs(c11-mx1);

    // dif = pow(dif, filterparam)
    dif1 = dif1 * dif1 * dif1;
    dif2 = dif2 * dif2 * dif2;

    c11 = (dif1 * mx1 + dif2 * mn1) / (dif1 + dif2);
        
    // 16-255    
    // gl_FragColor.xyz = c11 * 1.0669456 - 0.0669456;    
    // 16-235
    gl_FragColor.xyz = c11 * 1.16438356 - 0.07305936;    
    
}


gpuPeteOGL2.slv
Code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
 
/*
   
   Copyright (C) 2005 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;
uniform vec4 OGL2Size;

void main()
{
// 1.0/2048.0 = 0.00048828125
// 1.0/1024.0 = 0.0009765625
float x = OGL2Size.x * 0.0004883 * OGL2Param.x;
float y = OGL2Size.y * 0.0009766 * OGL2Param.y;

vec2 sd1 = vec2( x,y) * 0.5; 
vec2 sd2 = vec2(-x,y) * 0.5;

vec2 ddx = vec2(  x, 0.0); 
vec2 ddy = vec2(0.0,   y);

gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1].xy = gl_TexCoord[0].xy - sd1;
gl_TexCoord[2].xy = gl_TexCoord[0].xy - sd2;
gl_TexCoord[3].xy = gl_TexCoord[0].xy + sd1;
gl_TexCoord[4].xy = gl_TexCoord[0].xy + sd2;
gl_TexCoord[1].zw = gl_TexCoord[0].xy - ddy;
gl_TexCoord[2].zw = gl_TexCoord[0].xy + ddx;
gl_TexCoord[3].zw = gl_TexCoord[0].xy + ddy;
gl_TexCoord[4].zw = gl_TexCoord[0].xy - ddx;
}


[Dieser Beitrag wurde am 14.11.2009 - 12:40 von KrossX aktualisiert]





Signature

More : [1] [2]

Similarly threads:
Topics Created by Replies Boardname
Smart Texture Filtering GLSL shader (Copyright (c) 2004 Jaewon Jung) ShadX 7 pete_bernert
DOSBox - Probleme Myro 213 slydos
Wie findet ihr MoFi (Modified Filter) - AIM Crash Filter TsunamiDT 0 tsunamidt
Down in the Dumps (DOSBox) Myro 0 slydos
Does anyone have a link to a Smart Texture Filtering shader? FM 1 pete_bernert
Neuer Thread ...





Masthead

This forum is a free service of razyboard.com powered by:
Geizkragen Price Comparison. Top product in the price comparison: Krups Nespresso Essenza (XN2001)
Do you want a free forum in less than two minutes? Then click here!



Verwandte Suchbegriffe:
glsmarttexmag filter shader | gs2xsmartfilter | glsmarttexmag filter | glsmarttexmag | glsl hq3x float3
blank