Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why did GLSL change varying to in/out?

I know how to use both in/out variables, and varying variables. I am fully aware that using the in/out variables is better because it is not deprecated.

It is a very small thing, but I don't really understand why they changed this. Previously I could have the code in one shader, copy and paste it into the other, and it would be fine. Now I have to paste it into the other and change everything to "out" (instead of "in").

It is not that I mind doing this, I am just very curious about whether there is an advantage to the in/out variables, and if there isn't, why did the Khronos group change it.

like image 537
nedb Avatar asked Jan 06 '16 07:01

nedb


People also ask

What is a varying variable GLSL?

varying variables contain data shared from a vertex shader to a fragment shader. The variable must be written in the vertex shader and the read-only value in the fragment shader is then interpolated from the vertices which make up the fragment.

What is in and out in GLSL?

in / out for function parameters Functions in GLSL use a calling convention called "value-return." This means that values passed to functions are copied into parameters when the function is called, and outputs are copied out when the function returns.

When did GLSL come out?

Originally introduced as an extension to OpenGL 1.4, GLSL was formally included into the OpenGL 2.0 core in 2004 by the OpenGL ARB. It was the first major revision to OpenGL since the creation of OpenGL 1.0 in 1992.

Is OpenGL the same as GLSL?

The short version is: OpenGL is an API for rendering graphics, while GLSL (which stands for GL shading language) is a language that gives programmers the ability to modify pipeline shaders. To put it another way, GLSL is a (small) part of the overall OpenGL framework.


1 Answers

This was changed because there were no longer two shader stages. OpenGL 3.2 introduced Geometry Shaders, which are an optional stage between Vertex and Fragment shaders. It takes input from VS's and provides output to FS's.

So... how would you do that when you only have one keyword? You can't copy-and-paste the interface variables from the VS and FS into the same GS. You need some way to designate that a named variable is input from the VS or an output to the FS. And no, you can't just say that a variable is both.

Also, pay attention to the nature of the input variables in the GS. They are arrayed. So you couldn't just copy the VS varying definitions into the GS; you have to change them anyway.

It should also be noted that along with geometry shaders, they added input/output interface blocks, which group multiple interface variables under one heading. With these, you don't have to change several in/out pairs; you just change one.

like image 75
Nicol Bolas Avatar answered Oct 23 '22 21:10

Nicol Bolas