Graphics Flashcards

1
Q

What language are shaders written in?

A

In unity you write shader programs using the HLSL programming language.

Unity originally used the CG language, as such the name of some of unity’s shader keywords (CGPROGRAM) and file extensions(.cginc). Unity no longer uses CG, but these keywords and file extensions are still supported.

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

What syntax does unity use for shaders?

A

The HLSL language itself has two syntaxes: a “legacy” DX9-style syntax, and a more modern DX10+ style syntax.

The difference in syntax mostly is in how texture sampling functions work.

The legacy syntax uses sampler2D, tex2D(), and similar functions; this works on all platforms.

The DX10+ syntax uses Texture2D, SamplerState and .Sample() functions. Some forms of this syntax don’t work on OpenGL platforms, due to how textures and samplers are not different objects in OpenGL.

In Unity, you can avoid problems with HLSL syntax platform support by using predefined macros to declare and sample textures. Unity expands these macros to most appropriate syntax, depending on the platform that the shader is being compiled for.

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

What are the main types of shaders? (-vert, -frag, -compute)

A

Vertex shaders manipulate coordinates in 3D space and are called once per vertex. The purpose of the vertex shader is to set up the “gl_Position” variable; This is a special, global, and built-in GLSL variable. It’s used to store the position of the current vertex.

Fragment shaders define RGBA (red, blue, green, alpha) colors for each pixel being processed; a single fragment shader is called once per pixel. The purpose of the fragment shader is to set up the “gl_FragColor” variable. This is a built in GLSL variable like “gl_Position” is.

Compute shaders are programs that run on the graphics card, outside the normal render pipeline. They can be used for massive parallel GPGPU algorithms, or to accelerate parts of game rendering. While similar to regular shaders, compute shaders are asset files in your project, with a .compute file extension. They are written in DirectX11 style HLSL with minimal number of #pragma compilation directives to indicate which functions to compile as compute shader kernels.

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

What are surface shaders, and why use them? (This is unity specific and will be deprecated).

A

Surface shaders in unity is a code generation approach that makes it much easier to write lit shaders than using low level vertex/pixel shader programs.

It’s used as it generates all the repetitive code that would be written by hand for you.

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

How many passes can a shader have? What is the downside to multipass shaders?

A

One pass is a combination of the mesh, vertex, and pixel shader resulting in pixel data being written.

A shader file in unity may have one, or multiple passes, these shaders appear to be one shader but actually get expanded out to many different shader passes, not all of which run at the same time.

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

What does it mean to sample a texture?

A

Sampling is a process of getting a finite number of values from a function, map, image. These are then combined(interpolated) in order to produce as good a sampling value as possible to use in fragment calculations.

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

What is a draw call? What is a batch?

A

A draw call is a call to the graphics API to draw objects(draw a triangle), while a batch is a group of draw calls to be drawn together. Batching objects to be drawn together minimizes the state changes needed to draw each object inside the batch. This in turn leads to improved performance by reducing the CPU cost of rendering the objects.

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

How does dynamic batching work? Is dynamic batching always a speed up?

A

Dynamic batching works by transforming all GameObject vertices into world space on the CPU, so it is only an advantage if that work is smaller than doing a draw call. The resource requirements of a draw call depends on many factors, primarily the graphics API used. For example, on consoles or modern APIs like apple metal, the draw call overhead is generally much lower, and often dynamic batching cannot be an advantage at all.

Unity can automatically batch moving GameObjects into the same draw call if they share the same material and fulfill other criteria. Dynamic batching is done automatically and does not require any additional effect on your side.

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

What are the constraints regarding batching?

A

Built-in batching

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

What is a VBO?

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

What is the benefit of deferred lighting?(trade off)

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

Explain the difference between dynamic batching and GPU instancing?

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

What’s the difference between static and dynamic batching?

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