PDA

View Full Version : Updating legacy GLSL shaders to modern GLSL



cappah78
12-09-2016, 03:23 AM
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?

Silence
12-09-2016, 03:59 AM
See paragraph 7.3 and 7.6.1 from the GLSL (https://www.opengl.org/registry/doc/GLSLangSpec.Full.1.40.05.pdf) 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.

cappah78
12-09-2016, 04:26 AM
See paragraph 7.3 and 7.6.1 from the GLSL (https://www.opengl.org/registry/doc/GLSLangSpec.Full.1.40.05.pdf) 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

Silence
12-09-2016, 04:59 AM
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.

GClements
12-09-2016, 05:35 PM
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.