Skip to content

Instantly share code, notes, and snippets.

@RichardBray
Last active September 17, 2020 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardBray/e1126191e4d5563184a5de299032c667 to your computer and use it in GitHub Desktop.
Save RichardBray/e1126191e4d5563184a5de299032c667 to your computer and use it in GitHub Desktop.
Simple fragment shader for beginners with explanations
// # = Preprocessor macros
#ifdef GL_ES // OpenGL Embedded systems needed for openGL on web and mobile devices
precision mediump float; // level of precision for float https://stackoverflow.com/questions/13780609/what-does-precision-mediump-float-mean
// Lower precision means faster compilation but lower quality, above sets all floats to medium precision
#endif
void main() // Main entry point function like c/c++
{
// gl_FragColor = built in global variable to determine pixel color
// werid because you don't see it imported or extended it just exists
// vec4 = 4 dimensional vector vec expects float by default, other types can be done like so:
// bvec = boolean vector, ivec = integer vector, dvec = double vector, but float by default
// Full list of built-in variables can be found here https://www.khronos.org/registry/OpenGL-Refpages/
gl_FragColor = vec4(0.2, 0.3, 0.1, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment