From 93271a1113dde1bc988d5c63a48e79af4b1e3be0 Mon Sep 17 00:00:00 2001 From: Hurlu Date: Tue, 18 Jun 2019 11:47:39 +0900 Subject: [PATCH] Added teapot Scene --- BaseGLProject/BaseGLProject.vcxproj | 1 + BaseGLProject/BaseGLProject.vcxproj.filters | 3 + BaseGLProject/Dataset.cpp | 6 ++ BaseGLProject/MyGLWindow.cpp | 60 ++++++++++++++++++-- BaseGLProject/MyGLWindow.h | 3 +- BaseGLProject/Source.cpp | 44 +++++++------- BaseGLProject/default.jpg | Bin 266 -> 3129 bytes BaseGLProject/imgui.ini | 2 +- 8 files changed, 94 insertions(+), 25 deletions(-) diff --git a/BaseGLProject/BaseGLProject.vcxproj b/BaseGLProject/BaseGLProject.vcxproj index 281918c..05df6d9 100644 --- a/BaseGLProject/BaseGLProject.vcxproj +++ b/BaseGLProject/BaseGLProject.vcxproj @@ -229,6 +229,7 @@ + diff --git a/BaseGLProject/BaseGLProject.vcxproj.filters b/BaseGLProject/BaseGLProject.vcxproj.filters index e846013..4c3345f 100644 --- a/BaseGLProject/BaseGLProject.vcxproj.filters +++ b/BaseGLProject/BaseGLProject.vcxproj.filters @@ -226,5 +226,8 @@ Resource Files + + Resource Files + \ No newline at end of file diff --git a/BaseGLProject/Dataset.cpp b/BaseGLProject/Dataset.cpp index 226e27d..4aa6782 100644 --- a/BaseGLProject/Dataset.cpp +++ b/BaseGLProject/Dataset.cpp @@ -107,6 +107,12 @@ void Dataset::simpleFloor() colors = { { 0.7, 0.7, 0.7 },{ 0.7, 0.7, 0.7 },{ 0.7, 0.7, 0.7 }, { 0.7, 0.7, 0.7 },{ 0.7, 0.7, 0.7 },{ 0.7, 0.7, 0.7 } }; + + tex_mapping = { + { 0.0f, 0.0f },{ 1.0f, 0.0f },{ 1.0f, 1.0f }, // one triangle + { 1.0f, 1.0f },{ 0.0f, 1.0f },{ 0.0f, 0.0f } //the other triangle + }; + genNormals(); } diff --git a/BaseGLProject/MyGLWindow.cpp b/BaseGLProject/MyGLWindow.cpp index 042016c..bc5d1f6 100644 --- a/BaseGLProject/MyGLWindow.cpp +++ b/BaseGLProject/MyGLWindow.cpp @@ -104,8 +104,7 @@ void MyGlWindow::loadScene(SceneChoice scene) meshes.emplace_back(std::make_shared(moddata, "DSGeometryPass.vert", "DSGeometryPass.frag")); meshes[meshes.size() - 1]->textures["0"] = scnctx.textures["BrickTex"]; - meshes[meshes.size() - 1]->addStartRotation(glm::vec4(1, -1, 1, 90)); - meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(0, 1, 0, 0)); + meshes[meshes.size() - 1]->addStartRotation(glm::vec4(1, 0, 0, 90)); meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(pos_x, 0, 0, 0)); meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(0, 0, pos_z, 0)); pos_x += 2; @@ -125,7 +124,59 @@ void MyGlWindow::loadScene(SceneChoice scene) scnctx.lights.emplace_back(glm::vec3(light_r, light_g, light_b), glm::vec4(std::rand() % 40 - 20, std::rand() % 3 + 3, std::rand() % 40 - 20, 1)); } + break; + case TEAPOTS: + moddata.simpleFloor(); + meshes.emplace_back(std::make_shared(moddata, "DSGeometryPass.vert", "DSGeometryPass.frag")); + meshes[meshes.size() - 1]->textures["0"] = scnctx.textures["BrickTex"]; + meshes[meshes.size() - 1]->addStartScaling(glm::vec4(3, 1, 3, 0)); + meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(0, -1, 0, 0)); + moddata.simpleCube(); + meshes.emplace_back(std::make_shared(moddata, "DSGeometryPass.vert", "DSGeometryPass.frag")); + meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(-30, 0, 0, 0)); + meshes[meshes.size() - 1]->addStartScaling(glm::vec4(1, 5, 30, 0)); + + meshes.emplace_back(std::make_shared(moddata, "DSGeometryPass.vert", "DSGeometryPass.frag")); + meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(30, 0, 0, 0)); + meshes[meshes.size() - 1]->addStartScaling(glm::vec4(1, 5, 30, 0)); + + meshes.emplace_back(std::make_shared(moddata, "DSGeometryPass.vert", "DSGeometryPass.frag")); + meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(0, 0, 30, 0)); + meshes[meshes.size() - 1]->addStartScaling(glm::vec4(30, 5, 1, 0)); + + meshes.emplace_back(std::make_shared(moddata, "DSGeometryPass.vert", "DSGeometryPass.frag")); + meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(0, 0, -30, 0)); + meshes[meshes.size() - 1]->addStartScaling(glm::vec4(30, 5, 1, 0)); + + pos_x = -30 + 4.5; + pos_z = -30 + 4.5; + + for (int i = 1; i < 141; i++) + { + meshes.emplace_back(std::make_shared("teapot.obj", "DSGeometryPass.vert", "DSGeometryPass.frag")); + + meshes[meshes.size() - 1]->textures["0"] = scnctx.textures["DefaultTex"]; + meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(pos_x, 0, pos_z, 0)); + + pos_x += 5.9; + + if (i % 10 == 0) + { + pos_x = -30 + 4.5; + pos_z += 4; + } + } + + for (int i = 0; i < 64; i++) + { + float light_r = (std::rand() % 20) / 100.f; + float light_g = (std::rand() % 20) / 100.f; + float light_b = (std::rand() % 20) / 100.f; + scnctx.lights.emplace_back(glm::vec3(light_r, light_g, light_b), + glm::vec4(std::rand() % 60 - 30, std::rand() % 100 / 100, std::rand() % 60 - 30, 1)); + } + break; default: break; @@ -143,7 +194,8 @@ void MyGlWindow::textureSetup() scnctx.textures.emplace("BrickTex", Texture("brick1.jpg")); scnctx.textures.emplace("MossTex", Texture("moss.png")); - scnctx.textures.emplace("EarthTex", Texture("earth.jpg")); + scnctx.textures.emplace("EarthTex", Texture("earth.jpg")); + scnctx.textures.emplace("DefaultTex", Texture("default.jpg")); scnctx.textures.emplace("OgreTex", Texture("Models/ogre/ogre_diffuse.png")); scnctx.textures["OgreTex"].mat.shininess = 3.0f; scnctx.textures["OgreTex"].mat.ks = glm::vec3(0.1f, 0.1f, 0.1f); @@ -187,7 +239,7 @@ void MyGlWindow::setup() textureSetup(); multipassSetup(); - loadScene(MOUNTAIN); + loadScene(TEAPOTS); } void MyGlWindow::drawDeferredLight() diff --git a/BaseGLProject/MyGLWindow.h b/BaseGLProject/MyGLWindow.h index 5e349c1..4b16b1f 100644 --- a/BaseGLProject/MyGLWindow.h +++ b/BaseGLProject/MyGLWindow.h @@ -16,7 +16,8 @@ enum SceneChoice { MOUNTAIN, - CUBES + CUBES, + TEAPOTS }; struct vertexAttr { diff --git a/BaseGLProject/Source.cpp b/BaseGLProject/Source.cpp index e19a9a5..628063f 100644 --- a/BaseGLProject/Source.cpp +++ b/BaseGLProject/Source.cpp @@ -282,12 +282,15 @@ int loop(GLFWwindow *window) } if (ImGui::BeginCombo("Scene Choice", - (glWin.scene == MOUNTAIN) ? "Mountain" : "Cubes")) + (glWin.scene == MOUNTAIN) ? "Mountain" : + (glWin.scene == CUBES) ? "Cubes" : "Teapots")) { if (ImGui::Selectable("Mountain", &is_selected, 0, ImVec2(100, 10))) glWin.loadScene(SceneChoice::MOUNTAIN); if (ImGui::Selectable("Cubes", &is_selected, 0, ImVec2(100, 10))) glWin.loadScene(SceneChoice::CUBES); + if (ImGui::Selectable("Teapots", &is_selected, 0, ImVec2(100, 10))) + glWin.loadScene(SceneChoice::TEAPOTS); ImGui::EndCombo(); } @@ -315,26 +318,29 @@ int loop(GLFWwindow *window) strings[i] = lights_strs[i].c_str(); ImGui::ListBox("Lights", ¤t_light, strings, lights_strs.size()); - if (ImGui::SliderFloat("Selected light X", &glWin.scnctx.lights[current_light].location.x, -10, 10) - && glWin.scnctx.renderMode == DEFERRED_LIGHT) - glWin.multipassManager.recomputeDeferredLights(glWin.scnctx); - if (ImGui::SliderFloat("Selected light Y", &glWin.scnctx.lights[current_light].location.y, -10, 10) - && glWin.scnctx.renderMode == DEFERRED_LIGHT) - glWin.multipassManager.recomputeDeferredLights(glWin.scnctx); - if (ImGui::SliderFloat("Selected light Z", &glWin.scnctx.lights[current_light].location.z, -10, 10) - && glWin.scnctx.renderMode == DEFERRED_LIGHT) - glWin.multipassManager.recomputeDeferredLights(glWin.scnctx); + if (glWin.scnctx.lights.size() > 0) + { + if (ImGui::SliderFloat("Selected light X", &glWin.scnctx.lights[current_light].location.x, -10, 10) + && glWin.scnctx.renderMode == DEFERRED_LIGHT) + glWin.multipassManager.recomputeDeferredLights(glWin.scnctx); + if (ImGui::SliderFloat("Selected light Y", &glWin.scnctx.lights[current_light].location.y, -10, 10) + && glWin.scnctx.renderMode == DEFERRED_LIGHT) + glWin.multipassManager.recomputeDeferredLights(glWin.scnctx); + if (ImGui::SliderFloat("Selected light Z", &glWin.scnctx.lights[current_light].location.z, -10, 10) + && glWin.scnctx.renderMode == DEFERRED_LIGHT) + glWin.multipassManager.recomputeDeferredLights(glWin.scnctx); - if (ImGui::SliderFloat("Selected light R", &glWin.scnctx.lights[current_light].intensity.x, 0, 1) - && glWin.scnctx.renderMode == DEFERRED_LIGHT) - glWin.multipassManager.recomputeDeferredLights(glWin.scnctx); - if (ImGui::SliderFloat("Selected light G", &glWin.scnctx.lights[current_light].intensity.y, 0, 1) - && glWin.scnctx.renderMode == DEFERRED_LIGHT) - glWin.multipassManager.recomputeDeferredLights(glWin.scnctx); - if (ImGui::SliderFloat("Selected light B", &glWin.scnctx.lights[current_light].intensity.z, 0, 1) - && glWin.scnctx.renderMode == DEFERRED_LIGHT) - glWin.multipassManager.recomputeDeferredLights(glWin.scnctx); + if (ImGui::SliderFloat("Selected light R", &glWin.scnctx.lights[current_light].intensity.x, 0, 1) + && glWin.scnctx.renderMode == DEFERRED_LIGHT) + glWin.multipassManager.recomputeDeferredLights(glWin.scnctx); + if (ImGui::SliderFloat("Selected light G", &glWin.scnctx.lights[current_light].intensity.y, 0, 1) + && glWin.scnctx.renderMode == DEFERRED_LIGHT) + glWin.multipassManager.recomputeDeferredLights(glWin.scnctx); + if (ImGui::SliderFloat("Selected light B", &glWin.scnctx.lights[current_light].intensity.z, 0, 1) + && glWin.scnctx.renderMode == DEFERRED_LIGHT) + glWin.multipassManager.recomputeDeferredLights(glWin.scnctx); + } ImGui::Checkbox("Orbit Lights", &orbiting_lights); ImGui::SliderFloat("Orbit degrees / second", &light_speed, 0, 360); } diff --git a/BaseGLProject/default.jpg b/BaseGLProject/default.jpg index de7f284820fb20116560c9bbc71facff63e8339f..a7abae101bbb2651920c6e0aef6514cfaf455539 100644 GIT binary patch literal 3129 zcmeHJYj6`)6h8ajB%3ymO$jmBq)ln*l$xZmv>ly5LR-_JLrIGQI-_~?SFI{ty*Ve*xC#jE;yxi;iQ94|M#&L+Wdo_1sO{M6gBtYftv(e!2IY zd+v93v-eX*lyAV$P#3BLilU(iKcI{W@!E}@Z2+NADTn~TfsNvTLezlmhDjVoTtYGG zID^=O3+S<5hs}#v#=ZmFgV;Wy0nAx_eWnS>vg4csw<3UyaX8 z@=~n2Hu<8mFpW7$zHw~KWPTnopM@=1`=aRdI%m;`p2R52%V3lQ~yjV9UR8fz57rxXOzi1!aYHd&!bTWp0np=gTjyzO~AG zOL>LQOBSIt8jYlrta`oG>$E$)*KNuXFp6YP3{?QMkz$OLG7R~+PmWS8O$C3`49oF? zsL|@s;h+JqQVh*99LKUa`w-3pYvfE$&obV;Dk2nYkiDC>4~m6>14k|4rh5DC>)&|) z1CMNZ^s%jvKk?*_oliae%&y&g_73fP?)ew?zxdM2uf6`p!9$1NeCzFF?+m~D-uoYX z_|a!4KL6t6sgcpsW8-JO{qFl8&i?q*`3o0+xisRRcoCjcmS%PZFC+4zS(af1 z!i%E&32`IKIX%2-*(xEj!Cc_oB+7y9g9nak3M<0rEYaj~ZJx_FR&<_FQ6`*nR?}4-A|k(rx(D9#bm9k z=Vu+!$6He|JSrUMwKUd~>_vPJ;>!Ns9)foxmSY`}IO10jmnCt7h)2kHG>v~IxLw6~ z=p#$u zu-Ty=LeL0J;D9LfK__%UFD%Bs8%I(Q#`(Yu@isNS38SJI)d?|-SPttU0TDGG$UQ(G zv`lSNZ53X1h>`-RkG@uvi>RE0odB1&DaxONigI}f)yY=?N4hid>jwa;F5&pL%$Vz0 zfZQzrhlVp_(Om$Cw*pv4dm_n*nuiD;x(zkih5Z2fwWy{(1<>A^t{cvgdDwRfpapBS z;$wh4djS@<AKD8Gg&`X5ivAPE;JS|P9)lb(+UDFN?J+MX>~e%j>(|U zG3MxWhCGAOEL$uVDR-VVPqvz5i>xXl24h%G!*Lo}uhYxdZOSoJL{JK)425D~N)cJq z{}8Few23GvWb)7YyD5{$v4Jt*!#l7vdsZMJhATswFhs literal 266 zcmeAS@N?(olHy`uVBq!ia0vp^S|H591SGu{#_<3t#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DjSL74G){)!Z!;CxRP$B+p3rxzCTG8i%(KJd;yPyEO8v}uR4 zWcg0~%nLd^CzM?DwdRMjWQ%L6fY?;Wh!D2KKvFp(?|w2GH71HkEY}tWI+elG)z4*} HQ$iB}KGR)D diff --git a/BaseGLProject/imgui.ini b/BaseGLProject/imgui.ini index 640d8fc..533d4f3 100644 --- a/BaseGLProject/imgui.ini +++ b/BaseGLProject/imgui.ini @@ -84,7 +84,7 @@ Size=32,32 Collapsed=0 [Window][Light management] -Pos=11,173 +Pos=-7,119 Size=443,328 Collapsed=0