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?

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.

[QUOTE=Silence;1284971]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.[/QUOTE]

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.

[QUOTE=cappah78;1284969]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.
[/QUOTE]
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 [var]gl_FrontFacing[/var] 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.