Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Engine_Master_UPC/BinaryArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ void BinaryArchive::serialize(DirectX::SimpleMath::Vector3& val, const char* /*n
serializeRaw(&val, sizeof(val));
}

void BinaryArchive::serialize(DirectX::SimpleMath::Vector2& val, const char* /*name*/)
{
serializeRaw(&val, sizeof(val));
}

void BinaryArchive::serialize(DirectX::SimpleMath::Quaternion& val, const char* /*name*/)
{
serializeRaw(&val, sizeof(val));
Expand Down
1 change: 1 addition & 0 deletions Engine_Master_UPC/BinaryArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class BinaryArchive : public IArchive
void serializeRaw(void* data, size_t size, const char* name = "") override;

void serialize(DirectX::SimpleMath::Vector3& val, const char* name = "") override;
void serialize(DirectX::SimpleMath::Vector2& val, const char* name = "") override;
void serialize(DirectX::SimpleMath::Quaternion& val, const char* name = "") override;
void serialize(DirectX::SimpleMath::Color& val, const char* name = "") override;
void serialize(DirectX::SimpleMath::Matrix& val, const char* name = "") override;
Expand Down
6 changes: 5 additions & 1 deletion Engine_Master_UPC/ComponentFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "DamageHighlightComponent.h"
#include "DissolveComponent.h"
#include "SpectralComponent.h"
#include "FlowMapComponent.h"

// Prefab
#include "PrefabInstanceComponent.h"
Expand Down Expand Up @@ -113,6 +114,9 @@ std::unique_ptr<Component> ComponentFactory::createWithUID(ComponentType type, U
case ComponentType::DISSOLVE:
return std::make_unique<DissolveComponent>(id, owner);

case ComponentType::FLOW_MAP:
return std::make_unique<FlowMapComponent>(id, owner);

case ComponentType::SPECTRAL:
return std::make_unique<SpectralComponent>(id, owner);

Expand All @@ -121,4 +125,4 @@ std::unique_ptr<Component> ComponentFactory::createWithUID(ComponentType type, U
default:
return nullptr;
}
}
}
1 change: 1 addition & 0 deletions Engine_Master_UPC/ComponentType.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
X(PREFAB_INSTANCE) \
X(PLAYER_RENDER_BUFFER) \
X(DAMAGE_HIGHLIGHT) \
X(FLOW_MAP) \
X(DISSOLVE) \
X(SPECTRAL)

Expand Down
29 changes: 28 additions & 1 deletion Engine_Master_UPC/Engine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ $(SolutionDir)3rdParty\RecastNavigation\DebugUtils\Include;
<ClInclude Include="NavRuntimeBlockerComponent.h" />
<ClInclude Include="PdbPatcher.h" />
<ClInclude Include="PlayerPass.h" />
<ClInclude Include="FlowMapComponent.h" />
<ClInclude Include="FlowMapGPUData.h" />
<ClInclude Include="FlowMapPass.h" />
<ClInclude Include="PlayerRenderBufferComponent.h" />
<ClInclude Include="ScriptBuildSystem.h" />
<ClInclude Include="ScriptLibraryLoader.h" />
Expand Down Expand Up @@ -775,6 +778,8 @@ $(SolutionDir)3rdParty\RecastNavigation\DebugUtils\Include;
<ClCompile Include="CommandDeleteAsset.cpp" />
<ClCompile Include="CommandDeleteFolder.cpp" />
<ClCompile Include="DissolveComponent.cpp" />
<ClCompile Include="FlowMapComponent.cpp" />
<ClCompile Include="FlowMapPass.cpp" />
<ClCompile Include="EmitterAnimation.cpp" />
<ClCompile Include="EmitterArea.cpp" />
<ClCompile Include="EmitterColor.cpp" />
Expand Down Expand Up @@ -1157,6 +1162,28 @@ $(SolutionDir)3rdParty\RecastNavigation\DebugUtils\Include;
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">6.0</ShaderModel>
</FxCompile>
<FxCompile Include="FlowMapPS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='GameRelease|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='GameRelease|Win32'">Pixel</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">6.0</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">6.0</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='GameRelease|x64'">6.0</ShaderModel>
</FxCompile>
<FxCompile Include="FlowMapVS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='GameRelease|x64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='GameRelease|Win32'">Vertex</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">6.0</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">6.0</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='GameRelease|x64'">6.0</ShaderModel>
</FxCompile>
<FxCompile Include="PlayerVertexShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">6.0</ShaderModel>
Expand Down Expand Up @@ -1355,4 +1382,4 @@ $(SolutionDir)3rdParty\RecastNavigation\DebugUtils\Include;
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
147 changes: 147 additions & 0 deletions Engine_Master_UPC/FlowMapComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#include "Globals.h"
#include "FlowMapComponent.h"

#include "Application.h"
#include "JsonArchive.h"
#include "ModuleAssets.h"
#include "ModuleResources.h"
#include "ModuleTime.h"
#include "Texture.h"

#include <cmath>

FlowMapComponent::FlowMapComponent(UID id, GameObject* owner)
: Component(id, ComponentType::FLOW_MAP, owner)
{
}

std::unique_ptr<Component> FlowMapComponent::clone(GameObject* newOwner) const
{
auto result = std::make_unique<FlowMapComponent>(m_uuid, newOwner);
result->m_data = m_data;
result->m_textureAssetId = m_textureAssetId;
result->m_texture = m_texture;
result->m_textureAsset = m_textureAsset;
result->m_phase = m_phase;
return result;
}

void FlowMapComponent::update()
{
if (!m_data.enabled || m_data.speed == 0.0f)
return;

const float dt = app->getModuleTime()->deltaTime();
if (getTechnique() == FlowMapTechnique::FLOW_MAP_WATER)
{
m_phase += m_data.speed * dt;
m_phase -= std::floor(m_phase);
}
else
{
m_data.offset += m_data.direction * (m_data.speed * dt);
m_data.offset.x -= std::floor(m_data.offset.x);
m_data.offset.y -= std::floor(m_data.offset.y);
}

#ifdef _DEBUG
const uint32_t frame = app->getModuleTime()->frameCount();
if ((frame % 60u) == 0u)
{
DEBUG_LOG("[FlowMap] component=%llu offset=(%.4f, %.4f) speed=%.3f source=%u\n",
static_cast<unsigned long long>(m_uuid),
m_data.offset.x, m_data.offset.y, m_data.speed, m_data.source);
}
#endif
}

void FlowMapComponent::drawUi()
{
if (!ImGui::CollapsingHeader("Flow Map Settings", ImGuiTreeNodeFlags_DefaultOpen))
return;

int technique = static_cast<int>(m_data.technique);
const char* techniques[] = { "Directional Scroll", "Flow Map Water" };
if (ImGui::Combo("Technique", &technique, techniques, 2))
m_data.technique = static_cast<uint32_t>(technique);

if (getTechnique() == FlowMapTechnique::FLOW_MAP_WATER)
{
int source = static_cast<int>(m_data.source);
const char* sources[] = { "Direction", "Texture" };
if (ImGui::Combo("Source", &source, sources, 2))
m_data.source = static_cast<uint32_t>(source);
}

ImGui::DragFloat2("Direction", &m_data.direction.x, 0.01f, -1.0f, 1.0f);
ImGui::DragFloat2("Tiling", &m_data.tiling.x, 0.01f, 0.001f, 100.0f);
ImGui::DragFloat("Speed", &m_data.speed, 0.01f, -100.0f, 100.0f);
ImGui::DragFloat("Strength", &m_data.strength, 0.01f, 0.0f, 10.0f);
bool enabled = m_data.enabled != 0;
if (ImGui::Checkbox("Enabled", &enabled))
m_data.enabled = enabled ? 1u : 0u;

if (getSource() == FlowMapSource::TEXTURE)
{
ImGui::Button("Drop Flow Texture Here");
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("ASSET"))
{
UID* uid = static_cast<UID*>(payload->Data);
AssetId* reference = app->getModuleAssets()->findReference(*uid);
if (reference)
setTextureAssetId(*reference);
}
ImGui::EndDragDropTarget();
}
ImGui::SameLine();
ImGui::Text("Loaded: %s", m_texture ? "YES" : "NO");
}
}

void FlowMapComponent::serialize(IArchive& archive)
{
Component::serialize(archive);
archive.serialize(m_data.direction, "Direction");
archive.serialize(m_data.tiling, "Tiling");
archive.serialize(m_data.speed, "Speed");
archive.serialize(m_data.strength, "Strength");
archive.serialize(m_data.offset, "Offset");
archive.serialize(m_data.source, "Source");
archive.serialize(m_data.enabled, "Enabled");
archive.serialize(m_data.technique, "Technique");

if (archive.mode() == ArchiveMode::Input)
{
if (m_data.source > static_cast<uint32_t>(FlowMapSource::TEXTURE))
m_data.source = static_cast<uint32_t>(FlowMapSource::DIRECTION);
if (m_data.technique > static_cast<uint32_t>(FlowMapTechnique::FLOW_MAP_WATER))
m_data.technique = static_cast<uint32_t>(FlowMapTechnique::DIRECTIONAL_SCROLL);
}

archive.beginObject("TextureAssetId");
m_textureAssetId.serialize(archive);
archive.endObject();

if (archive.mode() == ArchiveMode::Input)
loadTexture();
}

void FlowMapComponent::setTextureAssetId(const AssetId& id)
{
m_textureAssetId = id;
loadTexture();
}

void FlowMapComponent::loadTexture()
{
m_texture.reset();
m_textureAsset.reset();
if (!m_textureAssetId.isValid())
return;

m_textureAsset = app->getModuleAssets()->load<TextureAsset>(m_textureAssetId);
if (m_textureAsset)
m_texture = app->getModuleResources()->createTexture(*m_textureAsset, true);
}
60 changes: 60 additions & 0 deletions Engine_Master_UPC/FlowMapComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#pragma once

#include "Component.h"
#include "TextureAsset.h"

class Texture;

enum class FlowMapSource : uint32_t
{
DIRECTION = 0,
TEXTURE = 1
};

enum class FlowMapTechnique : uint32_t
{
DIRECTIONAL_SCROLL = 0,
FLOW_MAP_WATER = 1
};

struct FlowMapData
{
Vector2 direction = Vector2(1.0f, 0.0f);
Vector2 tiling = Vector2::One;
float speed = 0.1f;
float strength = 0.1f;
Vector2 offset = Vector2::Zero;
uint32_t source = static_cast<uint32_t>(FlowMapSource::DIRECTION);
uint32_t enabled = 1;
uint32_t technique = static_cast<uint32_t>(FlowMapTechnique::DIRECTIONAL_SCROLL);
};

class FlowMapComponent : public Component
{
public:
FlowMapComponent(UID id, GameObject* owner);

std::unique_ptr<Component> clone(GameObject* newOwner) const override;
void update() override;
void drawUi() override;
void serialize(IArchive& archive) override;
void debugDraw() override {}
void onTransformChange() override {}

FlowMapData getData() const { return m_data; }
FlowMapSource getSource() const { return static_cast<FlowMapSource>(m_data.source); }
FlowMapTechnique getTechnique() const { return static_cast<FlowMapTechnique>(m_data.technique); }
Texture* getTexture() const { return m_texture.get(); }
float getPhase() const { return m_phase; }

void setTextureAssetId(const AssetId& id);

private:
void loadTexture();

FlowMapData m_data{};
AssetId m_textureAssetId{};
std::shared_ptr<Texture> m_texture;
std::shared_ptr<TextureAsset> m_textureAsset;
float m_phase = 0.0f;
};
18 changes: 18 additions & 0 deletions Engine_Master_UPC/FlowMapGPUData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "SimpleMath.h"
#include <cstdint>

struct FlowMapGPUData
{
DirectX::SimpleMath::Vector2 direction = DirectX::SimpleMath::Vector2::Zero;
DirectX::SimpleMath::Vector2 tiling = DirectX::SimpleMath::Vector2::One;
DirectX::SimpleMath::Vector2 offset = DirectX::SimpleMath::Vector2::Zero;
float strength = 0.0f;
uint32_t source = 0;
uint32_t enabled = 0;
uint32_t technique = 0;
float phase = 0.0f;
uint32_t paddingScalar = 0;
DirectX::SimpleMath::Vector2 padding = DirectX::SimpleMath::Vector2::Zero;
};
Loading