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

Homepage Members Register Login Search Old board


Neuer Thread ...


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:856
Send Message
...   Created on 15.04.2007 - 23:19Jump to top Quote this post Report this post Edit Delete


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:
 

// Experimental 2x scale shader -  vertex file
// Copyright (C) 2007 guest(r) - guest.r@gmail.com

uniform vec4 OGL2Size;
varying vec2 dx,dy,d1,d2;

void main()

{
float x = 1.0/OGL2Size.x;
float y = 1.0/OGL2Size.y;

d1 = vec2( x, y);
d2 = vec2(-x, y);
dx = vec2(x,0.0);
dy = vec2(0.0,y);

gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}



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:
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:
 

/*

  Experimental 2x resize shader - fragment file  (v0.001)

  Copyright (C) 2007 guest(r) - guest.r@gmail.com

  I'll try to code a shader which does some double image resizing.
  9+ texels (box style) input, 4 result texels output, classic approach - so to say.

  Since it's going to be a single pass shader, it'll do some bilinear interpolation afterwards.
  The idea is borrowed from the Scale2xSaI algorithm from mr. Derek Liauw Kie Fa.

  More patterns are to be added with time...

*/



const float p = 1.0;  // "linear" Interpolation type    


varying vec2 dx,dy,d1,d2;

uniform vec4 OGL2Size;
uniform sampler2D OGL2Texture;

void main()
{
    
    // Calculating texel coordinates

    vec2 OGL2Pos = gl_TexCoord[0].xy*OGL2Size.xy;
    vec2 fp  = fract(OGL2Pos);

    vec2 d11 = floor(OGL2Pos)/OGL2Size.xy;
    vec2 d00 = d11 - d1;
    vec2 d10 = d11 - dy;
    vec2 d20 = d11 - d2;
    vec2 d01 = d11 - dx;
    vec2 d21 = d11 + dx;
    vec2 d02 = d11 + d2;
    vec2 d12 = d11 + dy;
    vec2 d22 = d11 + d1;


    // Reading the texels

    vec3 c00 = texture2D(OGL2Texture,d00).xyz; 
    vec3 c10 = texture2D(OGL2Texture,d10).xyz;
    vec3 c20 = texture2D(OGL2Texture,d20).xyz;
    vec3 c01 = texture2D(OGL2Texture,d01).xyz;
    vec3 c11 = texture2D(OGL2Texture,d11).xyz;
    vec3 c21 = texture2D(OGL2Texture,d21).xyz;
    vec3 c02 = texture2D(OGL2Texture,d02).xyz;
    vec3 c12 = texture2D(OGL2Texture,d12).xyz;
    vec3 c22 = texture2D(OGL2Texture,d22).xyz;
    vec3 dt  = vec3(1.0,1.0,1.0);


    // Calculating color differences    

    float f00 = dot(abs(c00-c11),dt);
    float f10 = dot(abs(c10-c11),dt);
    float f20 = dot(abs(c20-c11),dt);
    float f01 = dot(abs(c01-c11),dt);
    float f11 = dot(abs(c11-c11),dt);
    float f21 = dot(abs(c21-c11),dt);
    float f02 = dot(abs(c02-c11),dt);
    float f12 = dot(abs(c12-c11),dt);
    float f22 = dot(abs(c22-c11),dt);
    float hrl = dot(abs(c01-c21),dt);
    float vrl = dot(abs(c10-c12),dt);
    float dg1 = dot(abs(c00-c22),dt);
    float dg2 = dot(abs(c02-c20),dt);


    // Calculating produtcs

    vec3 p00,p10,p01,p11;

    if ((f10==f21 && f01==f12 && f10!=f01) || (f01==f10 && f12==f21 && f01!=f12))
    {
        p00 = (c01+c11+c10)/3.0;
        p10 = (c21+c11+c10)/3.0;   
        p01 = (c01+c11+c12)/3.0;   
        p11 = (c12+c11+c21)/3.0;      
    }
    else

    if (max(f00,f22)==0.0 && f02!=f20) 
    {
        p00 = c11;
        p10 = (c21+c11+c10)/3.0;   
        p01 = (c01+c11+c12)/3.0;   
        p11 = c11;      
    }
    else
    
    if (max(f02,f20)==0.0 && f00!=f22) 
    {
        p00 = (c01+c11+c10)/3.0;
        p10 = c11;   
        p01 = c11;
        p11 = (c12+c11+c21)/3.0;      
    }
    else

    {
        p00 = c11;
        p10 = c11;
        p01 = c11;
        p11 = c11;
    }


    // product interpolation

    vec2 x = vec2(pow(1.0-fp.x,p),pow(fp.x,p));
    vec2 y = vec2(pow(1.0-fp.y,p),pow(fp.y,p));

    gl_FragColor.xyz = ((p00*x.x+p10*x.y)*y.x+(p01*x.x+p11*x.y)*y.y)/((x.x+x.y)*(y.x+y.y));

}



[Dieser Beitrag wurde am 16.04.2007 - 02:35 von guest aktualisiert]





Similarly threads:
Topics Created by Replies Boardname
Experimental 2x GLSL shader guest 5 pete_bernert
Natural Vision Shader + AA Shader v2.o = Best Shader for 2d !! zaykho 10 pete_bernert
Experimental? HariSeldon 3 eits
Experimental 6 Mel 0 spielleitung
Tyrrell P34 EXPERIMENTAL 1/20 kurtl 1 modelcars_and_bikes_austria
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:
resize shader | derek liauw kie fa -2xsai | ogl2size | scale2xsai scaling | scale2xsai | glsl resize texture2d | ogl2texture resize | glsl resize
blank