Previous Thread
Next Thread
Print Thread
Page 3 of 19 1 2 3 4 5 18 19
Joined: Jul 2007
Posts: 79
C
Member
Member
C Offline
Joined: Jul 2007
Posts: 79
I wanted to play with shaders for improving the look of vector games, but after realizing that currently this isn't implemented, I decided on a different approach: work with raster games and develop shaders that should also work on vector games, if their antialiased vectors were rendered into an offscreen buffer. Then, if I'm lucky, someone more familiar with the MAME codebase will like what they see and implement it.

This work is done using "screen bitmap" shaders, which operate on buffers at the final screen output resolution. First, I use shaders/glsl_plain to render to screen resolution with nearest-neighbor sampling:
[Linked Image from img156.imageshack.us]
The next part was the trickiest: simulate the look of OpenGL antialiased vectors. Eventually I came up with this shader, which seems to mostly work. Without gamma correction, it is the closest approximation to antialiased line drawing:
[Linked Image from img834.imageshack.us]
Adding gamma correction eliminates the unevenness of brightness:
[Linked Image from img135.imageshack.us]
Next, I do a 9x9 Gaussian blur. Fortunately this can be separated into two 9-tap filters instead of one 81-tap filter. First, vertically:
[Linked Image from img833.imageshack.us]
Then, horizontally:
[Linked Image from img143.imageshack.us]
I should mention that at each stage, blending is done in a linear colour space, which requires applying gamma and inverse gamma functions at each stage to avoid the loss of precision that would result from storing linear color in an 8-bit intermediate texture.

There are a couple more ways of making this more realistic. First, a CRT's video amplifier has limited bandwidth, so I use a horizontal Lanczos shader as the last "mame bitmap" shader (which takes the image at emulated resolution as its input and outputs at screen resolution) to slightly smooth the pixel transitions:
[Linked Image from img825.imageshack.us]
Together with the other shaders, this gives:
[Linked Image from img651.imageshack.us]
Finally, since this is in colour, I apply a slot mask overlay with -effect aperture2x4rb:
[Linked Image from img64.imageshack.us]

For a vector game, simulating limited bandwidth of the video amplifier probably couldn't be done with just shaders, although this is relatively unimportant.

Joined: Mar 2001
Posts: 17,239
Likes: 263
R
Very Senior Member
Very Senior Member
R Offline
Joined: Mar 2001
Posts: 17,239
Likes: 263
Holy cow, that looks *amazing*! Would you mind submitting it? smile

Joined: Jul 2007
Posts: 79
C
Member
Member
C Offline
Joined: Jul 2007
Posts: 79
Where would I submit the shaders? I'm aware of this SDLMAME shader pack from 2007, but currently MAME only has the two built-in shaders: nearest-neighbor and bilinear scaling. Is there an interest in packaging more shaders with MAME?

Joined: Mar 2001
Posts: 17,239
Likes: 263
R
Very Senior Member
Very Senior Member
R Offline
Joined: Mar 2001
Posts: 17,239
Likes: 263
If you don't have a website to post on, post a zip on one of the file sharing services (megaupload, that sort of thing) and post or PM me the URL.

Joined: Jul 2007
Posts: 79
C
Member
Member
C Offline
Joined: Jul 2007
Posts: 79
This set of shaders is available here. To reproduce the above, you'll also need the glsl_plain shader and the aperture2x4rb overlay, and a command line like
Code
mame -gl_glsl
  -glsl_shader_mame0 glsl_plain
  -glsl_shader_mame1 lanczosx
  -glsl_shader_screen0 beam
  -glsl_shader_screen1 gaussy
  -glsl_shader_screen2 gaussx
  -effect aperture2x4rb
Also, it seems that only drivers that output in 16-bit indexed colour work. It looks like the rgb32_lut version of the glsl_plain and glsl_bilinear shaders is broken, since they expect a colortable_texture of height 1, but the LUT is instead packed into a more square texture. Here is a less broken version of glsl_plain_rgb32_lut.fsh. The rgb32_lut shaders can be used instead of the rgb32_dir shaders by setting one of the video attributes on the command line to a value other than 1 (e.g. -gamma 1.01). And it looks like the rgb32_dir shaders are compiled but never get used (this is what I was referring to in the first post of this thread when I wrote that GLSL bilinear filtering only works on some games).

Joined: Jul 2008
Posts: 72
F
Member
Member
F Offline
Joined: Jul 2008
Posts: 72
I hate to sound too newbish, but what's the default dir for the shaders and the filter images?, I could only load them using absolute paths.

I also get these kind of errors on load, does this mean my video card doesn't support the features?, I wouldn't be surprised as it's an onboard intel card on this machine.

Code
src/osd/sdl/gl_shader_tool.c:370: GL Error: object 0x17 compilation failed
src/osd/sdl/gl_shader_tool.c:370 glInfoLog: Error: Preprocessor error
Error: failed to preprocess the source.

failed to process shader: <#version 130
#pragma optimize (on)
#pragma debug (off)

uniform sampler2D     mpass_texture;
uniform sampler2D     color_texture;
uniform vec2          color_texture_pow2_sz;

#define TEX2D(c) texture2D(mpass_texture,(c))
#define PI 3.141592653589

void main()
{
  vec2 xy = gl_TexCoord[0].st;

  vec2 uv_ratio     = fract(xy*color_texture_pow2_sz);
  vec2 one          = 1.0/color_texture_pow2_sz;

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

  vec4 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 * one.x, 0.0)),0.0,1.0);

  gl_FragColor = col;
}

>
failed to process shader_file: src/osd/sdl/shader/lanczosx_idx16_lut.fsh
OpenGL: GLSL loading mame bitmap shader 1 failed (src/osd/sdl/shader/lanczosx)
src/osd/sdl/drawogl.c:2907: GL Error: 1283 0x503

Joined: Jul 2007
Posts: 79
C
Member
Member
C Offline
Joined: Jul 2007
Posts: 79
The effect overlays can go in the artwork directory. I don't know of any default directory for shaders.

As for the errors, it might be your card. Try replacing the lanczosx shader with a second glsl_plain, since lanczosx is the only one that required a #version declaration to enable more features. It might also be the shaders, since I only have an nvidia card, and nvidia's shader compiler is very forgiving. I tried to get rid of all the implicit conversions, but I may have missed something and I have no way of testing a stricter compiler.

Joined: Jul 2008
Posts: 72
F
Member
Member
F Offline
Joined: Jul 2008
Posts: 72
Yup, that seems to be the problem, I'll test tomorrow with an nvidia card, thanks.

In any case, although I get no errors using two plain shaders, I still get no image when running it with shaders, but I guess it's a card problem too.

Joined: Mar 2001
Posts: 17,239
Likes: 263
R
Very Senior Member
Very Senior Member
R Offline
Joined: Mar 2001
Posts: 17,239
Likes: 263
Not all games will work with this - your best "smoke test" is to start with Gradius, the game he shows working. Some others will show no image with this method for the reasons he discussed.

Joined: Jul 2008
Posts: 72
F
Member
Member
F Offline
Joined: Jul 2008
Posts: 72
ah!, I must admit I didn't follow the thread. Gradius works as expected then, just have that other on this machine, I'll test another one later.

This looks very well, I hope we can have this working for everything.

Page 3 of 19 1 2 3 4 5 18 19

Moderated by  R. Belmont 

Link Copied to Clipboard
Who's Online Now
4 members (Darkstar, farngle, hal3000, 1 invisible), 58 guests, and 2 robots.
Key: Admin, Global Mod, Mod
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Forum Statistics
Forums9
Topics9,331
Posts122,197
Members5,077
Most Online1,283
Dec 21st, 2022
Our Sponsor
These forums are sponsored by Superior Solitaire, an ad-free card game collection for macOS and iOS. Download it today!

Superior Solitaire
Powered by UBB.threads™ PHP Forum Software 8.0.0