Fixed depth sorting for HUD elements.

This commit is contained in:
Tleety
2016-02-11 15:27:07 +01:00
parent 9f657ada4e
commit 6ba1e95da7
6 changed files with 18 additions and 32 deletions
+6 -3
View File
@@ -17,7 +17,7 @@
struct SpriteJob : RenderJob
{
SpriteJob(ComponentWrapper cSprite, Camera* camera, glm::mat4 matrix, World* world, glm::vec4 fillColor, float fillPercentage)
SpriteJob(ComponentWrapper cSprite, Camera* camera, glm::mat4 matrix, World* world, glm::vec4 fillColor, float fillPercentage, bool depthSorted)
: RenderJob()
{
Model = ResourceManager::Load<::Model>("Models/Core/UnitQuad.mesh");
@@ -34,8 +34,11 @@ struct SpriteJob : RenderJob
Color = cSprite["Color"];
Entity = cSprite.EntityID;
Position = Transform::AbsolutePosition(world, cSprite.EntityID);
glm::vec3 viewpos = glm::vec3(camera->ViewMatrix() * glm::vec4(Position, 1));
Depth = viewpos.z;
Depth = 0;
if (depthSorted) {
glm::vec3 viewpos = glm::vec3(camera->ViewMatrix() * glm::vec4(Position, 1));
Depth = viewpos.z;
}
World = world;
FillColor = fillColor;
@@ -17,33 +17,6 @@ public:
virtual void Update(double dt) override;
private:
//methods which will take care of specific events
/* EventRelay<CapturePointSystem, Events::TriggerTouch> m_ETriggerTouch;
bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e);
EventRelay<CapturePointSystem, Events::TriggerLeave> m_ETriggerLeave;
bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e);
EventRelay<CapturePointSystem, Events::Captured> m_ECaptured;
bool CapturePointSystem::OnCaptured(const Events::Captured& e);*/
//bool m_WinnerWasFound = false;
////need to track these variables for the captureSystem to work as per design!
//const int m_NotACapturePoint = 999;
//int m_RedTeamNextPossibleCapturePoint = m_NotACapturePoint;
//int m_BlueTeamNextPossibleCapturePoint = m_NotACapturePoint;
//int m_RedTeamHomeCapturePoint = m_NotACapturePoint;
//int m_BlueTeamHomeCapturePoint = m_NotACapturePoint;
//int m_NumberOfCapturePoints = 0;
//std::map<int, EntityWrapper> m_CapturePointNumberToEntityMap;
////std::vector<ComponentWrapper>
//const double m_CaptureTimeToTakeOver = 15.0;
//bool m_ResetTimers = false;
////vectors which will keep track of enter/leave changes
//std::vector<std::tuple<EntityWrapper, EntityWrapper>> m_ETriggerTouchVector;
//std::vector<std::tuple<EntityWrapper, EntityWrapper>> m_ETriggerLeaveVector;
};
#endif
+1
View File
@@ -4,4 +4,5 @@
<GlowMap></GlowMap>
<Color R="1" G="1" B="1" A="1"/>
<Visible>true</Visible>
<DepthSort>true</DepthSort>
</Sprite>
+3
View File
@@ -21,6 +21,9 @@
<xs:element name="Visible" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Whether the model is visible or not</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="DepthSort" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Whether the sprite should be sorted with depth or not. Only use false for textures that are on HUD</xs:documentation></xs:annotation>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
+5 -1
View File
@@ -623,9 +623,13 @@ void DrawFinalPass::DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, Rend
for(auto& job : jobs) {
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
RenderState jobState;
if (spriteJob) {
if(spriteJob->Depth == 0)
{
jobState.Disable(GL_DEPTH_TEST);
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(spriteJob->Matrix));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
+3 -1
View File
@@ -62,6 +62,7 @@ void RenderSystem::fillSprites(std::list<std::shared_ptr<RenderJob>>& jobs, Worl
std::string diffuseResource = cSprite["DiffuseTexture"];
std::string glowResource = cSprite["GlowMap"];
bool depthSorted = cSprite["DepthSort"];
if (diffuseResource.empty() && glowResource.empty()) {
continue;
}
@@ -77,7 +78,8 @@ void RenderSystem::fillSprites(std::list<std::shared_ptr<RenderJob>>& jobs, Worl
glm::mat4 modelMatrix = Transform::ModelMatrix(entity.ID, world);
//modelMatrix *= m_Camera->BillboardMatrix();
std::shared_ptr<SpriteJob> spriteJob = std::shared_ptr<SpriteJob>(new SpriteJob(cSprite, m_Camera, modelMatrix, world, fillColor, fillPercentage));
std::shared_ptr<SpriteJob> spriteJob = std::shared_ptr<SpriteJob>(new SpriteJob(cSprite, m_Camera, modelMatrix, world, fillColor, fillPercentage, depthSorted));
jobs.push_back(spriteJob);
}