Skip to content

Commit 1ba780f

Browse files
committed
Merge branch 'master' of https://github.com/cchampet/OpenGL
Conflicts: DiveInSpace/src/main.cpp
2 parents 34e1f22 + eefe5ae commit 1ba780f

File tree

8 files changed

+234
-5
lines changed

8 files changed

+234
-5
lines changed

DiveInSpace/shaders/imac.glsl

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#if defined(VERTEX)
2+
3+
uniform mat4 Projection;
4+
uniform mat4 View;
5+
uniform mat4 Object;
6+
uniform float Time;
7+
8+
in vec3 VertexPosition;
9+
in vec3 VertexNormal;
10+
in vec2 VertexTexCoord;
11+
12+
out vec2 uv;
13+
out vec3 normal;
14+
out vec3 position;
15+
out vec4 color;
16+
17+
18+
void main(void)
19+
{
20+
uv = VertexTexCoord;
21+
22+
23+
normal = vec3(Object * vec4((VertexNormal+1.0)*0.5, 1.0));
24+
25+
// Rotation
26+
mat3 rotX = mat3(
27+
vec3(1, 0, 0),
28+
vec3(0, cos(Time), -sin(Time)),
29+
vec3(0, sin(Time), cos(Time))
30+
);
31+
mat3 rotY = mat3(
32+
vec3(cos(Time), 0, sin(Time)),
33+
vec3(0, 1, 0),
34+
vec3(-sin(Time), 0, cos(Time))
35+
);
36+
37+
// Red : 0
38+
// Blue : 1
39+
// Green : 2
40+
41+
// Scale
42+
if(gl_InstanceID == 1) {
43+
position = vec3(Object * vec4(VertexPosition*2, 1.0));
44+
}
45+
else if(gl_InstanceID == 2) {
46+
position = vec3(Object * vec4(VertexPosition*1.2, 1.0));
47+
}
48+
else {
49+
position = vec3(Object * vec4(VertexPosition, 1.0));
50+
}
51+
52+
// Position
53+
if(gl_InstanceID == 0) {
54+
position.x -= 1;
55+
position.y -= 1;
56+
position.z += 2;
57+
color = vec4(1.f, 0.f, 0.f, 1.f);
58+
}
59+
60+
else if(gl_InstanceID == 2) {
61+
position.x += 1;
62+
position.y += 1;
63+
position.z += 3;
64+
color = vec4(0.f, 1.f, 0.f, 1.f);
65+
}
66+
67+
else {
68+
color = vec4(0.f, 0.f, 1.f, 1.f);
69+
}
70+
71+
// Rotation
72+
position *= rotX;
73+
position *= rotY;
74+
75+
position.z += 2*Time;
76+
77+
gl_Position = Projection * View * vec4(position, 1.0);
78+
79+
}
80+
81+
#endif
82+
83+
#if defined(FRAGMENT)
84+
85+
in vec2 uv;
86+
in vec3 position;
87+
in vec3 normal;
88+
in vec4 color;
89+
90+
uniform sampler2D Diffuse;
91+
uniform sampler2D Spec;
92+
93+
out vec4 Color;
94+
out vec4 Normal;
95+
96+
void main ()
97+
{
98+
99+
vec3 diffuse = texture(Diffuse, uv).rgb;
100+
float spec = texture(Spec, uv).r;
101+
102+
103+
Color = color;//vec4(diffuse, spec);
104+
Normal = vec4(normal, spec);
105+
}
106+
#endif

DiveInSpace/src/Geometry.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const int cube_triangleList[] = {0, 1, 2, 2, 1, 3, 4, 5, 6, 6, 5, 7, 8, 9, 10,
1919
const float cube_uvs[] = {0.f, 0.f, 0.f, 1.f, 1.f, 0.f, 1.f, 1.f, 0.f, 0.f, 0.f, 1.f, 1.f, 0.f, 1.f, 1.f, 0.f, 0.f, 0.f, 1.f, 1.f, 0.f, 1.f, 1.f, 0.f, 0.f, 0.f, 1.f, 1.f, 0.f, 1.f, 1.f, 0.f, 0.f, 0.f, 1.f, 1.f, 0.f, 1.f, 0.f, 1.f, 1.f, 0.f, 1.f, 1.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 1.f, 1.f, 0.f, };
2020
const float cube_vertices[] = {-0.5, -0.5, 0.5, 0.5, -0.5, 0.5, -0.5, 0.5, 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 0.5 };
2121
const float cube_normals[] = {0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, };
22-
22+
2323
//
2424
// Basic Plane => vao[1]
2525
//

DiveInSpace/src/LightManager.h

+24
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,30 @@ struct SpotLight
161161
1.5f, // External angle
162162
0.4f, // Internal angle
163163
1.f); // Intensity
164+
}
165+
166+
void createIMACLights(){
167+
// White light
168+
addDirLight(glm::vec3(0.f, -1.f, 0.f), // Direction
169+
glm::vec3(1.f, 1.f, 1.f), // Color
170+
glm::vec3(0.2f, 0.2f, 0.2f), // Specular
171+
0.5f); // Intensity
172+
173+
// White light
174+
addDirLight(glm::vec3(1.f, 0.f, 0.f),
175+
glm::vec3(1.f, 1.f, 1.f),
176+
glm::vec3(0.2f, 0.2f, 0.2f),
177+
0.5f);
178+
179+
// White light
180+
addDirLight(glm::vec3(0.f, 0.f, -1.f),
181+
glm::vec3(1.f, 1.f, 1.f),
182+
glm::vec3(0.2f, 0.2f, 0.2f),
183+
0.5f);
184+
185+
186+
187+
164188
}
165189

166190
void createTravel1Lights(){

DiveInSpace/src/ShaderManager.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ void ShaderManager::addShader(const char* shaderFile, int typemask, ListShaderTy
5050

5151
break;
5252

53+
case GBUFFER_IMAC:
54+
gbuffer_imac_projectionLocation = glGetUniformLocation(shader.program, "Projection");
55+
gbuffer_imac_viewLocation = glGetUniformLocation(shader.program, "View");
56+
gbuffer_imac_objectLocation = glGetUniformLocation(shader.program, "Object");
57+
gbuffer_imac_timeLocation = glGetUniformLocation(shader.program, "Time");
58+
gbuffer_imac_diffuseLocation = glGetUniformLocation(shader.program, "Diffuse");
59+
gbuffer_imac_specLocation = glGetUniformLocation(shader.program, "Spec");
60+
61+
break;
62+
63+
5364
case GBUFFER_TRAVEL_PLANETE:
5465
gbufferTravelPlanete_projectionLocation = glGetUniformLocation(shader.program, "Projection");
5566
gbufferTravelPlanete_viewLocation = glGetUniformLocation(shader.program, "View");
@@ -216,6 +227,16 @@ void ShaderManager::uploadUniforms(ListShaderType shaderType, glm::vec3 cameraEy
216227

217228
break;
218229

230+
case GBUFFER_IMAC:
231+
glUniformMatrix4fv(gbuffer_imac_projectionLocation, 1, 0, glm::value_ptr(ShaderManager::projection));
232+
glUniformMatrix4fv(gbuffer_imac_viewLocation, 1, 0, glm::value_ptr(worldToView));
233+
glUniformMatrix4fv(gbuffer_imac_objectLocation, 1, 0, glm::value_ptr(objectToWorld));
234+
glUniform1f(gbuffer_imac_timeLocation, t);
235+
glUniform1i(gbuffer_imac_diffuseLocation, 0);
236+
glUniform1i(gbuffer_imac_specLocation, 1);
237+
238+
break;
239+
219240
case GBUFFER_TRAVEL_PLANETE:
220241
glUniformMatrix4fv(gbufferTravelPlanete_projectionLocation, 1, 0, glm::value_ptr(ShaderManager::projection));
221242
glUniformMatrix4fv(gbufferTravelPlanete_viewLocation, 1, 0, glm::value_ptr(worldToView));

DiveInSpace/src/ShaderManager.h

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct ShaderManager
3333
*/
3434
enum ListShaderType{
3535
GBUFFER,
36+
GBUFFER_IMAC,
3637
GBUFFER_TRAVEL_PLANETE,
3738
GBUFFER_TRAVEL_SPIRAL,
3839
GBUFFER_TRAVEL_MONOLITHE,
@@ -156,6 +157,15 @@ struct ShaderManager
156157
GLuint gbuffer_diffuseLocation;
157158
GLuint gbuffer_specLocation;
158159

160+
// Location for gbuffer_imac_shader
161+
GLuint gbuffer_imac_projectionLocation;
162+
GLuint gbuffer_imac_viewLocation;
163+
GLuint gbuffer_imac_objectLocation;
164+
GLuint gbuffer_imac_timeLocation;
165+
GLuint gbuffer_imac_diffuseLocation;
166+
GLuint gbuffer_imac_specLocation;
167+
168+
159169
// Location for gbufferTravelPlanete_shader
160170
GLuint gbufferTravelPlanete_projectionLocation;
161171
GLuint gbufferTravelPlanete_viewLocation;

DiveInSpace/src/TextureManager.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,40 @@ void TextureManager::fillFrameBufferHal(GLuint fbo, GLuint* drawBuffers, int wid
327327
glBindFramebuffer(GL_FRAMEBUFFER, 0);
328328
}
329329

330+
void TextureManager::fillFrameBufferImac(GLuint fbo, GLuint* drawBuffers, int width, int height, ShaderManager& shaderManager, GLuint* bufferTextures, GLuint* vao, glm::vec3 cameraEye, double t){
331+
332+
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
333+
glDrawBuffers(2, drawBuffers);
334+
335+
// Viewport
336+
glViewport(0, 0, width, height );
337+
338+
// Default states
339+
glEnable(GL_DEPTH_TEST);
340+
341+
// Clear the front buffer
342+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
343+
344+
// Bind gbuffer shader
345+
glUseProgram(shaderManager.getShader(ShaderManager::GBUFFER_IMAC).program);
346+
347+
// Upload uniforms
348+
shaderManager.uploadUniforms(ShaderManager::GBUFFER_IMAC, cameraEye, t);
349+
350+
// Bind textures
351+
glActiveTexture(GL_TEXTURE0);
352+
glBindTexture(GL_TEXTURE_2D, bufferTextures[0]);
353+
glActiveTexture(GL_TEXTURE1);
354+
glBindTexture(GL_TEXTURE_2D, bufferTextures[1]);
355+
356+
// Render vaos
357+
glBindVertexArray(vao[0]); // Cube
358+
glDrawElementsInstanced(GL_TRIANGLES, cube_triangleCount * 3, GL_UNSIGNED_INT, (void*)0, 3);
359+
360+
// Unbind framebuffer
361+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
362+
}
363+
330364
void TextureManager::renderMainScreen(ShaderManager& shaderManager, int width, int height, GLuint bufferTexture, GLuint* vao, glm::vec3 cameraEye, double t){
331365

332366
glViewport( 0, 0, width, height);

DiveInSpace/src/TextureManager.h

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct TextureManager
2323
void fillFrameBufferTravel1(GLuint fbo, GLuint* drawBuffers, int width, int height, ShaderManager& shaderManager, GLuint* bufferTextures, GLuint* vao, glm::vec3 cameraEye, double t);
2424
void fillFrameBufferTravel2(GLuint fbo, GLuint* drawBuffers, int width, int height, ShaderManager& shaderManager, GLuint* bufferTextures, GLuint* vao, glm::vec3 cameraEye, double t);
2525
void fillFrameBufferHal(GLuint fbo, GLuint* drawBuffers, int width, int height, ShaderManager& shaderManager, GLuint* bufferTextures, GLuint* vao, glm::vec3 cameraEye, double t);
26+
void fillFrameBufferImac(GLuint fbo, GLuint* drawBuffers, int width, int height, ShaderManager& shaderManager, GLuint* bufferTextures, GLuint* vao, glm::vec3 cameraEye, double t);
2627

2728
void renderMainScreen(ShaderManager& shaderManager, int width, int height, GLuint bufferTexture, GLuint* vao, glm::vec3 cameraEye, double t);
2829
void renderDebugScreens(size_t nbMiniatures, int width, int height, GLuint* bufferTexture, GLuint* vao);

DiveInSpace/src/main.cpp

+37-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
* > 0 => activate the version of the scene (v1, v2...)
3737
*/
3838
#define MODE_HAL 0
39-
#define MODE_TRAVEL 4
39+
#define MODE_IMAC 1
40+
#define MODE_TRAVEL 0
4041

4142
#ifndef DEBUG_PRINT
4243
#define DEBUG_PRINT 1
@@ -122,7 +123,10 @@ int main( int argc, char **argv )
122123
#if MODE_HAL == 1
123124
lightManager.createHalLights();
124125
#endif
125-
126+
#if MODE_IMAC == 1
127+
lightManager.createIMACLights();
128+
#endif
129+
126130
#if MODE_TRAVEL == 1
127131
lightManager.createTravel1Lights();
128132
#endif
@@ -150,10 +154,13 @@ int main( int argc, char **argv )
150154
/* ------------------------------------------ Shaders ------------------------------------------ */
151155
/* --------------------------------------------------------------------------------------------- */
152156
shaderManager.addShader("shaders/gbuffer.glsl", Shader::VERTEX_SHADER | Shader::FRAGMENT_SHADER, ShaderManager::GBUFFER);
157+
shaderManager.addShader("shaders/imac.glsl", Shader::VERTEX_SHADER | Shader::FRAGMENT_SHADER, ShaderManager::GBUFFER_IMAC);
153158
shaderManager.addShader("shaders/gbufferTravelPlanete.glsl", Shader::VERTEX_SHADER | Shader::FRAGMENT_SHADER, ShaderManager::GBUFFER_TRAVEL_PLANETE);
154159
shaderManager.addShader("shaders/gbufferTravelSpiral.glsl", Shader::VERTEX_SHADER | Shader::FRAGMENT_SHADER, ShaderManager::GBUFFER_TRAVEL_SPIRAL);
155160
shaderManager.addShader("shaders/gbufferTravelMonolithe.glsl", Shader::VERTEX_SHADER | Shader::FRAGMENT_SHADER, ShaderManager::GBUFFER_TRAVEL_MONOLITHE);
156161
shaderManager.addShader("shaders/blit.glsl", Shader::VERTEX_SHADER | Shader::FRAGMENT_SHADER, ShaderManager::BLIT);
162+
163+
157164
//Light
158165
shaderManager.addShader("shaders/dirLight.glsl", Shader::VERTEX_SHADER | Shader::FRAGMENT_SHADER, ShaderManager::DIR_LIGHT);
159166
shaderManager.addShader("shaders/pointLight.glsl", Shader::VERTEX_SHADER | Shader::FRAGMENT_SHADER, ShaderManager::POINT_LIGHT);
@@ -473,6 +480,10 @@ int main( int argc, char **argv )
473480
textureManager.fillFrameBufferHal(gbufferFbo, gbufferDrawBuffers, width, height, shaderManager, textures, vao, camera.m_eye, t);
474481
#endif
475482

483+
#if MODE_IMAC == 1
484+
textureManager.fillFrameBufferImac(gbufferFbo, gbufferDrawBuffers, width, height, shaderManager, textures, vao, camera.m_eye, t);
485+
#endif
486+
476487
#if MODE_TRAVEL == 1
477488
textureManager.fillFrameBufferTravel1(gbufferFbo, gbufferDrawBuffers, width, height, shaderManager, textures, vao, camera.m_eye, t);
478489
#endif
@@ -497,6 +508,25 @@ int main( int argc, char **argv )
497508
lightManager.updateHalLights(t);
498509
#endif
499510

511+
// #if MODE_IMAC == 1
512+
// // LIGHTS
513+
// shaderManager.renderLighting(shaderManager, lightManager, width, height, gbufferTextures, fxBufferTextures[0], vao, camera.m_eye, t);
514+
// shaderManager.renderLighting(shaderManager, lightManager, width, height, gbufferTextures, fxBufferTextures[4], vao, camera.m_eye, t);
515+
// // COC
516+
// shaderManager.computeCoc(width, height, gbufferTextures[2], fxBufferTextures[2], vao, camera.m_eye, t);
517+
// // SOBEL
518+
// shaderManager.renderTextureWithShader(ShaderManager::SOBEL, width, height, fxBufferTextures, vao, 1, 0, camera.m_eye, t);
519+
// shaderManager.renderTextureWithShader(ShaderManager::SOBEL, width, height, fxBufferTextures, vao, 4, 0, camera.m_eye, t);
520+
// // BLUR
521+
// shaderManager.renderTextureWithShader(ShaderManager::BLUR, width, height, fxBufferTextures, vao, 3, 1, camera.m_eye, t);
522+
// // DOF
523+
// shaderManager.renderTextureWithShader(ShaderManager::DOF, width, height, fxBufferTextures, vao, 0, 1, camera.m_eye, t);
524+
// // GLOW
525+
// shaderManager.renderTextureWithShader(ShaderManager::GLOW, width, height, fxBufferTextures, vao, 1, 0, camera.m_eye, t);
526+
// // GAMMA
527+
// shaderManager.renderTextureWithShader(ShaderManager::GAMMA, width, height, fxBufferTextures, vao, 0, 1, camera.m_eye, t);
528+
// #endif
529+
500530
#if MODE_TRAVEL == 1
501531
lightManager.updateTravel1Lights(t);
502532
#endif
@@ -506,7 +536,7 @@ int main( int argc, char **argv )
506536
shaderManager.updateTravel2Elements(t);
507537
#endif
508538

509-
#if MODE_HAL == 1 || MODE_TRAVEL == 1 || MODE_TRAVEL == 2
539+
#if MODE_HAL == 1 || MODE_TRAVEL == 1 || MODE_TRAVEL == 2 || MODE_IMAC == 1
510540
// LIGHTS
511541
shaderManager.renderLighting(shaderManager, lightManager, width, height, gbufferTextures, fxBufferTextures[0], vao, camera.m_eye, t);
512542
shaderManager.renderLighting(shaderManager, lightManager, width, height, gbufferTextures, fxBufferTextures[4], vao, camera.m_eye, t);
@@ -536,7 +566,7 @@ int main( int argc, char **argv )
536566
shaderManager.renderTextureWithShader(ShaderManager::STAR, width, height, fxBufferTextures, vao, 1, 0, camera.m_eye, t);
537567
#endif
538568

539-
//
569+
//²²
540570
// Unbind framebuffer : now that we render all the textures, we can debind the fxBuffer
541571
//
542572
glBindFramebuffer(GL_FRAMEBUFFER, 0);
@@ -548,6 +578,9 @@ int main( int argc, char **argv )
548578
#if MODE_TRAVEL == 3 || MODE_TRAVEL == 4
549579
textureManager.renderMainScreen(shaderManager, width, height, fxBufferTextures[1], vao, camera.m_eye, t);
550580
#endif
581+
#if MODE_IMAC == 1
582+
textureManager.renderMainScreen(shaderManager, width, height, fxBufferTextures[0], vao, camera.m_eye, t);
583+
#endif
551584
// Display debug (pas à la noix non non non !)
552585
//textureManager.renderDebugScreens(3, width, height, gbufferTextures, vao);
553586
#if 1

0 commit comments

Comments
 (0)