Anaglyph glasses Stereoscopic 3D Shader :)

Discussion in 'Support!' started by maxpowerz, November 15, 2013.

  1. maxpowerz

    maxpowerz Post Master General

    Messages:
    2,208
    Likes Received:
    885
    Perssie from max to anyone with enough skill to write this into a shader somewhere.
    I'm working on trying to implement it, hopefully i will have a mod soon :)

    Its open for other modders to try as well, here is the code im using to get anaglyphic 3d.
    Code:
    #version 120
    #extension GL_EXT_geometry_shader4 : enable
    #extension GL_EXT_gpu_shader4 : enable
    
    varying float flag;
    uniform mat4 matrix;
    void main(void)
    {
    flag = 0.0;
    for(int i =0; i < 3; ++i)
    {
    gl_Position = gl_ModelViewProjectionMatrix * gl_PositionIn[i];
    EmitVertex();
    }
    EndPrimitive();
    flag = 1.0;
    for(int i =0; i < 3; +i)
    {
    gl_Position = matrix * gl_PositionIn[i];
    EmitVertex();
    }
    EndPrimitive();
    }
    
    Code:
    #version 110
    #extension GL_ARB_draw_buffers : enable
    
    varying float flag;
    
    void main()
    {
    vec4 color = (1.0);
    if(flag==0.0)
    {
    gl_FragData[0] = color;
    gl_FragData[1] = vec4(0.0);
    }
    else
    {
    gl_FragData[0] = vec4(0.0);
    gl_FragData[1] = color;
    }
    }
    Last edited: November 15, 2013
  2. bgolus

    bgolus Uber Alumni

    Messages:
    1,481
    Likes Received:
    2,299
    An anaglyph 3d shader wouldn't really be that difficult to setup as part of the post process system (once that's in place). A number of existing games on the console do 3d by taking the final image and a depth buffer and applying a relatively simple offset shader based on the depth. The same thing could be done for PA, though things like the sky (which is at "infinite" distance) would probably have to be special cased to not look too weird. It'll also fail pretty spectacularly for any transparent effects (like explosions, water, or the atmosphere) as these don't have any depth in the depth buffer.
    maxpowerz likes this.
  3. rabidfrog

    rabidfrog Member

    Messages:
    39
    Likes Received:
    4
    Forgive me if I'm wrong, but doesn't 3d work by showing you a different image to each eye, through fancy glasses (like the red blue cardboard glasses, or the fancy vertical horizontal slit ones). Therefore, couldn't you just have a separate render from a few in game distance units to the side displayed on the other eye? Or is this what you're talking about anyway?

    Edit: btw 3D PA = AWESOME
    maxpowerz likes this.
  4. maxpowerz

    maxpowerz Post Master General

    Messages:
    2,208
    Likes Received:
    885
    thats exactly what the shader code in my first post does,
    It grabs the whole overlay and based off of the depth buffer it seperates the red/cyan images creating an anaglyphic (red/cyan) effect.
    But currently i can't use it in PA because not everything has a depth buffer (like some effects) and its hard for me to write in a shader into the effects.json list without causeing PA.exe to crash (the devs were right the effect file is very picky about what you change and put in there)
    and i also need to use the shader on a final overlay where evrything is rendered together as one scene in a post process (i tried jumping that shader code into random shaders but it had undesirable effects .. lol. each shader seems to affect different parts of the end rendered scene)

    But in total i think PA would be eye popping in 3d, not in anaglyphic 3d but proper 3d, anaglyphic has the undesirable effect of making everything not in focus very purple hued wich kinda detracts from the overall beauty of the 3d engine itself.
    Last edited: November 18, 2013
  5. rabidfrog

    rabidfrog Member

    Messages:
    39
    Likes Received:
    4
    Makes a lot of sense now, keep working on that ;)
  6. bgolus

    bgolus Uber Alumni

    Messages:
    1,481
    Likes Received:
    2,299
    Stereoscopic 3d is indeed done by showing images to each eye from slightly different camera angles. However to actually render two views at the same time requires nearly twice as much rendering. For many games which are already capable of 60+ fps rendering the scene twice every frame isn't a big problem (as long as 30 fps is okay). This is what Call of Duty does.

    For most games on the consoles hitting 30 fps is hard enough, so rendering the game twice would mean the game would only run at 15 fps, which is totally unacceptable. In the past to continue to run at 30 fps for stereoscopic rendering games could render at a reduced resolution, or would render the game using a lower LOD setting than normal. These kinds of changes were often fairly easy to do as LOD content usually already existed for rendering objects in the distance or for split screen multiplayer. However this usually means the game looks significantly worse in stereo 3d than in "2d".

    Many recent games have started using some form of a technique called screen space stereo reprojection. This is the technique maxpowerz and I are talking about. The result is an approximation of what two cameras would see and produces an acceptable 3d effect that is often difficult to discern from "the real thing". Generally on the PC there's enough processing power to do it with two renders, and NVidia's 3d Vision and AMD's HD3D exist to try to use that extra power, but the technique has gotten popular enough that some PC games have started to use the approximation as well.

    TriOviz For Games, better known for green & magenta anaglyph 3d glasses, has an SDK for PC and consoles that implements this method. They have a quick explination of the technique on their site: http://trioviz-for-games.com/tfg-sdk/#SDK_2
    maxpowerz likes this.
  7. Culverin

    Culverin Post Master General

    Messages:
    1,069
    Likes Received:
    582
    See less = render less = less load.

    With gaming going mainstream, games on the last generation of consoles are more profitable than PC, almost all AAA titles are console-first so now most of those games are console ports. And as console games were were developed primarily for aging console hardware....
    The devs had to find a way to reduce rendering load.
    To reduce load, consoles have resorted to reducing Field of View (FoV) and locking the player to something rather narrow.

    Until the lastest generation of games, it was always an option on PC games.
    Some people literally get sick playing with such a congest view.

    (Side note: Curious if FoV will be an option in PA.... :p)
  8. bgolus

    bgolus Uber Alumni

    Messages:
    1,481
    Likes Received:
    2,299
    Lower FOV on console games (55~75 horizontal degrees) vs pc (75~110 horizontal degrees) isn't entirely about the performance benefits, which do exist. It's also about the expected distance between the display and the viewer. On PC there's an expectation that the viewer will be essentially with in arm's length of your display or closer. Console games you're generally going to be >5 feet away and even though it'll be a bigger screen it'll take up less of your view.

    Here's a good youtube video that explains it in more detail.


    It is entirely true that, as most games are made originally for consoles, the PC versions frequently forget to implement a different FOV to compensate.
    (We've been guilty of this, though not entirely because we forgot when doing the initial port but because we ran in to technical issues with our original implementations.)
    Last edited: November 20, 2013
    maxpowerz likes this.

Share This Page