Shaders in GLSL Flashcards

1
Q

What is not allowed in a fragment shader?

A

No access to adjacent fragments. Cannot change fragment position.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the conversion rules for GLSL?

A

There is no implicit conversion.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the basic types for GLSL?

A

void bool int float vec2 vec3 vec4 bvec2 bvec3 bvec4 ivec2 ivec3 ivec4 mat2 mat3 mat4 sampler2D samplerCube

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the non-type keywords in GLSL?

A

attribute const uniform varying break continue do for while if else in out inout true false lowp mediump highp precision invariant discard return struct

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What preprocessor directives are defined in GLSL?

A
#
#define
#undef
#if
#ifdef
#ifndef
#else
#elif
#endif
#error
#pragma
#extension
#version
#line
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the operator precedence for GLSL?

A
()
defined + - ~ !
* / %
\+ -
<< >>
< > =
== !=
&
^
|
&&
||
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a sampler type?

A

Sampler2D and SamplerCube are opaque handlers to textures.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the usage restrictions on sampler types?

A

They can only be declared as function parameters or uniforms. Their use in expressions is limited. The cannot be used as out or inout function parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an anonymous structure?

A
This:
struct S {
   int i;
};
S myStruct;
// Illegal in GLSL, need "struct S myStruct"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an embedded structure definition?

A
struct S {
  struct T {
  }
}
// Illegal in GLSL, but this is OK:
struct T {
}
struct S {
  T foo;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How are arrays initialized at declaration in GLSL?

A

This is impossible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How are variables scoped in GLSL?

A

By a system of statically nested scopes, as in C or Java { { } }.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the only shared global allowed in GLSL?

A

uniform

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How is const used in GLSL?

A

Compile-time constants and read-only function parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a GLSL attribute?

A

A linkage between a vertex shader and OpenGL ES per-vertex data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a GLSL uniform?

A

Uniforms form the linkage between a fragment shader, OpenGL ES, and the application. This value does not change across the primitive being processed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a GLSL varying?

A

A linkage between a vertex shader and a fragment shader through interpolation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are the storage qualifiers and the rules for when they are allowed?

A

default, const, attribute, varying, or uniform.
Local variables may only be default.
Function parameters can only use const.
Function return types and structures do not use qualifiers.

19
Q

What kind of data is used to communicate between runs of a shader?

A

None are allowed. This would defeat the SIMD nature of the GPU.

20
Q

What is “static use” of a variable?

A

It is when the code contains a compiled reference to the variable, even if the code is never executed.

21
Q

What do precision qualifiers do?

A

Specify minimum storage requirements for variables.

22
Q

What is the rule for precision of operations?

A

Operations preserve precision of their highest-precision operand, with the exception of a few computationally-intense built-in functions, such as atan().

23
Q

What does the precision keyword do for GLSL?

A

Creates a default precision for a storage type.

24
Q

What does variance refer to in shaders?

A

In general, the same expression may give different values in different shaders. Shaders are compiled independently, so different shaders may have different values for the same expression.

25
Q

gl_Position

A

The ultimate job of a vertex shader is to set gl_Position, a vec4 final position of the vertex.

26
Q

gl_FragColor

A

The ultimate job of a fragment shader is to set or discard gl_FragColor.

27
Q

Which precisions are supported by which shaders?

A

Vertex shaders support highp, mediump, and lowp. Fragment shaders support mediump and lowp, with highp being optional.

28
Q

What does this do?

vec3 foo = vec3(1.2);

A

This constructor initializes foo to (1.2, 1.2, 1.2).

29
Q

What does this do?

mat3 foo = mat3(3.4);

A

This constructor initializes the diagonal of foo to 3.4, and all other entries to 0.0.

30
Q

What does this do?
vec4 a = vec4(1.0,2.0,3.0,4.0);
vec3 b = vec3(a);

A

Shortens a by dropping 4.0 and assigns result to b.

31
Q

What is a structure constructor?

A

A structure constructor is created at structure declaration time. It matches the order and type of members as such:
struct light {
float a;
vec3 b;
};
light newLight = light(1.0,(0.1,0.2,0.3));

32
Q

Name all of the vector component aliases.

A

{x, y, z, w} // useful for vertex coordinates
{r, g, b, a} // useful for colors
{s, t, p, q} // useful for texture coordinates

33
Q

What is the type of

v4.xy

A

vec2

34
Q

Which element?

m[1][0]

A

e10, or the second row, first column.

35
Q

How many bits (typically) in lowp?

A

10 bits

36
Q

How many bits (typically) in medium?

A

16 bits

37
Q

How many bits (typically) in high?

A

24 bits

38
Q

How many uniforms are typically permitted in the system?

A

128

39
Q

What is the intrinsic declaration of gl_Position?

A

highp vec4 gl_Position

40
Q

What is the intrinsic declaration of gl_PointSize?

A

mediump float gl_Pointsize

41
Q

VNT

A

Vertex, Normal, Texture Coordinate. A vertex buffer format.

42
Q

What is the difference between static procedural deformation and dynamic procedural deformation?

A

Static procedural deformation creates time-independent effects, such as bumps on a metal surface from impact. Dynamic procedural deformation creates time-dependent effects, such as a flag waving or a creature breathing.

43
Q

How can vertex shaders aid in implementing environmental effects?

A

Effects like smoke or fog which depend on location or elevation can be calculated in a vertex shader.

44
Q

How is morphing implemented by a vertex shader?

A

Two different versions of an object are made available to the vertex shader. The shader blends the position of each vertex in these models.