Skip to content
Merged
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
22 changes: 22 additions & 0 deletions Source/Game-Lib/Game-Lib/ECS/Systems/CharacterController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,18 @@ namespace ECS::Systems
if (characterSingleton.moverEntity == entt::null || activeCamera.entity == entt::null)
return false;

ModelLoader* modelLoader = ServiceLocator::GetGameRenderer()->GetModelLoader();
auto& unit = registry->get<Components::Unit>(characterSingleton.moverEntity);

if ((modifier & KeybindModifier::Shift) != KeybindModifier::Invalid)
{
// Unhighlight previous target
if (unit.targetEntity != entt::null && registry->all_of<Components::Model>(unit.targetEntity))
{
auto& model = registry->get<Components::Model>(unit.targetEntity);
modelLoader->SetModelHighlight(model, 1.0f);
}

unit.targetEntity = entt::null;
return true;
}
Expand Down Expand Up @@ -252,7 +260,21 @@ namespace ECS::Systems
.targetGUID = targetNetworkID
}))
{
// Unhighlight previous target
if (registry->all_of<Components::Model>(unit.targetEntity))
{
auto& model = registry->get<Components::Model>(unit.targetEntity);
modelLoader->SetModelHighlight(model, 1.0f);
}

unit.targetEntity = targetEntity;

// Visually highlight the selected target for feedback
if (registry->all_of<Components::Model>(targetEntity))
{
auto& model = registry->get<Components::Model>(targetEntity);
modelLoader->SetModelHighlight(model, 1.5f);
}
}

return true;
Expand Down
18 changes: 17 additions & 1 deletion Source/Game-Lib/Game-Lib/Rendering/Model/ModelLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ void ModelLoader::Update(f32 deltaTime)
LoadRequestInternal& loadRequest = _internalLoadRequestsVector[i];

const DiscoveredModel& discoveredModel = _modelHashToDiscoveredModel[loadRequest.modelHash];
bool isSupported = discoveredModel.model->modelHeader.numVertices > 0;
bool isSupported = (loadRequest.entity == entt::null || registry->valid(loadRequest.entity)) && discoveredModel.model->modelHeader.numVertices > 0;
if (!isSupported)
continue;

Expand Down Expand Up @@ -842,6 +842,22 @@ void ModelLoader::SetModelTransparent(const ECS::Components::Model& model, bool
_modelRenderer->RequestChangeTransparency(model.instanceID, transparent, opacity);
}

void ModelLoader::SetEntityHighlight(entt::entity entity, f32 highlightIntensity)
{
entt::registry* registry = ServiceLocator::GetEnttRegistries()->gameRegistry;
auto& modelComponent = registry->get<ECS::Components::Model>(entity);

SetModelHighlight(modelComponent, highlightIntensity);
}

void ModelLoader::SetModelHighlight(const ECS::Components::Model& model, f32 highlightIntensity)
{
if (model.instanceID == std::numeric_limits<u32>().max())
return;

_modelRenderer->RequestChangeHighlight(model.instanceID, highlightIntensity);
}

void ModelLoader::EnableGroupForEntity(entt::entity entity, u32 groupID)
{
entt::registry* registry = ServiceLocator::GetEnttRegistries()->gameRegistry;
Expand Down
3 changes: 3 additions & 0 deletions Source/Game-Lib/Game-Lib/Rendering/Model/ModelLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ class ModelLoader
void SetEntityTransparent(entt::entity entity, bool transparent, f32 opacity);
void SetModelTransparent(const ECS::Components::Model& model, bool transparent, f32 opacity);

void SetEntityHighlight(entt::entity entity, f32 highlightIntensity);
void SetModelHighlight(const ECS::Components::Model& model, f32 highlightIntensity);

void EnableGroupForEntity(entt::entity entity, u32 groupID);
void EnableGroupForModel(const ECS::Components::Model& model, u32 groupID);

Expand Down
27 changes: 27 additions & 0 deletions Source/Game-Lib/Game-Lib/Rendering/Model/ModelRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,21 @@ void ModelRenderer::Update(f32 deltaTime)
_instancesDirty = true;
}

u32 numChangeHighlightRequests = static_cast<u32>(_changeHighlightRequests.try_dequeue_bulk(_changeHighlightWork.begin(), 256));
if (numChangeHighlightRequests > 0)
{
ZoneScopedN("Change Highlight Requests");
for (u32 i = 0; i < numChangeHighlightRequests; i++)
{
ChangeHighlightRequest& changeHighlightRequest = _changeHighlightWork[i];

InstanceData& instanceData = _instanceDatas[changeHighlightRequest.instanceID];
instanceData.highlightIntensity = changeHighlightRequest.highlightIntensity;
_instanceDatas.SetDirtyElement(changeHighlightRequest.instanceID);
}
_instancesDirty = true;
}

u32 numChangeSkyboxRequests = static_cast<u32>(_changeSkyboxRequests.try_dequeue_bulk(_changeSkyboxWork.begin(), 256));
if (numChangeSkyboxRequests > 0)
{
Expand Down Expand Up @@ -2125,6 +2140,17 @@ void ModelRenderer::RequestChangeTransparency(u32 instanceID, bool transparent,
_changeTransparencyRequests.enqueue(changeTransparencyRequest);
}

void ModelRenderer::RequestChangeHighlight(u32 instanceID, f32 highlightIntensity)
{
ChangeHighlightRequest changeHighlightRequest =
{
.instanceID = instanceID,
.highlightIntensity = highlightIntensity
};

_changeHighlightRequests.enqueue(changeHighlightRequest);
}

void ModelRenderer::RequestChangeSkybox(u32 instanceID, bool skybox)
{
ChangeSkyboxRequest changeSkyboxRequest =
Expand Down Expand Up @@ -2427,6 +2453,7 @@ void ModelRenderer::CreatePermanentResources()
_changeHairTextureWork.resize(256);
_changeVisibilityWork.resize(256);
_changeTransparencyWork.resize(256);
_changeHighlightWork.resize(256);
_changeSkyboxWork.resize(256);

static constexpr u32 NumSamplers = 4;
Expand Down
13 changes: 12 additions & 1 deletion Source/Game-Lib/Game-Lib/Rendering/Model/ModelRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ class ModelRenderer : CulledRenderer
u32 modelVertexOffset = InvalidID;
u32 animatedVertexOffset = InvalidID;
f32 opacity = 1.0f;
f32 highlightIntensity = 1.0f;
u32 padding0;
u32 padding1;
};

struct InstanceDataCPU
Expand Down Expand Up @@ -241,6 +241,13 @@ class ModelRenderer : CulledRenderer
f32 opacity = 1.0f;
};

struct ChangeHighlightRequest
{
public:
u32 instanceID = 0;
f32 highlightIntensity = 1.0f;
};

struct ChangeTextureUnitColorRequest
{
public:
Expand Down Expand Up @@ -320,6 +327,7 @@ class ModelRenderer : CulledRenderer
void RequestChangeHairTexture(u32 instanceID, Renderer::TextureID textureID);
void RequestChangeVisibility(u32 instanceID, bool visible);
void RequestChangeTransparency(u32 instanceID, bool transparent, f32 opacity);
void RequestChangeHighlight(u32 instanceID, f32 highlightIntensity);
void RequestChangeSkybox(u32 instanceID, bool skybox);

bool AddUninstancedAnimationData(u32 modelID, u32& boneMatrixOffset, u32& textureTransformMatrixOffset);
Expand Down Expand Up @@ -460,6 +468,9 @@ class ModelRenderer : CulledRenderer
moodycamel::ConcurrentQueue<ChangeTransparencyRequest> _changeTransparencyRequests;
std::vector<ChangeTransparencyRequest> _changeTransparencyWork;

moodycamel::ConcurrentQueue<ChangeHighlightRequest> _changeHighlightRequests;
std::vector<ChangeHighlightRequest> _changeHighlightWork;

moodycamel::ConcurrentQueue<ChangeSkyboxRequest> _changeSkyboxRequests;
std::vector<ChangeSkyboxRequest> _changeSkyboxWork;

Expand Down
7 changes: 7 additions & 0 deletions Source/Shaders/Shaders/Include/VisibilityBuffers.inc.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ struct PixelVertexData
float3 worldPos;
float4 viewPos;
float2 pixelPos;
float highlightIntensity;
};

PixelVertexData GetPixelVertexDataTerrain(const uint2 pixelPos, const VisibilityBuffer vBuffer, const uint cameraIndex, float2 renderSize)
Expand Down Expand Up @@ -413,6 +414,9 @@ PixelVertexData GetPixelVertexDataTerrain(const uint2 pixelPos, const Visibility
result.worldPos = InterpolateVertexAttribute(bary, vertices[0].position, vertices[1].position, vertices[2].position);
result.viewPos = mul(float4(result.worldPos, 1.0f), _cameras[cameraIndex].worldToView);
result.pixelPos = pixelPos;

result.highlightIntensity = 1.0f; // No highlight for terrain... yet?

return result;
}

Expand Down Expand Up @@ -462,6 +466,9 @@ PixelVertexData GetPixelVertexDataModel(const uint2 pixelPos, const VisibilityBu
result.worldPos = mul(float4(pixelVertexPos, 1.0f), instanceMatrix).xyz;
result.viewPos = mul(float4(result.worldPos, 1.0f), _cameras[cameraIndex].worldToView);
result.pixelPos = pixelPos;

result.highlightIntensity = instanceData.highlightIntensity;

return result;
}

Expand Down
3 changes: 3 additions & 0 deletions Source/Shaders/Shaders/MaterialPass.cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ float4 ShadeModel(const uint2 pixelPos, const float2 screenUV, const VisibilityB
// Apply lighting
color.rgb = ApplyLighting(screenUV, color.rgb, pixelVertexData, _constants.lightInfo, shadowSettings);

// Apply highlight
color.rgb *= pixelVertexData.highlightIntensity;

outPixelWorldPos = pixelVertexData.worldPos;
return saturate(color);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Shaders/Shaders/Model/ModelShared.inc.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ struct ModelInstanceData
uint modelVertexOffset;
uint animatedVertexOffset;
float opacity;
float highlightIntensity;
uint padding0;
uint padding1;
};

struct ModelDrawCallData
Expand Down
Loading