ShaderFrog / glsl-parser

A GLSL ES 1.0 and 3.0 parser that can preserve whitespace and comments
https://shaderfrog.com
107 stars 9 forks source link

gl_Position warning #34

Open crystalthoughts opened 3 weeks ago

crystalthoughts commented 3 weeks ago

Hi - the following shader gives a warning:

#version 300 es
in vec4 aPosition;
out vec2 vUV;

void main() {
    vUV = aPosition.xy * 0.5 + 0.5;
    gl_Position = aPosition;
}

Encountered undefined variable: "gl_Position"

is there a way to prevent this? Thanks for your library, so useful :)

AndrewRayCode commented 2 weeks ago

This is a known problem, and there are two issues:

  1. The parser does not have a way to specify if the input source code is vertex or fragment code. Right now the parser accepts a superset of GLSL that includes both valid vertex and fragment code. This is also called out in the limitations section of the readme.
  2. The parser does not currently respect the "7.1 Built-In Language Variables" section of the Khronos grammar spec, which includes definitions for variables like gl_Position. Right now the parser does not auto-include global variables. I think I need to solve 1 before I can address 2.

One quick option you have for now is to parse with {quite: true} as a parser option. This will hide warnings for truly undefined variables, but it might work for your use case.