Search code examples
glslfragment-shadervertex-shader

GLSL: vertex shader to fragment shader without varing


How to transfer data from vertex shader to fragment shader without changes? I need to say to the vertex pixels that they have this color. This color I can obtain only in the vertex shader.


Solution

  • Here's a good tutorial on GLSL: NeHe GLSL tutorial

    If you want to share data between vertex and fragment shaders use one of the built in types, for example gl_Color

    If you want to pass through the color computed by the vertex shader to through the fragment shader you would create a fragment shader with the following line: gl_FragColor = gl_Color

    gl_Color will be automatically set for you from the colors written by the vertex shader. You write a color from the vertex shader by setting one of the built-in variables, like gl_FrontColor, or one of it's peers: gl_BackColor etc.