Welcome to the GameZone24.net Forums - Serious Sam.
Page 1 of 4 123 ... LastLast
Results 1 to 15 of 49
  1. #1
    Workforce behind SSR
    Join Date
    November 2013
    Posts
    6

    Downloads:Uploads: 0

    [NEWS] Developer Blog 4: OpenGL and Shaders

    (Originally posted at: https://samrev.com/?p=8)

    Hello again and welcome to yet another developer blog by Mischie-... nope, wait, I just got word that Angelo is feeling better, so I'm going to give the keyboard to him and let him ramble on!


    Today, I want to talk a little bit about graphics. Specifically, OpenGL. In Serious Sam Classic you could change the graphics API between OpenGL and Direct3D. For Serious Sam Revolution, we have decided to drop support for Direct3D entirely. We've done this for a number of reasons, one in particular is that the 2 programmers that work on this project (am I talking in third person?) are not engine programmers, so we couldn't be bothered to maintain graphics APIs for both Direct3D and OpenGL, since it would take way too much time with way too little gain. With that being said, the other reason we've dropped Direct3D support is because OpenGL is backwards (and forwards) compatible, meaning that we can use 4.4 API calls (for example) in the current implementation without majorly redoing the entire graphics code. Getting D3D9 in a D3D8 application is a lot more complex, and potentially not even worth the trouble, since most (if not all) graphic cards nowadays support a decent enough version of OpenGL.

    Okay, moving on. Enough about Direct3D. Blegh, Microsoft. (Just kidding, I'm still a fan of their products.) What about OpenGL? What have we done to improve the graphics? So far we've mostly toyed around with shaders, and implementing it into the game in a way that level designers can use these shaders in however way they wish.

    We currently support vertex and fragment shaders for 2 things: models and post processing. Now what I can show you here is limited, mainly because I am not a shader programmer~ uh.. I mean.. mathemagician. But despite me not capable of writing amazing shaders, this should still get you excited that you will be able to potentially use this in your levels!

    Since a lot of regular people are reading this who probably don't know a lot about GLSL, I'm going to explain a little bit of how it exactly works, and what would be the exact potential for your levels. Let's go over a fairly simple and basic post processing shader first. We have a Post Processing Effect entity in our world, which we have given the following fragment shader:

    Code:
    #version 330 core
     
    in vec2 UV;
    out vec4 outColor;
    uniform sampler2D screen;
     
    void main()
    {
      // main color
      vec4 col = texture(screen, UV);
     
      // switch red and blue values around
      float red = col.x;
      col.x = col.z;
      col.z = red;
     
      // use that color
      outColor = col;
    }
    What the above shader does is take a pixel from the screen at the given UV coordinates, then switch around the red and blue values in the pixel, and then put it back in its place. Fairly simple, right? In our PP Effect entity, we've set the range to about 4 meters, so we can step in and out of the range of the entity. Here's the result:


    Now this shader is just the most basic shader you could probably think of. Most shaders are a lot more complex and confusing, as you can see at the amazing site Shadertoy (warning: this site might freeze your browser while it loads) Here's an example of a more complex shader that I wrote - I use the word "complex" as a relative term here - that uses the "distance" uniform to get the player's distance to the entity:

    Code:
    #version 330 core
    
    in vec2 UV;
    out vec4 outColor;
    uniform sampler2D screen;
    uniform vec2 resolution;
    uniform float distance;
    
    const float pi = 3.1415926;
    const float pi2 = 1.5707963;
    
    vec4 lerp(vec4 a, vec4 b, float x) {
      return a + (b - a) * x;
    }
    
    void main()
    {
      vec4 col = texture(screen, UV);
      vec4 sum = vec4(0);
      for(int x = -4; x <= 4; x++) {
        for(int y = -4; y <= 4; y++) {
          sum += texture(screen, vec2(
            UV.x + x * (1.0 / resolution.x),
            UV.y + y * (1.0 / resolution.y))) / 81.0;
        }
      }
      float delta = abs(sin(UV.x * pi + pi2)) / (distance / 21.4791f);
      outColor = lerp(col, vec4(sum.xyz, 1), delta);
    }
    The result of this is as seen below:


    Just for the heck of it, I decided to take a random shader from Shadertoy and use it as a Post Processing shader, just to show what you can do with this:


    Pretty, isn't it? I recommend you stroll around Shadertoy if you're interested in this kind of thing. That website is full of great demos, and it even has a WebGL playground where you can write your own shaders right in your browser.

    Oh, and you like gif animations, right? I'm sure you do. Here, have one.


    And ofcourse it also works on model holders, though I have yet to think of a decent example for that, so more on that later, I guess!


    On a more technical note, I should list the currently available uniform variables.

    • (PP only) sampler2D screen - the screen texture
    • (PP only) vec3 velocityrel - relative player velocity
    • (PP only) vec3 velocityabs - absolute player velocity
    • (PP only) float distance - distance between player and PP entity
    • (PP only) vec2 resolution - screen resolution
    • float time - time in seconds since the shader started
    • float paramN[0-4] - configurable parameters in entity


    Well, that's that. I believe this will open up a lot of possibilities in new and interesting gameplay, considering we've also been working on scriptabi~ uhh, I mean.. that's for a later developer blog.

    What do you think? Does this inspire you? What would you like to see modders do with this? Post it in the comments below!

    Until next week - Angelo the catt out.
    Last edited by Scratch; 02.12.2013 at 00:13.

  2. #2
    Golden^_+Imperator
    Join Date
    March 2008
    Location
    Currently Iceland
    Posts
    4,088

    Downloads: 201  Uploads: 24

    i love it




    *~>>Devils Ultimate d'Erektor<<~*

    People who lead a very successful business, usually tend to have extremely low freetime which results in depressions.
    The only thing that matters is personal happines and health, money can destroy both.
    ~Amco 2016

    It doesnt matter what you look like, or what stereotype you fulfill as long, as you're modest
    and respectful towards everyone, and feel comfortable about yourself.
    ~Amco 2020

    post your screens? played yesterday? of today? no screens available? No screens of january? december 2022? november 2022? no played matches in sam? hm sad. just stay a "legend" on gz these days. inactive since decades or activ as "Alias" with vpn lol. ~Vyebani User 2023


  3. #3
    Member
    Join Date
    July 2008
    Posts
    25,162

    Downloads: 21  Uploads: 0

    Looks awesome!

  4. #4
    Veteran Member
    Join Date
    February 2008
    Location
    Saint Petersburg
    Posts
    1,708

    Downloads: 12  Uploads: 0


  5. #5
    Member™
    Join Date
    February 2004
    Location
    LAS VEGAS
    Posts
    4,126

    Downloads: 39  Uploads: 0

    Me likey!

  6. #6
    Devils Clan
    Join Date
    January 2013
    Location
    KFC
    Posts
    533

    Downloads: 95  Uploads: 0

    cool

  7. #7
    Gospodski
    Join Date
    April 2012
    Posts
    5,012

    Downloads: 165  Uploads: 0

    awesome!

  8. #8
    InterPlayFigonaOwner
    Join Date
    May 2011
    Location
    Ireland
    Posts
    6,827

    Downloads: 49  Uploads: 0

    i read it twice now and i still dont get what this is abut :/
    Vladislav ] Prottoss [ Director macCream po va6emu ot4estvu DIRECTOR

    Vladislav ] Prottoss [ Director macCream po va6emu ot4estvu IMPERATOR

    Susperme Leader of GameZloty115.btc
    Susperme Leader of Immortals
    Susperme Leader of InterPlay
    Susperme Leader of FIGONA
    Susperme KING of FRANCE
    Susperme Leader of Devils



  9. #9
    VPN Elite

    Join Date
    January 2007
    Location
    Germany
    Posts
    6,388

    Downloads: 31  Uploads: 0

    Yes same, its just said that d3d is gone and totally replaced by OpenGL

    But i dont even know the difference


    hm sad. just stay a "legend" on gz these days. inactive since decades or activ as "Alias" with vpn lol.

  10. #10
    Campers Clan

    Join Date
    January 2008
    Location
    Macrony
    Posts
    12,653

    Downloads: 60  Uploads: 5

    Just hope the latest OpenGL version will be compatible with windows 8(x64), because we cant adjust the resolution to the screen scale.. even through the graphic pilote, i've been able to get the full screen in 1080 only with Direct 3D. Otherwise with open gl we still have that black area all around an unzoomed screen.
    (Talking abous SE classic with a Radeon HD7870)

    ^ steam profile access ^

    Corsair • Asus • Razer • Beyerdynamic

  11. #11
    Alligator Pit
    Join Date
    May 2005
    Location
    Netherlands
    Posts
    10,171

    Downloads:Uploads: 0

    Your.. I.. what?

    You do realize what the idea behind OpenGL is, right? Its implementation is completely dependent by the hardware vendor, not the OS.
    Disclaimer: Opinions expressed in this post are my own, not my employer's.

  12. #12
    Campers Clan

    Join Date
    January 2008
    Location
    Macrony
    Posts
    12,653

    Downloads: 60  Uploads: 5

    Ah.. well I couldn't know from where the problem could come from because I have changed my whole computer so for someone like me having a low knowledge in that domain and not having found any solution, the problem could come from anything..

    ^ steam profile access ^

    Corsair • Asus • Razer • Beyerdynamic

  13. #13
    Advanced Membury
    Join Date
    September 2011
    Location
    In the fog of the Lost Tomb
    Posts
    1,505

    Downloads: 52  Uploads: 0

    Only downside is OpenGL runs worse in terms of FPS.. I think? Or maybe I'm confusing with UT.. either way, good work on the shaders!

  14. #14
    Director
    Join Date
    June 2003
    Location
    zeo stole them frags
    Posts
    20,466

    Downloads: 34  Uploads: 10

    You're wrong Barktooth. I get over 300fps with OpenGL and around 160 with D3D.. there is a huge difference in fps but since my monitor is 75Hz with D3D and it doesn't work with openGL (the freqency other than default 60Hz), 75FPS is the minimum ammount of fps which makes the gameplay "smooth". It applies only to LCD displays though.
    Where r my 115e? and now we Have a Problem.
    -
    -----------------

    GameZone24.net Forums founder. The Director since 2003

  15. #15
    InterPlayFigonaOwner
    Join Date
    May 2011
    Location
    Ireland
    Posts
    6,827

    Downloads: 49  Uploads: 0

    dont remove D3D, cant use WH then


    btw Bark i get bigger fps in OpenGL too especially when using fraps to record something..
    Vladislav ] Prottoss [ Director macCream po va6emu ot4estvu DIRECTOR

    Vladislav ] Prottoss [ Director macCream po va6emu ot4estvu IMPERATOR

    Susperme Leader of GameZloty115.btc
    Susperme Leader of Immortals
    Susperme Leader of InterPlay
    Susperme Leader of FIGONA
    Susperme KING of FRANCE
    Susperme Leader of Devils



 

 
Page 1 of 4 123 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [NEWS] Developer Blog 2: Blockout with Mischievous
    By AlligatorPit in forum Serious Sam: Revolution
    Replies: 10
    Last Post: 26.02.2014, 19:17
  2. [NEWS] Discussion Blog
    By AlligatorPit in forum Serious Sam: Revolution
    Replies: 23
    Last Post: 27.11.2013, 08:12
  3. [NEWS] Developer Blog 1: Multiplayer Gamemodes
    By AlligatorPit in forum Serious Sam: Revolution
    Replies: 45
    Last Post: 18.11.2013, 02:19
  4. Blog posters
    By Ostap in forum Chatterbox
    Replies: 7
    Last Post: 26.11.2011, 17:51
  5. blog!
    By Arragon in forum Chatterbox
    Replies: 0
    Last Post: 09.07.2004, 00:08

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •