Made recolor a separate material attribute and added more color types
parent
a88d9cdd39
commit
3805851255
|
@ -74,6 +74,8 @@ struct Material
|
||||||
CullFace cullFace = CullFace::BACK;
|
CullFace cullFace = CullFace::BACK;
|
||||||
// Special tag
|
// Special tag
|
||||||
std::string tag = "";
|
std::string tag = "";
|
||||||
|
// Recolor name
|
||||||
|
std::string recolor = "";
|
||||||
// Recolor reference color
|
// Recolor reference color
|
||||||
Color recolorReference = { 0.0f, 0.0f, 0.0f, 0.0f };
|
Color recolorReference = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
|
@ -97,6 +99,7 @@ struct Material
|
||||||
&& alphaThreshold == other.alphaThreshold
|
&& alphaThreshold == other.alphaThreshold
|
||||||
&& cullFace == other.cullFace
|
&& cullFace == other.cullFace
|
||||||
&& tag == other.tag
|
&& tag == other.tag
|
||||||
|
&& recolor == other.recolor
|
||||||
&& recolorReference == other.recolorReference
|
&& recolorReference == other.recolorReference
|
||||||
&& variableDetail == other.variableDetail
|
&& variableDetail == other.variableDetail
|
||||||
&& detailTexture == other.detailTexture;
|
&& detailTexture == other.detailTexture;
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
#include "graphics/model/model_shadow_spot.h"
|
#include "graphics/model/model_shadow_spot.h"
|
||||||
|
|
||||||
#include "level/robotmain.h"
|
#include "level/robotmain.h"
|
||||||
|
#include "level/player_profile.h"
|
||||||
|
|
||||||
#include "math/geometry.h"
|
#include "math/geometry.h"
|
||||||
|
|
||||||
|
@ -882,7 +883,7 @@ int CEngine::CreateObject()
|
||||||
{
|
{
|
||||||
if (! m_objects[objRank].used)
|
if (! m_objects[objRank].used)
|
||||||
{
|
{
|
||||||
m_objects[objRank].LoadDefault();
|
m_objects[objRank] = {};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1150,7 +1151,7 @@ void CEngine::CreateShadowSpot(int objRank)
|
||||||
{
|
{
|
||||||
if (! m_shadowSpots[index].used)
|
if (! m_shadowSpots[index].used)
|
||||||
{
|
{
|
||||||
m_shadowSpots[index].LoadDefault();
|
m_shadowSpots[index] = {};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1361,7 +1362,7 @@ int CEngine::CreateGroundSpot()
|
||||||
{
|
{
|
||||||
if (! m_groundSpots[index].used)
|
if (! m_groundSpots[index].used)
|
||||||
{
|
{
|
||||||
m_groundSpots[index].LoadDefault();
|
m_groundSpots[index] = {};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1422,7 +1423,7 @@ void CEngine::CreateGroundMark(glm::vec3 pos, float radius,
|
||||||
float delay1, float delay2, float delay3,
|
float delay1, float delay2, float delay3,
|
||||||
int dx, int dy, char* table)
|
int dx, int dy, char* table)
|
||||||
{
|
{
|
||||||
m_groundMark.LoadDefault();
|
m_groundMark = {};
|
||||||
|
|
||||||
m_groundMark.draw = true;
|
m_groundMark.draw = true;
|
||||||
m_groundMark.phase = ENG_GR_MARK_PHASE_INC;
|
m_groundMark.phase = ENG_GR_MARK_PHASE_INC;
|
||||||
|
@ -1439,7 +1440,7 @@ void CEngine::CreateGroundMark(glm::vec3 pos, float radius,
|
||||||
|
|
||||||
void CEngine::DeleteGroundMark(int rank)
|
void CEngine::DeleteGroundMark(int rank)
|
||||||
{
|
{
|
||||||
m_groundMark.LoadDefault();
|
m_groundMark = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void CEngine::ComputeDistance()
|
void CEngine::ComputeDistance()
|
||||||
|
@ -2654,6 +2655,48 @@ bool CEngine::IsVisiblePoint(const glm::vec3 &pos)
|
||||||
return glm::distance(m_eyePt, pos) <= (m_deepView[0] * m_clippingDistance);
|
return glm::distance(m_eyePt, pos) <= (m_deepView[0] * m_clippingDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Color CEngine::GetObjectColor(int object, const std::string& name)
|
||||||
|
{
|
||||||
|
if (name == "team")
|
||||||
|
{
|
||||||
|
return CRobotMain::GetInstance().GetTeamColor(m_objects[object].team);
|
||||||
|
}
|
||||||
|
else if (name == "vehicle")
|
||||||
|
{
|
||||||
|
return CRobotMain::GetInstance().GetVehicleColor();
|
||||||
|
}
|
||||||
|
else if (name == "plant")
|
||||||
|
{
|
||||||
|
return CRobotMain::GetInstance().GetGreeneryColor();
|
||||||
|
}
|
||||||
|
else if (name == "alien")
|
||||||
|
{
|
||||||
|
return CRobotMain::GetInstance().GetAlienColor();
|
||||||
|
}
|
||||||
|
else if (name == "hair")
|
||||||
|
{
|
||||||
|
const auto& appearance = CRobotMain::GetInstance().GetPlayerProfile()->GetAppearance();
|
||||||
|
|
||||||
|
return appearance.colorHair;
|
||||||
|
}
|
||||||
|
else if (name == "suit")
|
||||||
|
{
|
||||||
|
const auto& appearance = CRobotMain::GetInstance().GetPlayerProfile()->GetAppearance();
|
||||||
|
|
||||||
|
return appearance.colorCombi;
|
||||||
|
}
|
||||||
|
else if (name == "band")
|
||||||
|
{
|
||||||
|
const auto& appearance = CRobotMain::GetInstance().GetPlayerProfile()->GetAppearance();
|
||||||
|
|
||||||
|
return appearance.colorBand;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Color(1.0, 1.0, 1.0, 1.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CEngine::ApplyChange()
|
void CEngine::ApplyChange()
|
||||||
{
|
{
|
||||||
SetFocus(m_focus);
|
SetFocus(m_focus);
|
||||||
|
@ -2941,54 +2984,27 @@ void CEngine::Draw3DScene()
|
||||||
|
|
||||||
Color color = data.material.albedoColor;
|
Color color = data.material.albedoColor;
|
||||||
|
|
||||||
bool recolor = false;
|
if (!data.material.tag.empty())
|
||||||
Color recolorFrom = {};
|
{
|
||||||
Color recolorTo = {};
|
Color c = GetObjectColor(objRank, data.material.tag);
|
||||||
float recolorTreshold = 0.0;
|
|
||||||
|
|
||||||
if (data.material.tag == "team")
|
if (c != Color(1.0, 1.0, 1.0, 1.0))
|
||||||
{
|
{
|
||||||
color = CRobotMain::GetInstance().GetTeamColor(m_objects[objRank].team);
|
color = c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (data.material.tag == "vehicle")
|
|
||||||
|
if (data.material.recolor.empty())
|
||||||
{
|
{
|
||||||
color = CRobotMain::GetInstance().GetVehicleColor();
|
objectRenderer->SetRecolor(false);
|
||||||
}
|
}
|
||||||
else if (data.material.tag == "plant")
|
else
|
||||||
{
|
{
|
||||||
color = CRobotMain::GetInstance().GetGreeneryColor();
|
Color recolorFrom = data.material.recolorReference;
|
||||||
}
|
Color recolorTo = GetObjectColor(objRank, data.material.recolor);
|
||||||
else if (data.material.tag == "alien")
|
float recolorThreshold = 0.1;
|
||||||
{
|
|
||||||
color = CRobotMain::GetInstance().GetAlienColor();
|
objectRenderer->SetRecolor(true, recolorFrom, recolorTo, recolorThreshold);
|
||||||
}
|
|
||||||
else if (data.material.tag == "recolor_team")
|
|
||||||
{
|
|
||||||
recolor = true;
|
|
||||||
recolorFrom = data.material.recolorReference;
|
|
||||||
recolorTo = CRobotMain::GetInstance().GetTeamColor(m_objects[objRank].team);
|
|
||||||
recolorTreshold = 0.1;
|
|
||||||
}
|
|
||||||
else if (data.material.tag == "recolor_vehicle")
|
|
||||||
{
|
|
||||||
recolor = true;
|
|
||||||
recolorFrom = data.material.recolorReference;
|
|
||||||
recolorTo = CRobotMain::GetInstance().GetVehicleColor();
|
|
||||||
recolorTreshold = 0.1;
|
|
||||||
}
|
|
||||||
else if (data.material.tag == "recolor_plant")
|
|
||||||
{
|
|
||||||
recolor = true;
|
|
||||||
recolorFrom = data.material.recolorReference;
|
|
||||||
recolorTo = CRobotMain::GetInstance().GetGreeneryColor();
|
|
||||||
recolorTreshold = 0.1;
|
|
||||||
}
|
|
||||||
else if (data.material.tag == "recolor_alien")
|
|
||||||
{
|
|
||||||
recolor = true;
|
|
||||||
recolorFrom = data.material.recolorReference;
|
|
||||||
recolorTo = CRobotMain::GetInstance().GetAlienColor();
|
|
||||||
recolorTreshold = 0.1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
objectRenderer->SetAlbedoColor(color);
|
objectRenderer->SetAlbedoColor(color);
|
||||||
|
@ -3001,8 +3017,6 @@ void CEngine::Draw3DScene()
|
||||||
objectRenderer->SetMaterialParams(data.material.roughness, data.material.metalness, data.material.aoStrength);
|
objectRenderer->SetMaterialParams(data.material.roughness, data.material.metalness, data.material.aoStrength);
|
||||||
objectRenderer->SetMaterialTexture(data.materialTexture);
|
objectRenderer->SetMaterialTexture(data.materialTexture);
|
||||||
|
|
||||||
objectRenderer->SetRecolor(recolor, recolorFrom, recolorTo, recolorTreshold);
|
|
||||||
|
|
||||||
objectRenderer->SetCullFace(data.material.cullFace);
|
objectRenderer->SetCullFace(data.material.cullFace);
|
||||||
objectRenderer->SetUVTransform(data.uvOffset, data.uvScale);
|
objectRenderer->SetUVTransform(data.uvOffset, data.uvScale);
|
||||||
objectRenderer->DrawObject(data.buffer);
|
objectRenderer->DrawObject(data.buffer);
|
||||||
|
@ -3647,8 +3661,9 @@ void CEngine::DrawInterface()
|
||||||
renderer->SetProjectionMatrix(m_matProj);
|
renderer->SetProjectionMatrix(m_matProj);
|
||||||
renderer->SetViewMatrix(m_matView);
|
renderer->SetViewMatrix(m_matView);
|
||||||
renderer->SetFog(fogStart, fogEnd, { fogColor.r, fogColor.g, fogColor.b });
|
renderer->SetFog(fogStart, fogEnd, { fogColor.r, fogColor.g, fogColor.b });
|
||||||
renderer->SetLighting(false);
|
renderer->SetLighting(true);
|
||||||
renderer->SetLight(glm::vec4(1.0, 1.0, -1.0, 0.0), 1.0f, glm::vec3(1.0));
|
renderer->SetLight(glm::vec4(1.0, 1.0, -1.0, 0.0), 0.8f, glm::vec3(1.0));
|
||||||
|
renderer->SetSky(Color(1.0, 1.0, 1.0), 0.2f);
|
||||||
renderer->SetTransparency(TransparencyMode::NONE);
|
renderer->SetTransparency(TransparencyMode::NONE);
|
||||||
renderer->SetAlphaScissor(0.0f);
|
renderer->SetAlphaScissor(0.0f);
|
||||||
renderer->SetShadowParams(0, nullptr);
|
renderer->SetShadowParams(0, nullptr);
|
||||||
|
@ -3692,6 +3707,32 @@ void CEngine::DrawInterface()
|
||||||
|
|
||||||
for (auto& data : p1.next)
|
for (auto& data : p1.next)
|
||||||
{
|
{
|
||||||
|
Color color = data.material.albedoColor;
|
||||||
|
|
||||||
|
if (!data.material.tag.empty())
|
||||||
|
{
|
||||||
|
Color c = GetObjectColor(objRank, data.material.tag);
|
||||||
|
|
||||||
|
if (c != Color(1.0, 1.0, 1.0, 1.0))
|
||||||
|
{
|
||||||
|
color = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.material.recolor.empty())
|
||||||
|
{
|
||||||
|
renderer->SetRecolor(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Color recolorFrom = data.material.recolorReference;
|
||||||
|
Color recolorTo = GetObjectColor(objRank, data.material.recolor);
|
||||||
|
float recolorThreshold = 0.3;
|
||||||
|
|
||||||
|
renderer->SetRecolor(true, recolorFrom, recolorTo, recolorThreshold);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer->SetAlbedoColor(color);
|
||||||
renderer->SetAlbedoTexture(data.albedoTexture);
|
renderer->SetAlbedoTexture(data.albedoTexture);
|
||||||
renderer->SetDetailTexture(data.detailTexture);
|
renderer->SetDetailTexture(data.detailTexture);
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ struct EngineObject
|
||||||
//! Type of object
|
//! Type of object
|
||||||
EngineObjectType type = ENG_OBJTYPE_NULL;
|
EngineObjectType type = ENG_OBJTYPE_NULL;
|
||||||
//! Transformation matrix
|
//! Transformation matrix
|
||||||
glm::mat4 transform;
|
glm::mat4 transform = {};
|
||||||
//! Distance to object from eye point
|
//! Distance to object from eye point
|
||||||
float distance = 0.0f;
|
float distance = 0.0f;
|
||||||
//! Rank of the associated shadow
|
//! Rank of the associated shadow
|
||||||
|
@ -140,12 +140,6 @@ struct EngineObject
|
||||||
bool ghost = false;
|
bool ghost = false;
|
||||||
//! Team
|
//! Team
|
||||||
int team = 0;
|
int team = 0;
|
||||||
|
|
||||||
//! Loads default values
|
|
||||||
inline void LoadDefault()
|
|
||||||
{
|
|
||||||
*this = EngineObject();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -186,11 +180,6 @@ struct EngineShadow
|
||||||
float intensity = 0.0f;
|
float intensity = 0.0f;
|
||||||
//! Height from the ground
|
//! Height from the ground
|
||||||
float height = 0.0f;
|
float height = 0.0f;
|
||||||
|
|
||||||
void LoadDefault()
|
|
||||||
{
|
|
||||||
*this = EngineShadow();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -202,7 +191,7 @@ struct EngineGroundSpot
|
||||||
//! If true, ground spot is valid
|
//! If true, ground spot is valid
|
||||||
bool used = false;
|
bool used = false;
|
||||||
//! Color of the shadow
|
//! Color of the shadow
|
||||||
Color color;
|
Color color = {};
|
||||||
//! Min altitude
|
//! Min altitude
|
||||||
float min = 0.0f;
|
float min = 0.0f;
|
||||||
//! Max altitude
|
//! Max altitude
|
||||||
|
@ -210,18 +199,13 @@ struct EngineGroundSpot
|
||||||
//! Transition area
|
//! Transition area
|
||||||
float smooth = 0.0f;
|
float smooth = 0.0f;
|
||||||
//! Position for the shadow
|
//! Position for the shadow
|
||||||
glm::vec3 pos{ 0, 0, 0 };
|
glm::vec3 pos = { 0, 0, 0 };
|
||||||
//! Radius of the shadow
|
//! Radius of the shadow
|
||||||
float radius = 0.0f;
|
float radius = 0.0f;
|
||||||
//! Position of the shadow drawn
|
//! Position of the shadow drawn
|
||||||
glm::vec3 drawPos{ 0, 0, 0 };
|
glm::vec3 drawPos = { 0, 0, 0 };
|
||||||
//! Radius of the shadow drawn
|
//! Radius of the shadow drawn
|
||||||
float drawRadius = 0.0f;
|
float drawRadius = 0.0f;
|
||||||
|
|
||||||
void LoadDefault()
|
|
||||||
{
|
|
||||||
*this = EngineGroundSpot();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -249,7 +233,7 @@ struct EngineGroundMark
|
||||||
//! If true, draw mark
|
//! If true, draw mark
|
||||||
bool draw = false;
|
bool draw = false;
|
||||||
//! Phase of life
|
//! Phase of life
|
||||||
EngineGroundMarkPhase phase = ENG_GR_MARK_PHASE_NULL;
|
EngineGroundMarkPhase phase = ENG_GR_MARK_PHASE_NULL;
|
||||||
//! Times for 3 life phases
|
//! Times for 3 life phases
|
||||||
float delay[3] = {};
|
float delay[3] = {};
|
||||||
//! Fixed time
|
//! Fixed time
|
||||||
|
@ -272,11 +256,6 @@ struct EngineGroundMark
|
||||||
int dy = 0;
|
int dy = 0;
|
||||||
//! Pointer to the table
|
//! Pointer to the table
|
||||||
char* table = nullptr;
|
char* table = nullptr;
|
||||||
|
|
||||||
void LoadDefault()
|
|
||||||
{
|
|
||||||
*this = EngineGroundMark();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -973,6 +952,9 @@ public:
|
||||||
//! Indicates whether a point is visible
|
//! Indicates whether a point is visible
|
||||||
bool IsVisiblePoint(const glm::vec3& pos);
|
bool IsVisiblePoint(const glm::vec3& pos);
|
||||||
|
|
||||||
|
//! Returns object material color
|
||||||
|
Color GetObjectColor(int object, const std::string& name);
|
||||||
|
|
||||||
//! Updates the scene after a change of parameters
|
//! Updates the scene after a change of parameters
|
||||||
void ApplyChange();
|
void ApplyChange();
|
||||||
|
|
||||||
|
|
|
@ -209,6 +209,11 @@ void GLTFLoader::ReadMaterials()
|
||||||
mat.tag = extras["tag"].get<std::string>();
|
mat.tag = extras["tag"].get<std::string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (extras.contains("recolor"))
|
||||||
|
{
|
||||||
|
mat.recolor = extras["recolor"].get<std::string>();
|
||||||
|
}
|
||||||
|
|
||||||
if (extras.contains("recolor_ref"))
|
if (extras.contains("recolor_ref"))
|
||||||
{
|
{
|
||||||
const auto& color = extras["recolor_ref"];
|
const auto& color = extras["recolor_ref"];
|
||||||
|
@ -218,33 +223,7 @@ void GLTFLoader::ReadMaterials()
|
||||||
float b = color[2];
|
float b = color[2];
|
||||||
|
|
||||||
mat.recolorReference = Color(r, g, b);
|
mat.recolorReference = Color(r, g, b);
|
||||||
}
|
|
||||||
|
|
||||||
if (extras.contains("energy"))
|
|
||||||
{
|
|
||||||
if (extras["energy"].get<int>() != 0)
|
|
||||||
mat.tag = "energy";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (extras.contains("tracker_1"))
|
|
||||||
{
|
|
||||||
if (extras["tracker_1"].get<int>() != 0)
|
|
||||||
mat.tag = "tracker_right";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (extras.contains("tracker_2"))
|
|
||||||
{
|
|
||||||
if (extras["tracker_2"].get<int>() != 0)
|
|
||||||
mat.tag = "tracker_left";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (extras.contains("transparency"))
|
|
||||||
{
|
|
||||||
if (extras["transparency"].get<int>() != 0)
|
|
||||||
{
|
|
||||||
mat.alphaMode = AlphaMode::MASK;
|
|
||||||
mat.alphaThreshold = 0.5f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue