| |
|
// MultiPowerSE shader
|
// by guest(r)
|
// one can change the type the power and interpolation functions
|
// in the body to achieve various processings or/and effects
|
// you can choose between allmost too many interpolation methodes
|
// and three different edge processing styles (= *muchos* different processing settings)
|
// should work with all Dx.9.0 cards
|
|
uniform vec4 OGL2Param;
|
uniform vec4 OGL2Size;
|
uniform sampler2D OGL2Texture;
|
|
|
// ******************** power functions ***********************
|
|
// they describe how the diference should be interpolated: linear, quadratic...
|
|
vec3 logg2(vec3 x)
|
{ return log2(vec3(1.0,1.0,1.0)+abs(x)); }
|
|
vec3 lin1(vec3 x)
|
{return abs(x)*0.5; }
|
|
vec3 lin2(vec3 x)
|
{return abs(x)*0.25; }
|
|
vec3 sqr1(vec3 x)
|
{return x*x; }
|
|
vec3 sqr2(vec3 x)
|
{return 2.0*x*x; }
|
|
vec3 cube1(vec3 x)
|
{return abs(x*x*x); }
|
|
vec3 cube2(vec3 x)
|
{return 2.0*abs(x*x*x); }
|
|
vec3 quad1(vec3 x)
|
{x*=x; return x*x; }
|
|
vec3 quad2(vec3 x)
|
{x*=x; return 2.0*x*x; }
|
|
vec3 zero(vec3 x)
|
{return vec3(0.0,0.0,0.0);} // fastest
|
|
/********************* Main functions *************************/
|
|
vec3 minplus(vec3 x, vec3 y, vec3 z)
|
{ return vec3(min(x.x,y.x),min(x.y,y.y),min(x.z,y.z))+z; }
|
|
vec3 maxminus(vec3 x, vec3 y, vec3 z)
|
{ return vec3(max(x.x,y.x),max(x.y,y.y),max(x.z,y.z))-z; }
|
|
vec3 minminus(vec3 x, vec3 y, vec3 z)
|
{ return vec3(min(x.x,y.x),min(x.y,y.y),min(x.z,y.z))-z; }
|
|
vec3 maxplus(vec3 x, vec3 y, vec3 z)
|
{ return vec3(max(x.x,y.x),max(x.y,y.y),max(x.z,y.z))+z; }
|
|
vec3 mid_plus(vec3 x, vec3 y, vec3 z)
|
{ return 0.5*(x + y + z); }
|
|
vec3 mid_minus(vec3 x, vec3 y, vec3 z)
|
{ return 0.5*(x + y - z); }
|
|
/********************* other functions ***********************/
|
|
float len3(vec3 x)
|
{ return abs(x.x)+abs(x.y)+abs(x.z); }
|
|
|
// ***********************************************************
|
|
void main()
|
{
|
vec4 t1,t2,c1,c2;
|
vec4 uy = texture2DProj(OGL2Texture, gl_TexCoord[0]);
|
vec4 lx = texture2DProj(OGL2Texture, gl_TexCoord[3]);
|
vec4 rx = texture2DProj(OGL2Texture, gl_TexCoord[1]);
|
vec4 dy = texture2DProj(OGL2Texture, gl_TexCoord[2]);
|
t1 = lx - rx; c1.w = 0.0; c2.w=0.0; // precaution
|
t2 = uy - dy;
|
|
// ********************** E D G E S ************************
|
// uncomment one of theese line to gain the edge-effect
|
|
// Edged version - may look good with less-pixelated 3D games
|
// c1.w = len3(t1.xyz);c2.w = len3(t2.xyz); c1.w = 0.45*c1.w; c2.w = 0.45*c2.w;
|
|
// EdgedSE version - dark edges when strong contrast
|
// c1.w = len3(t1.xyz);c2.w = len3(t2.xyz); c1.w*= 0.175*c1.w; c2.w*= 0.175*c2.w;
|
|
|
// you can use:
|
// *** sqrt | logg2 | lin1 | lin2 | sqr1 | sqr2 | cube1 | cube2 | quad1 | quad2 | zero ***
|
// function to calculate the additive value
|
// the shader was tested with one type of power function at the time.
|
|
t1.xyz = sqr1(t1.xyz);
|
t2.xyz = sqr1(t2.xyz);
|
|
|
// here you can select between interpolation starting-points
|
// *** minminus || minplus || maxminus || maxplus || mid_plus || mid_minus ***
|
// just rename the both functions below (and leave the parameters be)
|
|
c1.xyz = minminus(lx.xyz,rx.xyz,t1.xyz);
|
c2.xyz = minminus(uy.xyz,dy.xyz,t2.xyz);
|
|
c1.xyz = 0.5*(1.0-c1.w-c2.w)*(c1.xyz+c2.xyz);
|
gl_FragColor = c1;
|
}
|
|