-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.md.backup
More file actions
177 lines (139 loc) · 5.11 KB
/
README.md.backup
File metadata and controls
177 lines (139 loc) · 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# RenderGU
Rendering ground up (GU) using modern OpenGL.
## Current Engine Features
### Display state scene switching
#### Scene Data Examples
```
struct MenuScreenPrototypeData
{
unsigned int VAO = 0;
unsigned int shaderProgram = 0;
unsigned int texture = 0;
bool button1 = false;
bool button2 = false;
};
struct Scene1Data
{
unsigned int VAO = 0;
unsigned int shaderProgram = 0;
unsigned int texture = 0;
};
```
#### SceneData Interface
```
struct SceneData
{
MenuScreenPrototypeData menuScreenPrototypeData;
Scene1Data scene1Data;
}sceneData;
```
#### Display State
```
enum E_DISPLAY_STATE
{
MENU_SCREEN_PROTOTYPE,
SCENE_1,
//... etc,
}DISPLAY_STATE;
```
#### Main Display Function
```
void display(SceneData* sceneData)
{
switch(DISPLAY_STATE)
{
case MENU_SCREEN_PROTOTYPE:
display2DMenuPrototype(&sceneData->menuScreenPrototypeData.VAO,
&sceneData->menuScreenPrototypeData.shaderProgram,
&sceneData->menuScreenPrototypeData.texture,
sceneData->menuScreenPrototypeData.button1,
sceneData->menuScreenPrototypeData.button2);
break;
case SCENE_1:
displayScene1(&sceneData->scene1Data.VAO,
&sceneData->scene1Data.shaderProgram,
&sceneData->scene1Data.texture);
break;
// etc...
default:
break;
}
}
```
#### Call Site (Render Loop)
```
if (DISPLAY_STATE == MENU_SCREEN_PROTOTYPE)
{
// Example - this will later set shader uniform when rendering
// to attachments of currently bound framebuffer.
sceneData.menuScreenPrototypeData.button2 = true;
}
// Render to attachments of currently bound framebuffer
display(&sceneData)
```
### One-time Intra-Frame Scene Set Up
If there is no VAO do the following for each scene display, once only, inside a frame:
- Create model vertex data - i.e. the model
- Write your shaders
- Make the shader program
- Specify the vertices
### Shader Compilation and Linking Utility Functions
#### Function Interfaces
```
unsigned int compileVertexShader(const char* vertexShaderSource);
unsigned int compileFragmentShader(const char* fragmentShaderSource);
unsigned int compileComputeShader(const char* computeShaderSource);
unsigned int linkShaders(
unsigned int vertexShader,
unsigned int fragmentShader);
unsigned int linkShaders(unsigned int computeShader);
```
#### Function Call Site
```
*shaderProgram = linkShaders(compileVertexShader(vs), compileFragmentShader(fs));
```
### Real-time Console Performance Data

### Other Features
- Keyboard input with rising/falling edge handling
- 3D camera system (pitch, roll, yaw) and strafe
## Rendering Showcase
### Lighting
Phong Reflection:
$$Ambient + Diffuse + Specular$$
Phong Exponent, $p$:
$$\boldsymbol{viewDir}$$ and $$\boldsymbol{reflectionDir}$$ are unit vectors.
$$(max (\boldsymbol{viewDir} \cdot \boldsymbol{reflectionDir}, 0 ))^{p}$$
$\theta\$ is the angle between the above vectors. As $\cos \theta \in\ [0,1], p$ has the effect of simulating specular reflection more accurately (in the fragment shader, the specular reflection factor multiplies the light source).
|Ambient | Diffuse | Specular | $p$ | |
|--------|--------|---------|--|:--:|
| yes| yes|yes|32 ||
| no| yes|yes|32 |  |
| no| no|yes|32 ||
| yes| yes|yes|16 ||
| yes| yes|yes|64 ||
### Post-process Effects
Post-processing implemented by executing two render passes - the first one is an off screen render pass that renders the screen to a texture. This is achieved by creating a framebuffer and binding to that (using renderbuffers for when we don't need to sample depth and stencil buffers):
```
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureTarget, 0);
// Create renderbuffer for attaching depth to currently bound framebuffer
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 800, 600);
assert(glGetError() == 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo);
CheckFramebufferStatus();
```
There is:
- Inversion
- Grey-scale (simple average)
- Grey-scale (weighted average, eye)
- A scrolling effect
- Multiple Kernel effects: sharpen, blur, edge detection.
- Rear view mirror
## Resources
- [LearnOpenGL](https://learnopengl.com/)
- Fundamentals Of Computer Graphics 4th Edition (Marschner, S. and Shirley, P., 2018. Fundamentals of computer graphics. CRC Press.)
- Real Time Rendering 4th Edition (Akenine-Moller, T., Haines, E. and Hoffman, N., 2019. Real-time rendering. AK Peters/crc Press.)
- [Computer Graphcis with Modern OpenGL](https://www.udemy.com/course/graphics- with-modern-opengl/)