- Real-Time 3D Graphics with WebGL 2
- Farhad Ghayour Diego Cantor
- 276字
- 2021-06-10 19:43:06
Types
Here is a non-exhaustive list of the most common ESSL types:
- void: For functions that do not return a value or for an empty parameter list
- bool: A conditional type, taking on values of true or false
- int: A signed integer
- float: A single floating-point scalar
- vec2: A two-component floating-point vector
- vec3: A three-component floating-point vector
- vec4: A four-component floating-point vector
- bvec2: A two-component Boolean vector
- bvec3: A three-component Boolean vector
- bvec4: A four-component Boolean vector
- ivec2: A two-component integer vector
- ivec3: A three-component integer vector
- ivec4: A four-component integer vector
- mat2: A 2×2 floating-point matrix
- mat3: A 3×3 floating-point matrix
- mat4: A 4×4 floating-point matrix
- sampler2D: A handle for accessing a 2D texture
- sampler3D: A handle for accessing a 3D texture
- samplerCube: A handle for accessing a cube-mapped texture
- struct: Used to declare custom data structures based on standard types
ESSL
There are many other types and features that the OpenGL ES 3.0 shading language provides. Here is a useful guide that covers many of its core features: https://www.khronos.org/files/opengles3-quick-reference-card.pdf.
There are many other types and features that the OpenGL ES 3.0 shading language provides. Here is a useful guide that covers many of its core features: https://www.khronos.org/files/opengles3-quick-reference-card.pdf.
An input variable will have one of the qualifiers followed by one type. For example, we will declare our uLightColor variable as follows:
uniform vec4 uLightColor;
This means that the uLightColor variable is a uniform vector with four components.
The GLSL and ESSL Naming Convention
Convention dictates that we prefix shader variables with their type. This makes for clear and readable shader code. For example, for a given color uniform, you would name the variable uLightColor. For a position varying, vNormal. For a normal attribute, aVertexNormal.
Convention dictates that we prefix shader variables with their type. This makes for clear and readable shader code. For example, for a given color uniform, you would name the variable uLightColor. For a position varying, vNormal. For a normal attribute, aVertexNormal.