Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

OpenGL Shading Language

From Wikipedia, the free encyclopedia
(Redirected fromGlsl)
High-level shading language
Not to be confused withOpen Shading Language.
GLSL
Unofficial logo
Original authorOpenGL ARB
DeveloperKhronos Group
Initial releaseJuly 24, 2002; 23 years ago (2002-07-24) (as an extension)
Stable release
4.60.8 / August 14, 2023; 2 years ago (2023-08-14)[1]
PlatformCross-platform
TypeProgramming Language
Websitewww.opengl.org Edit this on Wikidata
Video games outsource rendering calculations to theGPU overOpenGL in real-time. Shaders are written inOpenGL Shading Language and compiled. The compiled programs are executed on the GPU.

OpenGL Shading Language (GLSL) is ahigh-levelshading language with a syntax based on theC programming language. It was created by theOpenGL ARB (OpenGL Architecture Review Board) to give developers more direct control of thegraphics pipeline without having to useARB assembly language or hardware-specific languages.

Background

[edit]

With advances in graphics cards, new features have been added to allow for increased flexibility in the rendering pipeline at thevertex andfragment level. Programmability at this level is achieved with the use of fragment and vertexshaders.

Originally, this functionality was achieved by writing shaders inARB assembly language – a complex and unintuitive task. TheOpenGL ARB created the OpenGL Shading Language to provide a more intuitive method for programming thegraphics processing unit while maintaining the open standards advantage that has driven OpenGL throughout its history.

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 ofOpenGL 1.0 in 1992.

Some benefits of using GLSL are:

  • Cross-platform compatibility on multiple operating systems, includingLinux,macOS andWindows.
  • The ability to write shaders that can be used on any hardware vendor's graphics card that supports the OpenGL Shading Language.
  • Each hardware vendor includes the GLSL compiler in their driver, thus allowing each vendor to create code optimized for their particular graphics card’s architecture.

Versions

[edit]

GLSL versions have evolved alongside specific versions of the OpenGL API. It is only with OpenGL versions 3.3 and above that the GLSL and OpenGL major and minor version numbers match. These versions for GLSL and OpenGL are related in the following table:

GLSL VersionOpenGL VersionDateShader Preprocessor
1.10.59[2]2.030 April 2004#version 110
1.20.8[3]2.107 September 2006#version 120
1.30.10[4]3.022 November 2009#version 130
1.40.08[5]3.122 November 2009#version 140
1.50.11[6]3.204 December 2009#version 150
3.30.6[7]3.311 March 2010#version 330
4.00.9[8]4.024 July 2010#version 400
4.10.6[9]4.124 July 2010#version 410
4.20.11[10]4.212 December 2011#version 420
4.30.8[11]4.37 February 2013#version 430
4.40.9[12]4.416 June 2014#version 440
4.50.7[13]4.509 May 2017#version 450
4.60.5[14]4.614 June 2018#version 460

OpenGL ES andWebGL useOpenGL ES Shading Language (abbreviated:GLSL ES orESSL).

GLSL ES versionOpenGL ES versionWebGL versionBased on GLSL versionDateShader Preprocessor
1.00.17[15]2.01.01.2012 May 2009#version 100
3.00.6[16]3.02.03.3029 January 2016#version 300 es
3.10.5[17]3.1GLSL ES 3.0029 January 2016#version 310 es
3.20.6[18]3.2GLSL ES 3.1010 July 2019#version 320 es

The two languages are related but not directly compatible. They can be interconverted throughSPIRV-Cross.[19]

Language

[edit]

Operators

[edit]

GLSL contains the same operators as theoperators in C and C++, with the exception ofpointers.Bitwise operators were added in version 1.30.

Functions and control structures

[edit]

Similar to theC programming language, GLSL supports loops and branching, for instance: if-else, for, switch, etc. Recursion is forbidden and checked for during compilation.

User-defined functions are supported and built-in functions are provided. The graphics card manufacturer may optimize built-in functions at the hardware level. Many of these functions are similar to those in the math library of the C programming language while others are specific to graphics programming. Most of the built-in functions and operators, can operate both on scalars and vectors (up to 4 elements), for one or both operands. Common built-in functions that are provided and are commonly used for graphics purposes are:mix,smoothstep,normalize,inversesqrt,clamp,length,distance,dot,cross,reflect,refract and vectormin andmax. Other functions likeabs,sin,pow, etc, are provided but they can also all operate on vector quantities, i.e.pow(vec3(1.5,2.0,2.5)),abs(vec3(0.1,-0.2,0.3))). GLSL supportsfunction overloading (for both built-in functions and operators, and user-defined functions), so there might be multiple function definitions with the same name, having different number of parameters or parameter types. Each of them can have own independent return type.

Preprocessor

[edit]

GLSL defines a subset of theC preprocessor (CPP), combined with its own special directives for specifying versions and OpenGL extensions. The parts removed from CPP are those relating to file names such as#include and__FILE__.[20]

TheGL_ARB_shading_language_include extension[21] (implemented for example in Nvidia drivers[22] on Windows and Linux, and all Mesa 20.0.0[23] drivers on Linux, FreeBSD and Android) implements ability to use#include in source code, allowing easier sharing of code and definitions between many shaders without extra manual pre-processing. Similar extensionGL_GOOGLE_include_directive andGL_GOOGLE_cpp_style_line_directive exist for using GLSL with Vulkan, and are supported in reference SPIR-V compiler (glslang aka glslangValidator).[24][25][26]

Compilation and execution

[edit]

GLSL shaders are not stand-alone applications; they require an application that utilizes the OpenGL API, which is available on many different platforms (e.g.,Linux,macOS,Windows). There are language bindings forC,C++,C#,JavaScript,Delphi,Java, and many more.

GLSL shaders themselves are simply a set ofstrings that are passed to the hardware vendor's driver for compilation from within an application using the OpenGL API's entry points. Shaders can be createdon the fly from within an application, or read-in as text files, but must be sent to the driver in the form of a string.

The set of APIs used to compile, link, and pass parameters to GLSL programs are specified in three OpenGL extensions, and became part of core OpenGL as of OpenGL Version 2.0. The API was expanded with geometry shaders in OpenGL 3.2, tessellation shaders in OpenGL 4.0 andcompute shaders in OpenGL 4.3. These OpenGL APIs are found in the extensions:

  • ARB vertex shader
  • ARB fragment shader
  • ARB shader objects
  • ARB geometry shader 4
  • ARB tessellation shader
  • ARB compute shader

GLSL shaders can also be used withVulkan, and are a common way of using shaders in Vulkan. GLSL shaders are precompiled before use, or at runtime, into a binary bytecode format calledSPIR-V, usually using offline compiler.

See also

[edit]

Other shading languages

[edit]

References

[edit]
Citations
  1. ^"The OpenGL® Shading Language, Version 4.60.8".
  2. ^"GLSL Language Specification, Version 1.10.59"(PDF).
  3. ^"GLSL Language Specification, Version 1.20.8"(PDF).
  4. ^"GLSL Language Specification, Version 1.30.10"(PDF).
  5. ^"GLSL Language Specification, Version 1.40.08"(PDF).
  6. ^"GLSL Language Specification, Version 1.50.11"(PDF).
  7. ^"GLSL Language Specification, Version 3.30.6"(PDF).
  8. ^"GLSL Language Specification, Version 4.00.9"(PDF).
  9. ^"GLSL Language Specification, Version 4.10.6"(PDF).
  10. ^"GLSL Language Specification, Version 4.20.11"(PDF).
  11. ^"GLSL Language Specification, Version 4.30.8"(PDF).
  12. ^"GLSL Language Specification, Version 4.40.9"(PDF).
  13. ^"GLSL Language Specification, Version 4.50.7"(PDF).
  14. ^"GLSL Language Specification, Version 4.60.5"(PDF).
  15. ^"GLSL ES Language Specification, Version 1.00, revision 17"(PDF).
  16. ^"GLSL ES Language Specification, Version 3.00, revision 6"(PDF).
  17. ^"The OpenGL ES® Shading Language, version 3.10, revision 5"(PDF).
  18. ^"The OpenGL ES® Shading Language, Version 3.20.6"(PDF).
  19. ^KhronosGroup/SPIRV-Cross, The Khronos Group, 2019-09-06, retrieved2019-09-08
  20. ^"Shader Preprocessor".OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition.
  21. ^"ARB_shading_language_include".Khronos.org. Retrieved2020-05-31.
  22. ^"NVIDIA driver 265.90 WHQL Quadro".LaptopVideo2Go Forums. Archived fromthe original on March 8, 2021.
  23. ^"Mesa 20.0.0 Release Notes / 2020-02-19".www.mesa3d.org. Archived fromthe original on 2020-05-12. Retrieved2020-05-31.
  24. ^"#include directive support by antiagainst · Pull Request #46 · KhronosGroup/glslang".GitHub. Retrieved2020-05-31.
  25. ^"Preprocessing line number handling by antiagainst · Pull Request #38 · KhronosGroup/glslang".GitHub.
  26. ^"Extend the syntax of #line and __FILE__ to support filename strings by antiagainst · Pull Request #43 · KhronosGroup/glslang".GitHub.
  27. ^"Metal Shading Language Specification Version 3.2".

Further reading

[edit]
Books
  • Rost, Randi J. (30 July 2009).OpenGL Shading Language (3rd ed.). Addison-Wesley.ISBN 978-0-321-63763-5.
  • Kessenich, John; Baldwin, David; Rost, Randi.The OpenGL Shading Language. Version 1.10.59. 3Dlabs, Inc. Ltd.
  • Bailey, Mike; Cunningham, Steve (22 April 2009).Graphics Shaders: Theory and Practice (2nd ed.). CRC Press.ISBN 978-1-56881-434-6.

External links

[edit]
Wikibooks has a book on the topic of:GLSL Programming
Khronos Group Standards
Active
Inactive
Authority control databasesEdit this at Wikidata
Retrieved from "https://en.wikipedia.org/w/index.php?title=OpenGL_Shading_Language&oldid=1324347849"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp