diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | maps/bigmap.txt | 1 | ||||
-rw-r--r-- | shaders/bloom1.fragment | 53 | ||||
-rw-r--r-- | shaders/bloom1.vertex | 11 | ||||
-rw-r--r-- | shaders/bloom2.fragment | 57 | ||||
-rw-r--r-- | shaders/bloom2.vertex | 11 | ||||
-rw-r--r-- | shaders/final.fragment | 50 | ||||
-rw-r--r-- | shaders/final.vertex | 23 | ||||
-rw-r--r-- | src/main.cpp | 44 | ||||
-rw-r--r-- | src/renderer.cpp | 73 |
10 files changed, 269 insertions, 56 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c0e0339..54aee1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -30,4 +30,6 @@ find_package(GLFW REQUIRED) | |||
30 | set(CMAKE_BUILD_TYPE Debug) | 30 | set(CMAKE_BUILD_TYPE Debug) |
31 | add_executable(Aromatherapy src/main.cpp src/map.cpp src/renderer.cpp) | 31 | add_executable(Aromatherapy src/main.cpp src/map.cpp src/renderer.cpp) |
32 | target_link_libraries(Aromatherapy ${OPENGL_LIBRARY} ${GLEW_LIBRARY} ${GLFW_LIBRARY}) | 32 | target_link_libraries(Aromatherapy ${OPENGL_LIBRARY} ${GLEW_LIBRARY} ${GLFW_LIBRARY}) |
33 | add_executable(translate_font src/translate_font.cpp src/renderer.cpp) | ||
34 | target_link_libraries(translate_font ${OPENGL_LIBRARY} ${GLEW_LIBRARY} ${GLFW_LIBRARY}) | ||
33 | install(TARGETS Aromatherapy RUNTIME DESTINATION ${BIN_DIR}) | 35 | install(TARGETS Aromatherapy RUNTIME DESTINATION ${BIN_DIR}) |
diff --git a/maps/bigmap.txt b/maps/bigmap.txt index ac5e9e2..00ab68e 100644 --- a/maps/bigmap.txt +++ b/maps/bigmap.txt | |||
@@ -21,5 +21,4 @@ XXX XXXXXXXXXXXX | |||
21 | XXXXXXXXXXXXXXXXXXXX | 21 | XXXXXXXXXXXXXXXXXXXX |
22 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | 22 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
23 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | 23 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
24 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
25 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \ No newline at end of file | 24 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \ No newline at end of file |
diff --git a/shaders/bloom1.fragment b/shaders/bloom1.fragment new file mode 100644 index 0000000..77031f2 --- /dev/null +++ b/shaders/bloom1.fragment | |||
@@ -0,0 +1,53 @@ | |||
1 | #version 330 core | ||
2 | |||
3 | in vec2 UV; | ||
4 | |||
5 | out vec3 color; | ||
6 | |||
7 | uniform sampler2D screenTex; | ||
8 | uniform float iGlobalTime; | ||
9 | |||
10 | float nrand(vec2 n) | ||
11 | { | ||
12 | return fract(sin(dot(n.xy, vec2(19.9898, 78.233))) * 43758.5453); | ||
13 | } | ||
14 | |||
15 | vec2 rot2d(vec2 p, float a) | ||
16 | { | ||
17 | vec2 sc = vec2(sin(a), cos(a)); | ||
18 | return vec2(dot(p, vec2(sc.y, -sc.x)), dot(p, sc.xy)); | ||
19 | } | ||
20 | |||
21 | void main() | ||
22 | { | ||
23 | const int NUM_TAPS = 12; | ||
24 | float max_siz = 1.0; | ||
25 | |||
26 | vec2 fTaps_Poisson[NUM_TAPS]; | ||
27 | fTaps_Poisson[0] = vec2(-.326, -.406); | ||
28 | fTaps_Poisson[1] = vec2(-.840, -.074); | ||
29 | fTaps_Poisson[2] = vec2(-.696, .457); | ||
30 | fTaps_Poisson[3] = vec2(-.203, .621); | ||
31 | fTaps_Poisson[4] = vec2( .962, -.195); | ||
32 | fTaps_Poisson[5] = vec2( .473, -.480); | ||
33 | fTaps_Poisson[6] = vec2( .519, .767); | ||
34 | fTaps_Poisson[7] = vec2( .185, -.893); | ||
35 | fTaps_Poisson[8] = vec2( .507, .064); | ||
36 | fTaps_Poisson[9] = vec2( .896, .412); | ||
37 | fTaps_Poisson[10] = vec2(-.322, -.933); | ||
38 | fTaps_Poisson[11] = vec2(-.792, -.598); | ||
39 | |||
40 | vec4 sum = vec4(0); | ||
41 | float rnd = 6.28 * nrand(UV + fract(iGlobalTime)); | ||
42 | vec4 basis = vec4(rot2d(vec2(1,0), rnd), rot2d(vec2(0,1), rnd)); | ||
43 | for (int i=0; i<NUM_TAPS; i++) | ||
44 | { | ||
45 | vec2 ofs = fTaps_Poisson[i]; | ||
46 | ofs = vec2(dot(ofs, basis.xz), dot(ofs, basis.yw)); | ||
47 | |||
48 | vec2 texcoord = UV + max_siz * ofs / vec2(1024.0,768.0); | ||
49 | sum += texture(screenTex, texcoord, -10.0); | ||
50 | } | ||
51 | |||
52 | color = (sum / vec4(NUM_TAPS)).rgb; | ||
53 | } | ||
diff --git a/shaders/bloom1.vertex b/shaders/bloom1.vertex new file mode 100644 index 0000000..37eeeb0 --- /dev/null +++ b/shaders/bloom1.vertex | |||
@@ -0,0 +1,11 @@ | |||
1 | #version 330 core | ||
2 | |||
3 | layout(location = 0) in vec3 vPos; | ||
4 | |||
5 | out vec2 UV; | ||
6 | |||
7 | void main() | ||
8 | { | ||
9 | gl_Position = vec4(vPos, 1); | ||
10 | UV = (vPos.xy + vec2(1,1))/2; | ||
11 | } | ||
diff --git a/shaders/bloom2.fragment b/shaders/bloom2.fragment new file mode 100644 index 0000000..323f441 --- /dev/null +++ b/shaders/bloom2.fragment | |||
@@ -0,0 +1,57 @@ | |||
1 | #version 330 core | ||
2 | |||
3 | in vec2 UV; | ||
4 | |||
5 | out vec3 color; | ||
6 | |||
7 | uniform sampler2D screenTex; | ||
8 | uniform sampler2D downsampledTex; | ||
9 | uniform float iGlobalTime; | ||
10 | |||
11 | float nrand(vec2 n) | ||
12 | { | ||
13 | return fract(sin(dot(n.xy, vec2(19.9898, 78.233))) * 43758.5453); | ||
14 | } | ||
15 | |||
16 | vec2 rot2d(vec2 p, float a) | ||
17 | { | ||
18 | vec2 sc = vec2(sin(a), cos(a)); | ||
19 | return vec2(dot(p, vec2(sc.y, -sc.x)), dot(p, sc.xy)); | ||
20 | } | ||
21 | |||
22 | void main() | ||
23 | { | ||
24 | const int NUM_TAPS = 12; | ||
25 | float max_siz = 1.0; | ||
26 | |||
27 | vec2 fTaps_Poisson[NUM_TAPS]; | ||
28 | fTaps_Poisson[0] = vec2(-.326, -.406); | ||
29 | fTaps_Poisson[1] = vec2(-.840, -.074); | ||
30 | fTaps_Poisson[2] = vec2(-.696, .457); | ||
31 | fTaps_Poisson[3] = vec2(-.203, .621); | ||
32 | fTaps_Poisson[4] = vec2( .962, -.195); | ||
33 | fTaps_Poisson[5] = vec2( .473, -.480); | ||
34 | fTaps_Poisson[6] = vec2( .519, .767); | ||
35 | fTaps_Poisson[7] = vec2( .185, -.893); | ||
36 | fTaps_Poisson[8] = vec2( .507, .064); | ||
37 | fTaps_Poisson[9] = vec2( .896, .412); | ||
38 | fTaps_Poisson[10] = vec2(-.322, -.933); | ||
39 | fTaps_Poisson[11] = vec2(-.792, -.598); | ||
40 | |||
41 | vec4 sum = vec4(0); | ||
42 | float rnd = 6.28 * nrand(UV + fract(iGlobalTime)); | ||
43 | vec4 basis = vec4(rot2d(vec2(1,0), rnd), rot2d(vec2(0,1), rnd)); | ||
44 | for (int i=0; i<NUM_TAPS; i++) | ||
45 | { | ||
46 | vec2 ofs = fTaps_Poisson[i]; | ||
47 | ofs = vec2(dot(ofs, basis.xz), dot(ofs, basis.yw)); | ||
48 | |||
49 | vec2 texcoord = UV + max_siz * ofs / vec2(64.0,48.0); | ||
50 | sum += texture(downsampledTex, texcoord, -10.0); | ||
51 | } | ||
52 | |||
53 | vec3 bloom_c = (sum / vec4(NUM_TAPS)).rgb; | ||
54 | bloom_c = vec3(bloom_c.r*bloom_c.r, bloom_c.g*bloom_c.g, bloom_c.b*bloom_c.b); | ||
55 | |||
56 | color = texture(screenTex, UV).rgb + bloom_c; | ||
57 | } | ||
diff --git a/shaders/bloom2.vertex b/shaders/bloom2.vertex new file mode 100644 index 0000000..37eeeb0 --- /dev/null +++ b/shaders/bloom2.vertex | |||
@@ -0,0 +1,11 @@ | |||
1 | #version 330 core | ||
2 | |||
3 | layout(location = 0) in vec3 vPos; | ||
4 | |||
5 | out vec2 UV; | ||
6 | |||
7 | void main() | ||
8 | { | ||
9 | gl_Position = vec4(vPos, 1); | ||
10 | UV = (vPos.xy + vec2(1,1))/2; | ||
11 | } | ||
diff --git a/shaders/final.fragment b/shaders/final.fragment index c900973..5feccb9 100644 --- a/shaders/final.fragment +++ b/shaders/final.fragment | |||
@@ -1,7 +1,10 @@ | |||
1 | #version 330 core | 1 | #version 330 core |
2 | 2 | ||
3 | in vec2 UV; | 3 | in vec2 UV; |
4 | in vec3 norm; | 4 | in vec3 normIn; |
5 | in vec3 camDirIn; | ||
6 | in vec3 lightDirIn; | ||
7 | //in vec3 vertPos; | ||
5 | 8 | ||
6 | out vec3 color; | 9 | out vec3 color; |
7 | 10 | ||
@@ -10,20 +13,19 @@ uniform sampler2D scanlinestex; | |||
10 | 13 | ||
11 | const vec2 UVScalar = vec2(1.0, 1.0); | 14 | const vec2 UVScalar = vec2(1.0, 1.0); |
12 | const vec2 UVOffset = vec2(0.0, 0.0); | 15 | const vec2 UVOffset = vec2(0.0, 0.0); |
13 | const vec2 CRTMask_Scale = vec2(85.0, 153.6); | 16 | const vec2 CRTMask_Scale = vec2(85.0, 153.6)*4.0; |
14 | const vec2 CRTMask_Offset = vec2(0.0, 0.0); | 17 | const vec2 CRTMask_Offset = vec2(0.0, 0.0); |
15 | const float Tuning_Overscan = 1.0; | 18 | const float Tuning_Overscan = 1.0; |
16 | const float Tuning_Dimming = 0.5; | 19 | const float Tuning_Dimming = 0.0; |
17 | const float Tuning_Satur = 1.35; | 20 | const float Tuning_Satur = 1.35; |
18 | const float Tuning_ReflScalar = 0.3; | 21 | const float Tuning_ReflScalar = 0.3; |
19 | const float Tuning_Barrel = 0.12; | 22 | const float Tuning_Barrel = 0; //0.12; |
20 | const float Tuning_Scanline_Brightness = 0.25; | 23 | const float Tuning_Scanline_Brightness = 0.5; |
21 | const float Tuning_Scanline_Opacity = 0.5; | 24 | const float Tuning_Scanline_Opacity = 0.5; |
22 | const float Tuning_Diff_Brightness = 0.5; | 25 | const float Tuning_Diff_Brightness = 0.5; |
23 | const float Tuning_Spec_Brightness = 0.35; | 26 | const float Tuning_Spec_Brightness = 0.35; |
24 | const float Tuning_Spec_Power = 50.0; | 27 | const float Tuning_Spec_Power = 50.0; |
25 | const float Tuning_Fres_Brightness = 1.0; | 28 | const float Tuning_Fres_Brightness = 1.0; |
26 | const vec3 Tuning_LightPos = vec3(5.0, -10.0, 0.0); | ||
27 | 29 | ||
28 | vec4 sampleCRT(vec2 uv) | 30 | vec4 sampleCRT(vec2 uv) |
29 | { | 31 | { |
@@ -52,5 +54,39 @@ vec4 sampleCRT(vec2 uv) | |||
52 | 54 | ||
53 | void main() | 55 | void main() |
54 | { | 56 | { |
55 | color = sampleCRT(UV).rgb; | 57 | vec3 norm = normalize(normIn); |
58 | vec3 camDir = normalize(camDirIn); | ||
59 | vec3 lightDir = normalize(lightDirIn); | ||
60 | //vec3 refl = reflect(camDir, normIn); | ||
61 | |||
62 | float diffuse = clamp(dot(norm, lightDir), 0.0f, 1.0f); | ||
63 | vec4 colordiff = vec4(0.175, 0.15, 0.2, 1) * diffuse * Tuning_Diff_Brightness; | ||
64 | |||
65 | vec3 halfVec = normalize(lightDir + camDir); | ||
66 | float spec = clamp(dot(norm, halfVec), 0.0f, 1.0f); | ||
67 | spec = pow(spec, Tuning_Spec_Power); | ||
68 | vec4 colorspec = vec4(0.25, 0.25, 0.25, 1) * spec * Tuning_Spec_Brightness; | ||
69 | |||
70 | float fres = 1.0f - dot(camDir, norm); | ||
71 | fres = (fres*fres) * Tuning_Fres_Brightness; | ||
72 | vec4 colorfres = vec4(0.45, 0.4, 0.5, 1) * fres;/* | ||
73 | |||
74 | float lambertian = max(dot(camDirNorm,norm),0.0); | ||
75 | vec4 colorspec = vec4(0.0); | ||
76 | vec4 colorfres = vec4(0.0); | ||
77 | vec4 colordiff = vec4(0.175,0.15,0.2,1) * lambertian * Tuning_Diff_Brightness; | ||
78 | if (lambertian > 0.0) | ||
79 | { | ||
80 | vec3 viewDir = normalize(-vertPos); | ||
81 | vec3 halfDir = normalize(camDirNorm + viewDir); | ||
82 | float specAngle = max(dot(halfDir, normnorm), 0.0); | ||
83 | colorspec = vec4(0.25,0.25,0.25,1) * pow(specAngle, Tuning_Spec_Power) * Tuning_Spec_Brightness; | ||
84 | }*/ | ||
85 | |||
86 | vec4 emissive = sampleCRT(UV); | ||
87 | |||
88 | vec4 nearfinal = colorfres + colordiff + colorspec + emissive; | ||
89 | vec4 final = nearfinal * mix(vec4(1,1,1,1), vec4(0,0,0,0), Tuning_Dimming); | ||
90 | |||
91 | color = final.rgb; | ||
56 | } | 92 | } |
diff --git a/shaders/final.vertex b/shaders/final.vertex index 825eb49..dda8626 100644 --- a/shaders/final.vertex +++ b/shaders/final.vertex | |||
@@ -4,11 +4,28 @@ layout(location = 0) in vec3 vertexPosition_modelspace; | |||
4 | layout(location = 1) in vec3 vertexNormal; | 4 | layout(location = 1) in vec3 vertexNormal; |
5 | 5 | ||
6 | out vec2 UV; | 6 | out vec2 UV; |
7 | out vec3 norm; | 7 | out vec3 normIn; |
8 | out vec3 camDirIn; | ||
9 | out vec3 lightDirIn; | ||
10 | //out vec3 vertPos; | ||
11 | |||
12 | uniform mat4 MVP; | ||
13 | uniform mat4 worldMat; | ||
14 | |||
15 | const vec3 Tuning_LightPos = vec3(1, 1, 1.0); | ||
8 | 16 | ||
9 | void main() | 17 | void main() |
10 | { | 18 | { |
11 | gl_Position = vec4(vertexPosition_modelspace,1); | 19 | gl_Position = MVP * vec4(vertexPosition_modelspace,1); |
12 | UV = (vertexPosition_modelspace.xy+vec2(1,1))/2.0; | 20 | UV = (vertexPosition_modelspace.xy+vec2(1,1))/2.0; |
13 | norm = vertexNormal; | 21 | normIn = vertexNormal; |
22 | |||
23 | mat3 invWorldRot = transpose(mat3(worldMat[0].xyz, worldMat[1].xyz, worldMat[2].xyz)); | ||
24 | //mat3 invWorldRot = mat3(1.0f); | ||
25 | vec3 worldPos = (worldMat * vec4(vertexPosition_modelspace,1)).xyz; | ||
26 | camDirIn = invWorldRot * (vec3(0,0,1) - worldPos); | ||
27 | //camDir = worldPos; | ||
28 | lightDirIn = invWorldRot * (Tuning_LightPos - worldPos); | ||
29 | //vec4 vertPos4 = vec4(vertexPosition_modelspace,1); | ||
30 | //vertPos = vec3(vertPos4) / vertPos4.w; | ||
14 | } | 31 | } |
diff --git a/src/main.cpp b/src/main.cpp index 7c1a21f..e1e1aa2 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
@@ -5,26 +5,6 @@ | |||
5 | 5 | ||
6 | using namespace::std; | 6 | using namespace::std; |
7 | 7 | ||
8 | #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WINDOWS__) || defined(__TOS_WIN__) | ||
9 | |||
10 | #include <windows.h> | ||
11 | |||
12 | inline void delay( unsigned long ms ) | ||
13 | { | ||
14 | Sleep( ms ); | ||
15 | } | ||
16 | |||
17 | #else /* presume POSIX */ | ||
18 | |||
19 | #include <unistd.h> | ||
20 | |||
21 | inline void delay( unsigned long ms ) | ||
22 | { | ||
23 | usleep( ms * 1000 ); | ||
24 | } | ||
25 | |||
26 | #endif | ||
27 | |||
28 | const int FRAMES_PER_SECOND = 60; | 8 | const int FRAMES_PER_SECOND = 60; |
29 | bool holding_left = false; | 9 | bool holding_left = false; |
30 | bool holding_right = false; | 10 | bool holding_right = false; |
@@ -81,21 +61,8 @@ int main() | |||
81 | 61 | ||
82 | Texture* tiles = loadTextureFromBMP("../res/tiles.bmp"); | 62 | Texture* tiles = loadTextureFromBMP("../res/tiles.bmp"); |
83 | 63 | ||
84 | double lastTime = glfwGetTime(); | ||
85 | int nbFrames = 0; | ||
86 | |||
87 | while (!quit) | 64 | while (!quit) |
88 | { | 65 | { |
89 | /* | ||
90 | double currentTime = glfwGetTime(); | ||
91 | nbFrames++; | ||
92 | if ( currentTime - lastTime >= 1.0 ){ // If last prinf() was more than 1 sec ago | ||
93 | // printf and reset timer | ||
94 | printf("%f ms/frame\n", 1000.0/double(nbFrames)); | ||
95 | nbFrames = 0; | ||
96 | lastTime += 1.0; | ||
97 | }*/ | ||
98 | |||
99 | if (holding_left && player->x_vel >= 0) | 66 | if (holding_left && player->x_vel >= 0) |
100 | { | 67 | { |
101 | player->x_vel = -2; | 68 | player->x_vel = -2; |
@@ -125,20 +92,11 @@ int main() | |||
125 | Rectangle dst_rect(player->x, player->y, player->w, player->h); | 92 | Rectangle dst_rect(player->x, player->y, player->w, player->h); |
126 | 93 | ||
127 | //blitTexture(tiles, buffer, &src_rect, &dst_rect); | 94 | //blitTexture(tiles, buffer, &src_rect, &dst_rect); |
128 | fillTexture(buffer, &dst_rect, 85, 85, 255); | 95 | fillTexture(buffer, &dst_rect, 255, 255, 255); |
129 | //fillTexture(buffer, NULL, 85, 85, 0); | ||
130 | 96 | ||
131 | renderScreen(buffer); | 97 | renderScreen(buffer); |
132 | 98 | ||
133 | //fuckThePolice(buffer); | ||
134 | |||
135 | glfwPollEvents(); | 99 | glfwPollEvents(); |
136 | |||
137 | // Regulate frame rate | ||
138 | /*if ((clock() - frame_start) < CLOCKS_PER_SEC / FRAMES_PER_SECOND) | ||
139 | { | ||
140 | //delay(((CLOCKS_PER_SEC / FRAMES_PER_SECOND) - clock() + frame_start) * CLOCKS_PER_SEC / 1000); | ||
141 | }*/ | ||
142 | } | 100 | } |
143 | 101 | ||
144 | delete map; | 102 | delete map; |
diff --git a/src/renderer.cpp b/src/renderer.cpp index ca356f3..3011e8f 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp | |||
@@ -14,6 +14,8 @@ static GLuint ntscShader; // The NTSC shader | |||
14 | static GLuint finalShader; // The passthrough shader | 14 | static GLuint finalShader; // The passthrough shader |
15 | static GLuint blitShader; // The blitting shader | 15 | static GLuint blitShader; // The blitting shader |
16 | static GLuint fillShader; // The fill shader | 16 | static GLuint fillShader; // The fill shader |
17 | static GLuint bloom1Shader; | ||
18 | static GLuint bloom2Shader; | ||
17 | 19 | ||
18 | // The buffers for the NTSC rendering process | 20 | // The buffers for the NTSC rendering process |
19 | static GLuint renderedTex1; | 21 | static GLuint renderedTex1; |
@@ -22,6 +24,8 @@ static GLuint renderedTexBufs[2]; | |||
22 | static int curBuf; | 24 | static int curBuf; |
23 | static GLuint artifactsTex; | 25 | static GLuint artifactsTex; |
24 | static GLuint scanlinesTex; | 26 | static GLuint scanlinesTex; |
27 | static GLuint preBloomTex; | ||
28 | static GLuint bloomPassTex; | ||
25 | 29 | ||
26 | GLuint LoadShaders(const char* vertex_file_path, const char* fragment_file_path) | 30 | GLuint LoadShaders(const char* vertex_file_path, const char* fragment_file_path) |
27 | { | 31 | { |
@@ -246,6 +250,23 @@ GLFWwindow* initRenderer() | |||
246 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 250 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
247 | renderedTexBufs[1] = renderedTex2; | 251 | renderedTexBufs[1] = renderedTex2; |
248 | 252 | ||
253 | // Set up bloom rendering buffers | ||
254 | glGenTextures(1, &preBloomTex); | ||
255 | glBindTexture(GL_TEXTURE_2D, preBloomTex); | ||
256 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024, 768, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); | ||
257 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
258 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
259 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||
260 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||
261 | |||
262 | glGenTextures(1, &bloomPassTex); | ||
263 | glBindTexture(GL_TEXTURE_2D, bloomPassTex); | ||
264 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 48, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); | ||
265 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
266 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
267 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||
268 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||
269 | |||
249 | curBuf = 0; | 270 | curBuf = 0; |
250 | 271 | ||
251 | artifactsTex = loadBMP_custom("../res/artifacts.bmp"); | 272 | artifactsTex = loadBMP_custom("../res/artifacts.bmp"); |
@@ -256,6 +277,8 @@ GLFWwindow* initRenderer() | |||
256 | finalShader = LoadShaders("../shaders/final.vertex", "../shaders/final.fragment"); | 277 | finalShader = LoadShaders("../shaders/final.vertex", "../shaders/final.fragment"); |
257 | blitShader = LoadShaders("../shaders/blit.vertex", "../shaders/blit.fragment"); | 278 | blitShader = LoadShaders("../shaders/blit.vertex", "../shaders/blit.fragment"); |
258 | fillShader = LoadShaders("../shaders/fill.vertex", "../shaders/fill.fragment"); | 279 | fillShader = LoadShaders("../shaders/fill.vertex", "../shaders/fill.fragment"); |
280 | bloom1Shader = LoadShaders("../shaders/bloom1.vertex", "../shaders/bloom1.fragment"); | ||
281 | bloom2Shader = LoadShaders("../shaders/bloom2.vertex", "../shaders/bloom2.fragment"); | ||
259 | 282 | ||
260 | rendererInitialized = true; | 283 | rendererInitialized = true; |
261 | 284 | ||
@@ -275,12 +298,16 @@ void destroyRenderer() | |||
275 | glDeleteProgram(finalShader); | 298 | glDeleteProgram(finalShader); |
276 | glDeleteProgram(blitShader); | 299 | glDeleteProgram(blitShader); |
277 | glDeleteProgram(fillShader); | 300 | glDeleteProgram(fillShader); |
301 | glDeleteProgram(bloom1Shader); | ||
302 | glDeleteProgram(bloom2Shader); | ||
278 | 303 | ||
279 | // Delete the NTSC rendering buffers | 304 | // Delete the NTSC rendering buffers |
280 | glDeleteTextures(1, &renderedTex1); | 305 | glDeleteTextures(1, &renderedTex1); |
281 | glDeleteTextures(1, &renderedTex2); | 306 | glDeleteTextures(1, &renderedTex2); |
282 | glDeleteTextures(1, &artifactsTex); | 307 | glDeleteTextures(1, &artifactsTex); |
283 | glDeleteTextures(1, &scanlinesTex); | 308 | glDeleteTextures(1, &scanlinesTex); |
309 | glDeleteTextures(1, &preBloomTex); | ||
310 | glDeleteTextures(1, &bloomPassTex); | ||
284 | 311 | ||
285 | // Delete the framebuffer | 312 | // Delete the framebuffer |
286 | glDeleteFramebuffers(1, &FramebufferName); | 313 | glDeleteFramebuffers(1, &FramebufferName); |
@@ -578,8 +605,9 @@ void renderScreen(Texture* tex) | |||
578 | glBindBuffer(GL_ARRAY_BUFFER, g_norms); | 605 | glBindBuffer(GL_ARRAY_BUFFER, g_norms); |
579 | glBufferData(GL_ARRAY_BUFFER, sizeof(g_norms_data), g_norms_data, GL_STATIC_DRAW); | 606 | glBufferData(GL_ARRAY_BUFFER, sizeof(g_norms_data), g_norms_data, GL_STATIC_DRAW); |
580 | 607 | ||
581 | // We're going to output to the window now | 608 | // We're going to render the screen now |
582 | glBindFramebuffer(GL_FRAMEBUFFER, 0); | 609 | //glBindFramebuffer(GL_FRAMEBUFFER, 0); |
610 | glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, preBloomTex, 0); | ||
583 | glViewport(0,0,1024,768); | 611 | glViewport(0,0,1024,768); |
584 | glClear(GL_COLOR_BUFFER_BIT); | 612 | glClear(GL_COLOR_BUFFER_BIT); |
585 | glUseProgram(finalShader); | 613 | glUseProgram(finalShader); |
@@ -606,6 +634,7 @@ void renderScreen(Texture* tex) | |||
606 | mat4 v_matrix = lookAt(vec3(0,0,1), vec3(0,0,0), vec3(0,1,0)); | 634 | mat4 v_matrix = lookAt(vec3(0,0,1), vec3(0,0,0), vec3(0,1,0)); |
607 | mat4 m_matrix = mat4(1.0f); | 635 | mat4 m_matrix = mat4(1.0f); |
608 | mat4 mvp_matrix = p_matrix * v_matrix * m_matrix; | 636 | mat4 mvp_matrix = p_matrix * v_matrix * m_matrix; |
637 | //mat4 mv_matrix = v_matrix * m_matrix; | ||
609 | 638 | ||
610 | glUniformMatrix4fv(glGetUniformLocation(finalShader, "MVP"), 1, GL_FALSE, &mvp_matrix[0][0]); | 639 | glUniformMatrix4fv(glGetUniformLocation(finalShader, "MVP"), 1, GL_FALSE, &mvp_matrix[0][0]); |
611 | glUniformMatrix4fv(glGetUniformLocation(finalShader, "worldMat"), 1, GL_FALSE, &m_matrix[0][0]); | 640 | glUniformMatrix4fv(glGetUniformLocation(finalShader, "worldMat"), 1, GL_FALSE, &m_matrix[0][0]); |
@@ -622,6 +651,46 @@ void renderScreen(Texture* tex) | |||
622 | glDisableVertexAttribArray(1); | 651 | glDisableVertexAttribArray(1); |
623 | glDisableVertexAttribArray(0); | 652 | glDisableVertexAttribArray(0); |
624 | 653 | ||
654 | // Do the first pass of bloom (downsampling and tapping) | ||
655 | glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, bloomPassTex, 0); | ||
656 | glViewport(0, 0, 64, 48); | ||
657 | glClear(GL_COLOR_BUFFER_BIT); | ||
658 | glUseProgram(bloom1Shader); | ||
659 | |||
660 | glActiveTexture(GL_TEXTURE0); | ||
661 | glBindTexture(GL_TEXTURE_2D, preBloomTex); | ||
662 | glUniform1i(glGetUniformLocation(bloom1Shader, "screenTex"), 0); | ||
663 | |||
664 | glUniform1f(glGetUniformLocation(bloom1Shader, "iGlobalTime"), glfwGetTime()); | ||
665 | |||
666 | glEnableVertexAttribArray(0); | ||
667 | glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); | ||
668 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); | ||
669 | glDrawArrays(GL_TRIANGLES, 0, 6); | ||
670 | glDisableVertexAttribArray(0); | ||
671 | |||
672 | // Do the second pass of bloom and render to screen | ||
673 | glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||
674 | glViewport(0, 0, 1024, 768); | ||
675 | glClear(GL_COLOR_BUFFER_BIT); | ||
676 | glUseProgram(bloom2Shader); | ||
677 | |||
678 | glActiveTexture(GL_TEXTURE0); | ||
679 | glBindTexture(GL_TEXTURE_2D, preBloomTex); | ||
680 | glUniform1i(glGetUniformLocation(bloom2Shader, "screenTex"), 0); | ||
681 | |||
682 | glActiveTexture(GL_TEXTURE1); | ||
683 | glBindTexture(GL_TEXTURE_2D, bloomPassTex); | ||
684 | glUniform1i(glGetUniformLocation(bloom2Shader, "downsampledTex"), 1); | ||
685 | |||
686 | glUniform1f(glGetUniformLocation(bloom2Shader, "iGlobalTime"), glfwGetTime()); | ||
687 | |||
688 | glEnableVertexAttribArray(0); | ||
689 | glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); | ||
690 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); | ||
691 | glDrawArrays(GL_TRIANGLES, 0, 6); | ||
692 | glDisableVertexAttribArray(0); | ||
693 | |||
625 | glfwSwapBuffers(window); | 694 | glfwSwapBuffers(window); |
626 | 695 | ||
627 | glDeleteBuffers(1, &g_norms); | 696 | glDeleteBuffers(1, &g_norms); |