Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Updating legacy GLSL shaders to modern GLSL

  1. #1
    Newbie Newbie
    Join Date
    May 2015
    Posts
    3

    Updating legacy GLSL shaders to modern GLSL

    I'm trying to update an old GLGL version 120 shader programs that I have and although most of it was of it was straight forward, the following I'm having trouble with:

    vertex shader: gl_FrontSecondaryColor, gl_FrontColor

    fragment shader: gl_Color, gl_SecondaryColor

    The problem is that I haven't been able to find amble alternatives for anything 4.2 and above.

    For example:
    The replacement for gl_FragColor is to create
    layout (location = 0) out vec4 fragColor;

    But for the other above stated, how exactly would they be handled?
    Last edited by cappah78; 12-09-2016 at 04:25 AM.

  2. #2
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    459
    See paragraph 7.3 and 7.6.1 from the GLSL specs.

    These are deprecated and available only if compatibility profile is enabled.

    For the secondary color you simply can add a vertex attribute that you will make it work the same.

  3. #3
    Newbie Newbie
    Join Date
    May 2015
    Posts
    3
    Quote Originally Posted by Silence View Post
    See paragraph 7.3 and 7.6.1 from the GLSL specs.

    These are deprecated and available only if compatibility profile is enabled.

    For the secondary color you simply can add a vertex attribute that you will make it work the same.
    Sorry, I mistakenly put 3.x instead of 450

  4. #4
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    459
    Quote Originally Posted by cappah78 View Post
    Sorry, I mistakenly put 3.x instead of 450
    I believe that this is not fixed.

    For the secondary color, use another vertex attribute that will store this secondary color. In your shader just use this attribute location as this secondary color.

    For the front and back faces, my guess is that you'll do it in two passes. First render CCW faces (these might be your front faces), then render again but with CW faces (these will then be your back faces). I am not really sure about this. Other people here will certainly provide fixes to what I said.

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,983
    Quote Originally Posted by cappah78 View Post
    I'm trying to update an old GLGL version 120 shader programs that I have and although most of it was of it was straight forward, the following I'm having trouble with:

    vertex shader: gl_FrontSecondaryColor, gl_FrontColor

    fragment shader: gl_Color, gl_SecondaryColor

    The problem is that I haven't been able to find amble alternatives for anything 4.2 and above.
    If you don't have separate front and back materials, you can just add an out variable for the colour.

    If you have separate front and back materials, then you need two variables for the front and back colours. The fragment shader can use the gl_FrontFacing variable to select which one to use. Alternatively, a geometry shader can select the appropriate colour, although the use of a geometry shader has significant overhead on most hardware, so the test should be performed in the fragment shader unless you will be using a geometry shader for other reasons.

Posting Permissions

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