diff --git a/3DEditor/CMakeLists.txt b/3DEditor/CMakeLists.txt index 4e22009..1a410b4 100644 --- a/3DEditor/CMakeLists.txt +++ b/3DEditor/CMakeLists.txt @@ -19,5 +19,6 @@ file(GLOB APP_SOURCES "./applications/*.cpp") add_executable(3DEditorApp ${APP_SOURCES}) target_link_libraries(3DEditorApp ${PROJECT_NAME}) -file(COPY "rsc" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/") -file(COPY "rsc/Font.ttf" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/") +file(COPY "../RasterRender/rsc" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/") +file(COPY "../Graphics/rsc" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/") +file(COPY "../3DScene/rsc" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/") diff --git a/3DEditor/private/Denoise.cpp b/3DEditor/private/Denoise.cpp index 7c4955a..a20672a 100644 --- a/3DEditor/private/Denoise.cpp +++ b/3DEditor/private/Denoise.cpp @@ -37,4 +37,4 @@ void Editor::denoise() { if (device.getError(errorMessage) != oidn::Error::None) { std::cerr << "Error: " << errorMessage << std::endl; } -} \ No newline at end of file +} diff --git a/3DEditor/private/Editor.cpp b/3DEditor/private/Editor.cpp index 59facdf..9641bf8 100644 --- a/3DEditor/private/Editor.cpp +++ b/3DEditor/private/Editor.cpp @@ -24,7 +24,10 @@ Editor::Editor() { void Editor::renderViewport() { switch (mRenderType) { case RenderType::RASTER: - mRasterRenderer.render(mScene, mScene.mRenderSettings.size); + mRasterRenderer.beginRender(mScene, mScene.mRenderSettings.size); + mRasterRenderer.renderDefault(mScene); + if (mActive) mRasterRenderer.renderOutline(mScene.mCamera, *mActive); + mRasterRenderer.endRender(); break; case RenderType::PATH_TRACER: @@ -54,6 +57,7 @@ uint4 Editor::getViewportTexID() { void Editor::loadDefaults() { mScene.load("rsc/scene/script.lua"); + mResetCamera = mScene.mCamera; } void Editor::setViewportSize(const Vec2F& size) { @@ -73,6 +77,7 @@ Editor::~Editor() { } void Editor::renderPathFrame() { + mScene.updateCache(); mPathRenderer.render(mScene, mPathTracerBuffers, mScene.mRenderSettings); sendBuffersToGPU(); } @@ -116,5 +121,20 @@ void Editor::navigationZoom(halnf factor) { } void Editor::navigationReset() { - mScene.mCamera.lookAtPoint({ 0, 0, 0 }, { 1, 5, 1 }, { 0, 0, 1 }); -} \ No newline at end of file + mScene.mCamera = mResetCamera; + // mScene.mCamera.lookAtPoint({ 0, 0, 0 }, { 1, 5, 1 }, { 0, 0, 1 }); +} + +void Editor::selectObject(const Vec2F& screenPos) { + mScene.updateCache(); + + auto dir = (mScene.mCamera.project(screenPos) - mScene.mCamera.getPos()).normalize(); + Ray ray = Ray( dir, mScene.mCamera.getPos() ); + + auto rayCastData = mScene.castRay(ray, 1000); + mActive = rayCastData.obj; +} + +Object* Editor::getActiveObject() { return mActive; } + +Scene* Editor::getScene() { return &mScene; } \ No newline at end of file diff --git a/3DEditor/public/Editor.hpp b/3DEditor/public/Editor.hpp index ee16122..a4c3b0f 100644 --- a/3DEditor/public/Editor.hpp +++ b/3DEditor/public/Editor.hpp @@ -28,6 +28,10 @@ namespace tp { void navigationZoom(halnf factor); void navigationReset(); + void selectObject(const Vec2F& screenPos); + Object* getActiveObject(); + + Scene* getScene(); private: void sendBuffersToGPU(); @@ -36,6 +40,8 @@ namespace tp { private: Scene mScene; + Camera mResetCamera; + RenderType mRenderType = RenderType::RASTER; RasterRender mRasterRenderer; @@ -43,5 +49,7 @@ namespace tp { RayTracer::OutputBuffers mPathTracerBuffers; uint4 mPathRenderTexture = 0; + + Object* mActive = nullptr; }; } \ No newline at end of file diff --git a/3DEditor/public/EditorWidget.hpp b/3DEditor/public/EditorWidget.hpp index 0914937..7b4e748 100644 --- a/3DEditor/public/EditorWidget.hpp +++ b/3DEditor/public/EditorWidget.hpp @@ -66,11 +66,13 @@ namespace tp { mNavigationOrbit.setText("Orbit"); mNavigationZoom.setText("Zoom"); mNavigationReset.setText("Reset"); + mNavigationSelect.setText("Select"); mNavigationMenu.addToMenu(&mNavigationPan); mNavigationMenu.addToMenu(&mNavigationOrbit); mNavigationMenu.addToMenu(&mNavigationZoom); mNavigationMenu.addToMenu(&mNavigationReset); + mNavigationMenu.addToMenu(&mNavigationSelect); mNavigationMenu.setText("Navigation"); } @@ -85,30 +87,39 @@ namespace tp { mNavigationOrbit.setAction( [this]() { mNavigationType = ORBIT; }); mNavigationPan.setAction( [this]() { mNavigationType = PAN; }); mNavigationZoom.setAction( [this](){ mNavigationType = ZOOM; }); + mNavigationSelect.setAction( [this](){ mNavigationType = SELECT; }); mNavigationReset.setAction( [this]() { mEditor->navigationReset(); }); } void process(const EventHandler& events) override { DockWidget::process(events); - auto pointer = events.getPointer(); - auto pointerPrev = events.getPointerPrev(); + if (auto obj = mEditor->getActiveObject()) { // dummy rotate active object + auto rotator = obj->mTopology.Basis.rotatorDir({1, 1, 1}, 0.1); + obj->mTopology.Basis = rotator * obj->mTopology.Basis; + } + + mEditor->getScene()->updateCache(); const auto& activeArea = mViewport.getArea(); + auto pointer = events.getPointer(); + auto pointerPrev = events.getPointerPrev(); + auto pointerRelative = (((pointer - activeArea.pos) / activeArea.size) - 0.5f) * 2; + if (activeArea.isInside(pointer) && events.isDown(InputID::MOUSE1)) { switch (mNavigationType) { case ORBIT: mEditor->navigationOrbit(events.getPointerDelta() / activeArea.size * 3); break; case PAN: { - auto pointerRelative = (((pointer - activeArea.pos) / activeArea.size) - 0.5f) * 2; auto prevPointerRelative = (((pointerPrev - activeArea.pos) / activeArea.size) - 0.5f) * 2; mEditor->navigationPan(prevPointerRelative, pointerRelative); } break; case ZOOM: mEditor->navigationZoom(1 + (events.getPointerDelta().y / activeArea.size.y)); break; + case SELECT: mEditor->selectObject(pointerRelative * -1); break; } } } @@ -129,13 +140,14 @@ namespace tp { ButtonWidget mRenderDeNoise; // Navigation - enum NavigationType { ORBIT, PAN, ZOOM } mNavigationType = ORBIT; + enum NavigationType { SELECT, ORBIT, PAN, ZOOM } mNavigationType = ORBIT; FloatingMenu mNavigationMenu; ButtonWidget mNavigationPan; ButtonWidget mNavigationOrbit; ButtonWidget mNavigationZoom; ButtonWidget mNavigationReset; + ButtonWidget mNavigationSelect; RGBA mBaseColor; }; diff --git a/3DScene/private/LuaFormat.cpp b/3DScene/private/LuaFormat.cpp index 3d61aad..acf4c9a 100644 --- a/3DScene/private/LuaFormat.cpp +++ b/3DScene/private/LuaFormat.cpp @@ -7,6 +7,61 @@ extern "C" { } #include +#include + +tp::Vec3F tp::Scene::getVec3(lua_State* state, const char* name) { + int stackSize = lua_gettop(state); + + // Access the "pos" field and validate it + lua_getfield(state, -1, name); + if (!lua_istable(state, -1) || lua_rawlen(state, -1) != 3) { + throw IOError(std::string("Invalid vec3 named ") + name); + } + + // Read the values from the table + float pos[3]; + for (int i = 0; i < 3; i++) { + lua_rawgeti(state, -1, i + 1); + if (lua_isnumber(state, -1)) { + pos[i] = lua_tonumber(state, -1); + } else { + throw IOError("vec3 values must be numbers"); + } + lua_pop(state, 1); // pop number + } + lua_pop(state, 1); // pop vec3 + + ASSERT(stackSize == lua_gettop(state)) + + return { pos[0], pos[1], pos[2] }; +} + +tp::Vec2F tp::Scene::getVec2(lua_State* state, const char* name) { + int stackSize = lua_gettop(state); + + // Access the "pos" field and validate it + lua_getfield(state, -1, name); + if (!lua_istable(state, -1) || lua_rawlen(state, -1) != 2) { + throw IOError(std::string("Invalid vec2 named ") + name); + } + + // Read the values from the table + float pos[2]; + for (int i = 0; i < 2; i++) { + lua_rawgeti(state, -1, i + 1); + if (lua_isnumber(state, -1)) { + pos[i] = lua_tonumber(state, -1); + } else { + throw IOError("vec3 values must be numbers"); + } + lua_pop(state, 1); // pop number + } + lua_pop(state, 1); // pop vec3 + + ASSERT(stackSize == lua_gettop(state)) + + return { pos[0], pos[1] }; +} // Function to read a Lua table representing RenderSettings int readRenderSettings(lua_State* L, tp::RenderSettings& settings) { @@ -53,23 +108,8 @@ int readRenderSettings(lua_State* L, tp::RenderSettings& settings) { } // Function to read a Lua table representing a light -int readLight(lua_State* L, tp::PointLight* light) { - lua_getfield(L, -1, "pos"); // Get the "pos" field from the light table - if (!lua_istable(L, -1)) { - printf("Light is missing the 'pos' table.\n"); - return 0; // Error - } - for (int i = 0; i < 3; i++) { - lua_rawgeti(L, -1, i + 1); // Index is 1-based in Lua - if (!lua_isnumber(L, -1)) { - printf("Light 'pos' field is not a number at index %d.\n", i); - lua_pop(L, 2); // Pop both the number and the 'pos' table - return 0; // Error - } - light->pos[i] = lua_tonumber(L, -1); - lua_pop(L, 1); // Pop the number - } - lua_pop(L, 1); // Pop the 'pos' table +int tp::Scene::readLight(lua_State* L, tp::PointLight* light) { + light->pos = getVec3(L, "pos"); lua_getfield(L, -1, "intensity"); // Get the "intensity" field from the light table if (!lua_isnumber(L, -1)) { @@ -121,66 +161,29 @@ bool tp::Scene::loadLuaFormat(const std::string& scenePath) { } // --- camera - - // Access Camera table - lua_getglobal(L, "Camera"); - if (!lua_istable(L, -1)) { - printf("Camera is not a table.\n"); - lua_close(L); - return false; - } - - // Verify you are inside the "Camera" table - int cameraTableIndex = lua_gettop(L); // Get the index of the "Camera" table - - // Access the "pos" field and validate it - lua_getfield(L, cameraTableIndex, "pos"); - if (!lua_istable(L, -1) || lua_rawlen(L, -1) != 3) { - printf("Invalid 'pos' field in Camera table.\n"); - lua_close(L); - return false; - } - - // Read the values from the table - float pos[3]; - for (int i = 0; i < 3; i++) { - lua_rawgeti(L, -1, i + 1); - if (lua_isnumber(L, -1)) { - pos[i] = lua_tonumber(L, -1); - } else { - printf("Invalid 'pos' field value at index %d.\n", i + 1); + { + lua_getglobal(L, "Camera"); + if (!lua_istable(L, -1)) { + printf("Camera is not a table.\n"); lua_close(L); return false; } + + Vec3F camPos = getVec3(L, "pos"); + Vec3F camTarget = getVec3(L, "target"); + Vec3F camUp = getVec3(L, "up"); + Vec2F camSize = getVec2(L, "size"); + + mRenderSettings.size = camSize; + + mCamera.lookAtPoint(camTarget, camPos, camUp); + mCamera.setFOV(3.14 / 4); + mCamera.setFar(100); + mCamera.setRatio((tp::halnf) camSize.y / (tp::halnf) camSize.x); + lua_pop(L, 1); } - // Access the "size_x" field and validate it - lua_getfield(L, cameraTableIndex, "size_x"); - if (!lua_isnumber(L, -1)) { - printf("Invalid or missing 'size_x' field in Camera table.\n"); - lua_close(L); - return false; - } - int size_x = lua_tointeger(L, -1); - lua_pop(L, 1); // Pop the 'size_x' value from the stack - - // Access the "size_y" field and validate it - lua_getfield(L, cameraTableIndex, "size_y"); - if (!lua_isnumber(L, -1)) { - printf("Invalid or missing 'size_y' field in Camera table.\n"); - lua_close(L); - return false; - } - int size_y = lua_tointeger(L, -1); - - mRenderSettings.size = { (tp::halnf) size_x, (tp::halnf) size_y }; - - mCamera.lookAtPoint({ 0, 0, 0 }, { pos[0], pos[1], pos[2] }, { 0, 0, 1 }); - mCamera.setFOV(3.14 / 4); - mCamera.setFar(100); - mCamera.setRatio((tp::halnf) size_y / (tp::halnf) size_x); - // ---------- LIGHTS { lua_getglobal(L, "Lights"); diff --git a/3DScene/private/OBJFormat.cpp b/3DScene/private/OBJFormat.cpp index 3fcf8ad..b97b87f 100644 --- a/3DScene/private/OBJFormat.cpp +++ b/3DScene/private/OBJFormat.cpp @@ -48,4 +48,39 @@ bool tp::Scene::loadOBJFormat(const std::string& objetsPath) { } return mObjects.size(); +} + +const tp::RayCastData& tp::Scene::castRay(const Ray& ray, alnf farVal) { + auto& out = mRayCastData; + + out.hit = false; + out.obj = nullptr; + + farVal *= farVal; + + for (auto obj : mObjects) { + for (auto trig : obj->mCache.TrigCaches) { + if (trig->castRay(ray)) { + + auto dist = (TrigCache::getHitPos() - ray.pos).length2(); + + if (farVal > dist && dist > EPSILON) { + out.trig = &trig.data(); + out.hitPos = TrigCache::getHitPos(); + out.obj = &obj.data(); + out.hit = true; + + farVal = dist; + } + } + } + } + + return mRayCastData; +} + +void tp::Scene::updateCache() { + for (auto obj : mObjects) { + obj->mCache.updateCache(); + } } \ No newline at end of file diff --git a/3DScene/private/Scene.cpp b/3DScene/private/Scene.cpp index f1927b2..6ef0399 100644 --- a/3DScene/private/Scene.cpp +++ b/3DScene/private/Scene.cpp @@ -2,5 +2,13 @@ #include "Scene.hpp" bool tp::Scene::load(const std::string& scenePath) { - return loadLuaFormat(scenePath); + try { + auto res = loadLuaFormat(scenePath); + if (!res) throw IOError("Failed loading lua script"); + } catch (const IOError& err) { + printf("Failed loading scene : %s\n", err.description.c_str()); + return false; + } + + return true; } \ No newline at end of file diff --git a/3DScene/public/Scene.hpp b/3DScene/public/Scene.hpp index f7aa56f..ac872f5 100644 --- a/3DScene/public/Scene.hpp +++ b/3DScene/public/Scene.hpp @@ -6,6 +6,8 @@ #include +struct lua_State; + namespace tp { struct RenderSettings { uhalni depth = 2; @@ -42,7 +44,22 @@ namespace tp { halnf intensity = 1.f; }; + struct RayCastData { + Object* obj = nullptr; + TrigCache* trig = nullptr; + Vec3F hitPos = { 0, 0, 0 }; + bool hit = false; + bool inv = false; + }; + class Scene { + struct IOError : public std::exception { + explicit IOError(std::string in) : + description(std::move(in)) {} + + std::string description; + }; + public: Scene() = default; @@ -51,11 +68,23 @@ namespace tp { bool loadLuaFormat(const std::string& scenePath); bool loadOBJFormat(const std::string& objectsPath); + const RayCastData& castRay(const Ray& ray, alnf farVal); + + void updateCache(); + + private: + Vec3F getVec3(lua_State* state, const char* name); + Vec2F getVec2(lua_State* state, const char* name); + + int readLight(lua_State* L, tp::PointLight* light); + public: Buffer mObjects; Buffer mLights; Camera mCamera; RenderSettings mRenderSettings; + + RayCastData mRayCastData; }; } diff --git a/3DEditor/rsc/scene/meshes.mtl b/3DScene/rsc/scene/meshes.mtl similarity index 100% rename from 3DEditor/rsc/scene/meshes.mtl rename to 3DScene/rsc/scene/meshes.mtl diff --git a/3DEditor/rsc/scene/meshes.obj b/3DScene/rsc/scene/meshes.obj similarity index 100% rename from 3DEditor/rsc/scene/meshes.obj rename to 3DScene/rsc/scene/meshes.obj diff --git a/3DEditor/rsc/scene/script.lua b/3DScene/rsc/scene/script.lua similarity index 75% rename from 3DEditor/rsc/scene/script.lua rename to 3DScene/rsc/scene/script.lua index ef6d484..42ea4c7 100644 --- a/3DEditor/rsc/scene/script.lua +++ b/3DScene/rsc/scene/script.lua @@ -2,9 +2,10 @@ Meshes = "meshes.obj" Camera = { - pos = { 0.5, 4.5, 0.2 }, - size_x = 600, - size_y = 800, + pos = { 0, 5, 0 }, + target = { 0, 0, 0 }, + up = { 0, 0, 1 }, + size = { 600, 800 }, } Lights = { diff --git a/Graphics/CMakeLists.txt b/Graphics/CMakeLists.txt index 1159d2a..3d4118b 100644 --- a/Graphics/CMakeLists.txt +++ b/Graphics/CMakeLists.txt @@ -19,5 +19,5 @@ target_link_libraries(Example${PROJECT_NAME} ${PROJECT_NAME} ${BINDINGS_LIBS}) target_include_directories(Example${PROJECT_NAME} PRIVATE ${BINDINGS_INCLUDE}) -file(COPY "examples/Font.ttf" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/") +file(COPY "../Graphics/rsc" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/") diff --git a/Graphics/examples/Font.ttf b/Graphics/examples/Font.ttf deleted file mode 100644 index 8a63054..0000000 Binary files a/Graphics/examples/Font.ttf and /dev/null differ diff --git a/Graphics/private/Canvas.cpp b/Graphics/private/Canvas.cpp index c108eff..bc29a17 100644 --- a/Graphics/private/Canvas.cpp +++ b/Graphics/private/Canvas.cpp @@ -27,7 +27,7 @@ Canvas::Canvas(Window* window) { mContext->vg = nvgCreateGL3(NVG_ANTIALIAS | NVG_STENCIL_STROKES); - if (nvgCreateFont(mContext->vg, "default", "Font.ttf") == -1) { + if (nvgCreateFont(mContext->vg, "default", "rsc/Font.ttf") == -1) { ASSERT(!"Cant create NVG font") } } diff --git a/Graphics/private/DebugGUI.cpp b/Graphics/private/DebugGUI.cpp index 03f6b1f..5880db1 100644 --- a/Graphics/private/DebugGUI.cpp +++ b/Graphics/private/DebugGUI.cpp @@ -36,7 +36,7 @@ DebugGUI::DebugGUI(Window* window) { ImGui_ImplOpenGL3_Init("#version 330"); ImGuiIO& io = ImGui::GetIO(); - io.Fonts->AddFontFromFileTTF("Font.ttf", 20.f); + io.Fonts->AddFontFromFileTTF("rsc/Font.ttf", 20.f); io.ConfigInputTrickleEventQueue = false; diff --git a/3DEditor/rsc/Font.ttf b/Graphics/rsc/Font.ttf similarity index 100% rename from 3DEditor/rsc/Font.ttf rename to Graphics/rsc/Font.ttf diff --git a/Math/private/Camera.cpp b/Math/private/Camera.cpp index 017b467..621297e 100644 --- a/Math/private/Camera.cpp +++ b/Math/private/Camera.cpp @@ -88,7 +88,7 @@ void Camera::lookAtPoint(const Vec3F& aTarget, const Vec3F& aPos, Vec3F aUp) { } mPos = aPos; mTarget = aTarget; - Vec3F f = (mPos - mTarget).normalize(); + Vec3F f = (mTarget - mPos).normalize(); mUp = f * (aUp.normalize() * f); } diff --git a/Math/public/Mat.hpp b/Math/public/Mat.hpp index 0c0344a..2483284 100644 --- a/Math/public/Mat.hpp +++ b/Math/public/Mat.hpp @@ -714,7 +714,7 @@ namespace tp { out[0] = { in[0][0], in[0][1], in[0][2], 0 }; out[1] = { in[1][0], in[1][1], in[1][2], 0 }; out[2] = { in[2][0], in[2][1], in[2][2], 0 }; - out[3] = Type(1); + out[3] = { Type(0), Type(0), Type(0), Type(1) }; return out; } } diff --git a/RasterRender/private/Render.cpp b/RasterRender/private/Render.cpp index af05b72..9b6da2c 100644 --- a/RasterRender/private/Render.cpp +++ b/RasterRender/private/Render.cpp @@ -3,20 +3,24 @@ using namespace tp; -RasterRender::RasterRender() : - mRenderBuffer({ 100, 100 }) -{ +RasterRender::RasterRender() { mDefaultShader.load("rsc/shaders/default.vert", nullptr, "rsc/shaders/default.frag", true); mSolidShader.load("rsc/shaders/default.vert", nullptr, "rsc/shaders/solid.frag", true); } RasterRender::~RasterRender() {} +void RasterRender::resize(const Vec2& size) { + auto sizeF = Vec2F(size.x, size.y); + mRenderBuffer.resize(sizeF); + mTempBuffer.resize(sizeF); +} + uint4 RasterRender::getRenderBufferID() { return mRenderBuffer.texId(); } Vec2F RasterRender::getBufferSize() { return mRenderBuffer.getSize(); } -void RasterRender::bindCameraShaderAttributes(Mat4F cameraMat) { +void RasterRender::bindCameraShaderAttributes(const Mat4F& cameraMat) { static auto camera = (GLint) mDefaultShader.getu("Camera"); glUniformMatrix4fv(camera, 1, true, &cameraMat[0][0]); } @@ -28,11 +32,18 @@ void RasterRender::bindObjectShaderAttributes(const Object& object) { Mat4F basisMat = toMat4(object.mTopology.Basis); Vec4F originPoint = toVec4(object.mTopology.Origin); + basisMat = basisMat.transpose(); + glUniform4fv(origin, 1, &originPoint[0]); glUniformMatrix4fv(basis, 1, false, &basisMat[0][0]); } void RasterRender::renderDefault(const Scene& geometry) { + mRenderBuffer.mClearCol = { 0.0f, 0.0f, 0.0f, 0.f }; + + mRenderBuffer.beginDraw(); + mRenderBuffer.clear(); + mDefaultShader.bind(); Mat4F cameraMat = geometry.mCamera.calculateTransformationMatrix(); @@ -55,10 +66,19 @@ void RasterRender::renderDefault(const Scene& geometry) { } mDefaultShader.unbind(); + + glDisable(GL_DEPTH_TEST); + + // glPolygonMode(GL_FRONT, GL_FILL); + // glPolygonMode(GL_BACK, GL_FILL); + + mRenderBuffer.endDraw(); } void RasterRender::renderOutline(const Camera& camera, const Object& object) { - glEnable(GL_STENCIL_TEST); + mRenderBuffer.beginDraw(); + + // glEnable(GL_STENCIL_TEST); mSolidShader.bind(); @@ -69,30 +89,23 @@ void RasterRender::renderOutline(const Camera& camera, const Object& object) { mSolidShader.unbind(); - glDisable(GL_STENCIL_TEST); + // glDisable(GL_STENCIL_TEST); + + mRenderBuffer.endDraw(); } -void RasterRender::render(const Scene& geometry, const Vec2& size) { +void RasterRender::beginRender(const Scene& geometry, const Vec2& size) { + resize(size); for (auto object : geometry.mObjects) { if (!object->mGUPBuffers) { object->mGUPBuffers = new ObjectBuffers(&object.data()); } } +} - mRenderBuffer.mClearCol = { 0.0f, 0.0f, 0.0f, 0.f }; - - mRenderBuffer.beginDraw(); - mRenderBuffer.clear(); - - renderDefault(geometry); - - // if (geometry.mObjects.size()) renderOutline(geometry.mCamera, geometry.mObjects.first()); - - // glPolygonMode(GL_FRONT, GL_FILL); - // glPolygonMode(GL_BACK, GL_FILL); - - mRenderBuffer.endDraw(); +void RasterRender::endRender() { + // pass } RenderBuffer* RasterRender::getRenderBuffer() { return &mRenderBuffer; } diff --git a/RasterRender/public/FrameBuffer.hpp b/RasterRender/public/FrameBuffer.hpp index 09dc82a..8c20aeb 100644 --- a/RasterRender/public/FrameBuffer.hpp +++ b/RasterRender/public/FrameBuffer.hpp @@ -7,7 +7,7 @@ namespace tp { class RenderBuffer { public: - explicit RenderBuffer(const Vec2F& size); + explicit RenderBuffer(const Vec2F& size = { 10, 10 }); RenderBuffer(const Vec2F& size, tp::uint1 samples); ~RenderBuffer(); diff --git a/RasterRender/public/RasterRender.hpp b/RasterRender/public/RasterRender.hpp index 12b4744..4824c93 100644 --- a/RasterRender/public/RasterRender.hpp +++ b/RasterRender/public/RasterRender.hpp @@ -12,20 +12,25 @@ namespace tp { RasterRender(); ~RasterRender(); - void render(const Scene& geometry, const Vec2& size); + void beginRender(const Scene& geometry, const Vec2& size); + void endRender(); + + void renderDefault(const Scene& geometry); + void renderOutline(const Camera& camera, const Object& object); + + void resize(const Vec2& size); + uint4 getRenderBufferID(); RenderBuffer* getRenderBuffer(); Vec2F getBufferSize(); private: - void renderDefault(const Scene& geometry); - void renderOutline(const Camera& camera, const Object& object); - void bindObjectShaderAttributes(const Object& object); - void bindCameraShaderAttributes(Mat4F cameraMat); + void bindCameraShaderAttributes(const Mat4F& cameraMat); private: RenderBuffer mRenderBuffer; + RenderBuffer mTempBuffer; RenderShader mDefaultShader; RenderShader mSolidShader; diff --git a/3DEditor/rsc/shaders/default.frag b/RasterRender/rsc/shaders/default.frag similarity index 100% rename from 3DEditor/rsc/shaders/default.frag rename to RasterRender/rsc/shaders/default.frag diff --git a/3DEditor/rsc/shaders/default.vert b/RasterRender/rsc/shaders/default.vert similarity index 83% rename from 3DEditor/rsc/shaders/default.vert rename to RasterRender/rsc/shaders/default.vert index 6a740e3..1d325ed 100644 --- a/3DEditor/rsc/shaders/default.vert +++ b/RasterRender/rsc/shaders/default.vert @@ -7,6 +7,7 @@ uniform mat4 Basis; uniform mat4 Camera; void main() { + // vec4 transformed = vec4(Point.xyz, 1.0); vec4 transformed = (Basis * vec4(Point.xyz, 1.0)) + Origin; gl_Position = Camera * transformed; } \ No newline at end of file diff --git a/3DEditor/rsc/shaders/solid.frag b/RasterRender/rsc/shaders/solid.frag similarity index 100% rename from 3DEditor/rsc/shaders/solid.frag rename to RasterRender/rsc/shaders/solid.frag diff --git a/RayTracer/private/RayTracer.cpp b/RayTracer/private/RayTracer.cpp index e8355e7..b7b85f0 100644 --- a/RayTracer/private/RayTracer.cpp +++ b/RayTracer/private/RayTracer.cpp @@ -43,6 +43,8 @@ normal = n1 * barycentric.x + n2 * barycentric.y + n3 * barycentric.z; using namespace tp; + +// TODO : de-duplicate in Scene? void RayTracer::castRay(const Ray& ray, RayCastData& out, alnf farVal) { out.hit = false; out.obj = nullptr; diff --git a/RayTracer/public/RayTracer.hpp b/RayTracer/public/RayTracer.hpp index 4067247..a21964a 100644 --- a/RayTracer/public/RayTracer.hpp +++ b/RayTracer/public/RayTracer.hpp @@ -30,14 +30,6 @@ namespace tp { void render(const Scene& scene, OutputBuffers& out, const RenderSettings& settings); private: - struct RayCastData { - const Object* obj = nullptr; - TrigCache* trig = nullptr; - Vec3F hitPos = { 0, 0, 0 }; - bool hit = false; - bool inv = false; - }; - struct LightData { halnf intensity = 0; };