First post, by Yushatak
- Rank
- Member
With the versions of DOSBox patched to use shaders when rendering in DirectX mode, I keep finding shaders that I'd like to use that refuse to function with DOSBox.
Ex. I've wanted CRT emulation in DOSBox for a while now, and I recently came across some shaders that do just that. I wanted to try them out, but when I dropped them in there, DOSBox complained about the formatting. I realized it had an XML header and footer, so I removed them. I then tried again, and it tossed errors about variable declarations being "unexpected" and such. I realize that some variables and function names need to be rewritten to conform to the standard set for DOSBox shaders, but what exactly needs to be done? What are the input variables, what is the main function name, is there any special outputs? Etc..
Anybody have a clue? 😖
Here's the shader I've been trying to get to work, needs variable name changes, but I don't know to what..
uniform sampler2D rubyTexture;
uniform vec2 rubyInputSize;
uniform vec2 rubyOutputSize;
uniform vec2 rubyTextureSize;
#define TEX2D(c) texture2D(rubyTexture,(c))
#define PI 3.141592653589
#define phase 0.0
#define gamma 2.7
#define distortion 0.2
vec2 barrelDistortion(vec2 coord) {
vec2 cc = coord*rubyTextureSize/rubyInputSize - 0.5;
float dist = dot(cc, cc);
return coord + (cc * (dist + distortion * dist * dist) * distortion)*rubyInputSize/rubyTextureSize;
}
void main()
{
vec2 xy = barrelDistortion(gl_TexCoord[0].xy);
vec2 one = 1.0/rubyTextureSize;
vec2 uv_ratio = fract(xy*rubyTextureSize);
xy.x = floor(xy.x/one.x)*one.x;
vec4 col, col2;
vec4 coeffs = vec4(1.0 + uv_ratio.x, uv_ratio.x, 1.0 - uv_ratio.x, 2.0 - uv_ratio.x);
coeffs = mix((sin(PI * coeffs) * sin(PI * coeffs / 2.0)) / (coeffs * coeffs), vec4(1.0), lessThan(abs(coeffs), vec4(0.01)));
coeffs = coeffs / (coeffs.x+coeffs.y+coeffs.z+coeffs.w);
col = clamp(coeffs.x * TEX2D(xy + vec2(-one.x,0.0)) + coeffs.y * TEX2D(xy) + coeffs.z * TEX2D(xy + vec2(one.x, 0.0)) + coeffs.w * TEX2D(xy + vec2(2.0 * one.x, 0.0)),0.0,1.0);
col2 = clamp(coeffs.x * TEX2D(xy + vec2(-one.x,one.y)) + coeffs.y * TEX2D(xy + vec2(0.0, one.y)) + coeffs.z * TEX2D(xy + one) + coeffs.w * TEX2D(xy + vec2(2.0 * one.x, one.y)),0.0,1.0);
col = pow(col, vec4(gamma));
col2 = pow(col2, vec4(gamma));
vec4 wid = 2.0 + 2.0 * pow(col, vec4(4.0));
vec4 weights = vec4(uv_ratio.y/0.3);
weights = 0.51*exp(-pow(weights*sqrt(2.0/wid),wid))/0.3/(0.6+0.2*wid);
wid = 2.0 + 2.0 * pow(col2,vec4(4.0));
vec4 weights2 = vec4((1.0-uv_ratio.y)/0.3);
weights2 = 0.51*exp(-pow(weights2*sqrt(2.0/wid),wid))/0.3/(0.6+0.2*wid);
vec4 mcol = vec4(1.0);
if ( mod(gl_TexCoord[0].x*rubyOutputSize.x*rubyTextureSize.x/rubyInputSize.x,2.0) < 1.0)
mcol.g = 0.7;
else
mcol.rb = vec2(0.7);
gl_FragColor = pow(mcol*(col * weights + col2 * weights2), vec4(1.0/2.2));
}