22 July 2012

Shaders

I have added some very basic support for shaders into the OpenGL backend. Right now, it looks for a "vertex.glsl" and a "fragment.glsl" to load as vertex and fragment shaders respectively. Eventually I want to have some manifest file that stores the properties of shader programs, but I have not done that yet.

Right now, two uniforms are passed to the shaders. The first is the texture to use called "texture". The second is a vec2 containing the width and height of the texture in pixels called "textureDimensions". This is useful since texture coordinates are in the range [0..1] so it is difficult to tell where one pixel ends and another starts. I have attached a shader program that implements scale2x (Advmame2x) by finding the position within a pixel using these uniforms. It duplicates the functionality of the scaler in the SDL backend, but it looks kinda funky with scale factors != 2. It can probably be modified to use a combination of Advmame3x and Advmame2x depending on subpixel position.

What is great about this is that no development tools are required to change the shader programs. So users can create and load shaders without having to configure build environments and compile ScummVM. Hopefully this can lower the barrier to making some creative works.

Advmame2x shader: https://gist.github.com/3161079
ScummVM branch with enabled shaders: https://github.com/singron/scummvm/tree/opengl

5 comments:

  1. What about this?

    https://github.com/Themaister/Emulator-Shader-Pack/tree/master/Cg
    https://github.com/twinaphex/mame72-libretro/tree/master/mame_0.72/Shaders
    https://github.com/libretro/common-shaders
    http://gitorious.org/bsnes/xml-shaders (supported by libretro/RetroArch)
    http://gitorious.org/bsnes/pages/XmlShaderFormat

    RetroArch (https://github.com/Themaister/RetroArch/)/

    Do you have some opinion about this? Would a portable shader format be possible for OSystem's ScummVM/ResidualVM?

    ReplyDelete
  2. We are looking into the XmlShaderFormat to be compatible with existing shaders for emulators.

    ReplyDelete
  3. Hi, I'm having trouble compiling with mingw, getting undefined reference glgenframebuffersext on line 1379 of opengl-graphics.cpp any ideas where I'm going wrong? :)

    ReplyDelete
    Replies
    1. Hi Gib. I was compiling on linux while making this. On linux, OpenGL extensions are declared in system headers. However on windows, they require some additional setup.

      First see if using "glext.h" and "wglext.h" headers from the OpenGL registry solves anything.

      http://www.opengl.org/registry/


      You probably still need to resolve the functions at runtime. For instance

      glGenFrameBuffersEXT = (PFNGLGLGENFRAMEBUFFERSEXTPROC) wglGetProcAddress("glGenFrameBuffersEXT");

      That weird character mess is just "PFNGL" + uppercase function name + "PROC". For the SDL backend you can use

      glGenFrameBuffersEXT = (glGenFrameBuffersEXT) SDL_GL_GetProcAddress("glGenFrameBuffersEXT");

      Delete
    2. Thanks a lot Eric, I'll give it a go

      Delete