adding transparent water

This commit is contained in:
2025-05-31 14:22:46 +02:00
parent 48decb4204
commit 88fead6cfc
8 changed files with 152 additions and 100 deletions

View File

@@ -21,13 +21,12 @@ namespace Scop
inline void AttachScript(std::shared_ptr<ActorScript> script) { p_script = script; }
inline void SetColor(Vec4f color) noexcept { m_color = color; }
inline void SetPosition(Vec3f position) noexcept { m_position = position; }
inline void SetScale(Vec3f scale) noexcept { m_scale = scale; }
inline void SetOrientation(Quatf orientation) noexcept { m_orientation = orientation; }
inline void SetVisibility(bool show) noexcept { m_is_visible = show; }
inline void SetIsOpaque(bool opaque) noexcept { m_is_opaque = opaque; }
[[nodiscard]] inline const Vec4f& GetColor() const noexcept { return m_color; }
[[nodiscard]] inline const Vec3f& GetPosition() const noexcept { return m_position; }
[[nodiscard]] inline const Vec3f& GetScale() const noexcept { return m_scale; }
[[nodiscard]] inline const Quatf& GetOrientation() const noexcept { return m_orientation; }
@@ -35,6 +34,7 @@ namespace Scop
[[nodiscard]] inline Model& GetModelRef() noexcept { return m_model; }
[[nodiscard]] inline std::uint64_t GetUUID() const noexcept { return m_uuid; }
[[nodiscard]] inline bool IsVisible() const noexcept { return m_is_visible; }
[[nodiscard]] inline bool IsOpaque() const noexcept { return m_is_opaque; }
~Actor();
@@ -44,12 +44,12 @@ namespace Scop
private:
Model m_model;
Quatf m_orientation = Quatf::Identity();
Vec4f m_color = Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f };
Vec3f m_position = Vec3f{ 0.0f, 0.0f, 0.0f };
Vec3f m_scale = Vec3f{ 1.0f, 1.0f, 1.0f };
std::shared_ptr<ActorScript> p_script;
std::uint64_t m_uuid;
bool m_is_visible = true;
bool m_is_opaque = true;
};
}

View File

@@ -67,8 +67,8 @@ namespace Scop
void SwitchToParent() const noexcept;
[[nodiscard]] inline ForwardData& GetForwardData() noexcept { return m_forward; }
[[nodiscard]] inline const std::map<std::uint64_t, Actor>& GetActors() const noexcept { return m_actors; }
[[nodiscard]] inline const std::map<std::uint64_t, Sprite>& GetSprites() const noexcept { return m_sprites; }
[[nodiscard]] inline const std::unordered_map<std::uint64_t, Actor>& GetActors() const noexcept { return m_actors; }
[[nodiscard]] inline const std::unordered_map<std::uint64_t, Sprite>& GetSprites() const noexcept { return m_sprites; }
[[nodiscard]] inline const std::string& GetName() const noexcept { return m_name; }
[[nodiscard]] inline GraphicPipeline& GetPipeline() noexcept { return m_pipeline; }
[[nodiscard]] inline std::shared_ptr<BaseCamera> GetCamera() const { return m_descriptor.camera; }
@@ -91,9 +91,9 @@ namespace Scop
DepthImage m_depth;
SceneDescriptor m_descriptor;
std::shared_ptr<CubeTexture> p_skybox;
std::map<std::uint64_t, Actor> m_actors;
std::map<std::uint64_t, Sprite> m_sprites;
std::map<std::uint64_t, Narrator> m_narrators;
std::unordered_map<std::uint64_t, Actor> m_actors;
std::unordered_map<std::uint64_t, Sprite> m_sprites;
std::unordered_map<std::uint64_t, Narrator> m_narrators;
std::vector<Scene> m_scene_children;
std::string m_name;
NonOwningPtr<Scene> p_parent;

View File

@@ -41,12 +41,7 @@ namespace Scop
pipeline.Init(pipeline_descriptor);
}
VkCommandBuffer cmd = renderer.GetActiveCommandBuffer();
pipeline.BindPipeline(cmd, 0, {});
for(const auto& [_, actor] : scene.GetActors())
{
if(!actor.IsVisible())
continue;
auto setup_model = [](const Actor& actor) -> ModelData {
ModelData model_data;
model_data.model_mat = Mat4f::Identity();
model_data.model_mat.SetTranslation(actor.GetPosition() - actor.GetModel().GetCenter());
@@ -54,8 +49,35 @@ namespace Scop
model_data.model_mat = Mat4f::Translate(-actor.GetModel().GetCenter()) * Mat4f::Rotate(actor.GetOrientation()) * model_data.model_mat;
model_data.normal_mat = model_data.model_mat;
model_data.normal_mat.Inverse().Transpose();
return model_data;
};
std::multimap<float, Actor&> sorted_actors;
VkCommandBuffer cmd = renderer.GetActiveCommandBuffer();
pipeline.BindPipeline(cmd, 0, {});
for(auto& [_, actor] : scene.GetActors())
{
if(!actor.IsVisible())
continue;
if(actor.IsOpaque())
{
auto model_data = setup_model(actor);
RenderCore::Get().vkCmdPushConstants(cmd, pipeline.GetPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(ModelData), &model_data);
actor.GetModel().Draw(cmd, *data.matrices_set, pipeline, *data.albedo_set, renderer.GetDrawCallsCounterRef(), renderer.GetPolygonDrawnCounterRef(), renderer.GetCurrentFrameIndex());
}
else
{
float distance = Vec3f::Distance(actor.GetPosition(), scene.GetCamera()->GetPosition());
sorted_actors.emplace(distance, const_cast<Actor&>(actor));
}
}
for(auto it = sorted_actors.rbegin(); it != sorted_actors.rend(); ++it)
{
if(!it->second.IsVisible())
continue;
auto model_data = setup_model(it->second);
RenderCore::Get().vkCmdPushConstants(cmd, pipeline.GetPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(ModelData), &model_data);
actor.GetModel().Draw(cmd, *data.matrices_set, pipeline, *data.albedo_set, renderer.GetDrawCallsCounterRef(), renderer.GetPolygonDrawnCounterRef(), renderer.GetCurrentFrameIndex());
it->second.GetModel().Draw(cmd, *data.matrices_set, pipeline, *data.albedo_set, renderer.GetDrawCallsCounterRef(), renderer.GetPolygonDrawnCounterRef(), renderer.GetCurrentFrameIndex());
}
pipeline.EndPipeline(cmd);
}