gordallott

Status:Offline Date registered: 24.02.2008 Post:1 Send Message | Created on 24.02.2008 - 18:32 |  |
I created this shader mearly for myself, its a combination of a scale2x shader and my own bloom code that i use often in my own coding projects, essentially i use it when playing sprite based rpg games, scale2x for nicer scaling and bloom to make the 'effects' slightly more impressive.
you can modify the sharpness and brightness defines to tweek the bloom (playstation seems to be easliy 'washed out' by bloom, brightness controls how much the bloomed areas effect the screen and sharpness controls the difference between the parts of the image that are bloomed and the parts that are not).
the scale2x is borrowed from something (i can't remember what, but its gpl'ed), i only use scale2x beacuse i generally play psx games on a television.
screenies (first with, then without bloom/scale):






and the code:
.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: | | | | uniform vec4 OGL2Param;
| uniform vec4 OGL2Size;
| uniform sampler2D OGL2Texture;
|
| #define SIGMOIDAL_BASE 2.0
|
| #define SIGMOIDAL_RANGE 20.0
|
| // the sharpness of the difference between bright and dark colours
| #define sharpness 0.85
|
| // the brightness of the resulting 'bloom'
| #define brightness 0.6
|
| void main()
|
| {
|
| vec4 colD,colF,colB,colH,col,tmp;
|
| vec2 sel;
|
|
|
| col = texture2DProj(OGL2Texture, gl_TexCoord[0]); // central (can be E0-E3)
|
| colD = texture2DProj(OGL2Texture, gl_TexCoord[1]); // D (left)
|
| colF = texture2DProj(OGL2Texture, gl_TexCoord[2]); // F (right)
|
| colB = texture2DProj(OGL2Texture, gl_TexCoord[3]); // B (top)
|
| colH = texture2DProj(OGL2Texture, gl_TexCoord[4]); // H (bottom)
|
|
|
| sel=fract(gl_TexCoord[0].xy * OGL2Size.xy); // where are we (E0-E3)?
|
| // E0 is default
|
| if(sel.y>=0.5) {tmp=colB;colB=colH;colH=tmp;} // E1 (or E3): swap B and H
|
| if(sel.x>=0.5) {tmp=colF;colF=colD;colD=tmp;} // E2 (or E3): swap D and F
|
|
|
| if(colB == colD && colB != colF && colD!=colH) // do the Scale2x rule
|
| col=colD;
|
|
| //bloom stuff
| vec4 blurcolor = (((colD + colF + colB + colH) * 0.25) + col) * 0.5;
|
| //contrast stretch
| //blurcolor = (blurcolor - 0.5) * 8.0 + 0.5;
| vec4 val = 1.0 / (1.0 + exp (-(SIGMOIDAL_BASE + (sharpness * SIGMOIDAL_RANGE)) * (blurcolor - 0.5)));
|
| val = val * brightness;
|
| gl_FragColor = 1.0 - ((1.0 - col) * (1.0 - val));
|
|
|
| }
|
|
| | |
.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: | | | |
| uniform vec4 OGL2Param;
| uniform vec4 OGL2Size;
|
| void main()
|
| {
|
| vec4 offsetx;
|
| vec4 offsety;
|
|
|
| gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
|
|
| offsetx.x = OGL2Param.x; // setup one x/y texel offset
|
| offsetx.y = 0.0; // we could also use "1.0/OGL2Size.x (y)", than it wouldn't
|
| offsetx.w = 0.0; // be dependand on the "shader effect level" setting...
|
| offsetx.z = 0.0; // but more choice is usual better, eh?
|
| offsety.y = OGL2Param.y;
|
| offsety.x = 0.0;
|
| offsety.w = 0.0;
|
| offsety.z = 0.0;
|
|
|
| gl_TexCoord[0] = gl_MultiTexCoord0; // center
|
| gl_TexCoord[1] = gl_TexCoord[0] - offsetx; // left
|
| gl_TexCoord[2] = gl_TexCoord[0] + offsetx; // right
|
| gl_TexCoord[3] = gl_TexCoord[0] - offsety; // top
|
| gl_TexCoord[4] = gl_TexCoord[0] + offsety; // bottom
|
| }
| | |
|