From fe5a3b254121022867e7cf8fe16704731113f8d6 Mon Sep 17 00:00:00 2001 From: Hurlu Date: Fri, 7 Jun 2019 11:16:16 +0900 Subject: [PATCH] mobility commit --- BaseGLProject/DSGeometryPass.frag | 26 ++++++++++---------------- BaseGLProject/DSGeometryPass.vert | 4 ++-- BaseGLProject/Models/Mesh.cpp | 14 ++++++++++---- BaseGLProject/MyGLWindow.cpp | 28 ++++++++++++++-------------- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/BaseGLProject/DSGeometryPass.frag b/BaseGLProject/DSGeometryPass.frag index c0c1918..5506a6c 100644 --- a/BaseGLProject/DSGeometryPass.frag +++ b/BaseGLProject/DSGeometryPass.frag @@ -1,29 +1,23 @@ #version 440 -//layout (location = 0) out vec3 gPosition; -//layout (location = 1) out vec3 gNormal; -//layout (location = 2) out vec4 gAlbedoSpec; +layout (location = 0) out vec3 gPosition; +layout (location = 1) out vec3 gNormal; +layout (location = 2) out vec4 gAlbedoSpec; in vec2 TexCoords; in vec3 FragPos; in vec3 Normal; -in vec3 RawColor; - -out vec3 FragColor; uniform sampler2D tex; void main() { - //gPosition = FragPos; + gPosition = FragPos; //gPosition = normalize(abs(FragPos)); -// gPosition = vec3(1,1,1); -// -// gNormal = normalize(Normal); -// -// gAlbedoSpec.rgb = vec3(1,0,1); -// gAlbedoSpec.a = 1; - //gAlbedoSpec.rgb = texture(tex, TexCoords).rgb; - //gAlbedoSpec.a = texture(texture_specular1, TexCoords).r; + //gPosition = vec3(1,1,1); + + gNormal = normalize(Normal); + + gAlbedoSpec.rgb = texture(tex, TexCoords).rgb; + gAlbedoSpec.a = 1; - FragColor = RawColor; } diff --git a/BaseGLProject/DSGeometryPass.vert b/BaseGLProject/DSGeometryPass.vert index 9734170..bacc130 100644 --- a/BaseGLProject/DSGeometryPass.vert +++ b/BaseGLProject/DSGeometryPass.vert @@ -7,7 +7,6 @@ layout(location=3) in vec2 v_texmap; out vec2 TexCoords; out vec3 FragPos; -out vec3 RawColor; out vec3 Normal; uniform mat4 mvp; @@ -20,5 +19,6 @@ void main(void) TexCoords = v_texmap; gl_Position = mvp * vec4(coord3d, 1.0f); FragPos = (ModelMatrix * vec4(coord3d, 1.0f)).xyz; - //FragPos = gl_Position.xyz; + //FragPos = coord3.xyz; + //FragPos = gl_Position.xyz; } \ No newline at end of file diff --git a/BaseGLProject/Models/Mesh.cpp b/BaseGLProject/Models/Mesh.cpp index a7a5b51..985f13f 100644 --- a/BaseGLProject/Models/Mesh.cpp +++ b/BaseGLProject/Models/Mesh.cpp @@ -343,7 +343,7 @@ void Mesh::draw(SceneContext &ctx) { MeshEntry * m = meshEntries[i]; - // Moving the object to his set position + // Moving the object to his set position model.glPushMatrix(); effectTransformations(); @@ -355,10 +355,16 @@ void Mesh::draw(SceneContext &ctx) { ctx.normalMatrix = glm::mat3(glm::transpose(glm::inverse(ctx.modelViewMatrix))); shader.addUniform("mvp", ctx.mvpMatrix); - shader.addUniform("NormalMatrix", ctx.normalMatrix); - shader.addUniform("ModelMatrix", ctx.modelMatrix); + //shader.addUniform("NormalMatrix", ctx.normalMatrix); + //shader.addUniform("ModelMatrix", ctx.modelMatrix); + + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, textures["0"].tex_ref); + meshEntries.at(i)->render(ctx, shader); + glBindTexture(GL_TEXTURE_2D, 0); + - meshEntries.at(i)->render(ctx, shader); model.glPopMatrix(); } shader.disable(); diff --git a/BaseGLProject/MyGLWindow.cpp b/BaseGLProject/MyGLWindow.cpp index 035b8de..a81095e 100644 --- a/BaseGLProject/MyGLWindow.cpp +++ b/BaseGLProject/MyGLWindow.cpp @@ -140,29 +140,29 @@ void MyGlWindow::setup() std::srand(18); int zob = std::rand(); - for (int i = 0; i < 1; i++) + for (int i = 0; i < 100; i++) { std::string cube_name = "Cube" + std::to_string(i); - meshes.emplace(cube_name, new Mesh(moddata, "DSGeometryPass.vert", "DSGeometryPass.frag")); - - /*meshes[cube_name]->textures["cube_tex"] = Texture("./Models/cube/color_map.png"); + meshes.emplace(cube_name, new Mesh(moddata, "DSGeometryPass.vert", "DSGeometryPass.frag")); + meshes[cube_name]->textures["0"] = _scnctx.textures["BrickTex"]; + - float pos_x = std::rand() % 100 + 50; - float pos_z = std::rand() % 100 + 50; + float pos_x = std::rand() % 100 - 50; + float pos_z = std::rand() % 100 - 50; - meshes[cube_name]->addStartTranslation(glm::vec4(0, 1, 0, 0)); + /*meshes[cube_name]->addStartTranslation(glm::vec4(0, 1, 0, 0)); meshes[cube_name]->addStartTranslation(glm::vec4(pos_x, 0, 0, 0)); meshes[cube_name]->addStartTranslation(glm::vec4(0, 0, pos_z, 0)); meshes[cube_name]->addStartRotation(glm::vec4(1, 0, 0, std::rand() % 360)); meshes[cube_name]->addStartRotation(glm::vec4(0, 1, 0, std::rand() % 360)); meshes[cube_name]->addStartRotation(glm::vec4(0, 0, 1, std::rand() % 360));*/ - //float light_r = (40 + std::rand() % 60) / 100.f; - //float light_g = (40 + std::rand() % 60) / 100.f; - //float light_b = (40 + std::rand() % 60) / 100.f; + float light_r = (40 + std::rand() % 60) / 100.f; + float light_g = (40 + std::rand() % 60) / 100.f; + float light_b = (40 + std::rand() % 60) / 100.f; - //_scnctx.lights.emplace("RandLight" + i, - // Light(glm::vec3(light_r, light_g, light_b), glm::vec4(pos_x, 2, pos_z, 1))); + _scnctx.lights.emplace("RandLight" + i, + Light(glm::vec3(light_r, light_g, light_b), glm::vec4(pos_x, 2, pos_z, 1))); } } @@ -184,12 +184,12 @@ void MyGlWindow::draw() glViewport(0, 0, _scnctx.width, _scnctx.height); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - //_multipassManager.enableFrameBufferTexture("position_buffer"); + _multipassManager.enableFrameBufferTexture("position_buffer"); for (auto it = meshes.begin(); it != meshes.end(); it++) (*it).second->draw(_scnctx); - //_multipassManager.drawResultToScreen(_scnctx); + _multipassManager.drawResultToScreen(_scnctx); } void MyGlWindow::resize(int w, int h)