From 6d484fe9d55ef2cf8b5442df0796d23c438ce0ed Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 14 Aug 2024 23:26:05 +0200 Subject: [PATCH] [BGFX] remove --- CMakeLists.txt | 70 +- include/overworld/Graphics/BGFX/API.h | 6 - include/overworld/Graphics/BGFX/Camera.h | 91 --- include/overworld/Graphics/BGFX/Context.h | 63 -- .../overworld/Graphics/BGFX/EmbeddedAssets.h | 57 -- include/overworld/Graphics/BGFX/MeshHandle.h | 15 - include/overworld/Graphics/BGFX/ModelHandle.h | 23 - include/overworld/Graphics/BGFX/Renderer.h | 82 -- include/overworld/Graphics/BGFX/Shader.h | 38 - .../overworld/Graphics/BGFX/ShadowsRenderer.h | 32 - include/overworld/Graphics/BGFX/Vertex.h | 16 - include/overworld/Graphics/Base/Camera.h | 86 --- .../Graphics/Base/CameraProjection.h | 19 - include/overworld/Graphics/Base/CameraView.h | 16 - .../overworld/Graphics/Base/InstanceData.h | 17 - include/overworld/Graphics/Base/Renderer.h | 46 -- .../Graphics/Base/ViewAntiAliasing.h | 25 - include/overworld/Graphics/Base/Window.h | 20 - .../Graphics/Base/WindowPlatformData.h | 13 - include/overworld/Graphics/GLFW3/Context.h | 30 - include/overworld/Graphics/GLFW3/Window.h | 28 - shaders/bgfx_shader.sh | 730 ------------------ shaders/defs/varying.def.sc | 7 - shaders/fs_default.sc | 107 --- shaders/fs_simple_shadows.sc | 5 - shaders/fs_skybox.sc | 10 - shaders/vs_default.sc | 13 - shaders/vs_simple_shadows.sc | 8 - shaders/vs_skybox.sc | 10 - src/Graphics/BGFX/Camera.cpp | 274 ------- src/Graphics/BGFX/Renderer.cpp | 519 ------------- src/Graphics/BGFX/ShadowsRenderer.cpp | 39 - src/Graphics/BGFX/Vertex.cpp | 19 - src/Graphics/Base/Renderer.cpp | 18 - src/Graphics/GLFW3/Window.cpp | 105 --- src/Nodes/Test1.cpp | 74 -- 36 files changed, 8 insertions(+), 2723 deletions(-) delete mode 100755 include/overworld/Graphics/BGFX/API.h delete mode 100755 include/overworld/Graphics/BGFX/Camera.h delete mode 100755 include/overworld/Graphics/BGFX/Context.h delete mode 100755 include/overworld/Graphics/BGFX/EmbeddedAssets.h delete mode 100755 include/overworld/Graphics/BGFX/MeshHandle.h delete mode 100644 include/overworld/Graphics/BGFX/ModelHandle.h delete mode 100755 include/overworld/Graphics/BGFX/Renderer.h delete mode 100644 include/overworld/Graphics/BGFX/Shader.h delete mode 100644 include/overworld/Graphics/BGFX/ShadowsRenderer.h delete mode 100755 include/overworld/Graphics/BGFX/Vertex.h delete mode 100755 include/overworld/Graphics/Base/Camera.h delete mode 100644 include/overworld/Graphics/Base/CameraProjection.h delete mode 100644 include/overworld/Graphics/Base/CameraView.h delete mode 100755 include/overworld/Graphics/Base/InstanceData.h delete mode 100755 include/overworld/Graphics/Base/Renderer.h delete mode 100644 include/overworld/Graphics/Base/ViewAntiAliasing.h delete mode 100755 include/overworld/Graphics/Base/Window.h delete mode 100755 include/overworld/Graphics/Base/WindowPlatformData.h delete mode 100755 include/overworld/Graphics/GLFW3/Context.h delete mode 100755 include/overworld/Graphics/GLFW3/Window.h delete mode 100755 shaders/bgfx_shader.sh delete mode 100755 shaders/defs/varying.def.sc delete mode 100755 shaders/fs_default.sc delete mode 100644 shaders/fs_simple_shadows.sc delete mode 100644 shaders/fs_skybox.sc delete mode 100755 shaders/vs_default.sc delete mode 100644 shaders/vs_simple_shadows.sc delete mode 100644 shaders/vs_skybox.sc delete mode 100755 src/Graphics/BGFX/Camera.cpp delete mode 100755 src/Graphics/BGFX/Renderer.cpp delete mode 100644 src/Graphics/BGFX/ShadowsRenderer.cpp delete mode 100755 src/Graphics/BGFX/Vertex.cpp delete mode 100644 src/Graphics/Base/Renderer.cpp delete mode 100755 src/Graphics/GLFW3/Window.cpp delete mode 100644 src/Nodes/Test1.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ca525e96..d58787dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,16 +110,6 @@ if(OWDS_USE_PHYSX) endif() endif() -# ##################################################################### -# # BGFX to render all of our 3D graphics ## -# ##################################################################### -FetchContent_Declare( - BGFX - GIT_REPOSITORY "https://github.com/bkaradzic/bgfx.cmake.git" - GIT_TAG "c2b7416a58a8610eecba5f6e3940e30c1b64e1f9" -) -FetchContent_MakeAvailable(BGFX) - owds_depend_msg_package(std_msgs) owds_depend_msg_package(sensor_msgs) owds_depend_msg_package(visualization_msgs) @@ -169,49 +159,10 @@ owds_add_ros_library(overworld_engine_common src/Engine/Common/Urdf/Actor.cpp src/Engine/Common/World.cpp) -# ################################## -set(overworld_vert_shaders - shaders/vs_default.sc - shaders/vs_simple_shadows.sc - shaders/vs_skybox.sc) - -set(overworld_frag_shaders - shaders/fs_default.sc - shaders/fs_simple_shadows.sc - shaders/fs_skybox.sc) - -bgfx_compile_shader_to_header( - TYPE VERTEX - SHADERS ${overworld_vert_shaders} - VARYING_DEF ${CMAKE_SOURCE_DIR}/shaders/defs/varying.def.sc - OUTPUT_DIR ${CMAKE_BINARY_DIR}/include/generated/shaders/) - -bgfx_compile_shader_to_header( - TYPE FRAGMENT - SHADERS ${overworld_frag_shaders} - VARYING_DEF ${CMAKE_SOURCE_DIR}/shaders/defs/varying.def.sc - OUTPUT_DIR ${CMAKE_BINARY_DIR}/include/generated/shaders/) - -owds_add_library(overworld_graphics - src/Graphics/Base/Renderer.cpp - src/Engine/Graphics/Assimp/ModelLoader.cpp - src/Graphics/BGFX/Camera.cpp - src/Graphics/BGFX/Renderer.cpp - src/Graphics/BGFX/ShadowsRenderer.cpp - src/Graphics/BGFX/Vertex.cpp - src/Graphics/GLFW3/Window.cpp - ${overworld_vert_shaders} - ${overworld_frag_shaders}) - -target_include_directories(overworld_graphics PUBLIC ${CMAKE_BINARY_DIR}/include/generated/shaders/) -target_link_libraries(overworld_graphics PUBLIC overworld_engine_common assimp bgfx bx glfw) -target_compile_definitions(overworld_graphics PUBLIC GLM_FORCE_RIGHT_HANDED) -target_compile_options(overworld_graphics PRIVATE $<$:-Wno-gnu-zero-variadic-macro-arguments>) - # ################################## owds_add_library(overworld_glad External/src/glad.c) -owds_add_library(overworld_graphics_new +owds_add_library(overworld_graphics src/Engine/Graphics/Assimp/ModelLoader.cpp src/Engine/Graphics/GLFW/Window.cpp src/Engine/Graphics/OpenGL/Camera.cpp @@ -222,8 +173,8 @@ owds_add_library(overworld_graphics_new src/Engine/Graphics/OpenGL/Shader.cpp src/Engine/Graphics/OpenGL/AmbientShadow.cpp src/Engine/Graphics/OpenGL/Texture2D.cpp) -target_link_libraries(overworld_graphics_new PUBLIC overworld_engine_common overworld_glad assimp glfw) -target_compile_options(overworld_graphics_new PRIVATE $<$:-Wno-unused-function>) +target_link_libraries(overworld_graphics PUBLIC overworld_engine_common overworld_glad assimp glfw) +target_compile_options(overworld_graphics PRIVATE $<$:-Wno-unused-function>) # ################################## if(OWDS_USE_PHYSX) @@ -373,23 +324,18 @@ owds_add_ros_executable(teleop # ################################## # ################################## -owds_add_ros_executable(overworld_test1 src/Nodes/Test1.cpp) -target_compile_options(overworld_test1 PRIVATE $<$:-Wno-gnu-zero-variadic-macro-arguments>) - -target_link_libraries(overworld_test1 - PUBLIC - overworld_graphics - overworld_physics) - owds_add_ros_executable(overworld_opengl src/Nodes/TestOpengl.cpp) target_compile_options(overworld_opengl PRIVATE $<$:-Wno-gnu-zero-variadic-macro-arguments>) target_link_libraries(overworld_opengl PUBLIC - overworld_graphics_new + overworld_graphics overworld_physics) # ################################## -owds_install_executables(overworld_test1) +owds_install_libs(overworld_graphics + overworld_glad + overworld_engine_common) + owds_install_executables(overworld_opengl) # ################################## diff --git a/include/overworld/Graphics/BGFX/API.h b/include/overworld/Graphics/BGFX/API.h deleted file mode 100755 index 39f8325e..00000000 --- a/include/overworld/Graphics/BGFX/API.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef OWDS_GRAPHICS_BGFX_API_H -#define OWDS_GRAPHICS_BGFX_API_H - -#include - -#endif // OWDS_GRAPHICS_BGFX_API_H \ No newline at end of file diff --git a/include/overworld/Graphics/BGFX/Camera.h b/include/overworld/Graphics/BGFX/Camera.h deleted file mode 100755 index 0eb19a08..00000000 --- a/include/overworld/Graphics/BGFX/Camera.h +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef OWDS_GRAPHICS_BGFX_CAMERA_H -#define OWDS_GRAPHICS_BGFX_CAMERA_H - -#include -#include -#include -#include -#include - -#include "overworld/Graphics/BGFX/API.h" -#include "overworld/Graphics/Base/Camera.h" - -namespace owds { - class World; -} - -namespace owds::bgfx { - class Camera final : public owds::Camera - { - private: - ::bgfx::ViewId id_{}; - owds::CameraView_e view_type_{}; - owds::CameraProjection_e projection_type_{}; - std::array view_dimensions_{}; - float field_of_view_ = 0.785398; // 45 deg - glm::vec3 world_eye_position_{}; - glm::vec3 world_eye_front_{}; - glm::vec3 world_eye_right_{}; - glm::vec3 world_eye_up_ = {0.f, 0., 1.f}; - std::array view_matrix_; - std::array proj_matrix_; - - glm::vec2 view_angles_{-90.0f, 0.0f}; // yaw/pitch in deg - - glm::vec2 mouse_current_position_{}; - glm::vec2 mouse_drag_start_position_{}; - bool is_dragging_mouse_ = false; - - bool key_state_front_ = false; - bool key_state_back_ = false; - bool key_state_left_ = false; - bool key_state_right_ = false; - - bool key_state_up_ = false; - bool key_state_down_ = false; - - std::bitset<16> mouse_btn_states_{}; - - float mouse_rotation_sensitivity_ = 0.1; - float mouse_translate_sensitivity_ = 0.035; - float mouse_scroll_sensitivity_ = 0.2; - - public: - bool show_debug_stats_ = false; - bool render_collision_models_ = false; - - Camera() = default; - void setViewId(::bgfx::ViewId id) { id_ = id; } - - void updateViewMatrix(); - void updateProjectionMatrix(); - void updateMatrices(); - - void setCameraView(owds::CameraView_e view_type) override; - void setProjection(owds::CameraProjection_e proj) override; - void setFieldOfView(float fov) override; - void setOutputAA(owds::ViewAntiAliasing_e aa_setting) override; - void setOutputFPS(std::uint64_t desired_target_fps) override; - void setOutputResolution(const std::array& resolution) override; - void setOutputClearColor(owds::Color clear_color) override; - void setCaptureCallback(std::function&)> callback) override; - void finalize() override; - void setPositionAndOrientation(const std::array& position, const std::array& orientation) override; - void setPositionAndLookAt(const std::array& eye_position, const std::array& dst_position) override; - - void recomputeDirectionVector(); - - void processUserKeyboardInput(float delta_time, int key, bool is_down) override; - void processUserMouseBtnInput(float delta_time, char btn, bool is_down) override; - void processUserMouseInput(float delta_time, float x, float y) override; - void processUserMouseScroll(float delta_time, float xoffset, float yoffset) override; - void update() override; - - glm::vec3 getPosition() const { return world_eye_position_; } - - private: - // glm::mat3 to_z_up_; - }; -} // namespace owds::bgfx - -#endif // OWDS_GRAPHICS_BGFX_CAMERA_H diff --git a/include/overworld/Graphics/BGFX/Context.h b/include/overworld/Graphics/BGFX/Context.h deleted file mode 100755 index 1322d659..00000000 --- a/include/overworld/Graphics/BGFX/Context.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef OWDS_GRAPHICS_BGFX_CONTEXT_H -#define OWDS_GRAPHICS_BGFX_CONTEXT_H - -#include -#include -#include -#include -#include - -#include "overworld/Engine/Common/Models/Model.h" -#include "overworld/Graphics/BGFX/API.h" -#include "overworld/Graphics/BGFX/MeshHandle.h" -#include "overworld/Graphics/BGFX/ModelHandle.h" -#include "overworld/Graphics/BGFX/Shader.h" -#include "overworld/Graphics/Base/InstanceData.h" - -namespace owds { - class Window; - class World; - class Camera; -} // namespace owds - -namespace owds::bgfx { - class Camera; - - class Context - { - public: - bool is_initialized_ = false; - std::uint32_t width_ = 640; - std::uint32_t height_ = 480; - std::uint32_t flags_ = BGFX_RESET_VSYNC; - bool has_size_changed_ = false; - bool instanced_rendering_supported = false; - std::vector> cameras_; - std::vector> camera_refs_; - owds::bgfx::Camera* render_camera_ = nullptr; - owds::World* world_ = nullptr; - - bool render_collision_models_ = false; - - std::unordered_map> named_cameras_; - std::unordered_map shaders_; - std::unordered_map loaded_uniforms_; - std::unordered_map loaded_textures_; - std::unordered_map loaded_meshes_; - - ::bgfx::TextureHandle white_tex_{}; - - std::unordered_map cached_models_; - std::unordered_map>> current_mesh_batches_; - - Context() = default; - - Context(const Context& other) = delete; - Context& operator=(const Context& other) = delete; - - Context(Context&& other) = delete; - Context& operator=(Context&& other) = delete; - }; -} // namespace owds::bgfx - -#endif // OWDS_GRAPHICS_BGFX_CONTEXT_H \ No newline at end of file diff --git a/include/overworld/Graphics/BGFX/EmbeddedAssets.h b/include/overworld/Graphics/BGFX/EmbeddedAssets.h deleted file mode 100755 index 5d14a809..00000000 --- a/include/overworld/Graphics/BGFX/EmbeddedAssets.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef OWDS_EMBEDDEDASSERTS_H -#define OWDS_EMBEDDEDASSERTS_H - -#include - -// OpenGL ES shaders -#include -#include -#include -#include -#include -#include - -// OpenGL shaders -#include -#include -#include -#include -#include -#include - -// Vulkan shaders -#include -#include -#include -#include -#include -#include - -#if defined(__WIN32__) || defined(_WIN32) - -// HLSL shaders -#include -#include -#include -#include -#include -#include - -#else - -// todo: figure out how to tell bgfx to stop trying to use DirectX11/X12 on linux -#undef BGFX_EMBEDDED_SHADER_DXBC -#define BGFX_EMBEDDED_SHADER_DXBC(type, name) {}, - -#endif - -static const ::bgfx::EmbeddedShader s_owds_embedded_shaders[] = { - BGFX_EMBEDDED_SHADER(vs_default), - BGFX_EMBEDDED_SHADER(fs_default), - BGFX_EMBEDDED_SHADER(vs_simple_shadows), - BGFX_EMBEDDED_SHADER(fs_simple_shadows), - BGFX_EMBEDDED_SHADER(vs_skybox), - BGFX_EMBEDDED_SHADER(fs_skybox), - BGFX_EMBEDDED_SHADER_END()}; - -#endif // OWDS_EMBEDDEDASSERTS_H diff --git a/include/overworld/Graphics/BGFX/MeshHandle.h b/include/overworld/Graphics/BGFX/MeshHandle.h deleted file mode 100755 index 18a96c81..00000000 --- a/include/overworld/Graphics/BGFX/MeshHandle.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef OWDS_GRAPHICS_BGFX_MESHHANDLE_H -#define OWDS_GRAPHICS_BGFX_MESHHANDLE_H - -#include "overworld/Graphics/BGFX/API.h" - -namespace owds::bgfx { - class MeshHandle - { - public: - ::bgfx::VertexBufferHandle vbh_{}; - ::bgfx::IndexBufferHandle ibh_{}; - }; -} // namespace owds::bgfx - -#endif // OWDS_GRAPHICS_BGFX_MESHHANDLE_H diff --git a/include/overworld/Graphics/BGFX/ModelHandle.h b/include/overworld/Graphics/BGFX/ModelHandle.h deleted file mode 100644 index dc46ccf7..00000000 --- a/include/overworld/Graphics/BGFX/ModelHandle.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef OWDS_GRAPHICS_BGFX_MODELHANDLE_H -#define OWDS_GRAPHICS_BGFX_MODELHANDLE_H - -#include - -#include "overworld/Engine/Common/Models/Color.h" -#include "overworld/Graphics/BGFX/API.h" -#include "overworld/Graphics/BGFX/MeshHandle.h" - -namespace owds::bgfx { - class ModelHandle - { - public: - ::owds::Color diffuse_color_{}; - float specular_; - float shininess_; - ::bgfx::TextureHandle tex_diffuse_{}; - ::bgfx::TextureHandle tex_specular_{}; - std::unordered_map meshes_; - }; -} // namespace owds::bgfx - -#endif // OWDS_GRAPHICS_BGFX_MODELHANDLE_H diff --git a/include/overworld/Graphics/BGFX/Renderer.h b/include/overworld/Graphics/BGFX/Renderer.h deleted file mode 100755 index a33a02ce..00000000 --- a/include/overworld/Graphics/BGFX/Renderer.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef OWDS_GRAPHICS_BGFX_RENDERER_H -#define OWDS_GRAPHICS_BGFX_RENDERER_H - -#include - -#include "overworld/Graphics/BGFX/Context.h" -#include "overworld/Graphics/BGFX/ShadowsRenderer.h" -#include "overworld/Graphics/Base/Renderer.h" - -namespace owds { - class Actor; - class ShapeBox; - class ShapeCapsule; - class ShapeCustomMesh; - class ShapeCylinder; - class ShapeDummy; - class ShapeSphere; - class Model; - class Mesh; - class Material; -} // namespace owds - -namespace owds::bgfx { - class Camera; - - class Renderer final : public owds::Renderer - { - public: - Renderer(); - ~Renderer() override; - - bool initialize(const owds::Window& window) override; - void cleanup() override; - void notifyPreReset() override; - void notifyPostReset() override; - void notifyResize(std::uint32_t new_width, std::uint32_t new_height) override; - - void runSanityChecks() override; - void commit() override; - - void attachWorld(World& world); - owds::Camera& createCamera(const std::string& alias_name) override; - - std::vector> getCameras() override; - owds::Camera* getRenderCamera() override; - - using owds::Renderer::createCamera; - - protected: - void commitCamera(const owds::bgfx::Camera& camera); - void commitShadows(); - void commitWorld(const owds::World& world); - void queueActorBatch(const owds::Actor& actor, const owds::ShapeBox& shape); - void queueActorBatch(const owds::Actor& actor, const owds::ShapeCapsule& shape); - void queueActorBatch(const owds::Actor& actor, const owds::ShapeCustomMesh& shape); - void queueActorBatch(const owds::Actor& actor, const owds::ShapeCylinder& shape); - void queueActorBatch(const owds::Actor& actor, const owds::ShapeDummy& shape); - void queueActorBatch(const owds::Actor& actor, const owds::ShapeSphere& shape); - - void loadModel(const owds::Model& model, const owds::Material& material); - void queueModelBatch(const owds::Model& model, const owds::Material& material, const std::array& model_mat); - - void render(std::uint64_t state, const owds::bgfx::Camera& camera, const std::string& shader = "default"); - void renderInstanced(std::uint64_t state); - - void initLightUniforms(); - void setLightUniforms(World* world); - void initMaterialUniforms(); - void setMaterialUniforms(const owds::bgfx::ModelHandle& model); - - ::bgfx::TextureHandle loadTexture(const std::string& file_name, - uint64_t flags = 0, - ::bgfx::TextureInfo* texture_info = nullptr, - bool flip = false, - bool cube_map = false); - - owds::bgfx::Context ctx_; - owds::bgfx::ShadowsRenderer shadows_renderer_; - }; -} // namespace owds::bgfx - -#endif // OWDS_GRAPHICS_BGFX_RENDERER_H \ No newline at end of file diff --git a/include/overworld/Graphics/BGFX/Shader.h b/include/overworld/Graphics/BGFX/Shader.h deleted file mode 100644 index f3d19fdb..00000000 --- a/include/overworld/Graphics/BGFX/Shader.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef OWDS_BGFX_SHADER_H -#define OWDS_BGFX_SHADER_H - -#include - -#include "overworld/Graphics/BGFX/API.h" -#include "overworld/Graphics/BGFX/EmbeddedAssets.h" - -namespace owds::bgfx { - - class Shader - { - public: - Shader(const std::string& vs_name, const std::string& fs_name) - { - const auto type = ::bgfx::getRendererType(); - const auto vsh = ::bgfx::createEmbeddedShader(s_owds_embedded_shaders, type, vs_name.c_str()); - const auto fsh = ::bgfx::createEmbeddedShader(s_owds_embedded_shaders, type, fs_name.c_str()); - handle_ = ::bgfx::createProgram(vsh, fsh, true); - } - - ~Shader() - { - ::bgfx::destroy(handle_); - } - - void submit(::bgfx::ViewId id = 0) - { - ::bgfx::submit(id, handle_); - } - - private: - ::bgfx::ProgramHandle handle_; - }; - -} // namespace owds::bgfx - -#endif // OWDS_BGFX_SHADER_H \ No newline at end of file diff --git a/include/overworld/Graphics/BGFX/ShadowsRenderer.h b/include/overworld/Graphics/BGFX/ShadowsRenderer.h deleted file mode 100644 index 669193b7..00000000 --- a/include/overworld/Graphics/BGFX/ShadowsRenderer.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef OWDS_GRAPHICS_BGFX_SHADOWSRENDERER_H -#define OWDS_GRAPHICS_BGFX_SHADOWSRENDERER_H - -#include - -#include "overworld/Graphics/BGFX/API.h" -#include "overworld/Graphics/BGFX/Camera.h" - -namespace owds::bgfx { - - class ShadowsRenderer - { - public: - ShadowsRenderer(::bgfx::ViewId view_id); - - bool initialize(); - - ::bgfx::TextureHandle texture_handle_; - Camera camera_; - - unsigned long state_; - - private: - std::uint32_t shadow_map_size_; - - ::bgfx::ViewId view_id_; - ::bgfx::FrameBufferHandle frame_buffer_; - }; - -} // namespace owds::bgfx - -#endif // OWDS_GRAPHICS_BGFX_SHADOWSRENDERER_H \ No newline at end of file diff --git a/include/overworld/Graphics/BGFX/Vertex.h b/include/overworld/Graphics/BGFX/Vertex.h deleted file mode 100755 index 64ac2f61..00000000 --- a/include/overworld/Graphics/BGFX/Vertex.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef OWDS_VERTEX_H -#define OWDS_VERTEX_H - -#include - -#include "overworld/Engine/Common/Models/Vertex.h" - -namespace owds::bgfx { - class Vertex : public owds::Vertex - { - public: - static ::bgfx::VertexLayout getMSLayout(); - }; -} // namespace owds::bgfx - -#endif // OWDS_VERTEX_H diff --git a/include/overworld/Graphics/Base/Camera.h b/include/overworld/Graphics/Base/Camera.h deleted file mode 100755 index bc6f65da..00000000 --- a/include/overworld/Graphics/Base/Camera.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef OWDS_GRAPHICS_BASE_CAMERA_H -#define OWDS_GRAPHICS_BASE_CAMERA_H - -#include - -#include "overworld/Engine/Common/Models/Color.h" -#include "overworld/Graphics/Base/CameraProjection.h" -#include "overworld/Graphics/Base/CameraView.h" -#include "overworld/Graphics/Base/ViewAntiAliasing.h" - -namespace owds { - - class Camera - { - public: - virtual ~Camera() noexcept = default; - - /** - * @param view_type What each option does is outlined where owds::CameraViewType is declared. - */ - virtual void setCameraView(owds::CameraView_e view_type) = 0; - - /** - * @param proj What each option does is outlined where owds::CameraProjection is declared. - */ - virtual void setProjection(owds::CameraProjection_e proj) = 0; - - /** - * Note: This only works when perspective projection is used. - * - * @param fov Self-explanatory - */ - virtual void setFieldOfView(float fov) = 0; - - /** - * @param mode todo - */ - virtual void setOutputAA(owds::ViewAntiAliasing_e mode) = 0; - - /** - * @param desired_target_fps If this value is zero, vsync is assumed to be desired. - */ - virtual void setOutputFPS(std::uint64_t desired_target_fps) = 0; - - /** - * Note: This setting may be ignored if the camera is currently previewed in a window. - * @param resolution Sets the framebuffer resolution for the camera's view, in pixels. - */ - virtual void setOutputResolution(const std::array& resolution) = 0; - - /** - * @param clear_color 8-bit RGBA color - */ - virtual void setOutputClearColor(owds::Color clear_color) = 0; - - /** - * You may set a capture callback which is called every frame containing the framebuffer's pixel data. - */ - virtual void setCaptureCallback(std::function&)> callback) = 0; - - /** - * Initializes some internal data structures and some settings won't be modifiable anymore after this call. - */ - virtual void finalize() = 0; - - /** - * @param position Position. - * @param orientation XYZ rotations (Yaw + Pitch + Roll), in radians. - */ - virtual void setPositionAndOrientation(const std::array& position, const std::array& orientation) = 0; - - /** - * @param eye_position Camera position. - * @param dst_position The position where to look at. - */ - virtual void setPositionAndLookAt(const std::array& eye_position, const std::array& dst_position) = 0; - - virtual void processUserKeyboardInput(float delta_time, int key, bool is_down) = 0; - virtual void processUserMouseBtnInput(float delta_time, char btn, bool is_down) = 0; - virtual void processUserMouseInput(float delta_time, float x, float y) = 0; - virtual void processUserMouseScroll(float delta_time, float xoffset, float yoffset) = 0; - virtual void update() = 0; - }; -} // namespace owds - -#endif // OWDS_GRAPHICS_BASE_CAMERA_H diff --git a/include/overworld/Graphics/Base/CameraProjection.h b/include/overworld/Graphics/Base/CameraProjection.h deleted file mode 100644 index cf4beb61..00000000 --- a/include/overworld/Graphics/Base/CameraProjection.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef OWDS_GRAPHICS_BASE_CAMERAPROJECTION_H -#define OWDS_GRAPHICS_BASE_CAMERAPROJECTION_H - -namespace owds { - /** - * Its best for you to look online about the differences between perspective and orthographic. - - * But generally, as a rule of thumb: - * - Use ePERSPECTIVE if you need 3D - * - Use eORTHOGRAPHIC if you need 2D - */ - enum class CameraProjection_e - { - perspective, - orthographic - }; -} // namespace owds - -#endif // OWDS_GRAPHICS_BASE_CAMERAPROJECTION_H \ No newline at end of file diff --git a/include/overworld/Graphics/Base/CameraView.h b/include/overworld/Graphics/Base/CameraView.h deleted file mode 100644 index fec3b20c..00000000 --- a/include/overworld/Graphics/Base/CameraView.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef OWDS_GRAPHICS_BASE_CAMERAVIEW_H -#define OWDS_GRAPHICS_BASE_CAMERAVIEW_H - -namespace owds { - /** - * regular_view Will render the world with all the colors, textures and all the fancy visual details. - * segmented_view Will randomly assign a color to every model & disable their textures. - */ - enum class CameraView_e - { - regular_view, - segmented_view - }; -} // namespace owds - -#endif // OWDS_GRAPHICS_BASE_CAMERAVIEW_H \ No newline at end of file diff --git a/include/overworld/Graphics/Base/InstanceData.h b/include/overworld/Graphics/Base/InstanceData.h deleted file mode 100755 index 58785bd9..00000000 --- a/include/overworld/Graphics/Base/InstanceData.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef OWDS_GRAPHICS_BASE_INSTANCEDATA_H -#define OWDS_GRAPHICS_BASE_INSTANCEDATA_H - -#include - -#include "overworld/Engine/Common/Models/Color.h" - -namespace owds { - class InstanceData - { - public: - std::array mvp_; - owds::Color rgba_; - }; -} // namespace owds - -#endif // OWDS_GRAPHICS_BASE_INSTANCEDATA_H diff --git a/include/overworld/Graphics/Base/Renderer.h b/include/overworld/Graphics/Base/Renderer.h deleted file mode 100755 index c078f561..00000000 --- a/include/overworld/Graphics/Base/Renderer.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef OWDS_GRAPHICS_BASE_RENDERER_H -#define OWDS_GRAPHICS_BASE_RENDERER_H - -#include -#include -#include -#include - -namespace owds { - class Window; - class World; - class Actor; - class Camera; - class AmbientLight; - class PointLights; - - class Renderer - { - public: - virtual ~Renderer() = default; - virtual bool initialize(const owds::Window& window) = 0; - virtual void cleanup() = 0; - virtual void notifyPreReset() = 0; - virtual void notifyPostReset() = 0; - virtual void notifyResize(std::uint32_t new_width, std::uint32_t new_height) = 0; - - // Call to `runSanityChecks` is optional, but recommended. - virtual void runSanityChecks() = 0; - - virtual void commit() = 0; - - /** - * @param alias_name This parameter is optional, leave empty if undesired. - */ - virtual owds::Camera& createCamera(const std::string& alias_name) = 0; - - virtual std::vector> getCameras() = 0; - virtual owds::Camera* getRenderCamera() = 0; - - protected: - const AmbientLight& getAmbientLight(World* world); - const PointLights& getPointLights(World* world); - }; -} // namespace owds - -#endif // OWDS_GRAPHICS_BASE_RENDERER_H diff --git a/include/overworld/Graphics/Base/ViewAntiAliasing.h b/include/overworld/Graphics/Base/ViewAntiAliasing.h deleted file mode 100644 index f96f0769..00000000 --- a/include/overworld/Graphics/Base/ViewAntiAliasing.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef OWDS_GRAPHICS_BASE_VIEWANTIALIASING_H -#define OWDS_GRAPHICS_BASE_VIEWANTIALIASING_H - -namespace owds { - /** - * off Disables anti-aliasing, recommended if high performance is desired and you don't care about about rough Graphics. - * msaa_x2 Will render at x2 the resolution and scale it down - * msaa_x4 Will render at x4 the resolution and scale it down - * msaa_x8 Will render at x8 the resolution and scale it down - * msaa_x16 Will render at x16 the resolution and scale it down - * - * There's not that many visual improvements above MSAA x4 so you probably want to stay at that level to avoid wasting system resources. - */ - enum class ViewAntiAliasing_e - { - off, - msaa_x1 = off, - msaa_x2, - msaa_x4, - msaa_x8, - msaa_x16 - }; -} - -#endif // OWDS_GRAPHICS_BASE_VIEWANTIALIASING_H diff --git a/include/overworld/Graphics/Base/Window.h b/include/overworld/Graphics/Base/Window.h deleted file mode 100755 index 8776bfd5..00000000 --- a/include/overworld/Graphics/Base/Window.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef OWDS_GRAPHICS_BASE_WINDOW_H -#define OWDS_GRAPHICS_BASE_WINDOW_H - -#include "overworld/Graphics/Base/WindowPlatformData.h" - -namespace owds { - class Renderer; - - class Window - { - public: - virtual ~Window() = default; - - [[nodiscard]] virtual WindowPlatformData getPlatformData() const = 0; - virtual void doPollEvents(owds::Renderer& renderer) = 0; - [[nodiscard]] virtual bool isCloseRequested() const = 0; - }; -} // namespace owds - -#endif // OWDS_GRAPHICS_BASE_WINDOW_H diff --git a/include/overworld/Graphics/Base/WindowPlatformData.h b/include/overworld/Graphics/Base/WindowPlatformData.h deleted file mode 100755 index 3736e55a..00000000 --- a/include/overworld/Graphics/Base/WindowPlatformData.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef OWDS_GRAPHICS_BASE_WINDOWPLATFORMDATA_H -#define OWDS_GRAPHICS_BASE_WINDOWPLATFORMDATA_H - -namespace owds { - class WindowPlatformData - { - public: - void* native_display_type_; - void* native_window_handle_; - }; -} // namespace owds - -#endif // OWDS_GRAPHICS_BASE_WINDOWPLATFORMDATA_H diff --git a/include/overworld/Graphics/GLFW3/Context.h b/include/overworld/Graphics/GLFW3/Context.h deleted file mode 100755 index 16325940..00000000 --- a/include/overworld/Graphics/GLFW3/Context.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef OWDS_GRAPHICS_GLFW3_CONTEXT_H -#define OWDS_GRAPHICS_GLFW3_CONTEXT_H - -#define GLFW_EXPOSE_NATIVE_X11 -#include -#include -#include - -namespace owds::glfw3 { - class Context - { - public: - std::uint32_t width_ = 640; - std::uint32_t height_ = 480; - bool has_size_changed_ = false; - GLFWwindow* glfw_window_ = nullptr; - owds::Camera* camera_ = nullptr; - - Context() = default; - ~Context() noexcept = default; - - Context(const Context& other) = delete; - Context& operator=(const Context& other) = delete; - - Context(Context&& other) = delete; - Context& operator=(Context&& other) = delete; - }; -} // namespace owds::glfw3 - -#endif // OWDS_GRAPHICS_GLFW3_CONTEXT_H \ No newline at end of file diff --git a/include/overworld/Graphics/GLFW3/Window.h b/include/overworld/Graphics/GLFW3/Window.h deleted file mode 100755 index 319b7ecb..00000000 --- a/include/overworld/Graphics/GLFW3/Window.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef OWDS_GRAPHICS_GLFW3_WINDOW_H -#define OWDS_GRAPHICS_GLFW3_WINDOW_H - -#include -#include - -#include "overworld/Graphics/Base/Window.h" - -namespace owds::glfw3 { - class Context; - - class Window final : public owds::Window - { - public: - Window(const std::string& name = "Overworld"); - ~Window() override; - - [[nodiscard]] WindowPlatformData getPlatformData() const override; - - void doPollEvents(owds::Renderer& renderer) override; - [[nodiscard]] bool isCloseRequested() const override; - - protected: - std::unique_ptr ctx_; - }; -} // namespace owds::glfw3 - -#endif // OWDS_GRAPHICS_GLFW3_WINDOW_H diff --git a/shaders/bgfx_shader.sh b/shaders/bgfx_shader.sh deleted file mode 100755 index 3fe839a6..00000000 --- a/shaders/bgfx_shader.sh +++ /dev/null @@ -1,730 +0,0 @@ -/* - * Copyright 2011-2024 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE - */ - -#ifndef BGFX_SHADER_H_HEADER_GUARD -#define BGFX_SHADER_H_HEADER_GUARD - -#if !defined(BGFX_CONFIG_MAX_BONES) -# define BGFX_CONFIG_MAX_BONES 32 -#endif // !defined(BGFX_CONFIG_MAX_BONES) - -#ifndef __cplusplus - -#if BGFX_SHADER_LANGUAGE_HLSL > 300 -# define BRANCH [branch] -# define LOOP [loop] -# define UNROLL [unroll] -#else -# define BRANCH -# define LOOP -# define UNROLL -#endif // BGFX_SHADER_LANGUAGE_HLSL > 300 - -#if (BGFX_SHADER_LANGUAGE_HLSL > 300 || BGFX_SHADER_LANGUAGE_METAL || BGFX_SHADER_LANGUAGE_SPIRV) && BGFX_SHADER_TYPE_FRAGMENT -# define EARLY_DEPTH_STENCIL [earlydepthstencil] -#else -# define EARLY_DEPTH_STENCIL -#endif // BGFX_SHADER_LANGUAGE_HLSL > 300 && BGFX_SHADER_TYPE_FRAGMENT - -#if BGFX_SHADER_LANGUAGE_GLSL -# define ARRAY_BEGIN(_type, _name, _count) _type _name[_count] = _type[]( -# define ARRAY_END() ) -#else -# define ARRAY_BEGIN(_type, _name, _count) _type _name[_count] = { -# define ARRAY_END() } -#endif // BGFX_SHADER_LANGUAGE_GLSL - -#if BGFX_SHADER_LANGUAGE_HLSL \ - || BGFX_SHADER_LANGUAGE_PSSL \ - || BGFX_SHADER_LANGUAGE_SPIRV \ - || BGFX_SHADER_LANGUAGE_METAL -# define CONST(_x) static const _x -# define dFdx(_x) ddx(_x) -# define dFdy(_y) ddy(-(_y)) -# define inversesqrt(_x) rsqrt(_x) -# define fract(_x) frac(_x) - -# define bvec2 bool2 -# define bvec3 bool3 -# define bvec4 bool4 - -// To be able to patch the uav registers on the DXBC SPDB Chunk (D3D11 renderer) the whitespaces around -// '_type[_reg]' are necessary. This only affects shaders with debug info (i.e., those that have the SPDB Chunk). -# if BGFX_SHADER_LANGUAGE_HLSL > 400 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL -# define REGISTER(_type, _reg) register( _type[_reg] ) -# else -# define REGISTER(_type, _reg) register(_type ## _reg) -# endif // BGFX_SHADER_LANGUAGE_HLSL - -# if BGFX_SHADER_LANGUAGE_HLSL > 300 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL -# if BGFX_SHADER_LANGUAGE_HLSL > 400 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL -# define dFdxCoarse(_x) ddx_coarse(_x) -# define dFdxFine(_x) ddx_fine(_x) -# define dFdyCoarse(_y) ddy_coarse(-(_y)) -# define dFdyFine(_y) ddy_fine(-(_y)) -# endif // BGFX_SHADER_LANGUAGE_HLSL > 400 - -# if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL -float intBitsToFloat(int _x) { return asfloat(_x); } -vec2 intBitsToFloat(uint2 _x) { return asfloat(_x); } -vec3 intBitsToFloat(uint3 _x) { return asfloat(_x); } -vec4 intBitsToFloat(uint4 _x) { return asfloat(_x); } -# endif // BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL - -float uintBitsToFloat(uint _x) { return asfloat(_x); } -vec2 uintBitsToFloat(uint2 _x) { return asfloat(_x); } -vec3 uintBitsToFloat(uint3 _x) { return asfloat(_x); } -vec4 uintBitsToFloat(uint4 _x) { return asfloat(_x); } - -uint floatBitsToUint(float _x) { return asuint(_x); } -uvec2 floatBitsToUint(vec2 _x) { return asuint(_x); } -uvec3 floatBitsToUint(vec3 _x) { return asuint(_x); } -uvec4 floatBitsToUint(vec4 _x) { return asuint(_x); } - -int floatBitsToInt(float _x) { return asint(_x); } -ivec2 floatBitsToInt(vec2 _x) { return asint(_x); } -ivec3 floatBitsToInt(vec3 _x) { return asint(_x); } -ivec4 floatBitsToInt(vec4 _x) { return asint(_x); } - -uint bitfieldReverse(uint _x) { return reversebits(_x); } -uint2 bitfieldReverse(uint2 _x) { return reversebits(_x); } -uint3 bitfieldReverse(uint3 _x) { return reversebits(_x); } -uint4 bitfieldReverse(uint4 _x) { return reversebits(_x); } - -# if !BGFX_SHADER_LANGUAGE_SPIRV -uint packHalf2x16(vec2 _x) -{ - return (f32tof16(_x.y)<<16) | f32tof16(_x.x); -} - -vec2 unpackHalf2x16(uint _x) -{ - return vec2(f16tof32(_x & 0xffff), f16tof32(_x >> 16) ); -} -# endif // !BGFX_SHADER_LANGUAGE_SPIRV - -struct BgfxSampler2D -{ - SamplerState m_sampler; - Texture2D m_texture; -}; - -struct BgfxISampler2D -{ - Texture2D m_texture; -}; - -struct BgfxUSampler2D -{ - Texture2D m_texture; -}; - -struct BgfxSampler2DArray -{ - SamplerState m_sampler; - Texture2DArray m_texture; -}; - -struct BgfxSampler2DShadow -{ - SamplerComparisonState m_sampler; - Texture2D m_texture; -}; - -struct BgfxSampler2DArrayShadow -{ - SamplerComparisonState m_sampler; - Texture2DArray m_texture; -}; - -struct BgfxSampler3D -{ - SamplerState m_sampler; - Texture3D m_texture; -}; - -struct BgfxISampler3D -{ - Texture3D m_texture; -}; - -struct BgfxUSampler3D -{ - Texture3D m_texture; -}; - -struct BgfxSamplerCube -{ - SamplerState m_sampler; - TextureCube m_texture; -}; - -struct BgfxSamplerCubeShadow -{ - SamplerComparisonState m_sampler; - TextureCube m_texture; -}; - -struct BgfxSampler2DMS -{ - Texture2DMS m_texture; -}; - -vec4 bgfxTexture2D(BgfxSampler2D _sampler, vec2 _coord) -{ - return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); -} - -vec4 bgfxTexture2DBias(BgfxSampler2D _sampler, vec2 _coord, float _bias) -{ - return _sampler.m_texture.SampleBias(_sampler.m_sampler, _coord, _bias); -} - -vec4 bgfxTexture2DLod(BgfxSampler2D _sampler, vec2 _coord, float _level) -{ - return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level); -} - -vec4 bgfxTexture2DLodOffset(BgfxSampler2D _sampler, vec2 _coord, float _level, ivec2 _offset) -{ - return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level, _offset); -} - -vec4 bgfxTexture2DProj(BgfxSampler2D _sampler, vec3 _coord) -{ - vec2 coord = _coord.xy * rcp(_coord.z); - return _sampler.m_texture.Sample(_sampler.m_sampler, coord); -} - -vec4 bgfxTexture2DProj(BgfxSampler2D _sampler, vec4 _coord) -{ - vec2 coord = _coord.xy * rcp(_coord.w); - return _sampler.m_texture.Sample(_sampler.m_sampler, coord); -} - -vec4 bgfxTexture2DGrad(BgfxSampler2D _sampler, vec2 _coord, vec2 _dPdx, vec2 _dPdy) -{ - return _sampler.m_texture.SampleGrad(_sampler.m_sampler, _coord, _dPdx, _dPdy); -} - -vec4 bgfxTexture2DArray(BgfxSampler2DArray _sampler, vec3 _coord) -{ - return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); -} - -vec4 bgfxTexture2DArrayLod(BgfxSampler2DArray _sampler, vec3 _coord, float _lod) -{ - return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _lod); -} - -vec4 bgfxTexture2DArrayLodOffset(BgfxSampler2DArray _sampler, vec3 _coord, float _level, ivec2 _offset) -{ - return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level, _offset); -} - -float bgfxShadow2D(BgfxSampler2DShadow _sampler, vec3 _coord) -{ - return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xy, _coord.z); -} - -float bgfxShadow2DProj(BgfxSampler2DShadow _sampler, vec4 _coord) -{ - vec3 coord = _coord.xyz * rcp(_coord.w); - return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, coord.xy, coord.z); -} - -vec2 bgfxTextureSize(BgfxSampler2DShadow _sampler, int _lod) -{ - vec2 result; - float numberOfMipMapLevels; - _sampler.m_texture.GetDimensions(_lod, result.x, result.y, numberOfMipMapLevels); - return result; -} - -vec4 bgfxShadow2DArray(BgfxSampler2DArrayShadow _sampler, vec4 _coord) -{ - return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xyz, _coord.w); -} - -vec2 bgfxTextureSize(BgfxSampler2DArrayShadow _sampler, int _lod) -{ - vec2 result; - float numberOfMipMapLevels; - float numberOfElements; - _sampler.m_texture.GetDimensions(_lod, result.x, result.y, numberOfElements, numberOfMipMapLevels); - return result; -} - -vec4 bgfxTexture3D(BgfxSampler3D _sampler, vec3 _coord) -{ - return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); -} - -vec4 bgfxTexture3DLod(BgfxSampler3D _sampler, vec3 _coord, float _level) -{ - return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level); -} - -ivec4 bgfxTexture3D(BgfxISampler3D _sampler, vec3 _coord) -{ - uvec3 size; - _sampler.m_texture.GetDimensions(size.x, size.y, size.z); - return _sampler.m_texture.Load(ivec4(_coord * size, 0) ); -} - -uvec4 bgfxTexture3D(BgfxUSampler3D _sampler, vec3 _coord) -{ - uvec3 size; - _sampler.m_texture.GetDimensions(size.x, size.y, size.z); - return _sampler.m_texture.Load(ivec4(_coord * size, 0) ); -} - -vec4 bgfxTextureCube(BgfxSamplerCube _sampler, vec3 _coord) -{ - return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); -} - -vec4 bgfxTextureCubeBias(BgfxSamplerCube _sampler, vec3 _coord, float _bias) -{ - return _sampler.m_texture.SampleBias(_sampler.m_sampler, _coord, _bias); -} - -vec4 bgfxTextureCubeLod(BgfxSamplerCube _sampler, vec3 _coord, float _level) -{ - return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level); -} - -float bgfxShadowCube(BgfxSamplerCubeShadow _sampler, vec4 _coord) -{ - return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xyz, _coord.w); -} - -vec4 bgfxTexelFetch(BgfxSampler2D _sampler, ivec2 _coord, int _lod) -{ - return _sampler.m_texture.Load(ivec3(_coord, _lod) ); -} - -vec4 bgfxTexelFetchOffset(BgfxSampler2D _sampler, ivec2 _coord, int _lod, ivec2 _offset) -{ - return _sampler.m_texture.Load(ivec3(_coord, _lod), _offset ); -} - -vec2 bgfxTextureSize(BgfxSampler2D _sampler, int _lod) -{ - vec2 result; - float numberOfMipMapLevels; - _sampler.m_texture.GetDimensions(_lod, result.x, result.y, numberOfMipMapLevels); - return result; -} - -vec2 bgfxTextureSize(BgfxISampler2D _sampler, int _lod) -{ - vec2 result; - float numberOfMipMapLevels; - _sampler.m_texture.GetDimensions(_lod, result.x, result.y, numberOfMipMapLevels); - return result; -} - -vec2 bgfxTextureSize(BgfxUSampler2D _sampler, int _lod) -{ - vec2 result; - float numberOfMipMapLevels; - _sampler.m_texture.GetDimensions(_lod, result.x, result.y, numberOfMipMapLevels); - return result; -} - -vec4 bgfxTextureGather0(BgfxSampler2D _sampler, vec2 _coord) -{ - return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord); -} - -vec4 bgfxTextureGather1(BgfxSampler2D _sampler, vec2 _coord) -{ - return _sampler.m_texture.GatherGreen(_sampler.m_sampler, _coord); -} - -vec4 bgfxTextureGather2(BgfxSampler2D _sampler, vec2 _coord) -{ - return _sampler.m_texture.GatherBlue(_sampler.m_sampler, _coord); -} - -vec4 bgfxTextureGather3(BgfxSampler2D _sampler, vec2 _coord) -{ - return _sampler.m_texture.GatherAlpha(_sampler.m_sampler, _coord); -} - -vec4 bgfxTextureGatherOffset0(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset) -{ - return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord, _offset); -} - -vec4 bgfxTextureGatherOffset1(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset) -{ - return _sampler.m_texture.GatherGreen(_sampler.m_sampler, _coord, _offset); -} - -vec4 bgfxTextureGatherOffset2(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset) -{ - return _sampler.m_texture.GatherBlue(_sampler.m_sampler, _coord, _offset); -} - -vec4 bgfxTextureGatherOffset3(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset) -{ - return _sampler.m_texture.GatherAlpha(_sampler.m_sampler, _coord, _offset); -} - -vec4 bgfxTextureGather0(BgfxSampler2DArray _sampler, vec3 _coord) -{ - return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord); -} - -vec4 bgfxTextureGather1(BgfxSampler2DArray _sampler, vec3 _coord) -{ - return _sampler.m_texture.GatherGreen(_sampler.m_sampler, _coord); -} - -vec4 bgfxTextureGather2(BgfxSampler2DArray _sampler, vec3 _coord) -{ - return _sampler.m_texture.GatherBlue(_sampler.m_sampler, _coord); -} - -vec4 bgfxTextureGather3(BgfxSampler2DArray _sampler, vec3 _coord) -{ - return _sampler.m_texture.GatherAlpha(_sampler.m_sampler, _coord); -} - -ivec4 bgfxTexelFetch(BgfxISampler2D _sampler, ivec2 _coord, int _lod) -{ - return _sampler.m_texture.Load(ivec3(_coord, _lod) ); -} - -uvec4 bgfxTexelFetch(BgfxUSampler2D _sampler, ivec2 _coord, int _lod) -{ - return _sampler.m_texture.Load(ivec3(_coord, _lod) ); -} - -vec4 bgfxTexelFetch(BgfxSampler2DMS _sampler, ivec2 _coord, int _sampleIdx) -{ - return _sampler.m_texture.Load(_coord, _sampleIdx); -} - -vec4 bgfxTexelFetch(BgfxSampler2DArray _sampler, ivec3 _coord, int _lod) -{ - return _sampler.m_texture.Load(ivec4(_coord, _lod) ); -} - -vec4 bgfxTexelFetch(BgfxSampler3D _sampler, ivec3 _coord, int _lod) -{ - return _sampler.m_texture.Load(ivec4(_coord, _lod) ); -} - -vec3 bgfxTextureSize(BgfxSampler3D _sampler, int _lod) -{ - vec3 result; - float numberOfMipMapLevels; - _sampler.m_texture.GetDimensions(_lod, result.x, result.y, result.z, numberOfMipMapLevels); - return result; -} - -# define SAMPLER2D(_name, _reg) \ - uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ - uniform Texture2D _name ## Texture : REGISTER(t, _reg); \ - static BgfxSampler2D _name = { _name ## Sampler, _name ## Texture } -# define ISAMPLER2D(_name, _reg) \ - uniform Texture2D _name ## Texture : REGISTER(t, _reg); \ - static BgfxISampler2D _name = { _name ## Texture } -# define USAMPLER2D(_name, _reg) \ - uniform Texture2D _name ## Texture : REGISTER(t, _reg); \ - static BgfxUSampler2D _name = { _name ## Texture } -# define sampler2D BgfxSampler2D -# define texture2D(_sampler, _coord) bgfxTexture2D(_sampler, _coord) -# define texture2DBias(_sampler, _coord, _bias) bgfxTexture2DBias(_sampler, _coord, _bias) -# define texture2DLod(_sampler, _coord, _level) bgfxTexture2DLod(_sampler, _coord, _level) -# define texture2DLodOffset(_sampler, _coord, _level, _offset) bgfxTexture2DLodOffset(_sampler, _coord, _level, _offset) -# define texture2DProj(_sampler, _coord) bgfxTexture2DProj(_sampler, _coord) -# define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) bgfxTexture2DGrad(_sampler, _coord, _dPdx, _dPdy) - -# define SAMPLER2DARRAY(_name, _reg) \ - uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ - uniform Texture2DArray _name ## Texture : REGISTER(t, _reg); \ - static BgfxSampler2DArray _name = { _name ## Sampler, _name ## Texture } -# define sampler2DArray BgfxSampler2DArray -# define texture2DArray(_sampler, _coord) bgfxTexture2DArray(_sampler, _coord) -# define texture2DArrayLod(_sampler, _coord, _lod) bgfxTexture2DArrayLod(_sampler, _coord, _lod) -# define texture2DArrayLodOffset(_sampler, _coord, _level, _offset) bgfxTexture2DArrayLodOffset(_sampler, _coord, _level, _offset) - -# define SAMPLER2DMS(_name, _reg) \ - uniform Texture2DMS _name ## Texture : REGISTER(t, _reg); \ - static BgfxSampler2DMS _name = { _name ## Texture } -# define sampler2DMS BgfxSampler2DMS - -# define SAMPLER2DSHADOW(_name, _reg) \ - uniform SamplerComparisonState _name ## SamplerComparison : REGISTER(s, _reg); \ - uniform Texture2D _name ## Texture : REGISTER(t, _reg); \ - static BgfxSampler2DShadow _name = { _name ## SamplerComparison, _name ## Texture } -# define sampler2DShadow BgfxSampler2DShadow -# define shadow2D(_sampler, _coord) bgfxShadow2D(_sampler, _coord) -# define shadow2DProj(_sampler, _coord) bgfxShadow2DProj(_sampler, _coord) - -# define SAMPLER2DARRAYSHADOW(_name, _reg) \ - uniform SamplerComparisonState _name ## SamplerComparison : REGISTER(s, _reg); \ - uniform Texture2DArray _name ## Texture : REGISTER(t, _reg); \ - static BgfxSampler2DArrayShadow _name = { _name ## SamplerComparison, _name ## Texture } -# define sampler2DArrayShadow BgfxSampler2DArrayShadow -# define shadow2DArray(_sampler, _coord) bgfxShadow2DArray(_sampler, _coord) - -# define SAMPLER3D(_name, _reg) \ - uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ - uniform Texture3D _name ## Texture : REGISTER(t, _reg); \ - static BgfxSampler3D _name = { _name ## Sampler, _name ## Texture } -# define ISAMPLER3D(_name, _reg) \ - uniform Texture3D _name ## Texture : REGISTER(t, _reg); \ - static BgfxISampler3D _name = { _name ## Texture } -# define USAMPLER3D(_name, _reg) \ - uniform Texture3D _name ## Texture : REGISTER(t, _reg); \ - static BgfxUSampler3D _name = { _name ## Texture } -# define sampler3D BgfxSampler3D -# define texture3D(_sampler, _coord) bgfxTexture3D(_sampler, _coord) -# define texture3DLod(_sampler, _coord, _level) bgfxTexture3DLod(_sampler, _coord, _level) - -# define SAMPLERCUBE(_name, _reg) \ - uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ - uniform TextureCube _name ## Texture : REGISTER(t, _reg); \ - static BgfxSamplerCube _name = { _name ## Sampler, _name ## Texture } -# define samplerCube BgfxSamplerCube -# define textureCube(_sampler, _coord) bgfxTextureCube(_sampler, _coord) -# define textureCubeBias(_sampler, _coord, _bias) bgfxTextureCubeBias(_sampler, _coord, _bias) -# define textureCubeLod(_sampler, _coord, _level) bgfxTextureCubeLod(_sampler, _coord, _level) - -# define SAMPLERCUBESHADOW(_name, _reg) \ - uniform SamplerComparisonState _name ## SamplerComparison : REGISTER(s, _reg); \ - uniform TextureCube _name ## Texture : REGISTER(t, _reg); \ - static BgfxSamplerCubeShadow _name = { _name ## SamplerComparison, _name ## Texture } -# define samplerCubeShadow BgfxSamplerCubeShadow -# define shadowCube(_sampler, _coord) bgfxShadowCube(_sampler, _coord) - -# define texelFetch(_sampler, _coord, _lod) bgfxTexelFetch(_sampler, _coord, _lod) -# define texelFetchOffset(_sampler, _coord, _lod, _offset) bgfxTexelFetchOffset(_sampler, _coord, _lod, _offset) -# define textureSize(_sampler, _lod) bgfxTextureSize(_sampler, _lod) -# define textureGather(_sampler, _coord, _comp) bgfxTextureGather ## _comp(_sampler, _coord) -# define textureGatherOffset(_sampler, _coord, _offset, _comp) bgfxTextureGatherOffset ## _comp(_sampler, _coord, _offset) -# else - -# define sampler2DShadow sampler2D - -vec4 bgfxTexture2DProj(sampler2D _sampler, vec3 _coord) -{ - return tex2Dproj(_sampler, vec4(_coord.xy, 0.0, _coord.z) ); -} - -vec4 bgfxTexture2DProj(sampler2D _sampler, vec4 _coord) -{ - return tex2Dproj(_sampler, _coord); -} - -float bgfxShadow2D(sampler2DShadow _sampler, vec3 _coord) -{ -#if 0 - float occluder = tex2D(_sampler, _coord.xy).x; - return step(_coord.z, occluder); -#else - return tex2Dproj(_sampler, vec4(_coord.xy, _coord.z, 1.0) ).x; -#endif // 0 -} - -float bgfxShadow2DProj(sampler2DShadow _sampler, vec4 _coord) -{ -#if 0 - vec3 coord = _coord.xyz * rcp(_coord.w); - float occluder = tex2D(_sampler, coord.xy).x; - return step(coord.z, occluder); -#else - return tex2Dproj(_sampler, _coord).x; -#endif // 0 -} - -# define SAMPLER2D(_name, _reg) uniform sampler2D _name : REGISTER(s, _reg) -# define SAMPLER2DMS(_name, _reg) uniform sampler2DMS _name : REGISTER(s, _reg) -# define texture2D(_sampler, _coord) tex2D(_sampler, _coord) -# define texture2DProj(_sampler, _coord) bgfxTexture2DProj(_sampler, _coord) - -# define SAMPLER2DARRAY(_name, _reg) SAMPLER2D(_name, _reg) -# define texture2DArray(_sampler, _coord) texture2D(_sampler, (_coord).xy) -# define texture2DArrayLod(_sampler, _coord, _lod) texture2DLod(_sampler, _coord, _lod) - -# define SAMPLER2DSHADOW(_name, _reg) uniform sampler2DShadow _name : REGISTER(s, _reg) -# define shadow2D(_sampler, _coord) bgfxShadow2D(_sampler, _coord) -# define shadow2DProj(_sampler, _coord) bgfxShadow2DProj(_sampler, _coord) - -# define SAMPLER3D(_name, _reg) uniform sampler3D _name : REGISTER(s, _reg) -# define texture3D(_sampler, _coord) tex3D(_sampler, _coord) - -# define SAMPLERCUBE(_name, _reg) uniform samplerCUBE _name : REGISTER(s, _reg) -# define textureCube(_sampler, _coord) texCUBE(_sampler, _coord) - -# define texture2DLod(_sampler, _coord, _level) tex2Dlod(_sampler, vec4( (_coord).xy, 0.0, _level) ) -# define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) tex2Dgrad(_sampler, _coord, _dPdx, _dPdy) -# define texture3DLod(_sampler, _coord, _level) tex3Dlod(_sampler, vec4( (_coord).xyz, _level) ) -# define textureCubeLod(_sampler, _coord, _level) texCUBElod(_sampler, vec4( (_coord).xyz, _level) ) - -# endif // BGFX_SHADER_LANGUAGE_HLSL > 300 - -vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_mtx, _vec); } -vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_vec, _mtx); } -vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_mtx, _vec); } -vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_vec, _mtx); } - -bvec2 lessThan(vec2 _a, vec2 _b) { return _a < _b; } -bvec3 lessThan(vec3 _a, vec3 _b) { return _a < _b; } -bvec4 lessThan(vec4 _a, vec4 _b) { return _a < _b; } - -bvec2 lessThanEqual(vec2 _a, vec2 _b) { return _a <= _b; } -bvec3 lessThanEqual(vec3 _a, vec3 _b) { return _a <= _b; } -bvec4 lessThanEqual(vec4 _a, vec4 _b) { return _a <= _b; } - -bvec2 greaterThan(vec2 _a, vec2 _b) { return _a > _b; } -bvec3 greaterThan(vec3 _a, vec3 _b) { return _a > _b; } -bvec4 greaterThan(vec4 _a, vec4 _b) { return _a > _b; } - -bvec2 greaterThanEqual(vec2 _a, vec2 _b) { return _a >= _b; } -bvec3 greaterThanEqual(vec3 _a, vec3 _b) { return _a >= _b; } -bvec4 greaterThanEqual(vec4 _a, vec4 _b) { return _a >= _b; } - -bvec2 notEqual(vec2 _a, vec2 _b) { return _a != _b; } -bvec3 notEqual(vec3 _a, vec3 _b) { return _a != _b; } -bvec4 notEqual(vec4 _a, vec4 _b) { return _a != _b; } - -bvec2 equal(vec2 _a, vec2 _b) { return _a == _b; } -bvec3 equal(vec3 _a, vec3 _b) { return _a == _b; } -bvec4 equal(vec4 _a, vec4 _b) { return _a == _b; } - -float mix(float _a, float _b, float _t) { return lerp(_a, _b, _t); } -vec2 mix(vec2 _a, vec2 _b, vec2 _t) { return lerp(_a, _b, _t); } -vec3 mix(vec3 _a, vec3 _b, vec3 _t) { return lerp(_a, _b, _t); } -vec4 mix(vec4 _a, vec4 _b, vec4 _t) { return lerp(_a, _b, _t); } - -float mod(float _a, float _b) { return _a - _b * floor(_a / _b); } -vec2 mod(vec2 _a, vec2 _b) { return _a - _b * floor(_a / _b); } -vec3 mod(vec3 _a, vec3 _b) { return _a - _b * floor(_a / _b); } -vec4 mod(vec4 _a, vec4 _b) { return _a - _b * floor(_a / _b); } - -#else -# define CONST(_x) const _x -# define atan2(_x, _y) atan(_x, _y) -# define mul(_a, _b) ( (_a) * (_b) ) -# define saturate(_x) clamp(_x, 0.0, 1.0) -# define SAMPLER2D(_name, _reg) uniform sampler2D _name -# define SAMPLER2DMS(_name, _reg) uniform sampler2DMS _name -# define SAMPLER3D(_name, _reg) uniform sampler3D _name -# define SAMPLERCUBE(_name, _reg) uniform samplerCube _name -# define SAMPLER2DSHADOW(_name, _reg) uniform sampler2DShadow _name - -# define SAMPLER2DARRAY(_name, _reg) uniform sampler2DArray _name -# define SAMPLER2DMSARRAY(_name, _reg) uniform sampler2DMSArray _name -# define SAMPLERCUBEARRAY(_name, _reg) uniform samplerCubeArray _name -# define SAMPLER2DARRAYSHADOW(_name, _reg) uniform sampler2DArrayShadow _name - -# define ISAMPLER2D(_name, _reg) uniform isampler2D _name -# define USAMPLER2D(_name, _reg) uniform usampler2D _name -# define ISAMPLER3D(_name, _reg) uniform isampler3D _name -# define USAMPLER3D(_name, _reg) uniform usampler3D _name - -# if BGFX_SHADER_LANGUAGE_GLSL >= 130 -# define texture2D(_sampler, _coord) texture(_sampler, _coord) -# define texture2DArray(_sampler, _coord) texture(_sampler, _coord) -# define texture3D(_sampler, _coord) texture(_sampler, _coord) -# define textureCube(_sampler, _coord) texture(_sampler, _coord) -# define texture2DLod(_sampler, _coord, _lod) textureLod(_sampler, _coord, _lod) -# define texture2DLodOffset(_sampler, _coord, _lod, _offset) textureLodOffset(_sampler, _coord, _lod, _offset) -# define texture2DBias(_sampler, _coord, _bias) texture(_sampler, _coord, _bias) -# define textureCubeBias(_sampler, _coord, _bias) texture(_sampler, _coord, _bias) -# else -# define texture2DBias(_sampler, _coord, _bias) texture2D(_sampler, _coord, _bias) -# define textureCubeBias(_sampler, _coord, _bias) textureCube(_sampler, _coord, _bias) -# endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 - -vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_vec, _mtx); } -vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_mtx, _vec); } -vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_vec, _mtx); } -vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_mtx, _vec); } - -float rcp(float _a) { return 1.0/_a; } -vec2 rcp(vec2 _a) { return vec2(1.0)/_a; } -vec3 rcp(vec3 _a) { return vec3(1.0)/_a; } -vec4 rcp(vec4 _a) { return vec4(1.0)/_a; } -#endif // BGFX_SHADER_LANGUAGE_* - -vec2 vec2_splat(float _x) { return vec2(_x, _x); } -vec3 vec3_splat(float _x) { return vec3(_x, _x, _x); } -vec4 vec4_splat(float _x) { return vec4(_x, _x, _x, _x); } - -#if BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL -uvec2 uvec2_splat(uint _x) { return uvec2(_x, _x); } -uvec3 uvec3_splat(uint _x) { return uvec3(_x, _x, _x); } -uvec4 uvec4_splat(uint _x) { return uvec4(_x, _x, _x, _x); } -#endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL - -mat4 mtxFromRows(vec4 _0, vec4 _1, vec4 _2, vec4 _3) -{ -#if BGFX_SHADER_LANGUAGE_GLSL - return transpose(mat4(_0, _1, _2, _3) ); -#else - return mat4(_0, _1, _2, _3); -#endif // BGFX_SHADER_LANGUAGE_GLSL -} -mat4 mtxFromCols(vec4 _0, vec4 _1, vec4 _2, vec4 _3) -{ -#if BGFX_SHADER_LANGUAGE_GLSL - return mat4(_0, _1, _2, _3); -#else - return transpose(mat4(_0, _1, _2, _3) ); -#endif // BGFX_SHADER_LANGUAGE_GLSL -} -mat3 mtxFromRows(vec3 _0, vec3 _1, vec3 _2) -{ -#if BGFX_SHADER_LANGUAGE_GLSL - return transpose(mat3(_0, _1, _2) ); -#else - return mat3(_0, _1, _2); -#endif // BGFX_SHADER_LANGUAGE_GLSL -} -mat3 mtxFromCols(vec3 _0, vec3 _1, vec3 _2) -{ -#if BGFX_SHADER_LANGUAGE_GLSL - return mat3(_0, _1, _2); -#else - return transpose(mat3(_0, _1, _2) ); -#endif // BGFX_SHADER_LANGUAGE_GLSL -} - -#if BGFX_SHADER_LANGUAGE_GLSL -#define mtxFromRows3(_0, _1, _2) transpose(mat3(_0, _1, _2) ) -#define mtxFromRows4(_0, _1, _2, _3) transpose(mat4(_0, _1, _2, _3) ) -#define mtxFromCols3(_0, _1, _2) mat3(_0, _1, _2) -#define mtxFromCols4(_0, _1, _2, _3) mat4(_0, _1, _2, _3) -#else -#define mtxFromRows3(_0, _1, _2) mat3(_0, _1, _2) -#define mtxFromRows4(_0, _1, _2, _3) mat4(_0, _1, _2, _3) -#define mtxFromCols3(_0, _1, _2) transpose(mat3(_0, _1, _2) ) -#define mtxFromCols4(_0, _1, _2, _3) transpose(mat4(_0, _1, _2, _3) ) -#endif // BGFX_SHADER_LANGUAGE_GLSL - -uniform vec4 u_viewRect; -uniform vec4 u_viewTexel; -uniform mat4 u_view; -uniform mat4 u_invView; -uniform mat4 u_proj; -uniform mat4 u_invProj; -uniform mat4 u_viewProj; -uniform mat4 u_invViewProj; -uniform mat4 u_model[BGFX_CONFIG_MAX_BONES]; -uniform mat4 u_modelView; -uniform mat4 u_modelViewProj; -uniform vec4 u_alphaRef4; -#define u_alphaRef u_alphaRef4.x - -#endif // __cplusplus - -#endif // BGFX_SHADER_H_HEADER_GUARD diff --git a/shaders/defs/varying.def.sc b/shaders/defs/varying.def.sc deleted file mode 100755 index 71c5db31..00000000 --- a/shaders/defs/varying.def.sc +++ /dev/null @@ -1,7 +0,0 @@ -vec3 a_position : POSITION; -vec3 a_normal : NORMAL; -vec2 a_texcoord0 : TEXCOORD0; - -vec3 v_position : POSITION0; -vec3 v_normal : NORMAL; -vec2 v_texcoord0 : TEXCOORD0; \ No newline at end of file diff --git a/shaders/fs_default.sc b/shaders/fs_default.sc deleted file mode 100755 index 00208571..00000000 --- a/shaders/fs_default.sc +++ /dev/null @@ -1,107 +0,0 @@ -$input v_position, v_normal, v_texcoord0 - -#include - -uniform sampler2D material_texture_diffuse; -uniform sampler2D material_texture_specular; -uniform sampler2D material_emission; -uniform vec4 material_shininess; // float -uniform vec4 material_color; -uniform vec4 material_specular; // float - -uniform vec4 dir_light_direction; // vec3 -uniform vec4 dir_light_ambient; -uniform vec4 dir_light_diffuse; -uniform vec4 dir_light_specular; - -#define MAX_NB_POINT_LIGHTS 20 -uniform vec4 point_light_position[MAX_NB_POINT_LIGHTS]; // vec3 -uniform vec4 point_light_ambient[MAX_NB_POINT_LIGHTS]; -uniform vec4 point_light_diffuse[MAX_NB_POINT_LIGHTS]; -uniform vec4 point_light_specular[MAX_NB_POINT_LIGHTS]; -uniform vec4 point_light_attenuation[MAX_NB_POINT_LIGHTS]; // vec3 -uniform vec4 nb_point_light; // float - -uniform vec4 view_position; // vec3 - -#define GAMMA 2.2f - -vec4 CalcDirLight(vec3 light_direction, vec4 light_ambient, - vec4 light_diffuse, vec4 light_specular, - vec3 normal, vec3 view_dir, vec2 texcoord0); -vec4 CalcPointLight(vec3 light_position, vec4 light_ambient, - vec4 light_diffuse, vec4 light_specular, - vec3 light_attenuation, - vec3 frag_pose, vec3 normal, vec3 view_dir, vec2 texcoord0); - -void main() -{ - // properties - vec3 norm = normalize(v_normal); - vec3 view_dir = normalize(view_position.xyz - v_position); - - // phase 1: Directional lighting - vec4 result = CalcDirLight(dir_light_direction.xyz, dir_light_ambient, - dir_light_diffuse, dir_light_specular, - norm, view_dir, v_texcoord0); - // phase 2: Point lights - for(int i = 0; i < int(nb_point_light.x); i++) - result += CalcPointLight(point_light_position[i].xyz, point_light_ambient[i], - point_light_diffuse[i], point_light_specular[i], - point_light_attenuation[i].xyz, - v_position, norm, view_dir, v_texcoord0); - - gl_FragColor = result; - gl_FragColor.rgb = pow(result.rgb, vec3(1.0f/GAMMA)); -} - -vec4 CalcDirLight(vec3 light_direction, vec4 light_ambient, - vec4 light_diffuse, vec4 light_specular, - vec3 normal, vec3 view_dir, vec2 texcoord0) -{ - vec3 light_dir = normalize(-light_direction.xyz); - vec3 halfway_dir = normalize(light_dir + view_dir); - // diffuse shading - float diff = max(dot(normal, light_dir), 0.0); - // specular shading - float spec = pow(max(dot(view_dir, halfway_dir), 0.0), material_shininess.x); - // combine results - vec4 ambient = light_ambient * texture2D(material_texture_diffuse, texcoord0) * material_color; - vec4 diffuse = light_diffuse * diff * texture2D(material_texture_diffuse, texcoord0); - vec4 specular = vec4(0.f); - if(material_specular.x >= 0.f) - specular = light_specular * spec * vec4(material_specular.x); - else - specular = light_specular * spec * vec4(texture2D(material_texture_specular, texcoord0).r); - return (ambient + diffuse + specular); -} - -vec4 CalcPointLight(vec3 light_position, vec4 light_ambient, - vec4 light_diffuse, vec4 light_specular, - vec3 light_attenuation, - vec3 frag_pose, vec3 normal, vec3 view_dir, vec2 texcoord0) -{ - vec3 light_dir = normalize(light_position - frag_pose); - vec3 halfway_dir = normalize(light_dir + view_dir); - // diffuse shading - float diff = max(dot(normal, light_dir), 0.0); - // specular shading - float spec = pow(max(dot(view_dir, halfway_dir), 0.0), material_shininess.x); - // attenuation - float distance = length(light_position - frag_pose); - float attenuation = 1.0 / (light_attenuation.x + light_attenuation.y * distance + - light_attenuation.z * (distance * distance)); - // combine results - vec4 ambient = light_ambient * texture2D(material_texture_diffuse, texcoord0); - vec4 diffuse = light_diffuse * diff * texture2D(material_texture_diffuse, texcoord0); - vec4 specular = vec4(0.f); - if(material_specular.x >= 0.f) - specular = light_specular * spec * vec4(material_specular.x); - else - specular = light_specular * spec * vec4(texture2D(material_texture_specular, texcoord0).r); - - ambient *= attenuation; - diffuse *= attenuation; - specular *= attenuation; - return (ambient + diffuse + specular); -} \ No newline at end of file diff --git a/shaders/fs_simple_shadows.sc b/shaders/fs_simple_shadows.sc deleted file mode 100644 index 324d68e9..00000000 --- a/shaders/fs_simple_shadows.sc +++ /dev/null @@ -1,5 +0,0 @@ -#include - -void main() -{ -} diff --git a/shaders/fs_skybox.sc b/shaders/fs_skybox.sc deleted file mode 100644 index 5f82b43b..00000000 --- a/shaders/fs_skybox.sc +++ /dev/null @@ -1,10 +0,0 @@ -$input v_position - -#include - -uniform samplerCube cube_texture; - -void main() -{ - gl_FragColor = textureCube(cube_texture, v_position);; -} diff --git a/shaders/vs_default.sc b/shaders/vs_default.sc deleted file mode 100755 index 7e45c5a7..00000000 --- a/shaders/vs_default.sc +++ /dev/null @@ -1,13 +0,0 @@ -$input a_position, a_normal, a_texcoord0 -$output v_position, v_normal, v_texcoord0 - -#include - -void main() -{ - v_position = vec3(u_model[0] * vec4(a_position, 1.0)); - v_normal = a_normal; - v_texcoord0 = a_texcoord0; - - gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0)); -} \ No newline at end of file diff --git a/shaders/vs_simple_shadows.sc b/shaders/vs_simple_shadows.sc deleted file mode 100644 index feab03f1..00000000 --- a/shaders/vs_simple_shadows.sc +++ /dev/null @@ -1,8 +0,0 @@ -$input a_position - -#include - -void main() -{ - gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0)); -} \ No newline at end of file diff --git a/shaders/vs_skybox.sc b/shaders/vs_skybox.sc deleted file mode 100644 index 403e2fa5..00000000 --- a/shaders/vs_skybox.sc +++ /dev/null @@ -1,10 +0,0 @@ -$input a_position -$output v_position - -#include - -void main() -{ - v_position = a_position; - gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0)); -} \ No newline at end of file diff --git a/src/Graphics/BGFX/Camera.cpp b/src/Graphics/BGFX/Camera.cpp deleted file mode 100755 index c0a6410f..00000000 --- a/src/Graphics/BGFX/Camera.cpp +++ /dev/null @@ -1,274 +0,0 @@ -#include "overworld/Graphics/BGFX/Camera.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "overworld/Engine/Common/Models/Color.h" -#include "overworld/Graphics/BGFX/API.h" -#include "overworld/Graphics/Base/CameraProjection.h" -#include "overworld/Graphics/Base/CameraView.h" -#include "overworld/Graphics/Base/ViewAntiAliasing.h" -#include "overworld/Helper/BitCast.h" -#include "overworld/Helper/GlmMath.h" - -namespace owds::bgfx { - - void Camera::updateViewMatrix() - { - view_matrix_ = FromM4(glm::lookAt( - world_eye_position_, - world_eye_position_ + world_eye_front_, - world_eye_up_)); - - ::bgfx::setViewTransform(id_, view_matrix_.data(), proj_matrix_.data()); - } - - void Camera::updateProjectionMatrix() - { - // todo: check if everything is setup correctly - switch(projection_type_) - { - case owds::CameraProjection_e::perspective: - { - constexpr auto near = 0.1f; - constexpr auto far = 100.f; - const auto aspect_ratio = view_dimensions_[0] / view_dimensions_[1]; - - if(::bgfx::getCaps()->homogeneousDepth) - { - proj_matrix_ = FromM4(glm::perspectiveLH_NO(field_of_view_, aspect_ratio, near, far)); - } - else - { - proj_matrix_ = FromM4(glm::perspectiveLH_ZO(field_of_view_, aspect_ratio, near, far)); - } - break; - } - case owds::CameraProjection_e::orthographic: - { - if(::bgfx::getCaps()->homogeneousDepth) - { - proj_matrix_ = FromM4(glm::orthoLH_NO(0, 0, view_dimensions_[0], view_dimensions_[1], -1000.0f, 1000.0f)); - } - else - { - proj_matrix_ = FromM4(glm::orthoLH_ZO(0, 0, view_dimensions_[0], view_dimensions_[1], -1000.0f, 1000.0f)); - } - break; - } - } - - ::bgfx::setViewTransform(id_, view_matrix_.data(), proj_matrix_.data()); - } - - void Camera::updateMatrices() - { - updateViewMatrix(); - updateProjectionMatrix(); - } - - void Camera::setCameraView(const owds::CameraView_e view_type) - { - view_type_ = view_type; - } - - void Camera::setProjection(const owds::CameraProjection_e proj) - { - projection_type_ = proj; - } - - void Camera::setFieldOfView(const float fov) - { - field_of_view_ = glm::radians(fov); - } - - void Camera::setOutputAA(const owds::ViewAntiAliasing_e aa_setting) - { - (void)aa_setting; // todo - } - - void Camera::setOutputFPS(const std::uint64_t desired_target_fps) - { - (void)desired_target_fps; // todo - } - - void Camera::setOutputResolution(const std::array& resolution) - { - view_dimensions_[0] = resolution[0]; - view_dimensions_[1] = resolution[1]; - ::bgfx::setViewRect(id_, 0, 0, static_cast(view_dimensions_[0]), static_cast(view_dimensions_[1])); - } - - void Camera::setOutputClearColor(const owds::Color clear_color) - { - (void)clear_color; - //::bgfx::setViewClear(id_, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, owds::BitCast(clear_color), 1.0f, 0); - } - - void Camera::setCaptureCallback(std::function&)> callback) - { - (void)callback; // todo - } - - void Camera::finalize() - { - recomputeDirectionVector(); - updateMatrices(); - } - - void Camera::setPositionAndOrientation(const std::array& position, const std::array& orientation) - { - // to verify - world_eye_position_ = ToV3(position); - view_angles_.x = orientation[2]; // yaw - view_angles_.y = orientation[1]; // pitch - recomputeDirectionVector(); - } - - void Camera::setPositionAndLookAt(const std::array& eye_position, const std::array& dst_position) - { - world_eye_position_ = ToV3(eye_position); - world_eye_front_ = ToV3(dst_position) - world_eye_position_; - - const auto xy = glm::sqrt(glm::pow(world_eye_front_.x, 2) + glm::pow(world_eye_front_.y, 2)); - - view_angles_.x = glm::degrees(glm::atan(world_eye_front_.y, world_eye_front_.x)); - view_angles_.y = glm::degrees(glm::atan(world_eye_front_.z, static_cast(xy))); - - recomputeDirectionVector(); - updateViewMatrix(); - } - - void Camera::recomputeDirectionVector() - { - glm::vec3 world_up(0.0f, 0.0f, 1.0f); - - glm::vec3 front; - front.x = cos(glm::radians(view_angles_.x)) * cos(glm::radians(view_angles_.y)); - front.y = sin(glm::radians(view_angles_.x)) * cos(glm::radians(view_angles_.y)); - front.z = sin(glm::radians(view_angles_.y)); - - world_eye_front_ = glm::normalize(front); - world_eye_right_ = glm::normalize(glm::cross(world_eye_front_, world_up)); // normalize the vectors, because their length gets closer to 0 the more you look up or down which results in slower movement. - world_eye_up_ = glm::normalize(glm::cross(world_eye_right_, world_eye_front_)); - } - - void Camera::processUserKeyboardInput(const float delta_time, const int key, const bool is_down) - { - switch(key) - { - case GLFW_KEY_F1: show_debug_stats_ = is_down; break; - case GLFW_KEY_F2: render_collision_models_ = is_down; break; - case GLFW_KEY_W: - case GLFW_KEY_UP: key_state_front_ = is_down; break; - case GLFW_KEY_S: - case GLFW_KEY_DOWN: key_state_back_ = is_down; break; - case GLFW_KEY_A: - case GLFW_KEY_LEFT: key_state_left_ = is_down; break; - case GLFW_KEY_D: - case GLFW_KEY_RIGHT: key_state_right_ = is_down; break; - case GLFW_KEY_SPACE: key_state_up_ = is_down; break; - case GLFW_KEY_LEFT_SHIFT: key_state_down_ = is_down; break; - } - - (void)delta_time; - (void)key; - (void)is_down; - } - - void Camera::processUserMouseBtnInput(const float delta_time, const char btn, const bool is_down) - { - mouse_btn_states_.set(btn, is_down); - - switch(btn) - { - case 1: // right - { - if(is_down) - { - mouse_drag_start_position_ = mouse_current_position_; - } - - is_dragging_mouse_ = is_down; - break; - } - case 2: // middle - { - if(is_down) - { - mouse_drag_start_position_ = mouse_current_position_; - } - - is_dragging_mouse_ = is_down; - break; - } - default:; - } - - (void)delta_time; - (void)btn; - (void)is_down; - } - - void Camera::processUserMouseInput(const float delta_time, const float x, const float y) - { - (void)delta_time; - mouse_current_position_ = {x, y}; - - if(mouse_btn_states_[1]) - { - const auto delta = (mouse_current_position_ - mouse_drag_start_position_) * mouse_rotation_sensitivity_; - mouse_drag_start_position_ = mouse_current_position_; - - view_angles_.x += delta.x; // yaw - view_angles_.y -= delta.y; // pitch - - if(view_angles_.y > 89.0f) - view_angles_.y = 89.0f; - if(view_angles_.y < -89.0f) - view_angles_.y = -89.0f; - - recomputeDirectionVector(); - } - else if(mouse_btn_states_[2]) - { - const auto delta = (mouse_current_position_ - mouse_drag_start_position_) * (mouse_translate_sensitivity_ * 0.5f); - mouse_drag_start_position_ = mouse_current_position_; - - world_eye_position_ -= world_eye_right_ * delta.x; - world_eye_position_ += world_eye_up_ * delta.y; - - recomputeDirectionVector(); - } - } - - void Camera::processUserMouseScroll(float delta_time, float xoffset, float yoffset) - { - (void)delta_time; - (void)xoffset; - world_eye_position_ += world_eye_front_ * (yoffset * mouse_scroll_sensitivity_); - } - - void Camera::update() - { - if(key_state_front_) - world_eye_position_ += world_eye_front_ * 0.1f; - if(key_state_back_) - world_eye_position_ -= world_eye_front_ * 0.1f; - if(key_state_right_) - world_eye_position_ += world_eye_right_ * 0.1f; - if(key_state_left_) - world_eye_position_ -= world_eye_right_ * 0.1f; - if(key_state_up_) - world_eye_position_ += world_eye_up_ * 0.1f; - if(key_state_down_) - world_eye_position_ -= world_eye_up_ * 0.1f; - } - -} // namespace owds::bgfx \ No newline at end of file diff --git a/src/Graphics/BGFX/Renderer.cpp b/src/Graphics/BGFX/Renderer.cpp deleted file mode 100755 index 24048021..00000000 --- a/src/Graphics/BGFX/Renderer.cpp +++ /dev/null @@ -1,519 +0,0 @@ -#include "overworld/Graphics/BGFX/Renderer.h" - -#include -#include -#include -#include -#include -#include - -#include "overworld/Engine/Common/Models/Model.h" -#include "overworld/Engine/Common/Urdf/Actor.h" -#include "overworld/Engine/Common/World.h" -#include "overworld/Graphics/BGFX/Camera.h" -#include "overworld/Graphics/BGFX/Vertex.h" -#include "overworld/Graphics/Base/Window.h" -#include "overworld/Helper/GlmMath.h" - -#define STB_IMAGE_IMPLEMENTATION -#include "stb_image.h" - -#define RENDER_SHADOW_PASS_ID 1 -#define RENDER_SCENE_PASS_ID 0 - -namespace owds::bgfx { - - Renderer::Renderer() : shadows_renderer_(RENDER_SHADOW_PASS_ID) - {} - - Renderer::~Renderer() - { - delete ctx_.render_camera_; - } - - ::bgfx::VertexBufferHandle test_vbh; - ::bgfx::IndexBufferHandle test_ibh; - - bool Renderer::initialize(const owds::Window& window) - { - const auto data = window.getPlatformData(); - - ::bgfx::PlatformData pd; - pd.ndt = data.native_display_type_; - pd.nwh = data.native_window_handle_; - - ::bgfx::Init init; - init.type = ::bgfx::RendererType::OpenGL; - init.resolution.width = ctx_.width_; - init.resolution.height = ctx_.height_; - init.resolution.reset = ctx_.flags_; - init.vendorId = BGFX_PCI_ID_NONE; - init.platformData = pd; - - if(!::bgfx::init(init)) - { - return false; - } - - // const auto caps = ::bgfx::getCaps(); - // ctx_.instanced_rendering_supported = caps->supported & BGFX_CAPS_INSTANCING; - - ::bgfx::setViewClear(RENDER_SCENE_PASS_ID, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x443355FF, 1.0f, 0); - - ctx_.shaders_.emplace(std::piecewise_construct, std::make_tuple("default"), std::make_tuple("vs_default", "fs_default")); - ctx_.shaders_.emplace(std::piecewise_construct, std::make_tuple("skybox"), std::make_tuple("vs_skybox", "fs_skybox")); - ctx_.shaders_.emplace(std::piecewise_construct, std::make_tuple("simple_shadows"), std::make_tuple("vs_simple_shadows", "fs_simple_shadows")); - ctx_.is_initialized_ = true; - ctx_.render_camera_ = new owds::bgfx::Camera(); - ctx_.render_camera_->setViewId(RENDER_SCENE_PASS_ID); - - shadows_renderer_.initialize(); - - initMaterialUniforms(); - initLightUniforms(); - - ctx_.loaded_uniforms_["view_position"] = ::bgfx::createUniform("view_position", ::bgfx::UniformType::Vec4); - - static owds::Color white_pixel{255, 255, 255, 255}; - - ctx_.white_tex_ = ::bgfx::createTexture2D( - 1, - 1, - false, - 1, - ::bgfx::TextureFormat::RGBA8, - 0, - ::bgfx::makeRef(&white_pixel, sizeof white_pixel)); - - return true; - } - - void Renderer::cleanup() - { - ::bgfx::shutdown(); - } - - void Renderer::notifyPreReset() - { - // todo - } - - void Renderer::notifyPostReset() - { - // todo - } - - void Renderer::notifyResize(const std::uint32_t new_width, const std::uint32_t new_height) - { - ctx_.width_ = new_width; - ctx_.height_ = new_height; - ctx_.has_size_changed_ = true; - } - - void Renderer::runSanityChecks() - { - // todo: add some checks - } - - void Renderer::commit() - { - if(ctx_.has_size_changed_) - { - ctx_.has_size_changed_ = false; - ::bgfx::reset(ctx_.width_, ctx_.height_, ctx_.flags_); - } - - for(auto& [id, batch] : ctx_.current_mesh_batches_) - { - batch.clear(); - } - - commitWorld(*(ctx_.world_)); - - ctx_.render_camera_->setOutputResolution({static_cast(ctx_.width_), static_cast(ctx_.height_)}); - ctx_.render_camera_->updateMatrices(); - commitCamera(*ctx_.render_camera_); - // commitShadows(); - - for(const auto& camera : ctx_.cameras_) - { - commitCamera(*camera); - } - - ::bgfx::frame(); - } - - void Renderer::attachWorld(World& world) - { - ctx_.world_ = std::addressof(world); - } - - owds::Camera& Renderer::createCamera(const std::string& alias_name) - { - assert(ctx_.is_initialized_ && "The renderer must be initialized before creating a camera"); - - const auto& camera = ctx_.cameras_.emplace_back(std::make_unique()); - - ctx_.camera_refs_.emplace_back(*camera); - - if(!alias_name.empty()) - { - ctx_.named_cameras_.emplace(alias_name, std::ref(*camera)); - } - - return *camera; - } - - std::vector> Renderer::getCameras() - { - return ctx_.camera_refs_; - } - - owds::Camera* Renderer::getRenderCamera() - { - return ctx_.render_camera_; - } - - void Renderer::commitCamera(const owds::bgfx::Camera& camera) - { - constexpr auto state = 0 | - BGFX_STATE_WRITE_RGB | - BGFX_STATE_WRITE_A | - BGFX_STATE_WRITE_Z | - BGFX_STATE_DEPTH_TEST_LESS | - BGFX_STATE_CULL_CCW; // | - // BGFX_STATE_MSAA; - - ::bgfx::setDebug(camera.show_debug_stats_ ? BGFX_DEBUG_STATS : 0); - - ctx_.render_collision_models_ = camera.render_collision_models_; - - ::bgfx::touch(0); // Submit an empty primitive for rendering. Uniforms and draw state will be applied but no geometry will be submitted. - if(ctx_.instanced_rendering_supported) - { - renderInstanced(state); - } - else - { - render(state, camera); - } - } - - void Renderer::commitShadows() - { - auto state = shadows_renderer_.state_; - - ::bgfx::setDebug(shadows_renderer_.camera_.show_debug_stats_ ? BGFX_DEBUG_STATS : 0); - - ctx_.render_collision_models_ = shadows_renderer_.camera_.render_collision_models_; - - ::bgfx::touch(0); // Submit an empty primitive for rendering. Uniforms and draw state will be applied but no geometry will be submitted. - if(ctx_.instanced_rendering_supported) - { - renderInstanced(state); - } - else - { - render(state, shadows_renderer_.camera_, "simple_shadows"); - } - } - - void Renderer::commitWorld(const owds::World& world) - { - for(const auto& actor : world.getActors()) - { - if(ctx_.render_collision_models_) - { - std::visit([this, &actor](const auto& shape_resolv) { queueActorBatch(actor, shape_resolv); }, actor.get().collision_shape_); - } - else - { - for(const auto& shape : actor.get().visual_shapes_) - { - std::visit([this, &actor](const auto& shape_resolv) { queueActorBatch(actor, shape_resolv); }, shape); - } - } - } - } - - void Renderer::queueActorBatch(const owds::Actor& actor, const owds::ShapeBox& shape) - { - const auto size_mat = glm::scale(glm::mat4(1.f), ToV3(shape.half_extents_)); - const auto model_mat = ToM4(actor.getModelMatrix()) * size_mat; - - queueModelBatch(shape.box_model_, {"", shape.diffuse_color_, shape.diffuse_color_, 0., "", "", ""}, FromM4(model_mat)); - } - - void Renderer::queueActorBatch(const owds::Actor& actor, const owds::ShapeCapsule& shape) - { - (void)actor; // todo - (void)shape; // todo - } - - void Renderer::queueActorBatch(const owds::Actor& actor, const owds::ShapeCustomMesh& shape) - { - const auto size_mat = glm::scale(glm::mat4(1.f), shape.scale_); - const auto model_mat = ToM4(actor.getModelMatrix()) * size_mat; - - queueModelBatch(shape.custom_model_, shape.material_, FromM4(model_mat)); - } - - void Renderer::queueActorBatch(const owds::Actor& actor, const owds::ShapeCylinder& shape) - { - const auto size_mat = glm::scale(glm::mat4(1.f), glm::vec3(shape.radius_, shape.height_, shape.radius_)); - const auto model_mat = ToM4(actor.getModelMatrix()) * size_mat; - - queueModelBatch(shape.cylinder_model_, {"", shape.diffuse_color_, shape.diffuse_color_, 0., "", "", ""}, FromM4(model_mat)); - } - - void Renderer::queueActorBatch(const owds::Actor& actor, const owds::ShapeDummy& shape) - { - (void)actor; - (void)shape; - } - - void Renderer::queueActorBatch(const owds::Actor& actor, const owds::ShapeSphere& shape) - { - (void)actor; // todo - (void)shape; // todo - } - - void Renderer::loadModel(const owds::Model& model, const owds::Material& material) - { - if(model.meshes_.empty()) - return; - - auto model_it = ctx_.cached_models_.find(model.id_); - if(model_it != ctx_.cached_models_.end()) - return; - - model_it = ctx_.cached_models_.insert({model.id_, {}}).first; - - // Colors - model_it->second.diffuse_color_ = material.diffuse_color_; - model_it->second.shininess_ = 64.f; // TODO take from material - model_it->second.specular_ = 0.1f; // TODO take from material - - // Material - if(material.diffuse_texture_.empty() == false) - { - auto text_it = ctx_.loaded_textures_.find(material.diffuse_texture_); - if(text_it == ctx_.loaded_textures_.end()) - { - model_it->second.tex_diffuse_ = loadTexture(material.diffuse_texture_, BGFX_TEXTURE_SRGB); - ctx_.loaded_textures_[material.diffuse_texture_] = model_it->second.tex_diffuse_; - } - else - model_it->second.tex_diffuse_ = text_it->second; - } - else - model_it->second.tex_diffuse_ = ctx_.white_tex_; - - // Meshes - for(const auto& mesh : model.meshes_) - { - auto mesh_it = ctx_.loaded_meshes_.find(mesh.id_); - if(mesh_it == ctx_.loaded_meshes_.end()) - { - mesh_it = ctx_.loaded_meshes_.emplace(mesh.id_, owds::bgfx::MeshHandle{ - ::bgfx::createVertexBuffer(::bgfx::makeRef(mesh.vertices_.data(), - mesh.vertices_.size() * sizeof(mesh.vertices_[0])), - Vertex::getMSLayout()), - ::bgfx::createIndexBuffer(::bgfx::makeRef(mesh.indices_.data(), - mesh.indices_.size() * sizeof(mesh.indices_[0])), - BGFX_BUFFER_INDEX32)}) - .first; - } - - model_it->second.meshes_.emplace(mesh.id_, mesh_it->second); - } - } - - void Renderer::queueModelBatch(const owds::Model& model, const owds::Material& material, const std::array& model_mat) - { - loadModel(model, material); - - for(auto& mesh : model.meshes_) - ctx_.current_mesh_batches_[model.id_][mesh.id_].emplace_back(owds::InstanceData{model_mat, {}}); // TODO add instance data ? - } - - void Renderer::render(const std::uint64_t state, const owds::bgfx::Camera& camera, const std::string& shader) - { - srand(0); - - setLightUniforms(ctx_.world_); - - auto view_position = glm::vec4(camera.getPosition(), 0.0f); - ::bgfx::setUniform(ctx_.loaded_uniforms_["view_position"], glm::value_ptr(view_position)); - - for(auto& [model_id, batch] : ctx_.current_mesh_batches_) - { - auto& model = ctx_.cached_models_[model_id]; - setMaterialUniforms(model); - - for(auto& [mesh_id, transforms] : batch) - { - const auto& mesh = model.meshes_[mesh_id]; - - for(const auto& transform : transforms) - { - ::bgfx::setTransform(transform.mvp_.data(), 1); - - ::bgfx::setVertexBuffer(0, mesh.vbh_); - ::bgfx::setIndexBuffer(mesh.ibh_); - - ::bgfx::setState(state); - ctx_.shaders_.at(shader).submit(0); - } - } - } - } - - void Renderer::renderInstanced(const std::uint64_t state) - { - for(auto& [model_id, batch] : ctx_.current_mesh_batches_) - { - auto& model = ctx_.cached_models_[model_id]; - setMaterialUniforms(model); - - for(auto& [mesh_id, transforms] : batch) - { - const auto& mesh = model.meshes_[mesh_id]; - - ::bgfx::InstanceDataBuffer idb{}; - ::bgfx::allocInstanceDataBuffer(&idb, transforms.size(), sizeof(transforms[0])); - - std::memcpy(idb.data, transforms.data(), transforms.size() * sizeof(transforms[0])); - - ::bgfx::setVertexBuffer(0, mesh.vbh_); - ::bgfx::setIndexBuffer(mesh.ibh_); - - ::bgfx::setInstanceDataBuffer(&idb); - - ::bgfx::setState(state); - ctx_.shaders_.at("default").submit(0); - } - } - } - - void Renderer::initLightUniforms() - { - ctx_.loaded_uniforms_["dir_light_direction"] = ::bgfx::createUniform("dir_light_direction", ::bgfx::UniformType::Vec4); - ctx_.loaded_uniforms_["dir_light_ambient"] = ::bgfx::createUniform("dir_light_ambient", ::bgfx::UniformType::Vec4); - ctx_.loaded_uniforms_["dir_light_diffuse"] = ::bgfx::createUniform("dir_light_diffuse", ::bgfx::UniformType::Vec4); - ctx_.loaded_uniforms_["dir_light_specular"] = ::bgfx::createUniform("dir_light_specular", ::bgfx::UniformType::Vec4); - - ctx_.loaded_uniforms_["point_light_position"] = ::bgfx::createUniform("point_light_position", ::bgfx::UniformType::Vec4, PointLights::MAX_POINT_LIGHTS); - ctx_.loaded_uniforms_["point_light_ambient"] = ::bgfx::createUniform("point_light_ambient", ::bgfx::UniformType::Vec4, PointLights::MAX_POINT_LIGHTS); - ctx_.loaded_uniforms_["point_light_diffuse"] = ::bgfx::createUniform("point_light_diffuse", ::bgfx::UniformType::Vec4, PointLights::MAX_POINT_LIGHTS); - ctx_.loaded_uniforms_["point_light_specular"] = ::bgfx::createUniform("point_light_specular", ::bgfx::UniformType::Vec4, PointLights::MAX_POINT_LIGHTS); - ctx_.loaded_uniforms_["point_light_attenuation"] = ::bgfx::createUniform("point_light_attenuation", ::bgfx::UniformType::Vec4, PointLights::MAX_POINT_LIGHTS); - ctx_.loaded_uniforms_["nb_point_light"] = ::bgfx::createUniform("nb_point_light", ::bgfx::UniformType::Vec4); - } - - void Renderer::setLightUniforms(World* world) - { - if(world == nullptr) - return; - - ::bgfx::setUniform(ctx_.loaded_uniforms_["dir_light_ambient"], glm::value_ptr(getAmbientLight(world).getAmbient())); - ::bgfx::setUniform(ctx_.loaded_uniforms_["dir_light_diffuse"], glm::value_ptr(getAmbientLight(world).getDiffuse())); - ::bgfx::setUniform(ctx_.loaded_uniforms_["dir_light_specular"], glm::value_ptr(getAmbientLight(world).getSpecular())); - ::bgfx::setUniform(ctx_.loaded_uniforms_["dir_light_direction"], glm::value_ptr(getAmbientLight(world).getDirection())); - - ::bgfx::setUniform(ctx_.loaded_uniforms_["point_light_ambient"], glm::value_ptr(getPointLights(world).getAmbients().at(0)), PointLights::MAX_POINT_LIGHTS); - ::bgfx::setUniform(ctx_.loaded_uniforms_["point_light_diffuse"], glm::value_ptr(getPointLights(world).getDiffuses().at(0)), PointLights::MAX_POINT_LIGHTS); - ::bgfx::setUniform(ctx_.loaded_uniforms_["point_light_specular"], glm::value_ptr(getPointLights(world).getSpeculars().at(0)), PointLights::MAX_POINT_LIGHTS); - ::bgfx::setUniform(ctx_.loaded_uniforms_["point_light_position"], glm::value_ptr(getPointLights(world).getPositions().at(0)), PointLights::MAX_POINT_LIGHTS); - ::bgfx::setUniform(ctx_.loaded_uniforms_["point_light_attenuation"], glm::value_ptr(getPointLights(world).getAttenuations().at(0)), PointLights::MAX_POINT_LIGHTS); - ::bgfx::setUniform(ctx_.loaded_uniforms_["nb_point_light"], glm::value_ptr(getPointLights(world).getNbLights())); - } - - void Renderer::initMaterialUniforms() - { - ctx_.loaded_uniforms_["material_texture_diffuse"] = ::bgfx::createUniform("material_texture_diffuse", ::bgfx::UniformType::Sampler); - ctx_.loaded_uniforms_["material_texture_specular"] = ::bgfx::createUniform("material_texture_specular", ::bgfx::UniformType::Sampler); - ctx_.loaded_uniforms_["material_color"] = ::bgfx::createUniform("material_color", ::bgfx::UniformType::Vec4); - ctx_.loaded_uniforms_["material_shininess"] = ::bgfx::createUniform("material_shininess", ::bgfx::UniformType::Vec4); - ctx_.loaded_uniforms_["material_specular"] = ::bgfx::createUniform("material_specular", ::bgfx::UniformType::Vec4); - } - - void Renderer::setMaterialUniforms(const owds::bgfx::ModelHandle& model) - { - ::bgfx::setTexture(0, ctx_.loaded_uniforms_["material_texture_diffuse"], model.tex_diffuse_); - auto material_shininess = glm::vec4(model.shininess_, 0.f, 0.f, 0.f); - ::bgfx::setUniform(ctx_.loaded_uniforms_["material_shininess"], glm::value_ptr(material_shininess)); - auto material_specular = glm::vec4(model.specular_, 0.f, 0.f, 0.f); - ::bgfx::setUniform(ctx_.loaded_uniforms_["material_specular"], glm::value_ptr(material_specular)); - auto material_color = glm::vec4(model.diffuse_color_.r_, - model.diffuse_color_.g_, - model.diffuse_color_.b_, - model.diffuse_color_.a_); - ::bgfx::setUniform(ctx_.loaded_uniforms_["material_color"], glm::value_ptr(material_color)); - } - - ::bgfx::TextureHandle Renderer::loadTexture(const std::string& file_name, - uint64_t flags, - ::bgfx::TextureInfo* texture_info, - bool flip, - bool cube_map) - { - // flag BGFX_TEXTURE_SRGB - ::bgfx::TextureHandle handle; - - int width = 0, height = 0, channels = 0; - stbi_set_flip_vertically_on_load(flip); - unsigned char* data = stbi_load(file_name.c_str(), &width, &height, &channels, 0); - - if(data != nullptr) - { - const ::bgfx::Memory* mem = ::bgfx::makeRef(data, width * height * channels, [](void* ptr, void* user_data) { - (void)user_data; - stbi_image_free(ptr); - }); - - ::bgfx::TextureFormat::Enum format; - if(channels == 1) - format = ::bgfx::TextureFormat::R8; - else if(channels == 3) - format = ::bgfx::TextureFormat::RGB8; - else if(channels == 4) - format = ::bgfx::TextureFormat::RGBA8; - - if(texture_info != nullptr) - { - ::bgfx::calcTextureSize(*texture_info, - uint16_t(width), - uint16_t(height), - uint16_t(0), // depth - cube_map, - false, // umMips > 1 - 1, // num layers - format); - } - - if(cube_map) - { - handle = ::bgfx::createTextureCube(uint16_t(width), - false, // umMips > 1 - channels, format, - flags, mem); - } - else if(::bgfx::isTextureValid(0, false, channels, format, flags)) - { - handle = ::bgfx::createTexture2D(uint16_t(width), - uint16_t(height), - false, // umMips > 1 - 1, // num layers - format, - flags, mem); - } - - if(::bgfx::isValid(handle)) - ::bgfx::setName(handle, file_name.c_str(), file_name.size()); - } - - return handle; - } - -} // namespace owds::bgfx \ No newline at end of file diff --git a/src/Graphics/BGFX/ShadowsRenderer.cpp b/src/Graphics/BGFX/ShadowsRenderer.cpp deleted file mode 100644 index 36f14b58..00000000 --- a/src/Graphics/BGFX/ShadowsRenderer.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "overworld/Graphics/BGFX/ShadowsRenderer.h" - -namespace owds::bgfx { - - ShadowsRenderer::ShadowsRenderer(::bgfx::ViewId view_id) : shadow_map_size_(512), - view_id_(view_id) - - { - state_ = BGFX_STATE_WRITE_Z | - BGFX_STATE_DEPTH_TEST_LESS | - BGFX_STATE_CULL_CCW | - BGFX_STATE_MSAA; - } - - bool ShadowsRenderer::initialize() - { - ::bgfx::TextureHandle textures[] = - { - ::bgfx::createTexture2D( - shadow_map_size_, shadow_map_size_, false, 1, ::bgfx::TextureFormat::D16, BGFX_TEXTURE_RT | BGFX_SAMPLER_COMPARE_LEQUAL), - }; - - texture_handle_ = textures[0]; - frame_buffer_ = ::bgfx::createFrameBuffer(1, textures, true); - - camera_.setViewId(view_id_); - camera_.setCameraView(owds::CameraView_e::segmented_view); - camera_.setProjection(owds::CameraProjection_e::orthographic); - camera_.setFieldOfView(80.f); - camera_.setOutputResolution({(float)shadow_map_size_, (float)shadow_map_size_}); - camera_.finalize(); - - ::bgfx::setViewFrameBuffer(view_id_, frame_buffer_); - ::bgfx::setViewClear(view_id_, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x303030ff, 1.0f, 0); - - return true; - } - -} // namespace owds::bgfx \ No newline at end of file diff --git a/src/Graphics/BGFX/Vertex.cpp b/src/Graphics/BGFX/Vertex.cpp deleted file mode 100755 index 9dc8f274..00000000 --- a/src/Graphics/BGFX/Vertex.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "overworld/Graphics/BGFX/Vertex.h" - -namespace owds::bgfx { - ::bgfx::VertexLayout Vertex::getMSLayout() - { - static ::bgfx::VertexLayout ms_layout = []() { - ::bgfx::VertexLayout ms_layout; - - ms_layout.begin() - .add(::bgfx::Attrib::Position, 3, ::bgfx::AttribType::Float) - .add(::bgfx::Attrib::Normal, 3, ::bgfx::AttribType::Float) - .add(::bgfx::Attrib::TexCoord0, 2, ::bgfx::AttribType::Float) - .end(); - - return ms_layout; - }(); - return ms_layout; - } -} // namespace owds::bgfx \ No newline at end of file diff --git a/src/Graphics/Base/Renderer.cpp b/src/Graphics/Base/Renderer.cpp deleted file mode 100644 index 1c51e5ec..00000000 --- a/src/Graphics/Base/Renderer.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "overworld/Graphics/Base/Renderer.h" - -#include "overworld/Engine/Common/Lights/AmbientLight.h" -#include "overworld/Engine/Common/World.h" - -namespace owds { - - const AmbientLight& Renderer::getAmbientLight(World* world) - { - return world->ambient_light_; - } - - const PointLights& Renderer::getPointLights(World* world) - { - return world->point_lights_; - } - -} // namespace owds \ No newline at end of file diff --git a/src/Graphics/GLFW3/Window.cpp b/src/Graphics/GLFW3/Window.cpp deleted file mode 100755 index 6d54067c..00000000 --- a/src/Graphics/GLFW3/Window.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#include "overworld/Graphics/GLFW3/Window.h" - -#include -#include -#include -#include - -#include "overworld/Graphics/Base/Renderer.h" -#include "overworld/Graphics/GLFW3/Context.h" - -namespace owds::glfw3 { - - Window::Window(const std::string& name) : ctx_(std::make_unique()) - { - glfwInit(); - glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); - ctx_->glfw_window_ = glfwCreateWindow(640, 480, name.c_str(), nullptr, nullptr); - - glfwSetWindowUserPointer(ctx_->glfw_window_, this); - glfwSetWindowSizeCallback(ctx_->glfw_window_, [](GLFWwindow* window, const int width, const int height) { - auto* const user_ptr = glfwGetWindowUserPointer(window); - - const auto& ctx = static_cast(user_ptr)->ctx_; - ctx->width_ = width; - ctx->height_ = height; - ctx->has_size_changed_ = true; - }); - - glfwSetKeyCallback(ctx_->glfw_window_, [](GLFWwindow* window, const int key, const int scancode, const int action, const int mods) { - (void)scancode; - (void)mods; - - if(action == GLFW_REPEAT) - return; - - auto* const user_ptr = glfwGetWindowUserPointer(window); - const auto& ctx_ = static_cast(user_ptr)->ctx_; - - if(ctx_->camera_ != nullptr) - ctx_->camera_->processUserKeyboardInput(0.f, key, action == GLFW_PRESS); - }); - - glfwSetCursorPosCallback(ctx_->glfw_window_, [](GLFWwindow* window, const double xpos, const double ypos) { - auto* const user_ptr = glfwGetWindowUserPointer(window); - const auto& ctx_ = reinterpret_cast(user_ptr)->ctx_; - - if(ctx_->camera_ != nullptr) - ctx_->camera_->processUserMouseInput(0.f, static_cast(xpos), static_cast(ypos)); - }); - - glfwSetScrollCallback(ctx_->glfw_window_, [](GLFWwindow* window, double xoffset, double yoffset) { - auto* const user_ptr = glfwGetWindowUserPointer(window); - const auto& ctx_ = reinterpret_cast(user_ptr)->ctx_; - - if(ctx_->camera_ != nullptr) - ctx_->camera_->processUserMouseScroll(0.f, static_cast(xoffset), static_cast(yoffset)); - }); - - glfwSetMouseButtonCallback(ctx_->glfw_window_, [](GLFWwindow* window, const int button, const int action, int mods) { - (void)mods; - - if(action == GLFW_REPEAT) - return; - - auto* const user_ptr = glfwGetWindowUserPointer(window); - const auto& ctx_ = reinterpret_cast(user_ptr)->ctx_; - - if(ctx_->camera_ != nullptr) - ctx_->camera_->processUserMouseBtnInput(0.f, button, action == GLFW_PRESS); - }); - } - - Window::~Window() - { - glfwDestroyWindow(ctx_->glfw_window_); - glfwTerminate(); - } - - WindowPlatformData Window::getPlatformData() const - { - return { - reinterpret_cast(glfwGetX11Display()), - reinterpret_cast(glfwGetX11Window(ctx_->glfw_window_))}; - } - - void Window::doPollEvents(owds::Renderer& renderer) - { - glfwPollEvents(); - - ctx_->camera_ = renderer.getRenderCamera(); - if(ctx_->camera_ != nullptr) - ctx_->camera_->update(); - - if(ctx_->has_size_changed_) - { - ctx_->has_size_changed_ = false; - renderer.notifyResize(ctx_->width_, ctx_->height_); - } - } - - bool Window::isCloseRequested() const - { - return glfwWindowShouldClose(ctx_->glfw_window_); - } -} // namespace owds::glfw3 \ No newline at end of file diff --git a/src/Nodes/Test1.cpp b/src/Nodes/Test1.cpp deleted file mode 100644 index e906f14b..00000000 --- a/src/Nodes/Test1.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include -#include -#include - -#include "overworld/Engine/Common/Models/ModelManager.h" -#include "overworld/Engine/Graphics/Assimp/ModelLoader.h" - -#if !OWDS_USE_PHYSX -#include -#include -using DefaultEngine = owds::bullet3::World; -#else -#include -#include -using DefaultEngine = owds::physx::World; -#endif - -#include -#include - -int main() -{ - { - auto& mgr = owds::ModelManager::get(); - mgr.setModelLoader(); - } - - owds::glfw3::Window window; - owds::bgfx::Renderer renderer; - - renderer.initialize(window); - - DefaultEngine world(owds::compat::owds_ros::getShareDirectory("overworld")); - - world.setAmbientLight({-0.2f, -1.0f, -0.3f}, - {1.0f, 0.976f, 0.898f}, - 0.3, 0.5, 1.0); - - world.addPointLight({2.0f, -2.0f, 1.0f}, - {1.0f, 1.0f, 1.0f}, - 0.4, 0.5, 1.0, - 10.f); - - world.addPointLight({10.0f, -2.0f, 1.0f}, - {0.0f, 1.0f, 1.0f}, - 0.5, 0.5, 1.0, - 7.0f); - - renderer.attachWorld(world); - - // auto& cam = renderer.createCamera("john"); - renderer.runSanityChecks(); - - auto* cam = renderer.getRenderCamera(); - cam->setCameraView(owds::CameraView_e::segmented_view); - cam->setProjection(owds::CameraProjection_e::perspective); - cam->setFieldOfView(80.f); - cam->setOutputAA(owds::ViewAntiAliasing_e::msaa_x8); - cam->setOutputResolution({640, 480}); - cam->setPositionAndLookAt({5, 5, 5}, {0, 0, 0}); - cam->finalize(); - - (void)world.loadRobotFromDescription("models/adream/adream.urdf"); - - while(!window.isCloseRequested()) - { - window.doPollEvents(renderer); - world.stepSimulation(1.f / 144.f); - renderer.commit(); - } - - return 0; -}