Merge remote-tracking branch 'origin/master' into ExplosionEffectV2

# Conflicts:
#	resources/Schema/Components/ExplosionEffect.xml
#	resources/Shaders/ExplosionEffect.geom.glsl
#	src/Game/Systems/ExplosionEffectSystem.cpp
This commit is contained in:
FakeShemp
2016-03-10 11:49:51 +01:00
184 changed files with 36165 additions and 12717 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
const EntityWrapper EntityWrapper::Invalid = EntityWrapper(nullptr, EntityID_Invalid);
const std::string EntityWrapper::Name()
const std::string EntityWrapper::Name() const
{
return World->GetName(ID);
}
+6 -6
View File
@@ -24,7 +24,7 @@ glm::vec3 Transform::AbsolutePosition(World* world, EntityID entity)
while (entity != EntityID_Invalid) {
ComponentWrapper transform = world->GetComponent(entity, "Transform");
EntityID parent = world->GetParent(entity);
position += Transform::AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"];
position += Transform::AbsoluteScale(world, parent) * (Transform::AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"]);
entity = parent;
}
@@ -89,12 +89,12 @@ glm::mat4 Transform::ModelMatrix(EntityID entity, World* world)
{
return AbsoluteTransformation(EntityWrapper(world, entity));
glm::vec3 position = Transform::AbsolutePosition(world, entity);
glm::quat orientation = Transform::AbsoluteOrientation(world, entity);
glm::vec3 scale = Transform::AbsoluteScale(world, entity);
//glm::vec3 position = Transform::AbsolutePosition(world, entity);
//glm::quat orientation = Transform::AbsoluteOrientation(world, entity);
//glm::vec3 scale = Transform::AbsoluteScale(world, entity);
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
return modelMatrix;
//glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
//return modelMatrix;
}
glm::vec3 Transform::TransformPoint(const glm::vec3& point, const glm::mat4& matrix)
+2 -2
View File
@@ -7,7 +7,7 @@ EditorRenderSystem::EditorRenderSystem(SystemParams params, IRenderer* renderer,
{
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &EditorRenderSystem::OnSetCamera);
auto resolution = Rectangle::Rectangle(1280, 720);
m_EditorCamera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.01f, 5000.f);
m_EditorCamera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.001f, 500.f);
}
void EditorRenderSystem::Update(double dt)
@@ -54,7 +54,7 @@ void EditorRenderSystem::Update(double dt)
EntityWrapper entity(m_World, cModel.EntityID);
glm::mat4 modelMatrix = Transform::ModelMatrix(entity.ID, entity.World);
for (auto matGroup : model->MaterialGroups()) {
std::shared_ptr<ModelJob> modelJob = std::make_shared<ModelJob>(model, scene.Camera, modelMatrix, matGroup, cModel, entity.World, glm::vec4(0), 0.f, false);
std::shared_ptr<ModelJob> modelJob = std::make_shared<ModelJob>(model, scene.Camera, modelMatrix, matGroup, cModel, entity.World, glm::vec4(0), 0.f, false, false);
if (cModel["Transparent"]) {
scene.Jobs.TransparentObjects.push_back(modelJob);
} else {
+9 -2
View File
@@ -204,14 +204,21 @@ bool EditorSystem::OnWidgetDelta(const Events::WidgetDelta& e)
if (m_CurrentSelection.Valid()) {
if (m_WidgetSpace == EditorGUI::WidgetSpace::Global) {
glm::quat parentOrientation;
glm::vec3 parentScale(1.f);
EntityWrapper parent = m_CurrentSelection.Parent();
if (parent.Valid()) {
parentOrientation = glm::inverse(Transform::AbsoluteOrientation(parent));
parentScale = Transform::AbsoluteScale(parent);
}
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation;
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation / parentScale;
} else if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) {
glm::vec3 parentScale(1.f);
EntityWrapper parent = m_CurrentSelection.Parent();
if (parent.Valid()) {
parentScale = Transform::AbsoluteScale(parent);
}
glm::quat selectionOri = glm::quat((glm::vec3)m_CurrentSelection["Transform"]["Orientation"]);
glm::vec3 localTranslation = selectionOri * e.Translation;
glm::vec3 localTranslation = selectionOri * e.Translation / parentScale;
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += localTranslation;
}
m_EditorGUI->SetDirty(m_CurrentSelection);
+2 -2
View File
@@ -40,7 +40,7 @@ bool ButtonSystem::OnMousePress(const Events::MousePress& e)
//You have clicked on a button entity, send pressed event.
if (m_World->HasComponent(m_PickData.Entity, "InputCmdButton")) {
Events::InputCommand eInputCmd;
eInputCmd.PlayerID = LocalPlayer.ID;
eInputCmd.PlayerID = -1;
eInputCmd.Player = LocalPlayer;
EntityWrapper button = EntityWrapper(m_World, m_PickData.Entity);
eInputCmd.Command = (std::string)button["InputCmdButton"]["Command"];
@@ -68,7 +68,7 @@ bool ButtonSystem::OnMouseRelease(const Events::MouseRelease& e)
if (m_World->HasComponent(m_PickData.Entity, "InputCmdButton")) {
Events::InputCommand eInputCmd;
eInputCmd.PlayerID = LocalPlayer.ID;
eInputCmd.PlayerID = -1;
eInputCmd.Player = LocalPlayer;
EntityWrapper button = EntityWrapper(m_World, m_PickData.Entity);
eInputCmd.Command = (std::string)button["InputCmdButton"]["Command"];
-57
View File
@@ -1,57 +0,0 @@
#include "GUI/MainMenuSystem.h"
MainMenuSystem::MainMenuSystem(SystemParams params, IRenderer* renderer)
: System(params)
, ImpureSystem()
, m_Renderer(renderer)
{
EVENT_SUBSCRIBE_MEMBER(m_EPressed, &MainMenuSystem::OnButtonPress);
EVENT_SUBSCRIBE_MEMBER(m_EReleased, &MainMenuSystem::OnButtonRelease);
EVENT_SUBSCRIBE_MEMBER(m_EClicked, &MainMenuSystem::OnButtonClick);
}
void MainMenuSystem::Update(double dt)
{
}
bool MainMenuSystem::OnButtonClick(const Events::ButtonClicked& e)
{
if(e.EntityName == "Play") {
//Run play code
} else if(e.EntityName == "Connect") {
//Run connect code
} else if(e.EntityName == "Host") {
//Run host code
} else if(e.EntityName == "Quit") {
printf("No, you stay");
} else if (e.EntityName == "Res1080") {
glfwSetWindowSize(m_Renderer->Window(), 1920, 1080);
printf("\n1080");
} else if (e.EntityName == "Res720") {
glfwSetWindowSize(m_Renderer->Window(), 1280, 720);
glViewport(0, 0, 1280, 720);
printf("\n720");
} else if (e.EntityName == "Res480") {
glfwSetWindowSize(m_Renderer->Window(), 854, 480);
glViewport(0, 0, 854, 480);
printf("\n480");
} else if (e.EntityName == "FullScreen") {
printf("No fullscreen for now");
}
return true;
}
bool MainMenuSystem::OnButtonRelease(const Events::ButtonReleased& e)
{
return true;
}
bool MainMenuSystem::OnButtonPress(const Events::ButtonPressed& e)
{
return true;
}
+9 -5
View File
@@ -45,7 +45,7 @@ void InputProxy::Update(double dt)
}
}
void InputProxy::Process()
void InputProxy::Process(bool suppressNewEvents /*= false*/)
{
for (auto& pair : m_CommandHandlers) {
const std::string& command = pair.first;
@@ -62,8 +62,10 @@ void InputProxy::Process()
e.PlayerID = -1;
e.Command = command;
e.Value = currentValue;
m_EventBroker->Publish(e);
//LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, e.PlayerID);
if (!suppressNewEvents || e.Value == 0) {
m_EventBroker->Publish(e);
//LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, e.PlayerID);
}
m_LastCommandValues[command] = currentValue;
}
}
@@ -78,8 +80,10 @@ void InputProxy::Process()
e.Value += value;
}
//e.Value = std::max(-1.f, std::min(e.Value, 1.f));
m_EventBroker->Publish(e);
//LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, e.PlayerID);
if (!suppressNewEvents || e.Value == 0) {
m_EventBroker->Publish(e);
//LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, e.PlayerID);
}
}
m_CommandQueue.clear();
}
+47 -11
View File
@@ -35,6 +35,7 @@ void Client::Connect(std::string address, int port)
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &Client::OnDoubleJump);
EVENT_SUBSCRIBE_MEMBER(m_EDashAbility, &Client::OnDashAbility);
EVENT_SUBSCRIBE_MEMBER(m_ESearchForServers, &Client::OnSearchForServers);
EVENT_SUBSCRIBE_MEMBER(m_EConnectRequest, &Client::OnConnectRequest);
auto config = ResourceManager::Load<ConfigFile>("Config.ini");
m_Address = address;
if (address.empty()) {
@@ -82,7 +83,10 @@ void Client::Update()
if (m_SearchingForServers) {
if (m_SearchingTime < (1000* (std::clock() - m_StartSearchTime) / (double)CLOCKS_PER_SEC)) {
m_SearchingForServers = false;
displayServerlist();
//displayServerlist();
Events::DisplayServerlist e;
e.Serverlist = m_Serverlist;
m_EventBroker->Publish(e);
}
}
@@ -177,8 +181,8 @@ void Client::parseTCPConnect(Packet& packet)
Packet UnreliablePacket(MessageType::Connect, m_SendPacketID);
// Add player id and other stuff
packet.WritePrimitive(m_PlayerID);
// m_Unreliable.Send(packet);
// LOG_INFO("Sent UDP Connect Server");
// m_Unreliable.Send(packet);
// LOG_INFO("Sent UDP Connect Server");
}
void Client::parsePlayerConnected(Packet & packet)
@@ -453,29 +457,25 @@ void Client::parseSnapshot(Packet& packet)
void Client::disconnect()
{
removeWorld();
m_IsConnected = false;
m_PreviousPacketID = 0;
m_PacketID = 0;
Packet packet(MessageType::Disconnect, m_SendPacketID);
m_Reliable.Send(packet);
m_Reliable.Disconnect();
createMainMenu();
}
bool Client::OnInputCommand(const Events::InputCommand & e)
{
// TEMP
if (e.Command == "SearchForServers" && e.Value > 0) {
Events::SearchForServers e;
m_EventBroker->Publish(e);
}
if (e.PlayerID != -1) {
return false;
}
if (e.Command == "ConnectToServer") { // Connect for now
if (e.Value > 0) {
m_Reliable.Connect(m_PlayerName, m_Address, m_Port);
//m_Reliable.Connect(m_PlayerName, m_Address, m_Port);
// m_Unreliable.Connect(m_PlayerName, m_Address, m_Port);
}
//LOG_DEBUG("Client::OnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);
@@ -548,12 +548,28 @@ bool Client::OnDashAbility(const Events::DashAbility& e)
return true;
}
bool Client::OnConnectRequest(const Events::ConnectRequest& e)
{
removeWorld();
if (m_Reliable.Connect(m_PlayerName, e.IP, e.Port)) {
// The client sent a successful connect message
return true;
} else {
// The client could not send a successful connect message
createMainMenu();
// Load the main menu again ?
return false;
}
return false;
}
bool Client::OnSearchForServers(const Events::SearchForServers& e)
{
m_SearchingForServers = true;
m_StartSearchTime = std::clock();
m_Serverlist.clear();
LOG_INFO("Searching for LAN servers...\n");
Packet packet(MessageType::ServerlistRequest);
m_ServerlistRequest.Broadcast(packet, 13); // TODO: Config
return true;
@@ -675,6 +691,26 @@ void Client::displayServerlist()
}
}
void Client::removeWorld()
{
std::vector<EntityID> childrenToBeDeleted;
auto rootEntites = m_World->GetDirectChildren(EntityID_Invalid);
for (auto it = rootEntites.first; it != rootEntites.second; it++) {
childrenToBeDeleted.push_back(it->second);
}
for (int i = 0; i < childrenToBeDeleted.size(); ++i) {
m_World->DeleteEntity(childrenToBeDeleted[i]);
}
}
void Client::createMainMenu()
{
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/StartMenu.xml");
entityFile->MergeInto(m_World);
}
bool Client::clientServerMapsHasEntity(EntityID clientEntityID)
{
if (m_ClientIDToServerID.find(clientEntityID) != m_ClientIDToServerID.end()) {
+6 -18
View File
@@ -7,6 +7,8 @@ Server::Server(World* world, EventBroker* eventBroker, int port)
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
snapshotInterval = 1000 * config->Get<float>("Networking.SnapshotInterval", 0.05f);
pingIntervalMs = config->Get<float>("Networking.PingIntervalMs", 1000);
m_ServerName = config->Get<std::string>("Networking.Name", "Unnamed");
// Subscribe to events
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &Server::OnInputCommand);
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &Server::OnPlayerSpawned);
@@ -162,7 +164,7 @@ void Server::unreliableBroadcast(Packet& packet)
{
for (auto& kv : m_ConnectedPlayers) {
packet.ChangePacketID(kv.second.PacketID);
// m_Unreliable.Send(packet, kv.second);
// m_Unreliable.Send(packet, kv.second);
}
}
@@ -410,7 +412,7 @@ void Server::parseServerlistRequest(boost::asio::ip::udp::endpoint endpoint)
Packet packet(MessageType::ServerlistRequest);
packet.WriteString(m_Reliable.Address());
packet.WritePrimitive<int>(m_Reliable.Port());
packet.WriteString("SERVERNAME");
packet.WriteString(m_ServerName);
packet.WritePrimitive<int>(m_ConnectedPlayers.size());
m_ServerlistRequest.Send(packet);
}
@@ -641,21 +643,7 @@ void Server::parsePlayerTransform(Packet& packet)
bool Server::shouldSendToClient(EntityWrapper childEntity)
{
auto children = m_World->GetDirectChildren(childEntity.ID);
for (auto it = children.first; it != children.second; it++) {
EntityWrapper child(m_World, it->second);
if (child.HasComponent("CapturePoint") || child.HasComponent("HealthPickup")
|| child.HasComponent("AmmoPickup")) {
return true;
}
}
return childEntity.HasComponent("Player")
|| childEntity.FirstParentWithComponent("Player").Valid()
|| childEntity.HasComponent("CapturePoint")
|| childEntity.HasComponent("HealthPickup")
|| childEntity.HasComponent("AmmoPickup")
|| childEntity.HasComponent("ScoreScreen")
|| childEntity.FirstParentWithComponent("ScoreScreen").Valid();
return childEntity.HasComponent("NetworkComponent") || childEntity.FirstParentWithComponent("NetworkComponent").Valid();
}
PlayerID Server::getPlayerIDFromEndpoint()
@@ -674,7 +662,7 @@ PlayerID Server::getPlayerIDFromEndpoint()
PlayerID Server::getPlayerIDFromEntityID(EntityID entityID)
{
for(auto& kv : m_ConnectedPlayers) {
for (auto& kv : m_ConnectedPlayers) {
if (entityID == kv.second.EntityID) {
return kv.first;
}
+4 -1
View File
@@ -10,7 +10,7 @@ TCPClient::~TCPClient()
{
}
void TCPClient::Connect(std::string playerName, std::string address, int port)
bool TCPClient::Connect(std::string playerName, std::string address, int port)
{
if (m_Socket) {
if (m_IsConnected) {
@@ -19,6 +19,7 @@ void TCPClient::Connect(std::string playerName, std::string address, int port)
Send(packet);
LOG_INFO("Connect message sent again!");
}
return true;
}
else if (!m_IsConnected) {
boost::system::error_code error = boost::asio::error::host_not_found;
@@ -34,11 +35,13 @@ void TCPClient::Connect(std::string playerName, std::string address, int port)
packet.WriteString(playerName);
Send(packet);
LOG_INFO("Connect message sent!");
return true;
}
// If error
else {
m_Socket->close();
m_Socket = nullptr;
return false;
}
}
}
+3 -2
View File
@@ -10,14 +10,15 @@ UDPClient::~UDPClient()
{
}
void UDPClient::Connect(std::string playerName, std::string address, int port)
bool UDPClient::Connect(std::string playerName, std::string address, int port)
{
if (m_Socket) {
return;
return false;
}
m_ReceiverEndpoint = udp::endpoint(boost::asio::ip::address().from_string(address), port);
m_Socket = boost::shared_ptr<boost::asio::ip::udp::socket>(new boost::asio::ip::udp::socket(m_IOService));
m_Socket->open(boost::asio::ip::udp::v4());
return true;
}
void UDPClient::Disconnect()
+164 -38
View File
@@ -4,6 +4,8 @@ AnimationSystem::AnimationSystem(SystemParams params)
: System(params)
{
EVENT_SUBSCRIBE_MEMBER(m_EAutoAnimationBlend, &AnimationSystem::OnAutoAnimationBlend);
EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &AnimationSystem::OnEntityDeleted);
EVENT_SUBSCRIBE_MEMBER(m_ESetBlendWeight, &AnimationSystem::OnSetBlendWeight);
}
void AnimationSystem::Update(double dt)
@@ -122,16 +124,16 @@ void AnimationSystem::UpdateAnimations(double dt)
}
}
void AnimationSystem::UpdateWeights(double dt)
{
for (auto& autoBlendQueue : m_AutoBlendQueues) {
if(autoBlendQueue.second.HasActiveBlendJob()) {
AutoBlendQueue::AutoBlendJob& blendJob = autoBlendQueue.second.GetActiveBlendJob();
std::shared_ptr<BlendTree> blendTree = autoBlendQueue.second.GetBlendTree();
for (auto it = m_AutoBlendQueues.begin(); it != m_AutoBlendQueues.end(); ) {
/* LOG_INFO("%s", it->first.Name().c_str());
it->second.PrintQueue();*/
if(it->second.HasActiveBlendJob()) {
AutoBlendQueue::AutoBlendJob& blendJob = it->second.GetActiveBlendJob();
//LOG_INFO("%s", blendJob.RootNode.Name().c_str());
std::shared_ptr<BlendTree> blendTree = it->second.GetBlendTree();
if (blendTree != nullptr) {
if (blendJob.Duration != 0.0) {
blendJob.BlendInfo.progress = glm::clamp(blendJob.CurrentTime / blendJob.Duration, 0.0, 1.0);
@@ -140,10 +142,17 @@ void AnimationSystem::UpdateWeights(double dt)
}
blendJob.BlendInfo = blendTree->AutoBlendStep(blendJob.BlendInfo);
} else {
it = m_AutoBlendQueues.erase(it);
}
it++;
} else {
if (it->second.Empty()) {
it = m_AutoBlendQueues.erase(it);
} else {
it++;
}
}
}
}
@@ -177,46 +186,163 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e)
return false;
}
EntityWrapper subTreeRoot;
EntityWrapper subTreeRoot = blendTree->GetSubTreeRoot(e.NodeName);
if (e.SingleLevelBlend) {
subTreeRoot = blendTree->GetSubTreeRoot(e.NodeName);
if (!subTreeRoot.Valid()) {
return false;
}
if (!subTreeRoot.Valid()) {
return false;
}
AutoBlendQueue::AutoBlendJob abj;
abj.AnimationEntity = e.AnimationEntity;
abj.CurrentTime = 0.0;
abj.Delay = e.Delay;
abj.Duration = e.Duration;
abj.RootNode = e.RootNode;
AutoBlendQueue::AutoBlendJob abj;
abj.AnimationEntity = e.AnimationEntity;
abj.CurrentTime = 0.0;
abj.Delay = e.Delay;
abj.Duration = e.Duration;
abj.RootNode = e.RootNode;
abj.BlendInfo.NodeName = e.NodeName;
abj.BlendInfo.progress = 0.0;
abj.BlendInfo.Start = e.Start;
abj.BlendInfo.SingleBlend = e.SingleLevelBlend;
abj.BlendInfo.Weight = e.Weight;
abj.BlendInfo.NodeName = e.NodeName;
abj.BlendInfo.progress = 0.0;
abj.BlendInfo.Start = e.Start;
abj.BlendInfo.SingleBlend = e.SingleLevelBlend;
abj.BlendInfo.Weight = e.Weight;
EntityWrapper nodeEntity = subTreeRoot.FirstChildByName(e.NodeName); // more than one
if (nodeEntity.Valid()) {
if (nodeEntity.HasComponent("Animation")) {
const Skeleton::Animation* animation = skeleton->GetAnimation(nodeEntity["Animation"]["AnimationName"]);
(bool&)nodeEntity["Animation"]["Reverse"] = e.Reverse;
std::vector<EntityWrapper> animationEntities = blendTree->GetEntitesByName(e.NodeName); // more than one
for(auto entity : animationEntities)
if (entity.Valid()) {
if (entity.HasComponent("Animation")) {
const Skeleton::Animation* animation = skeleton->GetAnimation(entity["Animation"]["AnimationName"]);
(bool&)entity["Animation"]["Reverse"] = e.Reverse;
if (e.Restart) {
if (animation != nullptr) {
if (e.Restart) {
if (e.Reverse) {
(double&)nodeEntity["Animation"]["Time"] = animation->Duration;
} else {
(double&)nodeEntity["Animation"]["Time"] = 0.0;
if (e.Restart) {
if (animation != nullptr) {
if (e.Restart) {
if (e.Reverse) {
(double&)entity["Animation"]["Time"] = animation->Duration;
} else {
(double&)entity["Animation"]["Time"] = 0.0;
}
}
}
}
}
}
m_AutoBlendQueues[subTreeRoot].Insert(abj);
} else {
std::vector<EntityWrapper> subtreeroots = blendTree->GetSingleLevelRoots(e.NodeName);
for(auto entity : subtreeroots) {
subTreeRoot = entity;
if (!subTreeRoot.Valid()) {
return false;
}
AutoBlendQueue::AutoBlendJob abj;
abj.AnimationEntity = e.AnimationEntity;
abj.CurrentTime = 0.0;
abj.Delay = e.Delay;
abj.Duration = e.Duration;
abj.RootNode = e.RootNode;
abj.BlendInfo.NodeName = e.NodeName;
abj.BlendInfo.progress = 0.0;
abj.BlendInfo.Start = e.Start;
abj.BlendInfo.SingleBlend = e.SingleLevelBlend;
abj.BlendInfo.Weight = e.Weight;
m_AutoBlendQueues[subTreeRoot].Insert(abj);
}
std::vector<EntityWrapper> animationEntities = blendTree->GetEntitesByName(e.NodeName); // more than one
for (auto entity : animationEntities)
if (entity.Valid()) {
if (entity.HasComponent("Animation")) {
const Skeleton::Animation* animation = skeleton->GetAnimation(entity["Animation"]["AnimationName"]);
(bool&)entity["Animation"]["Reverse"] = e.Reverse;
if (e.Restart) {
if (animation != nullptr) {
if (e.Restart) {
if (e.Reverse) {
(double&)entity["Animation"]["Time"] = animation->Duration;
} else {
(double&)entity["Animation"]["Time"] = 0.0;
}
}
}
}
}
}
}
m_AutoBlendQueues[subTreeRoot].Insert(abj);
return true;
}
bool AnimationSystem::OnEntityDeleted(Events::EntityDeleted& e)
{
EntityWrapper entity = EntityWrapper(m_World, e.DeletedEntity);
if (entity.HasComponent("Model")) {
Model* model;
try {
model = ResourceManager::Load<::Model, true>(entity["Model"]["Resource"]);
} catch (const std::exception&) {
return false;
}
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
if (skeleton == nullptr) {
return false;
}
if (skeleton->BlendTrees.find(entity) != skeleton->BlendTrees.end()) {
skeleton->BlendTrees.erase(entity);
}
}
}
bool AnimationSystem::OnSetBlendWeight(Events::SetBlendWeight& e)
{
if (!e.RootNode.Valid()) {
return false;
}
if (!e.RootNode.HasComponent("Model")) {
return false;
}
Model* model;
try {
model = ResourceManager::Load<::Model, true>((std::string)e.RootNode["Model"]["Resource"]);
} catch (const std::exception&) {
return false;
}
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
if (skeleton == nullptr) {
return false;
}
std::shared_ptr<BlendTree> blendTree;
if (skeleton->BlendTrees.find(e.RootNode) != skeleton->BlendTrees.end()) {
blendTree = skeleton->BlendTrees.at(e.RootNode);
} else {
return false;
}
if(e.Weight >= 0 && e.Weight <= 1) {
blendTree->SetWeightByName(e.NodeName, e.Weight);
return true;
} else {
return false;
}
}
+8 -6
View File
@@ -38,11 +38,14 @@ void AutoBlendQueue::Insert(AutoBlendJob autoBlendJob)
double animationSpeed = (double)autoBlendJob.AnimationEntity["Animation"]["Speed"];
double animationTime = (double)autoBlendJob.AnimationEntity["Animation"]["Time"];
if ((bool)autoBlendJob.AnimationEntity["Animation"]["Reverse"]) {
AnimationDuration = (animation->Duration * animationSpeed) - (animation->Duration - animationTime);
if (animationSpeed != 0) {
if ((bool)autoBlendJob.AnimationEntity["Animation"]["Reverse"]) {
AnimationDuration = (animation->Duration / animationSpeed) - (animation->Duration - animationTime);
} else {
AnimationDuration = (animation->Duration / animationSpeed) - animationTime;
}
} else {
AnimationDuration = (animation->Duration * animationSpeed) - animationTime;
return;
}
blendNode.StartTime += AnimationDuration;
@@ -75,7 +78,6 @@ void AutoBlendQueue::Insert(AutoBlendJob autoBlendJob)
}
}
m_BlendQueue.clear();
m_BlendQueue.push_back(blendNode);
}
@@ -124,7 +126,7 @@ bool AutoBlendQueue::HasActiveBlendJob()
try {
model = ResourceManager::Load<::Model, true>(blendJob.RootNode["Model"]["Resource"]);
} catch (const std::exception&) {
m_BlendQueue.pop_front();
//m_BlendQueue.pop_front();
return HasActiveBlendJob();
}
+53 -6
View File
@@ -2,11 +2,8 @@
BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton)
{
m_Skeleton = skeleton;
if (ModelEntity.HasComponent("Animation")) {
const Skeleton::Animation* animation = skeleton->GetAnimation(ModelEntity["Animation"]["AnimationName"]);
if (animation == nullptr) {
@@ -217,7 +214,6 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo)
}
}
}
return blendInfo;
}
@@ -270,7 +266,7 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo)
currentNode = currentNode->Parent;
if (blendInfo.SingleBlend) {
break;
return blendInfo;;
}
}
} else if(goalNodes.size() >= 2) {
@@ -331,9 +327,11 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo)
lastNode = currentNode;
currentNode = currentNode->Parent;
if (blendInfo.SingleBlend) {
return blendInfo;
}
}
}
}
return blendInfo;
@@ -427,6 +425,55 @@ EntityWrapper BlendTree::GetSubTreeRoot(std::string nodeName)
return subTreeRoots.front()->Entity;
}
std::vector<EntityWrapper> BlendTree::GetSingleLevelRoots(std::string name)
{
std::vector<Node*> nodes = FindNodesByName(name);
std::vector<EntityWrapper> entities;
for (auto it = nodes.begin(); it != nodes.end(); it++) {
Node* currentNode = (*it)->Parent;
if(currentNode->Entity.Valid()) {
entities.push_back(currentNode->Entity);
}
}
return entities;
}
std::vector<EntityWrapper> BlendTree::GetEntitesByName(std::string name)
{
std::vector<Node*> nodes = FindNodesByName(name);
std::vector<EntityWrapper> entities;
for (auto it = nodes.begin(); it != nodes.end(); it++) {
Node* currentNode = (*it);
if (currentNode->Entity.Valid()) {
entities.push_back(currentNode->Entity);
}
}
return entities;
}
void BlendTree::SetWeightByName(std::string name, double weight)
{
std::vector<Node*> nodes = FindNodesByName(name);
for (auto node : nodes) {
EntityWrapper entity = node->Entity;
if(entity.HasComponent("Blend")) {
entity["Blend"]["Weight"] = weight;
node->Weight = weight;
}
}
}
void BlendTree::Blend(std::map<int, Skeleton::PoseData>& pose)
{
Node* currentNode;
+282
View File
@@ -0,0 +1,282 @@
#include "Rendering/BlurHUD.h"
BlurHUD::BlurHUD(IRenderer* renderer)
: m_Renderer(renderer)
{
InitializeShaderPrograms();
InitializeBuffers();
InitializeTextures();
}
void BlurHUD::InitializeTextures()
{
m_BlackTexture = CommonFunctions::TryLoadResource<Texture, false>("Textures/Core/Black.png");
m_ScreenQuad = ResourceManager::Load<Model>("Models/Core/ScreenQuad.mesh");
}
void BlurHUD::InitializeShaderPrograms()
{
m_GaussianProgram_horiz = ResourceManager::Load<ShaderProgram>("##GaussianProgramHoriz");
if (m_GaussianProgram_horiz->GetHandle() == 0) {
m_GaussianProgram_horiz->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Gaussian_horiz.vert.glsl")));
m_GaussianProgram_horiz->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Gaussian_horiz.frag.glsl")));
m_GaussianProgram_horiz->Compile();
m_GaussianProgram_horiz->BindFragDataLocation(0, "fragmentColor");
m_GaussianProgram_horiz->Link();
}
m_GaussianProgram_vert = ResourceManager::Load<ShaderProgram>("##GaussianProgramVert");
if (m_GaussianProgram_vert->GetHandle() == 0) {
m_GaussianProgram_vert->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Gaussian_vert.vert.glsl")));
m_GaussianProgram_vert->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Gaussian_vert.frag.glsl")));
m_GaussianProgram_vert->Compile();
m_GaussianProgram_vert->BindFragDataLocation(0, "fragmentColor");
m_GaussianProgram_vert->Link();
}
m_FillDepthStencilProgram = ResourceManager::Load<ShaderProgram>("#FillDepthStencilProgram");
if (m_FillDepthStencilProgram->GetHandle() == 0) {
m_FillDepthStencilProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/FillDepthBuffer.vert.glsl")));
m_FillDepthStencilProgram->Compile();
m_FillDepthStencilProgram->Link();
}
m_CombineTexturesProgram = ResourceManager::Load<ShaderProgram>("#CombineTexturesProgram");
if (m_CombineTexturesProgram->GetHandle() == 0) {
m_CombineTexturesProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/CombineTexture.vert.glsl")));
m_CombineTexturesProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/CombineTexture.frag.glsl")));
m_CombineTexturesProgram->Compile();
m_CombineTexturesProgram->BindFragDataLocation(0, "sceneColor");
m_CombineTexturesProgram->BindFragDataLocation(1, "bloomColor");
m_CombineTexturesProgram->Link();
}
GLERROR("Creating DepthFill program");
}
void BlurHUD::InitializeBuffers()
{
glm::vec2 res = glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glm::vec2 res2 = glm::vec2(m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality);
CommonFunctions::GenerateTexture(&m_DepthStencil_horiz, GL_CLAMP_TO_BORDER, GL_NEAREST,
res2, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
CommonFunctions::GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_NEAREST,
res2, GL_RGBA16F, GL_RGBA, GL_FLOAT);
if (m_GaussianFrameBuffer_horiz.GetHandle() == 0) {
m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthStencil_horiz, GL_DEPTH_STENCIL_ATTACHMENT)));
m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0)));
}
m_GaussianFrameBuffer_horiz.Generate();
CommonFunctions::GenerateTexture(&m_DepthStencil_vert, GL_CLAMP_TO_BORDER, GL_NEAREST,
res2, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
CommonFunctions::GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_NEAREST,
res2, GL_RGBA16F, GL_RGBA, GL_FLOAT);
if (m_GaussianFrameBuffer_vert.GetHandle() == 0) {
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthStencil_vert, GL_DEPTH_STENCIL_ATTACHMENT)));
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_vert, GL_COLOR_ATTACHMENT0)));
}
m_GaussianFrameBuffer_vert.Generate();
CommonFunctions::GenerateTexture(&m_CombinedTexture, GL_CLAMP_TO_BORDER, GL_NEAREST,
res, GL_RGB16F, GL_RGB, GL_FLOAT);
if (m_CombinedTextureBuffer.GetHandle() == 0) {
m_CombinedTextureBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_CombinedTexture, GL_COLOR_ATTACHMENT0)));
}
m_CombinedTextureBuffer.Generate();
}
void BlurHUD::ClearBuffer()
{
GLERROR("PRE");
m_GaussianFrameBuffer_horiz.Bind();
glClearColor(0.f, 0.f, 0.f, 0.f);
glClearStencil(0x00);
glStencilMask(~0);
glDisable(GL_SCISSOR_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_GaussianFrameBuffer_horiz.Unbind();
m_GaussianFrameBuffer_vert.Bind();
glClearColor(0.f, 0.f, 0.f, 0.f);
glClearStencil(0x00);
glStencilMask(~0);
glDisable(GL_SCISSOR_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_GaussianFrameBuffer_vert.Unbind();
m_CombinedTextureBuffer.Bind();
glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);
m_CombinedTextureBuffer.Unbind();
GLERROR("END");
}
//Returns the finished blurred texture
GLuint BlurHUD::Draw(GLuint texture, RenderScene& scene)
{
GLERROR("DrawBloomPass::Draw: Pre");
FillStencil(scene);
RenderState state;
state.Disable(GL_BLEND);
state.Disable(GL_DEPTH_TEST);
state.Disable(GL_CULL_FACE);
state.Enable(GL_STENCIL_TEST);
state.StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
state.StencilFunc(GL_EQUAL, 1, 0xFF);
state.StencilMask(0x00);
state.DepthMask(GL_FALSE);
state.Enable(GL_SCISSOR_TEST);
GLuint shaderHandle_horiz = m_GaussianProgram_horiz->GetHandle();
GLuint shaderHandle_vert = m_GaussianProgram_vert->GetHandle();
//Horizontal pass, first use the given texture then save it to the horizontal framebuffer.
m_GaussianFrameBuffer_horiz.Bind();
glViewport(0, 0, m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality);
glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
m_GaussianProgram_horiz->Bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
//Iterate some times to make it more gaussian.
for (int i = 1; i < m_Iterations; i++) {
//Vertical pass
m_GaussianFrameBuffer_vert.Bind();
m_GaussianProgram_vert->Bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_horiz);
glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
//horizontal pass
m_GaussianFrameBuffer_vert.Unbind();
m_GaussianFrameBuffer_horiz.Bind();
m_GaussianProgram_horiz->Bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_vert);
glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
m_GaussianFrameBuffer_horiz.Unbind();
}
//final vertical gaussian after the iterations are done
m_GaussianFrameBuffer_vert.Bind();
m_GaussianProgram_vert->Bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_horiz);
glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
GLERROR("DrawBloomPass::Draw: END");
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
return m_GaussianTexture_vert;
}
void BlurHUD::OnWindowResize()
{
CommonFunctions::GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality), GL_RGB16F, GL_RGB, GL_FLOAT);
m_GaussianFrameBuffer_vert.Generate();
CommonFunctions::GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality), GL_RGB16F, GL_RGB, GL_FLOAT);
m_GaussianFrameBuffer_horiz.Generate();
}
void BlurHUD::FillStencil(RenderScene& scene)
{
RenderState state;
state.BindFramebuffer(m_GaussianFrameBuffer_horiz.GetHandle());
state.Disable(GL_DEPTH_TEST);
state.Enable(GL_CULL_FACE);
state.Enable(GL_STENCIL_TEST);
state.StencilFunc(GL_ALWAYS, 1, 0xFF);
state.StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
state.StencilMask(0xFF);
glViewport(0, 0, m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality);
m_FillDepthStencilProgram->Bind();
GLuint shaderHandle = m_FillDepthStencilProgram->GetHandle();
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()));
for (auto& job : scene.Jobs.SpriteJob) {
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
if (!spriteJob) {
continue;
}
if (!spriteJob->BlurBackground) {
continue;
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(spriteJob->Matrix));
glBindVertexArray(spriteJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, spriteJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex*sizeof(unsigned int)));
}
state.BindFramebuffer(m_GaussianFrameBuffer_vert.GetHandle());
for (auto& job : scene.Jobs.SpriteJob) {
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
if (!spriteJob) {
continue;
}
if(!spriteJob->BlurBackground) {
continue;
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(spriteJob->Matrix));
glBindVertexArray(spriteJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, spriteJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex*sizeof(unsigned int)));
}
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
}
//Texture 1 will be used if texture 2 is black at that texel, else texture 2 is used.
GLuint BlurHUD::CombineTextures(GLuint texture1, GLuint texture2)
{
//RenderState state;
//state.BindFramebuffer(m_CombinedTextureBuffer.GetHandle());
//state.Disable(GL_DEPTH_TEST);
//state.Disable(GL_STENCIL_TEST);
m_CombineTexturesProgram->Bind();
glActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texture1);
glBindTexture(GL_TEXTURE_2D, texture2);
glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
return m_CombinedTexture;
}
@@ -50,13 +50,15 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp
glm::vec4 perspective;
glm::decompose(boneTransform, scale, rotation, translation, skew, perspective);
glm::vec3 angles = glm::vec3(-glm::pitch(rotation), -glm::yaw(rotation), -glm::roll(rotation));
rotation = glm::quat((glm::vec3)entity["BoneAttachment"]["OrientationOffset"]) * rotation;
rotation = glm::inverse(rotation);
glm::vec3 angles = glm::eulerAngles(rotation);
if ((bool)entity["BoneAttachment"]["InheritPosition"]) {
(glm::vec3&)entity["Transform"]["Position"] = translation + (glm::vec3)entity["BoneAttachment"]["PositionOffset"];
}
if ((bool)entity["BoneAttachment"]["InheritOrientation"]) {
(glm::vec3&)entity["Transform"]["Orientation"] = angles + (glm::vec3)entity["BoneAttachment"]["OrientationOffset"];
(glm::vec3&)entity["Transform"]["Orientation"] = angles;
}
if ((bool)entity["BoneAttachment"]["InheritScale"]) {
(glm::vec3&)entity["Transform"]["Scale"] = scale * (glm::vec3)entity["BoneAttachment"]["ScaleOffset"];
+6 -1
View File
@@ -9,9 +9,14 @@ DrawBloomPass::DrawBloomPass(IRenderer* renderer, ConfigFile* config)
ChangeQuality(m_Config->Get<int>("GLOW.Quality", 2));
}
DrawBloomPass::~DrawBloomPass() {
CommonFunctions::DeleteTexture(&m_GaussianTexture_horiz);
CommonFunctions::DeleteTexture(&m_GaussianTexture_vert);
}
void DrawBloomPass::InitializeTextures()
{
m_BlackTexture = CommonFunctions::LoadTexture("Textures/Core/Black.png", false);
m_BlackTexture = CommonFunctions::TryLoadResource<Texture, false>("Textures/Core/Black.png");
}
void DrawBloomPass::ChangeQuality(int quality)
+381 -115
View File
@@ -1,9 +1,10 @@
#include "Rendering/DrawFinalPass.h"
DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass)
DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, ShadowPass* shadowPass)
: m_Renderer(renderer)
, m_LightCullingPass(lightCullingPass)
, m_CubeMapPass(cubeMapPass)
, m_SSAOPass(ssaoPass)
, m_ShadowPass(shadowPass)
{
//TODO: Make sure that uniforms are not sent into shader if not needed.
m_ShieldPixelRate = 8;
@@ -12,13 +13,21 @@ DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCulling
InitializeFrameBuffers();
}
DrawFinalPass::~DrawFinalPass(){
CommonFunctions::DeleteTexture(&m_BloomTexture);
CommonFunctions::DeleteTexture(&m_SceneTexture);
CommonFunctions::DeleteTexture(&m_DepthBuffer);
CommonFunctions::DeleteTexture(&m_ShieldBuffer);
CommonFunctions::DeleteTexture(&m_CubeMapTexture);
}
void DrawFinalPass::InitializeTextures()
{
m_WhiteTexture = CommonFunctions::LoadTexture("Textures/Core/White.png", false);
m_BlackTexture = CommonFunctions::LoadTexture("Textures/Core/Black.png", false);
m_NeutralNormalTexture = CommonFunctions::LoadTexture("Textures/Core/NeutralNormalMap.png", false);
m_GreyTexture = CommonFunctions::LoadTexture("Textures/Core/Grey.png", false);
m_ErrorTexture = CommonFunctions::LoadTexture("Textures/Core/ErrorTexture.png", false);
m_WhiteTexture = CommonFunctions::TryLoadResource<Texture, false>("Textures/Core/White.png");
m_BlackTexture = CommonFunctions::TryLoadResource<Texture, false>("Textures/Core/Black.png");
m_NeutralNormalTexture = CommonFunctions::TryLoadResource<Texture, false>("Textures/Core/NeutralNormalMap.png");
m_GreyTexture = CommonFunctions::TryLoadResource<Texture, false>("Textures/Core/Grey.png");
m_ErrorTexture = CommonFunctions::TryLoadResource<Texture, false>("Textures/Core/ErrorTexture.png");
}
void DrawFinalPass::InitializeFrameBuffers()
@@ -233,7 +242,7 @@ void DrawFinalPass::InitializeShaderPrograms()
}
void DrawFinalPass::Draw(RenderScene& scene)
void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
{
GLERROR("Pre");
DrawFinalPassState* stateDethp = new DrawFinalPassState(m_ShieldDepthFrameBuffer.GetHandle());
@@ -280,16 +289,32 @@ void DrawFinalPass::Draw(RenderScene& scene)
DrawModelRenderQueuesWithShieldCheck(scene.Jobs.TransparentObjects, scene); //might need changing
GLERROR("Shielded Transparent objects");
//Generate blur texture.
delete state;
if (scene.ShouldBlur) {
//This needs to be drawn only when the full scene is being renderd, and then let be, otherwise sprite and other shit will show on it.
m_FullBlurredTexture = blurHUDPass->Draw(m_SceneTexture, scene);
}
DrawFinalPassState* stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
if(scene.ShouldBlur) {
//Combine nonblur and blur texture
stateSprite->Disable(GL_DEPTH_TEST);
stateSprite->Disable(GL_STENCIL_TEST);
m_CombinedTexture = blurHUDPass->CombineTextures(m_SceneTexture, m_FullBlurredTexture);
}
//Draw Transparen objects
//state->BlendFunc(GL_ONE, GL_ONE);
//state->StencilFunc(GL_EQUAL, 1, 0xFF);
//DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene);
GLERROR("TransparentObjects");
//state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
stateSprite->Enable(GL_DEPTH_TEST);
DrawSprites(scene.Jobs.SpriteJob, scene);
GLERROR("SpriteJobs");
delete state;
delete stateSprite;
GLERROR("END");
}
@@ -335,6 +360,8 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
GLuint explosionSkinnedHandle = m_ExplosionEffectSkinnedProgram->GetHandle();
GLuint explosionSplatMapSkinnedHandle = m_ExplosionEffectSplatMapSkinnedProgram->GetHandle();
GLuint forwardSplatMapSkinnedHandle = m_ForwardPlusSplatMapSkinnedProgram->GetHandle();
GLuint lastShader = 0;
unsigned int lastModel = 0;
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightCullingPass->LightSSBO());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO());
@@ -343,6 +370,13 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_SSAOPass->SSAOTexture());
glActiveTexture(GL_TEXTURE30);
if (m_ShadowPass->DepthMap() != NULL) {
glBindTexture(GL_TEXTURE_2D_ARRAY, m_ShadowPass->DepthMap());
} else {
glBindTexture(GL_TEXTURE_2D_ARRAY, m_WhiteTexture->m_Texture);
}
for (auto &job : jobs) {
auto explosionEffectJob = std::dynamic_pointer_cast<ExplosionEffectJob>(job);
if (explosionEffectJob) {
@@ -351,9 +385,17 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
case RawModel::MaterialType::SingleTextures:
{
if (explosionEffectJob->Model->IsSkinned()) {
m_ExplosionEffectSkinnedProgram->Bind();
GLERROR("Bind ExplosionEffectSkinned program");
if (lastShader != m_ExplosionEffectSkinnedProgram->GetHandle()) {
m_ExplosionEffectSkinnedProgram->Bind();
lastShader = m_ExplosionEffectSkinnedProgram->GetHandle();
GLERROR("Bind ExplosionEffectSkinned program");
glUniform1i(glGetUniformLocation(explosionSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSkinned Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSkinnedHandle, explosionEffectJob, scene);
//bind textures
@@ -373,8 +415,17 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
}
else {
m_ExplosionEffectProgram->Bind();
GLERROR("Bind ExplosionEffect program");
if (lastShader != m_ExplosionEffectProgram->GetHandle()) {
m_ExplosionEffectProgram->Bind();
lastShader = m_ExplosionEffectProgram->GetHandle();
GLERROR("Bind ExplosionEffect program");
glUniform1i(glGetUniformLocation(explosionHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffect Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionHandle, explosionEffectJob, scene);
//bind textures
@@ -388,8 +439,17 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
case RawModel::MaterialType::SplatMapping:
{
if (explosionEffectJob->Model->IsSkinned()) {
m_ExplosionEffectSplatMapSkinnedProgram->Bind();
GLERROR("Bind ExplosionEffectSplatMapSkinned program");
if (lastShader != m_ExplosionEffectSplatMapSkinnedProgram->GetHandle()) {
m_ExplosionEffectSplatMapSkinnedProgram->Bind();
lastShader = m_ExplosionEffectSplatMapSkinnedProgram->GetHandle();
GLERROR("Bind ExplosionEffectSplatMapSkinned program");
glUniform1i(glGetUniformLocation(explosionSplatMapSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSplatMapSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSplatMapSkinned Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSplatMapSkinnedHandle, explosionEffectJob, scene);
//bind textures
@@ -405,9 +465,17 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
}
else {
m_ExplosionEffectSplatMapProgram->Bind();
GLERROR("Bind ExplosionEffectSplatMap program");
//bind uniforms
if (lastShader != m_ExplosionEffectSplatMapProgram->GetHandle()) {
m_ExplosionEffectSplatMapProgram->Bind();
lastShader = m_ExplosionEffectSplatMapProgram->GetHandle();
GLERROR("Bind ExplosionEffectSplatMap program");
glUniform1i(glGetUniformLocation(explosionSplatMapHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSplatMapHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSplatMapHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSplatMap Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSplatMapHandle, explosionEffectJob, scene);
//bind textures
@@ -420,8 +488,11 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
glDisable(GL_CULL_FACE);
//draw
glBindVertexArray(explosionEffectJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer);
if (lastModel != explosionEffectJob->ModelID) {
glBindVertexArray(explosionEffectJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer);
lastModel = explosionEffectJob->ModelID;
}
glDrawElements(GL_TRIANGLES, explosionEffectJob->EndIndex - explosionEffectJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(explosionEffectJob->StartIndex*sizeof(unsigned int)));
glEnable(GL_CULL_FACE);
GLERROR("explosion effect end");
@@ -435,8 +506,17 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
case RawModel::MaterialType::SingleTextures:
{
if (modelJob->Model->IsSkinned()) {
m_ForwardPlusSkinnedProgram->Bind();
GLERROR("Bind ForwardPlusSkinnedProgram");
if (lastShader != m_ForwardPlusSkinnedProgram->GetHandle()) {
m_ForwardPlusSkinnedProgram->Bind();
lastShader = m_ForwardPlusSkinnedProgram->GetHandle();
GLERROR("Bind ForwardPlusSkinnedProgram program");
glUniform1i(glGetUniformLocation(forwardSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ForwardPlusSkinnedProgram Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSkinnedHandle, modelJob, scene);
//bind textures
@@ -454,8 +534,17 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
else {
m_ForwardPlusProgram->Bind();
GLERROR("Bind ForwardPlusProgram");
if (lastShader != m_ForwardPlusProgram->GetHandle()) {
m_ForwardPlusProgram->Bind();
lastShader = m_ForwardPlusProgram->GetHandle();
GLERROR("Bind ForwardPlusProgram program");
glUniform1i(glGetUniformLocation(forwardHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ForwardPlusProgram Uniforms");
}
//bind uniforms
BindModelUniforms(forwardHandle, modelJob, scene);
//bind textures
@@ -469,8 +558,17 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
case RawModel::MaterialType::SplatMapping:
{
if (modelJob->Model->IsSkinned()) {
m_ForwardPlusSplatMapSkinnedProgram->Bind();
GLERROR("Bind SplatMap program");
if (lastShader != m_ForwardPlusSplatMapSkinnedProgram->GetHandle()) {
m_ForwardPlusSplatMapSkinnedProgram->Bind();
lastShader = m_ForwardPlusSplatMapSkinnedProgram->GetHandle();
GLERROR("Bind SkinnedSplatMapProgram program");
glUniform1i(glGetUniformLocation(forwardSplatMapSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSplatMapSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind SkinnedSplatMapProgram Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSplatMapSkinnedHandle, modelJob, scene);
//bind textures
@@ -486,8 +584,17 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
}
else {
m_ForwardPlusSplatMapProgram->Bind();
GLERROR("Bind SplatMap program");
if (lastShader != m_ForwardPlusSplatMapProgram->GetHandle()) {
m_ForwardPlusSplatMapProgram->Bind();
lastShader = m_ForwardPlusSplatMapProgram->GetHandle();
GLERROR("Bind SplatMap program");
glUniform1i(glGetUniformLocation(forwardSplatMapHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSplatMapHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSplatMapHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind SplatMap Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSplatMapHandle, modelJob, scene);
//bind textures
@@ -498,8 +605,11 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
}
}
//draw
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
if (lastModel != modelJob->ModelID) {
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
lastModel = modelJob->ModelID;
}
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex*sizeof(unsigned int)));
if (GLERROR("models end")) {
continue;
@@ -528,6 +638,8 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
GLuint explosionSkinnedShieldCheckHandle = m_ExplosionEffectSkinnedShieldCheckProgram->GetHandle();
GLuint explosionSplatMapSkinnedShieldCheckHandle = m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->GetHandle();
GLuint forwardSplatMapSkinnedShieldCheckHandle = m_ForwardPlusSplatMapSkinnedShieldCheckProgram->GetHandle();
GLuint lastShader = 0;
unsigned int lastModel = 0;
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightCullingPass->LightSSBO());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO());
@@ -548,9 +660,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
case RawModel::MaterialType::SingleTextures:
{
if (explosionEffectJob->Model->IsSkinned()) {
m_ExplosionEffectSkinnedShieldCheckProgram->Bind();
GLERROR("Bind ExplosionEffectSkinned program");
if (lastShader != m_ExplosionEffectSkinnedShieldCheckProgram->GetHandle()) {
m_ExplosionEffectSkinnedShieldCheckProgram->Bind();
lastShader = m_ExplosionEffectSkinnedShieldCheckProgram->GetHandle();
GLERROR("Bind ExplosionEffectSkinned program");
glUniform1i(glGetUniformLocation(explosionSkinnedShieldCheckHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedShieldCheckHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedShieldCheckHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSkinnedShieldCheckHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSkinnedShieldCheckHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSkinned Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSkinnedShieldCheckHandle, explosionEffectJob, scene);
//bind textures
@@ -569,8 +689,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
}
else {
m_ExplosionEffectShieldCheckProgram->Bind();
GLERROR("Bind ExplosionEffect program");
if (lastShader != m_ExplosionEffectShieldCheckProgram->GetHandle()) {
m_ExplosionEffectShieldCheckProgram->Bind();
lastShader = m_ExplosionEffectShieldCheckProgram->GetHandle();
GLERROR("Bind ExplosionEffect program");
glUniform1i(glGetUniformLocation(explosionShieldCheckHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionShieldCheckHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionShieldCheckHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionShieldCheckHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionShieldCheckHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffect Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionShieldCheckHandle, explosionEffectJob, scene);
//bind textures
@@ -585,8 +714,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
case RawModel::MaterialType::SplatMapping:
{
if (explosionEffectJob->Model->IsSkinned()) {
m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->Bind();
GLERROR("Bind ExplosionEffectSplatMapSkinned program");
if (lastShader != m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->GetHandle()) {
m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->Bind();
lastShader = m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->GetHandle();
GLERROR("Bind ExplosionEffectSplatMapSkinned program");
glUniform1i(glGetUniformLocation(explosionSplatMapSkinnedShieldCheckHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedShieldCheckHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedShieldCheckHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSplatMapSkinnedShieldCheckHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSplatMapSkinnedShieldCheckHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSplatMapSkinned Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSplatMapSkinnedShieldCheckHandle, explosionEffectJob, scene);
//bind textures
@@ -603,9 +741,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
}
else {
m_ExplosionEffectSplatMapShieldCheckProgram->Bind();
GLERROR("Bind ExplosionEffectSplatMap program");
//bind uniforms
if (lastShader != m_ExplosionEffectSplatMapShieldCheckProgram->GetHandle()) {
m_ExplosionEffectSplatMapShieldCheckProgram->Bind();
lastShader = m_ExplosionEffectSplatMapShieldCheckProgram->GetHandle();
GLERROR("Bind ExplosionEffectSplatMap program");
glUniform1i(glGetUniformLocation(explosionSplatMapShieldCheckHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapShieldCheckHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapShieldCheckHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSplatMapShieldCheckHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSplatMapShieldCheckHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSplatMap Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSplatMapShieldCheckHandle, explosionEffectJob, scene);
//bind textures
@@ -621,9 +767,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
case RawModel::MaterialType::SingleTextures:
{
if (explosionEffectJob->Model->IsSkinned()) {
m_ExplosionEffectSkinnedProgram->Bind();
GLERROR("Bind ExplosionEffectSkinned program");
if (lastShader != m_ExplosionEffectSkinnedProgram->GetHandle()) {
m_ExplosionEffectSkinnedProgram->Bind();
lastShader = m_ExplosionEffectSkinnedProgram->GetHandle();
GLERROR("Bind ExplosionEffectSkinned program");
glUniform1i(glGetUniformLocation(explosionSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSkinned Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSkinnedHandle, explosionEffectJob, scene);
//bind textures
@@ -641,8 +795,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
else {
m_ExplosionEffectProgram->Bind();
GLERROR("Bind ExplosionEffect program");
if (lastShader != m_ExplosionEffectProgram->GetHandle()) {
m_ExplosionEffectProgram->Bind();
lastShader = m_ExplosionEffectProgram->GetHandle();
GLERROR("Bind ExplosionEffect program");
glUniform1i(glGetUniformLocation(explosionHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffect Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionHandle, explosionEffectJob, scene);
//bind textures
@@ -656,8 +819,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
case RawModel::MaterialType::SplatMapping:
{
if (explosionEffectJob->Model->IsSkinned()) {
m_ExplosionEffectSplatMapSkinnedProgram->Bind();
GLERROR("Bind ExplosionEffectSplatMapSkinned program");
if (lastShader != m_ExplosionEffectSplatMapSkinnedProgram->GetHandle()) {
m_ExplosionEffectSplatMapSkinnedProgram->Bind();
lastShader = m_ExplosionEffectSplatMapSkinnedProgram->GetHandle();
GLERROR("Bind ExplosionEffectSkinnedSplatMap program");
glUniform1i(glGetUniformLocation(explosionSplatMapSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSplatMapSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSkinnedSplatMap Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSplatMapSkinnedHandle, explosionEffectJob, scene);
//bind textures
@@ -673,9 +845,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
}
else {
m_ExplosionEffectSplatMapProgram->Bind();
GLERROR("Bind ExplosionEffectSplatMap program");
//bind uniforms
if (lastShader != m_ExplosionEffectSplatMapProgram->GetHandle()) {
m_ExplosionEffectSplatMapProgram->Bind();
lastShader = m_ExplosionEffectSplatMapProgram->GetHandle();
GLERROR("Bind ExplosionEffectSplatMap program");
glUniform1i(glGetUniformLocation(explosionSplatMapHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSplatMapHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSplatMapHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSplatMap Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSplatMapHandle, explosionEffectJob, scene);
//bind textures
@@ -689,8 +869,11 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
glDisable(GL_CULL_FACE);
//draw
glBindVertexArray(explosionEffectJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer);
if (lastModel != explosionEffectJob->ModelID) {
glBindVertexArray(explosionEffectJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer);
lastModel = explosionEffectJob->ModelID;
}
glDrawElements(GL_TRIANGLES, explosionEffectJob->EndIndex - explosionEffectJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(explosionEffectJob->StartIndex*sizeof(unsigned int)));
glEnable(GL_CULL_FACE);
GLERROR("explosion effect end");
@@ -705,8 +888,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
case RawModel::MaterialType::SingleTextures:
{
if (modelJob->Model->IsSkinned()) {
m_ForwardPlusSkinnedShieldCheckProgram->Bind();
GLERROR("Bind ForwardPlusSkinnedProgram");
if (lastShader != m_ForwardPlusSkinnedShieldCheckProgram->GetHandle()) {
m_ForwardPlusSkinnedShieldCheckProgram->Bind();
lastShader = m_ForwardPlusSkinnedShieldCheckProgram->GetHandle();
GLERROR("Bind ForwardPlusSkinnedProgram program");
glUniform1i(glGetUniformLocation(forwardSkinnedShieldCheckHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedShieldCheckHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedShieldCheckHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSkinnedShieldCheckHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSkinnedShieldCheckHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ForwardPlusSkinnedProgram Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSkinnedShieldCheckHandle, modelJob, scene);
//bind textures
@@ -725,8 +917,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
}
else {
m_ForwardPlusShieldCheckProgram->Bind();
GLERROR("Bind ForwardPlusProgram");
if (lastShader != m_ForwardPlusShieldCheckProgram->GetHandle()) {
m_ForwardPlusShieldCheckProgram->Bind();
lastShader = m_ForwardPlusShieldCheckProgram->GetHandle();
GLERROR("Bind ForwardPlusProgram program");
glUniform1i(glGetUniformLocation(forwardShieldCheckHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardShieldCheckHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardShieldCheckHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardShieldCheckHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardShieldCheckHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ForwardPlusProgram Uniforms");
}
//bind uniforms
BindModelUniforms(forwardShieldCheckHandle, modelJob, scene);
//bind textures
@@ -740,8 +941,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
case RawModel::MaterialType::SplatMapping:
{
if (modelJob->Model->IsSkinned()) {
m_ForwardPlusSplatMapSkinnedShieldCheckProgram->Bind();
GLERROR("Bind SplatMap program");
if (lastShader != m_ForwardPlusSplatMapSkinnedShieldCheckProgram->GetHandle()) {
m_ForwardPlusSplatMapSkinnedShieldCheckProgram->Bind();
lastShader = m_ForwardPlusSplatMapSkinnedShieldCheckProgram->GetHandle();
GLERROR("Bind ForwardPlusProgramSplatMapSkinned program");
glUniform1i(glGetUniformLocation(forwardSplatMapSkinnedShieldCheckHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedShieldCheckHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedShieldCheckHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSplatMapSkinnedShieldCheckHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSplatMapSkinnedShieldCheckHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ForwardPlusProgramSplatMapSkinned Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSplatMapSkinnedShieldCheckHandle, modelJob, scene);
//bind textures
@@ -757,8 +967,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedShieldCheckHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
else {
m_ForwardPlusSplatMapShieldCheckProgram->Bind();
GLERROR("Bind SplatMap program");
if (lastShader != m_ForwardPlusSplatMapShieldCheckProgram->GetHandle()) {
m_ForwardPlusSplatMapShieldCheckProgram->Bind();
lastShader = m_ForwardPlusSplatMapShieldCheckProgram->GetHandle();
GLERROR("Bind SplatMap program");
glUniform1i(glGetUniformLocation(forwardSplatShieldCheckHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSplatShieldCheckHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSplatShieldCheckHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSplatShieldCheckHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSplatShieldCheckHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind SplatMap Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSplatShieldCheckHandle, modelJob, scene);
//bind textures
@@ -774,8 +993,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
case RawModel::MaterialType::SingleTextures:
{
if (modelJob->Model->IsSkinned()) {
m_ForwardPlusSkinnedProgram->Bind();
GLERROR("Bind ForwardPlusSkinnedProgram");
if (lastShader != m_ForwardPlusSkinnedProgram->GetHandle()) {
m_ForwardPlusSkinnedProgram->Bind();
lastShader = m_ForwardPlusSkinnedProgram->GetHandle();
GLERROR("Bind ForwardPlusSkinnedProgram program");
glUniform1i(glGetUniformLocation(forwardSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ForwardPlusSkinnedProgram Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSkinnedHandle, modelJob, scene);
//bind textures
@@ -794,8 +1022,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
}
else {
m_ForwardPlusProgram->Bind();
GLERROR("Bind ForwardPlusProgram");
if (lastShader != m_ForwardPlusProgram->GetHandle()) {
m_ForwardPlusProgram->Bind();
lastShader = m_ForwardPlusProgram->GetHandle();
GLERROR("Bind ForwardPlusProgram program");
glUniform1i(glGetUniformLocation(forwardHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ForwardPlusProgram Uniforms");
}
//bind uniforms
BindModelUniforms(forwardHandle, modelJob, scene);
//bind textures
@@ -809,8 +1046,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
case RawModel::MaterialType::SplatMapping:
{
if (modelJob->Model->IsSkinned()) {
m_ForwardPlusSplatMapSkinnedProgram->Bind();
GLERROR("Bind SplatMap program");
if (lastShader != m_ForwardPlusSplatMapSkinnedProgram->GetHandle()) {
m_ForwardPlusSplatMapSkinnedProgram->Bind();
lastShader = m_ForwardPlusSplatMapSkinnedProgram->GetHandle();
GLERROR("Bind SplatMap program");
glUniform1i(glGetUniformLocation(forwardSplatMapSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSplatMapSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind SplatMap Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSplatMapSkinnedHandle, modelJob, scene);
//bind textures
@@ -826,8 +1072,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
else {
m_ForwardPlusSplatMapProgram->Bind();
GLERROR("Bind SplatMap program");
if (lastShader != m_ForwardPlusSplatMapProgram->GetHandle()) {
m_ForwardPlusSplatMapProgram->Bind();
lastShader = m_ForwardPlusSplatMapProgram->GetHandle();
GLERROR("Bind SplatMap program");
glUniform1i(glGetUniformLocation(forwardSplatMapHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSplatMapHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSplatMapHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind SplatMap Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSplatMapHandle, modelJob, scene);
//bind textures
@@ -839,8 +1094,11 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
}
}
//draw
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
if (lastModel != modelJob->ModelID) {
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
lastModel = modelJob->ModelID;
}
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex*sizeof(unsigned int)));
if (GLERROR("models end")) {
continue;
@@ -945,17 +1203,26 @@ void DrawFinalPass::DrawShieldedModelRenderQueue(std::list<std::shared_ptr<Rende
void DrawFinalPass::DrawToDepthStencilBuffer(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene)
{
GLuint shaderSkinnedHandle = m_FillDepthStencilBufferSkinnedProgram->GetHandle();
GLuint shaderHandle = m_FillDepthStencilBufferProgram->GetHandle();
GLuint lastShader = 0;
for (auto &job : jobs) {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if(modelJob->Model->IsSkinned()) {
m_FillDepthStencilBufferSkinnedProgram->Bind();
GLuint shaderHandle = m_FillDepthStencilBufferSkinnedProgram->GetHandle();
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()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
if (lastShader != m_FillDepthStencilBufferSkinnedProgram->GetHandle()) {
m_FillDepthStencilBufferSkinnedProgram->Bind();
lastShader = m_FillDepthStencilBufferSkinnedProgram->GetHandle();
glUniform1i(glGetUniformLocation(shaderSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(shaderSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(shaderSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind Uniforms 1");
}
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * modelJob->Matrix));
GLERROR("Bind PVM uniform");
std::vector<glm::mat4> frameBones;
if (modelJob->BlendTree != nullptr) {
@@ -966,11 +1233,19 @@ void DrawFinalPass::DrawToDepthStencilBuffer(std::list<std::shared_ptr<RenderJob
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
} else {
m_FillDepthStencilBufferProgram->Bind();
GLuint shaderHandle = m_FillDepthStencilBufferProgram->GetHandle();
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()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
if (lastShader != m_FillDepthStencilBufferProgram->GetHandle()) {
m_FillDepthStencilBufferProgram->Bind();
lastShader = m_FillDepthStencilBufferProgram->GetHandle();
glUniform1i(glGetUniformLocation(shaderHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
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()));
glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(shaderHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind Uniforms 2");
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * modelJob->Matrix));
GLERROR("Bind PVM uniform");
}
@@ -992,6 +1267,9 @@ void DrawFinalPass::DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, Rend
GLuint shaderHandle = m_SpriteProgram->GetHandle();
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPos"), 1, glm::value_ptr(scene.Camera->Position()));
for(auto& job : jobs) {
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
RenderState jobState;
@@ -1000,10 +1278,7 @@ void DrawFinalPass::DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, Rend
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()));
glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPos"), 1, glm::value_ptr(scene.Camera->Position()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * spriteJob->Matrix));
glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(spriteJob->Color));
glUniform4fv(glGetUniformLocation(shaderHandle, "FillColor"), 1, glm::value_ptr(spriteJob->FillColor));
glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), spriteJob->FillPercentage);
@@ -1033,17 +1308,14 @@ void DrawFinalPass::DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, Rend
void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr<ExplosionEffectJob>& job, RenderScene& scene)
{
glUniform1i(glGetUniformLocation(shaderHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
GLERROR("Bind 1 uniform");
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(job->Matrix));
GLERROR("Bind 2 uniform");
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
GLERROR("Bind 3 uniform");
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
GLERROR("Bind 4 uniform");
glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
GLERROR("Bind 5 uniform");
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * job->Matrix));
GLERROR("Bind PVM uniform");
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "VM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix() * job->Matrix));
GLERROR("Bind VM uniform");
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "TIM"), 1, GL_FALSE, glm::value_ptr(glm::transpose(glm::inverse(job->Matrix))));
GLERROR("Bind TIM uniform");
glUniform3fv(glGetUniformLocation(shaderHandle, "ExplosionOrigin"), 1, glm::value_ptr(job->ExplosionOrigin));
GLERROR("Bind 6 uniform");
@@ -1083,29 +1355,25 @@ void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr<E
GLERROR("Bind 18 uniform");
glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), job->FillPercentage);
GLERROR("Bind 19 uniform");
glUniform4fv(glGetUniformLocation(shaderHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind 20 uniform");
glUniform1f(glGetUniformLocation(shaderHandle, "GlowIntensity"), job->GlowIntensity);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightP"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightP().data()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightV().data()));
glUniform1fv(glGetUniformLocation(shaderHandle, "FarDistance"), MAX_SPLITS, m_ShadowPass->FarDistance().data());
GLERROR("END");
}
void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptr<ModelJob>& job, RenderScene& scene)
{
glUniform1i(glGetUniformLocation(shaderHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
GLERROR("Bind 1 uniform");
GLint Location_M = glGetUniformLocation(shaderHandle, "M");
glUniformMatrix4fv(Location_M, 1, GL_FALSE, glm::value_ptr(job->Matrix));
GLERROR("Bind 2 uniform");
GLint Location_V = glGetUniformLocation(shaderHandle, "V");
glUniformMatrix4fv(Location_V, 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
GLERROR("Bind 3 uniform");
GLint Location_P = glGetUniformLocation(shaderHandle, "P");
glUniformMatrix4fv(Location_P, 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
GLERROR("Bind 4 uniform");
GLint Location_ScreenDimensions = glGetUniformLocation(shaderHandle, "ScreenDimensions");
glUniform2f(Location_ScreenDimensions, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
GLERROR("Bind 5 uniform");
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * job->Matrix));
GLERROR("Bind PVM uniform");
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "VM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix() * job->Matrix));
GLERROR("Bind VM uniform");
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "TIM"), 1, GL_FALSE, glm::value_ptr(glm::transpose(glm::inverse(job->Matrix))));
GLERROR("Bind TIM uniform");
GLint Location_FillPercentage = glGetUniformLocation(shaderHandle, "FillPercentage");
glUniform1f(Location_FillPercentage, job->FillPercentage);
@@ -1118,14 +1386,12 @@ void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptr<Model
GLERROR("Bind 8 uniform");
GLint Location_Color = glGetUniformLocation(shaderHandle, "Color");
glUniform4fv(Location_Color, 1, glm::value_ptr(job->Color));
GLERROR("Bind 9 uniform");
GLint Location_AmbientColor = glGetUniformLocation(shaderHandle, "AmbientColor");
glUniform4fv(Location_AmbientColor, 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind 10 uniform");
GLint Location_GlowIntensity = glGetUniformLocation(shaderHandle, "GlowIntensity");
glUniform1f(Location_GlowIntensity, job->GlowIntensity);
glUniform1f(Location_GlowIntensity, job->GlowIntensity);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightP"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightP().data()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightV().data()));
glUniform1fv(glGetUniformLocation(shaderHandle, "FarDistance"), MAX_SPLITS, m_ShadowPass->FarDistance().data());
GLERROR("END");
}
+11 -1
View File
@@ -24,6 +24,13 @@ RenderBuffer::~RenderBuffer()
}
}
Texture2DArray::~Texture2DArray()
{
if (m_ResourceHandle != 0) {
glDeleteTextures(1, m_ResourceHandle);
}
}
FrameBuffer::~FrameBuffer()
{
@@ -53,12 +60,15 @@ void FrameBuffer::Generate()
case GL_TEXTURE_2D:
glFramebufferTexture2D(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle, 0);
GLERROR("FrameBuffer generate: glFramebufferTexture2D");
break;
case GL_RENDERBUFFER:
glFramebufferRenderbuffer(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle);
GLERROR("FrameBuffer generate: glFramebufferRenderbuffer");
break;
case GL_TEXTURE_2D_ARRAY:
glFramebufferTexture(GL_FRAMEBUFFER, (*it)->m_Attachment, *(*it)->m_ResourceHandle, 0);
GLERROR("FrameBuffer generate: glFramebufferTexture2DArray");
break;
}
GLERROR("2");
+9 -9
View File
@@ -10,31 +10,31 @@ Model::Model(std::string fileName)
case RawModel::MaterialType::SingleTextures:
{
RawModel::MaterialSingleTextures* materialSingleTexture = static_cast<RawModel::MaterialSingleTextures*>(materialProperty.material);
materialSingleTexture->ColorMap.Texture = CommonFunctions::LoadTexture(materialSingleTexture->ColorMap.TexturePath, false);
materialSingleTexture->NormalMap.Texture = CommonFunctions::LoadTexture(materialSingleTexture->NormalMap.TexturePath, false);
materialSingleTexture->SpecularMap.Texture = CommonFunctions::LoadTexture(materialSingleTexture->SpecularMap.TexturePath, false);
materialSingleTexture->IncandescenceMap.Texture = CommonFunctions::LoadTexture(materialSingleTexture->IncandescenceMap.TexturePath, false);
materialSingleTexture->ColorMap.Texture = CommonFunctions::TryLoadResource<Texture, false>(materialSingleTexture->ColorMap.TexturePath);
materialSingleTexture->NormalMap.Texture = CommonFunctions::TryLoadResource<Texture, false>(materialSingleTexture->NormalMap.TexturePath);
materialSingleTexture->SpecularMap.Texture = CommonFunctions::TryLoadResource<Texture, false>(materialSingleTexture->SpecularMap.TexturePath);
materialSingleTexture->IncandescenceMap.Texture = CommonFunctions::TryLoadResource<Texture, false>(materialSingleTexture->IncandescenceMap.TexturePath);
}
break;
case RawModel::MaterialType::SplatMapping:
{
RawModel::MaterialSplatMapping* materialSplatMapping = static_cast<RawModel::MaterialSplatMapping*>(materialProperty.material);
materialSplatMapping->SplatMap.Texture = CommonFunctions::LoadTexture(materialSplatMapping->SplatMap.TexturePath, false);
materialSplatMapping->SplatMap.Texture = CommonFunctions::TryLoadResource<Texture, false>(materialSplatMapping->SplatMap.TexturePath);
for (auto& texture : materialSplatMapping->ColorMaps)
{
texture.Texture = CommonFunctions::LoadTexture(texture.TexturePath, false);
texture.Texture = CommonFunctions::TryLoadResource<Texture, false>(texture.TexturePath);
}
for (auto& texture : materialSplatMapping->NormalMaps)
{
texture.Texture = CommonFunctions::LoadTexture(texture.TexturePath, false);
texture.Texture = CommonFunctions::TryLoadResource<Texture, false>(texture.TexturePath);
}
for (auto& texture : materialSplatMapping->SpecularMaps)
{
texture.Texture = CommonFunctions::LoadTexture(texture.TexturePath, false);
texture.Texture = CommonFunctions::TryLoadResource<Texture, false>(texture.TexturePath);
}
for (auto& texture : materialSplatMapping->IncandescenceMaps)
{
texture.Texture = CommonFunctions::LoadTexture(texture.TexturePath, false);
texture.Texture = CommonFunctions::TryLoadResource<Texture, false>(texture.TexturePath);
}
}
break;
+38 -28
View File
@@ -12,7 +12,8 @@ PickingPass::PickingPass(IRenderer* renderer, EventBroker* eb)
PickingPass::~PickingPass()
{
CommonFunctions::DeleteTexture(&m_PickingTexture);
CommonFunctions::DeleteTexture(&m_DepthBuffer);
}
@@ -61,8 +62,9 @@ void PickingPass::Draw(RenderScene& scene)
//TODO: Render: Add code for more jobs than modeljobs.
GLuint shaderHandle = m_PickingProgram->GetHandle();
GLuint shaderSkinnedHandle = m_PickingSkinnedProgram->GetHandle();
GLuint lastShader = 0;
unsigned int lastModel = 0;
m_PickingProgram->Bind();
if (scene.ClearDepth) {
//glClear(GL_DEPTH_BUFFER_BIT);
state->Disable(GL_DEPTH_TEST);
@@ -98,10 +100,11 @@ void PickingPass::Draw(RenderScene& scene)
m_PickingColorsToEntity[glm::ivec2(pickColor[0], pickColor[1])] = pickInfo;
if (modelJob->Model->IsSkinned()) {
m_PickingSkinnedProgram->Bind();
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
if (lastShader != m_PickingSkinnedProgram->GetHandle()) {
m_PickingSkinnedProgram->Bind();
lastShader = m_PickingSkinnedProgram->GetHandle();
}
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * modelJob->Matrix));
glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
std::vector<glm::mat4> frameBones;
@@ -114,15 +117,19 @@ void PickingPass::Draw(RenderScene& scene)
} else {
m_PickingProgram->Bind();
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->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()));
if (lastShader != m_PickingProgram->GetHandle()) {
m_PickingProgram->Bind();
lastShader = m_PickingProgram->GetHandle();
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * modelJob->Matrix));
glUniform2fv(glGetUniformLocation(shaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
}
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
if (lastModel != modelJob->ModelID) {
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
lastModel = modelJob->ModelID;
}
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
}
}
@@ -208,10 +215,11 @@ void PickingPass::Draw(RenderScene& scene)
m_PickingColorsToEntity[glm::ivec2(pickColor[0], pickColor[1])] = pickInfo;
if (modelJob->Model->IsSkinned()) {
m_PickingSkinnedProgram->Bind();
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
if (lastShader != m_PickingSkinnedProgram->GetHandle()) {
m_PickingSkinnedProgram->Bind();
lastShader = m_PickingSkinnedProgram->GetHandle();
}
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * modelJob->Matrix));
glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
std::vector<glm::mat4> frameBones;
@@ -224,19 +232,24 @@ void PickingPass::Draw(RenderScene& scene)
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
} else {
m_PickingProgram->Bind();
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->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()));
if (lastShader != m_PickingProgram->GetHandle()) {
m_PickingProgram->Bind();
lastShader = m_PickingProgram->GetHandle();
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * modelJob->Matrix));
glUniform2fv(glGetUniformLocation(shaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
}
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
if (lastModel != modelJob->ModelID) {
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
lastModel = modelJob->ModelID;
}
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
}
}
m_PickingProgram->Bind();
for (auto& job : scene.Jobs.SpriteJob) {
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
if (!spriteJob->Pickable) {
@@ -271,14 +284,11 @@ void PickingPass::Draw(RenderScene& scene)
m_PickingColorsToEntity[glm::ivec2(pickColor[0], pickColor[1])] = pickInfo;
m_PickingProgram->Bind();
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()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * spriteJob->Matrix));
glUniform2fv(glGetUniformLocation(shaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
glBindVertexArray(spriteJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, spriteJob->Model->ElementBuffer);
glBindVertexArray(spriteJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, spriteJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex * sizeof(unsigned int)));
}
}
+6 -3
View File
@@ -258,7 +258,8 @@ void RenderSystem::fillModels(RenderScene::Queues &Jobs)
m_World,
fillColor,
fillPercentage,
isShielded
isShielded,
false
));
if (m_World->HasComponent(cModel.EntityID, "Shield")){
explosionEffectJob->CalculateHash();
@@ -296,7 +297,8 @@ void RenderSystem::fillModels(RenderScene::Queues &Jobs)
m_World,
fillColor,
fillPercentage,
isShielded
isShielded,
(bool)cModel["Shadow"]
));
if (m_World->HasComponent(cModel.EntityID, "Shield")) {
modelJob->CalculateHash();
@@ -435,6 +437,7 @@ void RenderSystem::Update(double dt)
}
RenderScene scene;
scene.ShouldBlur = true;
scene.Camera = m_Camera;
scene.Viewport = Rectangle(1280, 720);
@@ -448,7 +451,7 @@ void RenderSystem::Update(double dt)
fillModels(scene.Jobs);
fillPointLights(scene.Jobs.PointLight, m_World);
//TODO: Make sure all objects needed are also sorted.
scene.Jobs.OpaqueObjects.sort();
scene.Jobs.OpaqueObjects.sort([](auto& a, auto& b) {return *a < *b; });
fillSprites(scene.Jobs.SpriteJob, m_World);
fillDirectionalLights(scene.Jobs.DirectionalLight, m_World);
fillText(scene.Jobs.Text, m_World);
+33 -6
View File
@@ -2,6 +2,19 @@
std::unordered_map<GLFWwindow*, Renderer*> Renderer::m_WindowToRenderer;
Renderer::~Renderer() {
delete m_PickingPass;
delete m_LightCullingPass;
delete m_ImGuiRenderPass;
delete m_DrawFinalPass;
delete m_DrawScreenQuadPass;
delete m_DrawBloomPass;
delete m_DrawColorCorrectionPass;
delete m_SSAOPass;
delete m_CubeMapPass;
delete m_TextPass;
}
void Renderer::Initialize()
{
m_SSAO_Quality = m_Config->Get<int>("SSAO.Quality", 0);
@@ -110,7 +123,7 @@ void Renderer::Draw(RenderFrame& frame)
{
GLERROR("PRE");
glBindFramebuffer(GL_FRAMEBUFFER, 0);
ImGui::Combo("Draw textures", &m_DebugTextureToDraw, "Final\0Scene\0Bloom\0Gaussian\0Picking\0Ambient Occlusion");
ImGui::Combo("Draw textures", &m_DebugTextureToDraw, "Final\0Scene\0Bloom\0Gaussian\0Picking\0Ambient Occlusion\0Combined Scene Texture\0Full Blurred Texture");
ImGui::Combo("CubeMap", &m_CubeMapTexture, "Nevada(512)\0Sky(1024)");
if(m_CubeMapTexture == 0) {
m_CubeMapPass->LoadTextures("Nevada");
@@ -133,6 +146,9 @@ void Renderer::Draw(RenderFrame& frame)
m_DrawFinalPass->ClearBuffer();
m_DrawBloomPass->ClearBuffer();
m_SSAOPass->ClearBuffer();
m_ShadowPass->ClearBuffer();
m_BlurHUDPass->ClearBuffer();
m_ShadowPass->DebugGUI();
PerformanceTimer::StopTimer("Renderer-ClearBuffers");
GLERROR("ClearBuffers");
for (auto scene : frame.RenderScenes) {
@@ -148,6 +164,9 @@ void Renderer::Draw(RenderFrame& frame)
PerformanceTimer::StartTimer("Renderer-Depth");
SortRenderJobsByDepth(*scene);
GLERROR("SortByDepth");
PerformanceTimer::StartTimerAndStopPrevious("Draw shadow maps");
m_ShadowPass->Draw(*scene);
GLERROR("Draw shadow maps");
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Generate Frustrums");
m_LightCullingPass->GenerateNewFrustum(*scene);
GLERROR("Generate frustums");
@@ -158,7 +177,7 @@ void Renderer::Draw(RenderFrame& frame)
m_LightCullingPass->CullLights(*scene);
GLERROR("LightCulling");
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Geometry+Light");
m_DrawFinalPass->Draw(*scene);
m_DrawFinalPass->Draw(*scene, m_BlurHUDPass);
GLERROR("Draw Geometry+Light");
//m_DrawScenePass->Draw(*scene);
@@ -194,6 +213,12 @@ void Renderer::Draw(RenderFrame& frame)
if (m_DebugTextureToDraw == 5) {
m_DrawScreenQuadPass->Draw(m_SSAOPass->SSAOTexture());
}
if (m_DebugTextureToDraw == 6) {
m_DrawScreenQuadPass->Draw(m_DrawFinalPass->CombinedSceneTexture());
}
if (m_DebugTextureToDraw == 7) {
m_DrawScreenQuadPass->Draw(m_DrawFinalPass->FullBlurredTexture());
}
PerformanceTimer::StopTimer("Renderer-Misc Debug Draws");
PerformanceTimer::StartTimer("Renderer-ImGuiRenderPass");
@@ -213,8 +238,8 @@ PickData Renderer::Pick(glm::vec2 screenCoord)
void Renderer::InitializeTextures()
{
m_ErrorTexture = CommonFunctions::LoadTexture("Textures/Core/ErrorTexture.png", false);
m_WhiteTexture = CommonFunctions::LoadTexture("Textures/Core/White.png", false);
m_ErrorTexture = CommonFunctions::TryLoadResource<Texture, false>("Textures/Core/ErrorTexture.png");
m_WhiteTexture = CommonFunctions::TryLoadResource<Texture, false>("Textures/Core/White.png");
}
@@ -244,9 +269,11 @@ void Renderer::InitializeRenderPasses()
m_LightCullingPass = new LightCullingPass(this);
m_CubeMapPass = new CubeMapPass(this);
m_SSAOPass = new SSAOPass(this, m_Config);
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass);
m_ShadowPass = new ShadowPass(this);
m_BlurHUDPass = new BlurHUD(this);
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass, m_ShadowPass);
m_DrawScreenQuadPass = new DrawScreenQuadPass(this);
m_DrawBloomPass = new DrawBloomPass(this, m_Config);
m_DrawColorCorrectionPass = new DrawColorCorrectionPass(this);
}
+8 -1
View File
@@ -4,12 +4,19 @@ SSAOPass::SSAOPass(IRenderer* renderer, ConfigFile* config)
: m_Renderer(renderer)
, m_Config(config)
{
m_WhiteTexture = CommonFunctions::LoadTexture("Textures/Core/White.png", false);
m_WhiteTexture = CommonFunctions::TryLoadResource<Texture, false>("Textures/Core/White.png");
ChangeQuality(m_Config->Get<int>("SSAO.Quality", 0));
}
SSAOPass::~SSAOPass() {
CommonFunctions::DeleteTexture(&m_SSAOTexture);
CommonFunctions::DeleteTexture(&m_SSAOViewSpaceZTexture);
CommonFunctions::DeleteTexture(&m_Gaussian_horiz);
CommonFunctions::DeleteTexture(&m_Gaussian_vert);
}
void SSAOPass::ChangeQuality(int quality)
{
if (m_Quality == quality) {
+39 -11
View File
@@ -4,22 +4,32 @@ GLuint Shader::CompileShader(GLenum shaderType, std::string fileName)
{
LOG_INFO("Compiling shader \"%s\"", fileName.c_str());
std::string shaderFile;
std::ifstream in(fileName, std::ios::in);
if (!in) {
LOG_ERROR("Error: Failed to open shader file \"%s\"", fileName.c_str());
return 0;
}
in.seekg(0, std::ios::end);
shaderFile.resize((int)in.tellg());
in.seekg(0, std::ios::beg);
in.read(&shaderFile[0], shaderFile.size());
in.close();
std::string shaderFile = ReadFile(fileName);
GLuint shader = glCreateShader(shaderType);
if (GLERROR("glCreateShader"))
return 0;
std::size_t startPos = 0;
std::size_t SEofNewFile[2];
std::string key = "#include";
while((startPos = shaderFile.find(key, startPos)) != std::string::npos)
{
SEofNewFile[0] = shaderFile.find('"', startPos+key.length())+1;
SEofNewFile[1] = shaderFile.find('"', SEofNewFile[0]);
if (SEofNewFile[0] == std::string::npos || SEofNewFile[1] == std::string::npos)
return 0;
std::string replacementFileName = shaderFile.substr(SEofNewFile[0], SEofNewFile[1] - SEofNewFile[0]);
std::string replacementString = ReadFile(replacementFileName);
size_t firstof = replacementString.find_first_of((char)0);
replacementString.erase(firstof, replacementString.size() - firstof);
if (replacementString.length() <= 0)
return 0;
shaderFile.replace(startPos, SEofNewFile[1]+2 - startPos, replacementString + "\n");
startPos += replacementString.length(); //This might not be wanted.
}
const GLchar* shaderFiles = shaderFile.c_str();
const GLint length = static_cast<GLint>(shaderFile.length());
glShaderSource(shader, 1, &shaderFiles, &length);
@@ -46,6 +56,24 @@ GLuint Shader::CompileShader(GLenum shaderType, std::string fileName)
return shader;
}
std::string Shader::ReadFile(std::string fileName)
{
std::string shaderFile;
std::ifstream in(fileName, std::ios::in);
if (!in) {
LOG_ERROR("Error: Failed to open shader file \"%s\"", fileName.c_str());
return "";
}
in.seekg(0, std::ios::end);
shaderFile.resize((int)in.tellg());
in.seekg(0, std::ios::beg);
in.read(&shaderFile[0], shaderFile.size());
in.close();
return shaderFile;
}
Shader::Shader(GLenum shaderType, std::string fileName) : m_ShaderType(shaderType), m_FileName(fileName)
{
m_ShaderHandle = 0;
+365
View File
@@ -0,0 +1,365 @@
#include "Rendering/ShadowPass.h"
ShadowPass::ShadowPass(IRenderer * renderer, int shadow_res_x, int shadow_res_y)
{
m_Renderer = renderer;
m_ResolutionSizeWidth = shadow_res_x;
m_ResolutionSizeHeight = shadow_res_y;
InitializeFrameBuffers();
InitializeShaderPrograms();
}
ShadowPass::ShadowPass(IRenderer * renderer)
{
m_Renderer = renderer;
InitializeFrameBuffers();
InitializeShaderPrograms();
}
ShadowPass::~ShadowPass()
{
}
void ShadowPass::DebugGUI()
{
ImGui::Checkbox("EnableShadows", &m_EnableShadows);
ImGui::DragFloat2("ShadowMapNearFar", m_NearFarPlane, 1.f, -1000.f, 1000.f);
ImGui::DragFloat("ShadowClippingWeight", &m_SplitWeight, 0.001f, 0.f, 1.f);
ImGui::Checkbox("ShadowTransparentObjects", &m_TransparentObjects);
ImGui::Checkbox("ShadowOnTextureAlphas", &m_TexturedShadows);
}
void ShadowPass::InitializeCameras(RenderScene & scene)
{
for (int i = 0; i < m_CurrentNrOfSplits; i++) {
m_shadowFrusta[i].AspectRatio = scene.Camera->AspectRatio();
m_shadowFrusta[i].FOV = scene.Camera->FOV();
}
}
// UpdateSplitDist computes the near and far distances for every frustum slice
// in camera eye space - that is, at what distance does a slice start and end
void ShadowPass::UpdateSplitDist(std::array<ShadowFrustum, MAX_SPLITS>& frusta, float near_distance, float far_distance)
{
float lambda = m_SplitWeight;
float ratio = far_distance / near_distance;
frusta[0].NearClip = near_distance;
for (int i = 1; i < m_CurrentNrOfSplits; i++) {
float si = i / static_cast<float>(m_CurrentNrOfSplits);
frusta[i].NearClip = lambda * (near_distance * powf(ratio, si)) + (1 - lambda) * (near_distance + (far_distance - near_distance) * si);
frusta[i - 1].FarClip = frusta[i].NearClip * 1.005f;
}
frusta[m_CurrentNrOfSplits - 1].FarClip = far_distance;
}
void ShadowPass::UpdateFrustumPoints(ShadowFrustum& frustum, glm::mat4 p, glm::mat4 v)
{
std::array<glm::vec4, 8> CornerPoint = {
glm::vec4(-1.f, -1.f, -1.f, 1.f),
glm::vec4(-1.f, 1.f, -1.f, 1.f),
glm::vec4(1.f, 1.f, -1.f, 1.f),
glm::vec4(1.f, -1.f, -1.f, 1.f),
glm::vec4(-1.f, -1.f, 1.f, 1.f),
glm::vec4(-1.f, 1.f, 1.f, 1.f),
glm::vec4(1.f, 1.f, 1.f, 1.f),
glm::vec4(1.f, -1.f, 1.f, 1.f)
};
for (int i = 0; i < 8; i++) {
glm::vec4 NDC = glm::inverse(p) * CornerPoint[i];
NDC = NDC / NDC.w;
frustum.CornerPoint[i] = glm::vec3(glm::inverse(v) * NDC);
}
}
// Compute the 8 corner points of the current view frustum in world space
void ShadowPass::UpdateFrustumPoints(ShadowFrustum& frustum, glm::vec3 camera_position, glm::vec3 view_dir)
{
glm::vec3 up = glm::vec3(0.f, 1.f, 0.f);
glm::vec3 right = glm::normalize(glm::cross(view_dir, up));
glm::vec3 far_center = camera_position + glm::normalize(view_dir) * frustum.FarClip;
glm::vec3 near_center = camera_position + glm::normalize(view_dir) * frustum.NearClip;
frustum.MiddlePoint = near_center + (far_center - near_center) * 0.5f;
up = glm::normalize(glm::cross(right, view_dir));
// these heights and widths are half the heights and widths of the near and far plane rectangles.
float near_height = tan(frustum.FOV / 2.f) * frustum.NearClip;
float near_width = near_height * frustum.AspectRatio;
float far_height = tan(frustum.FOV / 2.f) * frustum.FarClip;
float far_width = far_height * frustum.AspectRatio;
frustum.CornerPoint[0] = near_center - up * near_height - right * near_width;
frustum.CornerPoint[1] = near_center + up * near_height - right * near_width;
frustum.CornerPoint[2] = near_center + up * near_height + right * near_width;
frustum.CornerPoint[3] = near_center - up * near_height + right * near_width;
frustum.CornerPoint[4] = far_center - up * far_height - right * far_width;
frustum.CornerPoint[5] = far_center + up * far_height - right * far_width;
frustum.CornerPoint[6] = far_center + up * far_height + right * far_width;
frustum.CornerPoint[7] = far_center - up * far_height + right * far_width;
}
float ShadowPass::FindRadius(ShadowFrustum& frustum)
{
float radius = 0.f;
for (int i = 0; i < 8; i++) {
float distance = glm::distance(frustum.MiddlePoint, frustum.CornerPoint[i]);
if (distance > radius) {
radius = distance;
}
}
frustum.Radius = radius;
return radius;
}
void ShadowPass::InitializeFrameBuffers()
{
// Depth texture
glGenTextures(1, &m_DepthMap);
glBindTexture(GL_TEXTURE_2D_ARRAY, m_DepthMap);
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_DEPTH_COMPONENT16, m_ResolutionSizeWidth, m_ResolutionSizeHeight, m_CurrentNrOfSplits);
//glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeight, m_CurrentNrOfSplits, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
glTexParameterfv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR, glm::vec4(1.f).data);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
m_DepthBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2DArray(&m_DepthMap, GL_DEPTH_ATTACHMENT)));
m_DepthBuffer.Generate();
GLERROR("depthMap failed END");
}
void ShadowPass::InitializeShaderPrograms()
{
m_ShadowProgram = ResourceManager::Load<ShaderProgram>("#ShadowProgram");
m_ShadowProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Shadow.vert.glsl")));
m_ShadowProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Shadow.frag.glsl")));
m_ShadowProgram->Compile();
m_ShadowProgram->BindFragDataLocation(0, "ShadowMap");
m_ShadowProgram->Link();
m_ShadowProgramSkinned = ResourceManager::Load<ShaderProgram>("#ShadowProgramSkinned");
m_ShadowProgramSkinned->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ShadowSkinned.vert.glsl")));
m_ShadowProgramSkinned->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Shadow.frag.glsl")));
m_ShadowProgramSkinned->Compile();
m_ShadowProgramSkinned->BindFragDataLocation(0, "ShadowMap");
m_ShadowProgramSkinned->Link();
}
void ShadowPass::ClearBuffer()
{
m_DepthBuffer.Bind();
for (int i = 0; i < m_CurrentNrOfSplits; i++) {
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0, i);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
m_DepthBuffer.Unbind();
}
void ShadowPass::PointsToLightspace(ShadowFrustum& frustum, glm::mat4 v)
{
float left = INFINITY;
float right = -INFINITY;
float bottom = INFINITY;
float top = -INFINITY;
for (int i = 0; i < 8; i++)
{
glm::vec3 tempPoint = glm::vec3(v * glm::vec4(frustum.CornerPoint[i], 1.f));
if (tempPoint.x < left) { left = tempPoint.x; }
if (tempPoint.x > right) { right = tempPoint.x; }
if (tempPoint.y < bottom) { bottom = tempPoint.y; }
if (tempPoint.y > top) { top = tempPoint.y; }
}
frustum.LRBT = { left, right, bottom, top };
}
void ShadowPass::RadiusToLightspace(ShadowFrustum& frustum)
{
float quantizationStep = 1.0f / m_ResolutionSizeHeight;
float left = -frustum.Radius;
float right = frustum.Radius;
float bottom = -frustum.Radius;
float top = frustum.Radius;
frustum.LRBT = { left, right, bottom, top };
}
void ShadowPass::Draw(RenderScene & scene)
{
if (m_EnableShadows) {
InitializeCameras(scene);
UpdateSplitDist(m_shadowFrusta, scene.Camera->NearClip(), scene.Camera->FarClip());
ShadowPassState* state = new ShadowPassState(m_DepthBuffer.GetHandle());
glViewport(0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeight);
for (int i = 0; i < m_CurrentNrOfSplits; i++) {
UpdateFrustumPoints(m_shadowFrusta[i], scene.Camera->Position(), scene.Camera->Forward());
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0, i);
GLuint shaderHandle;
for (auto &job : scene.Jobs.DirectionalLight) {
auto directionalLightJob = std::dynamic_pointer_cast<DirectionalLightJob>(job);
if (directionalLightJob) {
m_LightView[i] = glm::lookAt(glm::vec3(-directionalLightJob->Direction) + m_shadowFrusta[i].MiddlePoint, m_shadowFrusta[i].MiddlePoint, glm::vec3(0.f, 1.f, 0.f));
PointsToLightspace(m_shadowFrusta[i], m_LightView[i]);
//FindRadius(m_shadowFrusta[i]);
//RadiusToLightspace(m_shadowFrusta[i]);
m_LightProjection[i] = glm::ortho(m_shadowFrusta[i].LRBT[LEFT], m_shadowFrusta[i].LRBT[RIGHT], m_shadowFrusta[i].LRBT[BOTTOM], m_shadowFrusta[i].LRBT[TOP], m_NearFarPlane[NEAR], m_NearFarPlane[FAR]);
m_ShadowProgram->Bind();
shaderHandle = m_ShadowProgram->GetHandle();
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i]));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView[i]));
m_ShadowProgramSkinned->Bind();
shaderHandle = m_ShadowProgramSkinned->GetHandle();
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i]));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView[i]));
GLERROR("ShadowLight ERROR");
for (auto &objectJob : scene.Jobs.OpaqueObjects) {
if (!std::dynamic_pointer_cast<ExplosionEffectJob>(objectJob)) {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(objectJob);
if (!modelJob->Shadow) {
continue;
}
if(modelJob->Model->IsSkinned()) {
m_ShadowProgramSkinned->Bind();
shaderHandle = m_ShadowProgramSkinned->GetHandle();
std::vector<glm::mat4> frameBones;
if (modelJob->BlendTree != nullptr) {
frameBones = modelJob->BlendTree->GetFinalPose();
} else {
frameBones = modelJob->Skeleton->GetTPose();
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
} else {
m_ShadowProgram->Bind();
shaderHandle = m_ShadowProgram->GetHandle();
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), 1.f);
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
GLERROR("Shadow Draw ERROR");
}
}
if (m_TransparentObjects) {
state->CullFace(GL_BACK);
for (auto &objectJob : scene.Jobs.TransparentObjects) {
if (!std::dynamic_pointer_cast<ExplosionEffectJob>(objectJob)) {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(objectJob);
if (!modelJob->Shadow) {
continue;
}
if (modelJob->Model->IsSkinned()) {
m_ShadowProgramSkinned->Bind();
shaderHandle = m_ShadowProgramSkinned->GetHandle();
std::vector<glm::mat4> frameBones;
if (modelJob->BlendTree != nullptr) {
frameBones = modelJob->BlendTree->GetFinalPose();
} else {
frameBones = modelJob->Skeleton->GetTPose();
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
} else {
m_ShadowProgram->Bind();
shaderHandle = m_ShadowProgram->GetHandle();
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), modelJob->Color.a);
if (m_TexturedShadows) {
switch (modelJob->Type) {
case RawModel::MaterialType::SingleTextures:
case RawModel::MaterialType::Basic:
{
glActiveTexture(GL_TEXTURE24);
if (modelJob->DiffuseTexture.size() > 0 && modelJob->DiffuseTexture[0]->Texture != nullptr) {
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture[0]->Texture->m_Texture);
glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(modelJob->DiffuseTexture[0]->UVRepeat));
}
else {
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f)));
}
break;
}
case RawModel::MaterialType::SplatMapping:
{
glActiveTexture(GL_TEXTURE24);
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f)));
break;
}
}
}
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
GLERROR("Shadow Draw ERROR");
}
}
state->CullFace(GL_FRONT);
}
}
}
}
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
m_DepthBuffer.Unbind();
delete state;
}
}
+19
View File
@@ -0,0 +1,19 @@
#include "Rendering/ShadowPassState.h"
ShadowPassState::ShadowPassState(GLuint frameBuffer)
{
BindFramebuffer(frameBuffer);
Enable(GL_DEPTH_TEST);
Enable(GL_CULL_FACE);
Disable(GL_BLEND);
Disable(GL_TEXTURE_2D);
CullFace(GL_FRONT);
ClearColor(glm::vec4(0.f, 0.f, 0.f, 0.f));
//Enable(GL_ALPHA_TEST);
//glAlphaFunc(GL_GREATER, 0.9f);
}
ShadowPassState::~ShadowPassState()
{
}
+2
View File
@@ -321,6 +321,8 @@ Skeleton::~Skeleton()
for (auto &kv : Bones) {
delete kv.second;
}
BlendTrees.clear();
}
const Skeleton::Animation* Skeleton::GetAnimation(std::string name)
+2 -14
View File
@@ -4,18 +4,6 @@ Texture::Texture(std::string path)
{
PNG* img = ResourceManager::Load<PNG, true>(path); //TODO: Make this threaded. Catch exeptions in all other load places.
//PNG image(path);
//if (img->Width == 0 && img->Height == 0 || img->Format == Image::ImageFormat::Unknown) {
// //image = PNG("Textures/Core/ErrorTexture.png");
// //return; // Temporary fix to remove crash
// if (img->Width == 0 && img->Height == 0 || img->Format == Image::ImageFormat::Unknown) {
// LOG_ERROR("Couldn't even load the error texture. This is a dark day indeed.");
// return;
// }
//}
this->Width = img->Width;
this->Height = img->Height;
this->Data = img->Data;
@@ -29,9 +17,9 @@ Texture::Texture(std::string path)
format = GL_RGBA;
break;
}
// Construct the OpenGL texture
glGenTextures(1, &m_Texture);
glBindTexture(GL_TEXTURE_2D, m_Texture);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+11
View File
@@ -0,0 +1,11 @@
#include "Rendering/TextureSprite.h"
TextureSprite::TextureSprite(std::string path)
:Texture(path)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST);
GLERROR("Texture load");
}
@@ -1,23 +1,5 @@
#include "Rendering/Util/CommonFunctions.h"
Texture* CommonFunctions::LoadTexture(std::string path, bool threaded)
{
Texture* img;
try {
if(threaded) {
img = ResourceManager::Load<Texture, true>(path);
} else {
img = ResourceManager::Load<Texture, false>(path);
}
} catch (const Resource::StillLoadingException&) {
img = ResourceManager::Load<Texture>("Textures/Core/ErrorTexture.png");
} catch (const std::exception&) {
img = nullptr;
}
return img;
}
void CommonFunctions::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type)
{
glDeleteTextures(1, texture);
+1 -1
View File
@@ -37,7 +37,7 @@ ScreenCoords::PixelData ScreenCoords::ToPixelData(float x, float y, FrameBuffer*
glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pdata);
GLERROR("glReadPixels(pdata) Error");
PickDataBuffer->Unbind();
GLERROR("Unbind Error");
glBindFramebuffer(GL_FRAMEBUFFER, DepthBuffer);
GLERROR("glBindFramebuffer(DepthBuffer) Error");
float depthData;
+10 -9
View File
@@ -35,8 +35,12 @@
#include "Game/Systems/BoostSystem.h"
#include "Game/Systems/BoostIconsHUDSystem.h"
#include "Game/Systems/ScoreScreenSystem.h"
#include "Game/Systems/SpectatorCameraSystem.h"
#include "GUI/ButtonSystem.h"
#include "GUI/MainMenuSystem.h"
#include "Game/Systems/MainMenuSystem.h"
#include "Game/Systems/ServerListSystem.h"
#include "Game/Systems/StartSystem.h"
#include "Rendering/TextureSprite.h"
Game::Game(int argc, char* argv[])
@@ -48,6 +52,7 @@ Game::Game(int argc, char* argv[])
ResourceManager::RegisterType<Model>("Model");
ResourceManager::RegisterType<RawModel>("RawModel");
ResourceManager::RegisterType<Texture>("Texture");
ResourceManager::RegisterType<TextureSprite>("TextureSprite");
ResourceManager::RegisterType<PNG>("Png");
ResourceManager::RegisterType<ShaderProgram>("ShaderProgram");
ResourceManager::RegisterType<EntityFile>("EntityFile");
@@ -137,25 +142,21 @@ Game::Game(int argc, char* argv[])
m_SystemPipeline->AddSystem<LifetimeSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CapturePointSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CapturePointHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PickupSpawnSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<AmmoPickupSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<DamageIndicatorSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<TextFieldReader>(updateOrderLevel);
m_SystemPipeline->AddSystem<AbilityCooldownHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CapturePointArrowHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<KillFeedSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CapturePointSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CapturePointHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PickupSpawnSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<AmmoPickupSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<DamageIndicatorSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<TextFieldReader>(updateOrderLevel);
m_SystemPipeline->AddSystem<KillFeedSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<BoostSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<ButtonSystem>(updateOrderLevel, m_Renderer);
m_SystemPipeline->AddSystem<MainMenuSystem>(updateOrderLevel, m_Renderer);
m_SystemPipeline->AddSystem<BoostIconsHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<ScoreScreenSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<SpectatorCameraSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<ServerListSystem>(updateOrderLevel, m_Renderer);
m_SystemPipeline->AddSystem<StartSystem>(updateOrderLevel);
// Populate Octree with collidables
++updateOrderLevel;
m_SystemPipeline->AddSystem<FillOctreeSystem>(updateOrderLevel, m_OctreeCollision, "Collidable");
@@ -218,7 +219,7 @@ void Game::Tick()
PerformanceTimer::StartTimerAndStopPrevious("InputProxy");
m_InputProxy->Update(dt);
m_EventBroker->Swap();
m_InputProxy->Process();
m_InputProxy->Process(ImGui::GetIO().WantCaptureKeyboard || ImGui::GetIO().WantCaptureMouse);
m_EventBroker->Swap();
PerformanceTimer::StartTimerAndStopPrevious("SoundManager");
@@ -15,7 +15,9 @@ bool MultiplayerSnapshotFilter::FilterComponent(EntityWrapper entity, SharedComp
|| component.Info.Name == "AssaultWeapon"
|| component.Info.Name == "DefenderWeapon"
|| component.Info.Name == "Animation"
|| component.Info.Name == "AnimationOffset"
|| component.Info.Name == "Blend"
|| component.Info.Name == "BlendAdditive"
|| component.Info.Name == "BlendOverride"
|| entity.Name() == "PlayerName"
) {
return false;
+59 -10
View File
@@ -11,23 +11,72 @@ void AbilityCooldownHUDSystem::Update(double dt)
for (auto& abilityHUDC : *abilityHUDs) {
EntityWrapper entity = EntityWrapper(m_World, abilityHUDC.EntityID);
EntityWrapper abilityEntity = entity.FirstParentWithComponent("DashAbility");
if (!abilityEntity.Valid())
return;
EntityWrapper cooldownTextEntity = entity.FirstChildByName("Cooldown");
std::string abilityName = "";
double maxAbilityCD = (double)abilityEntity["DashAbility"]["CoolDownMaxTimer"];
double currentAbilityCD = (double)abilityEntity["DashAbility"]["CoolDownTimer"];
if (!abilityEntity.Valid()) {
//If we dont have a dash ability on player, we check for Sprint ability
abilityEntity = entity.FirstParentWithComponent("SprintAbility");
currentAbilityCD = currentAbilityCD >= 0.0 ? currentAbilityCD : 0.0;
if (!abilityEntity.Valid()) {
//If we dont have a sprint ability on player, we check for shield ability
abilityEntity = entity.FirstParentWithComponent("ShieldAbility");
if(cooldownTextEntity.Valid()) {
if(cooldownTextEntity.HasComponent("Text"))
{
std::string t = (std::string&)cooldownTextEntity["Text"]["Content"] = std::to_string(currentAbilityCD).substr(0, 3);
if (!abilityEntity.Valid()) {
//If we dont have a shield ability, we return, since we cannot do anything.
return;
} else {
//If we have a shield ability, we set the right icon
abilityName = "ShieldAbility";
if (entity.HasComponent("Sprite")) {
(std::string&)entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\SheildDots-01.png";
}
}
} else {
//If we do have a sprint ability, we change the icon
abilityName = "SprintAbility";
if (entity.HasComponent("Sprite")) {
(std::string&)entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\Dash-01.png";
}
}
} else {
//If we have a dash ability, we set the icon to the correct one.
abilityName = "DashAbility";
if (entity.HasComponent("Sprite")) {
(std::string&)entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\Superman-01.png";
}
}
EntityWrapper cooldownTextEntity = entity.FirstChildByName("Cooldown");
//TODO: Fix so this track correctly for shield and sprint depending on how they work.
double maxAbilityCD, currentAbilityCD;
if (abilityName == "DashAbility") {
maxAbilityCD = (double)abilityEntity[abilityName]["CoolDownMaxTimer"];
currentAbilityCD = (double)abilityEntity[abilityName]["CoolDownTimer"];
currentAbilityCD = currentAbilityCD >= 0.0 ? currentAbilityCD : 0.0;
if (cooldownTextEntity.Valid()) {
if (cooldownTextEntity.HasComponent("Text")) {
std::string t = (std::string&)cooldownTextEntity["Text"]["Content"] = std::to_string(currentAbilityCD).substr(0, 3);
}
}
}
if (abilityName == "ShieldAbility") {
maxAbilityCD = 0.0;
currentAbilityCD = 1 - (bool)abilityEntity[abilityName]["Active"];
}
if (abilityName == "SprintAbility") {
maxAbilityCD = 0.0;
currentAbilityCD = 1 - (bool)abilityEntity[abilityName]["Active"];
}
if (entity.HasComponent("Fill")) {
entity["Fill"]["Percentage"] = currentAbilityCD/maxAbilityCD;
}
}
}
+65 -16
View File
@@ -37,8 +37,7 @@ void AmmoPickupSystem::Update(double dt)
//erase the current element (somePickup)
it = m_ETriggerTouchVector.erase(it);
}
else {
} else {
it++;
}
}
@@ -48,7 +47,7 @@ void AmmoPickupSystem::Update(double dt)
m_PickupAtMaximum.erase(it);
break;
}
if ((int)it->player["AssaultWeapon"]["Ammo"] < (int)it->player["AssaultWeapon"]["MaxAmmo"]) {
if (!DoesPlayerHaveMaxAmmo(it->player)) {
DoPickup(it->player, it->trigger);
m_PickupAtMaximum.erase(it);
break;
@@ -56,6 +55,58 @@ void AmmoPickupSystem::Update(double dt)
}
}
}
bool AmmoPickupSystem::DoesPlayerHaveMaxAmmo(EntityWrapper &player) {
PlayerClass playerClass = DetermineClass(player);
if (playerClass == PlayerClass::Defender) {
return !((int)player["DefenderWeapon"]["Ammo"] < (int)player["DefenderWeapon"]["MaxAmmo"]);
} else if (playerClass == PlayerClass::Sniper) {
return !((int)player["SniperWeapon"]["Ammo"] < (int)player["SniperWeapon"]["MaxAmmo"]);
} else if (playerClass == PlayerClass::Assault) {
return !((int)player["AssaultWeapon"]["Ammo"] < (int)player["AssaultWeapon"]["MaxAmmo"]);
} else {
return false;
}
}
void AmmoPickupSystem::SetPlayerAmmo(EntityWrapper &player, int ammoGain) {
int maxWeaponAmmo = GetPlayerMaxAmmo(player);
PlayerClass playerClass = DetermineClass(player);
if (playerClass == PlayerClass::Defender) {
(int&)player["DefenderWeapon"]["Ammo"] = std::min((int)player["DefenderWeapon"]["Ammo"] + ammoGain, maxWeaponAmmo);
} else if (playerClass == PlayerClass::Sniper) {
(int&)player["SniperWeapon"]["Ammo"] = std::min((int)player["SniperWeapon"]["Ammo"] + ammoGain, maxWeaponAmmo);
} else if (playerClass == PlayerClass::Assault) {
(int&)player["AssaultWeapon"]["Ammo"] = std::min((int)player["AssaultWeapon"]["Ammo"] + ammoGain, maxWeaponAmmo);
} else {
//unknown class - ignore
}
}
int AmmoPickupSystem::GetPlayerMaxAmmo(EntityWrapper &player) {
PlayerClass playerClass = DetermineClass(player);
if (playerClass == PlayerClass::Defender) {
return (int)player["DefenderWeapon"]["MaxAmmo"];
} else if (playerClass == PlayerClass::Sniper) {
return (int)player["SniperWeapon"]["MaxAmmo"];
} else if (playerClass == PlayerClass::Assault) {
return (int)player["AssaultWeapon"]["MaxAmmo"];
} else {
return -1;
}
}
AmmoPickupSystem::PlayerClass AmmoPickupSystem::DetermineClass(EntityWrapper &player)
{
//determine the class based on what component the inflictor-player has
if (m_World->HasComponent(player.ID, "DashAbility")) {
return PlayerClass::Assault;
}
if (m_World->HasComponent(player.ID, "ShieldAbility")) {
return PlayerClass::Defender;
}
if (m_World->HasComponent(player.ID, "SprintAbility")) {
return PlayerClass::Sniper;
}
return PlayerClass::None;
}
bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
{
@@ -63,7 +114,7 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
return false;
}
//TODO: add other weapontypes
if (!e.Entity.HasComponent("AssaultWeapon")) {
if (DetermineClass(e.Entity) == PlayerClass::None) {
return false;
}
if (!e.Trigger.HasComponent("AmmoPickup")) {
@@ -71,7 +122,7 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
}
//if at maxammo, save the trigger-touch to a vector since standing inside it will not re-trigger the trigger
if ((int)e.Entity["AssaultWeapon"]["Ammo"] >= (int)e.Entity["AssaultWeapon"]["MaxAmmo"]) {
if (DoesPlayerHaveMaxAmmo(e.Entity)) {
m_PickupAtMaximum.push_back({ e.Entity, e.Trigger });
return false;
}
@@ -85,18 +136,16 @@ bool AmmoPickupSystem::OnAmmoPickup(Events::AmmoPickup & e)
return false;
}
//TODO: add other weapontypes
if (!e.Player.HasComponent("AssaultWeapon")) {
if (DetermineClass(e.Player) == PlayerClass::None) {
return false;
}
int maxWeaponAmmo = (int)e.Player["AssaultWeapon"]["MaxAmmo"];
int& currentAmmo = (int)e.Player["AssaultWeapon"]["Ammo"];
//cant pick up ammopacks if you are already at MaxAmmo
if (currentAmmo >= maxWeaponAmmo) {
if (DoesPlayerHaveMaxAmmo(e.Player)) {
return false;
}
SetPlayerAmmo(e.Player, e.AmmoGain);
currentAmmo = std::min(currentAmmo + e.AmmoGain, maxWeaponAmmo);
return false;
return true;
}
bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
@@ -114,8 +163,11 @@ bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
}
void AmmoPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) {
int maxWeaponAmmo = (int)player["AssaultWeapon"]["MaxAmmo"];
int& currentAmmo = (int)player["AssaultWeapon"]["Ammo"];
//trigger should be valid but if it isnt we just return (to avoid crash)
if (!trigger.Valid()) {
return;
}
int maxWeaponAmmo = GetPlayerMaxAmmo(player);
int ammoGiven = 0.01*(double)trigger["AmmoPickup"]["AmmoGain"] * maxWeaponAmmo;
Events::AmmoPickup ePlayerAmmoPickup;
@@ -123,9 +175,6 @@ void AmmoPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) {
ePlayerAmmoPickup.Player = player;
m_EventBroker->Publish(ePlayerAmmoPickup);
//immediately give the player the ammo (on server)
currentAmmo = std::min(currentAmmo + ammoGiven, maxWeaponAmmo);
//copy position, ammogain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object)
//we need to copy all values since each value can be different for each ammoPickup
m_ETriggerTouchVector.push_back({ (glm::vec3)trigger["Transform"]["Position"], trigger["AmmoPickup"]["AmmoGain"],
+12
View File
@@ -69,6 +69,7 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
int ownedBy = teamComponent["Team"];
int redTeamPlayersStandingInside = 0;
int blueTeamPlayersStandingInside = 0;
//note: old color system
if (capturePointEntity.HasComponent("Model")) {
//Now sets team color to the capturepoint, or white if it is uncaptured.
capturePointEntity["Model"]["Color"] = ownedBy == blueTeam ? glm::vec4(0, 0.0f, 1, 0.3) : ownedBy == redTeam ? glm::vec4(1, 0.0f, 0, 0.3) : glm::vec4(1, 1, 1, 0.3);
@@ -102,7 +103,18 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
nextPossibleCapturePoint["Blue"] = i - 1;
}
}
if (m_RecentlyCapturedNeedNextCapturePointNow) {
//change what model is displaying (change all in case 2 capturepoints has been captured on the same frame)
for (int i = 0; i < m_NumberOfCapturePoints; i++) {
auto owner = (int)m_CapturePointNumberToEntityMap[i]["Team"]["Team"];
if (m_CapturePointNumberToEntityMap[i].FirstChildByName("Red").ID != EntityID_Invalid) {
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Red")["Model"]["Visible"] = owner == redTeam ? true : false;
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Blue")["Model"]["Visible"] = owner == blueTeam ? true : false;
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Spectator")["Model"]["Visible"] = owner == spectatorTeam ? true : false;
}
}
//save the next cap points and publish the captured event
m_CapturedEvent.BlueTeamNextCapturePoint = m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Blue"]];
m_CapturedEvent.RedTeamNextCapturePoint = m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Red"]];
m_EventBroker->Publish(m_CapturedEvent);
+11 -5
View File
@@ -8,12 +8,13 @@ DamageIndicatorSystem::DamageIndicatorSystem(SystemParams params)
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &DamageIndicatorSystem::OnSetCamera);
//load texture to cache
auto texture = CommonFunctions::LoadTexture("Textures/DamageIndicator.png", false);
auto texture = CommonFunctions::TryLoadResource<Texture, false>("Textures/DamageIndicator.png");
auto entityFile = ResourceManager::Load<EntityXMLFile>("Schema/Entities/DamageIndicator.xml");
m_NetworkEnabled = ResourceManager::Load<ConfigFile>("Config.ini")->Get("Networking.StartNetwork", false);
}
void DamageIndicatorSystem::Update(double dt) {
if (!IsServer && LocalPlayer.Valid()) {
if ((!IsServer || !m_NetworkEnabled) && LocalPlayer.Valid()) {
for (auto& iter = updateDamageIndicatorVector.begin(); iter != updateDamageIndicatorVector.end(); iter++) {
if (!iter->spriteEntity.Valid()) {
updateDamageIndicatorVector.erase(iter);
@@ -40,10 +41,15 @@ bool DamageIndicatorSystem::OnPlayerDamage(Events::PlayerDamage& e)
return false;
}
//friendly fire - return
if (e.Damage < 0.1f) {
return false;
}
glm::vec3 inflictorPos = e.Inflictor["Transform"]["Position"];
//if testing
#ifdef INDICATOR_TEST
inflictorPos = DamageIndicatorTest(e.Victim);
inflictorPos = DamageIndicatorTest(e.Victim);
#endif
float angleBetweenVectors = CalculateAngle(e.Victim, inflictorPos);
@@ -55,7 +61,7 @@ bool DamageIndicatorSystem::OnPlayerDamage(Events::PlayerDamage& e)
//simply set the rotation z-wise to the angleBetweenVectors
sprite["Transform"]["Orientation"] = glm::vec3(0, 0, angleBetweenVectors);
if (!IsServer) {
if (!IsServer || !m_NetworkEnabled) {
updateDamageIndicatorVector.emplace_back(sprite, inflictorPos);
}
@@ -122,7 +128,7 @@ glm::vec3 DamageIndicatorSystem::DamageIndicatorTest(EntityWrapper player) {
}
m_TestVar++;
auto inflictorPos = glm::vec3(currentPos.x + testVar*6.0f, currentPos.y, currentPos.z + testVar2*6.0f);
auto inflictorPos = glm::vec3(currentPos.x + testVar*6.0f, currentPos.y, currentPos.z + testVar2*6.0f);
//load the explosioneffect XML
auto deathEffect = ResourceManager::Load<EntityXMLFile>("Schema/Entities/PlayerDeathExplosionWithCamera.xml");
+12 -15
View File
@@ -2,20 +2,17 @@
void ExplosionEffectSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt)
{
if ((double)component["TimeSinceDeath"] > (double)component["ExplosionDuration"]) {
(double)component["TimeSinceDeath"] = 0.f;
if ((bool)component["Pulsate"] == true) {
(bool)component["Reverse"] = false;
}
}
double& delay = (double)component["Delay"];
if (delay > 0) {
delay = std::max(0.0, delay - dt);
}
//((glm::vec2&)component["Velocity"]).x = glm::min(((glm::vec2)component["Velocity"]).x, ((glm::vec2)component["Velocity"]).y);
if (delay <= 0) {
double& timeSinceDeath = component["TimeSinceDeath"];
timeSinceDeath += (double)component["Speed"] * dt;
if (timeSinceDeath < 0 || timeSinceDeath > (double)component["ExplosionDuration"]) {
timeSinceDeath = 0.0;
}
}
}
(double&)component["TimeSinceDeath"] += dt;
if ((bool)component["Pulsate"] == true) {
if ((double)component["TimeSinceDeath"] > (double)component["ExplosionDuration"] * 0.5) {
(bool)component["Reverse"] = true;
}
}
}
+93
View File
@@ -0,0 +1,93 @@
#include "../Game/Systems/MainMenuSystem.h"
MainMenuSystem::MainMenuSystem(SystemParams params, IRenderer* renderer)
: System(params)
, ImpureSystem()
, m_Renderer(renderer)
{
EVENT_SUBSCRIBE_MEMBER(m_EPressed, &MainMenuSystem::OnButtonPress);
EVENT_SUBSCRIBE_MEMBER(m_EReleased, &MainMenuSystem::OnButtonRelease);
EVENT_SUBSCRIBE_MEMBER(m_EClicked, &MainMenuSystem::OnButtonClick);
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &MainMenuSystem::OnInputCommand);
}
void MainMenuSystem::Update(double dt)
{
}
bool MainMenuSystem::OnButtonClick(const Events::ButtonClicked& e)
{
if (e.EntityName == "ServerIdentityConnect") {
EntityWrapper entity = e.Entity;
EntityWrapper serverIdentityEntity = entity.FirstParentWithComponent("ServerIdentity");
if(serverIdentityEntity.Valid()) {
Events::ConnectRequest event;
event.IP = (std::string)serverIdentityEntity["ServerIdentity"]["IP"];
event.Port = (int)serverIdentityEntity["ServerIdentity"]["Port"];
printf("\n ----Request Server Connect----\nIP: %s\nPort: %i\n ------------------------------", event.IP, event.Port);
m_EventBroker->Publish(event);
}
}
return true;
}
bool MainMenuSystem::OnButtonRelease(const Events::ButtonReleased& e)
{
return true;
}
bool MainMenuSystem::OnButtonPress(const Events::ButtonPressed& e)
{
return true;
}
bool MainMenuSystem::OnInputCommand(const Events::InputCommand& e)
{
if(e.Command == "Play" && e.Value == 1) {
auto menus = m_World->GetComponents("Menu");
if (menus == nullptr) {
return 0;
}
if (m_OpenSubMenu == EntityWrapper::Invalid) {
//No submenu is open, open one.
for (auto& menu : *menus) {
EntityWrapper menuEntity = EntityWrapper(m_World, menu.EntityID);
auto serverListSpawner = menuEntity.FirstChildByName(e.Command + "Spawner");
if (!serverListSpawner.HasComponent("Spawner")) {
return 0;
}
m_OpenSubMenu = SpawnerSystem::Spawn(serverListSpawner, serverListSpawner);
Events::SearchForServers event;
m_EventBroker->Publish(event);
break;
}
} else if(!m_OpenSubMenu.HasComponent("ServerList")) {
//Menu is open, but not the right one, delete the old one and open a new one.
m_World->DeleteEntity(m_OpenSubMenu.ID);
m_OpenSubMenu = EntityWrapper::Invalid;
for (auto& menu : *menus) {
EntityWrapper menuEntity = EntityWrapper(m_World, menu.EntityID);
auto serverListSpawner = menuEntity.FirstChildByName(e.Command + "Spawner");
if (!serverListSpawner.HasComponent("Spawner")) {
return 0;
}
m_OpenSubMenu = SpawnerSystem::Spawn(serverListSpawner, serverListSpawner);
Events::SearchForServers event;
m_EventBroker->Publish(event);
break;
}
} else {
//Serverlist submenu is open, close it.
m_World->DeleteEntity(m_OpenSubMenu.ID);
m_OpenSubMenu = EntityWrapper::Invalid;
}
} else if (e.Command == "RefreshServerList" && e.Value == 1){
Events::SearchForServers event;
m_EventBroker->Publish(event);
}
return true;
}
+4
View File
@@ -83,6 +83,10 @@ bool PickupSpawnSystem::OnTriggerLeave(Events::TriggerLeave& e)
}
void PickupSpawnSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger)
{
//trigger should be valid but if it isnt we just return (to avoid crash)
if (!trigger.Valid()) {
return;
}
double healthGiven = 0.01*(double)trigger["HealthPickup"]["HealthGain"] * (double)player["Health"]["MaxHealth"];
//only the server will increase the players hp and set it in the next delta
+30 -7
View File
@@ -1,10 +1,12 @@
#include "Systems/PlayerDeathSystem.h"
#include "Core/ELockMouse.h"
PlayerDeathSystem::PlayerDeathSystem(SystemParams params)
: System(params)
{
EVENT_SUBSCRIBE_MEMBER(m_OnPlayerDeath, &PlayerDeathSystem::OnPlayerDeath);
EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &PlayerDeathSystem::OnEntityDeleted);
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &PlayerDeathSystem::OnInputCommand);
}
void PlayerDeathSystem::Update(double dt)
@@ -33,10 +35,10 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
//components that we need from player
auto playerModel = player.FirstChildByName("PlayerModel");
if (!playerModel.Valid()) {
return;
}
if (!playerModel.HasComponent("Model") || !playerModel.HasComponent("Animation")) {
if (player == LocalPlayer) {
setSpectatorCamera();
}
return;
}
auto playerEntityModel = playerModel["Model"];
@@ -68,14 +70,35 @@ bool PlayerDeathSystem::OnEntityDeleted(Events::EntityDeleted& e)
if (m_LocalPlayerDeathEffect.ID != e.DeletedEntity) {
return false;
}
// If the player hasn't spawned already, activate the spectator camera.
if (!LocalPlayer.Valid()) {
setSpectatorCamera();
}
return true;
}
void PlayerDeathSystem::setSpectatorCamera()
{
// Look for the spectator camera entity in the level.
EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera");
if (!spectatorCam.Valid() || !spectatorCam.HasComponent("Camera") || LocalPlayer.Valid()) {
return false;
if (!spectatorCam.HasComponent("Camera")) {
return;
}
Events::SetCamera eSetCamera;
eSetCamera.CameraEntity = spectatorCam;
m_EventBroker->Publish(eSetCamera);
return true;
Events::UnlockMouse unlock;
m_EventBroker->Publish(unlock);
}
bool PlayerDeathSystem::OnInputCommand(Events::InputCommand& e)
{
if (e.Value == 0 || e.Command != "SwapToTeamPick" && e.Command != "SwapToClassPick") {
return false;
}
// Ensure that we don't set spectator camera if the player deliberately changes to class/team pick.
m_LocalPlayerDeathEffect = EntityWrapper::Invalid;
return true;
}
+45 -48
View File
@@ -81,27 +81,18 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
cameraOrientation.x += controller->Rotation().x;
// Limit camera pitch so we don't break our necks
cameraOrientation.x = glm::clamp(cameraOrientation.x, -glm::half_pi<float>(), glm::half_pi<float>());
// Set third person model aim pitch
EntityWrapper playerModel = player.FirstChildByName("PlayerModel");
//Third-person aim
if (playerModel.Valid()) {
EntityWrapper aimPrimaryEntity = playerModel.FirstChildByName("AimPrimary");
EntityWrapper aimPrimaryEntity = playerModel.FirstChildByName("Aim");
if(aimPrimaryEntity.Valid()){
if(aimPrimaryEntity.HasComponent("Animation")) {
float pitch = cameraOrientation.x + 0.2f;
double time = (pitch + glm::half_pi<float>()) / glm::pi<float>();
float pitch = cameraOrientation.x;
double time = ((pitch + glm::half_pi<float>()) / glm::pi<float>());
(double&)aimPrimaryEntity["Animation"]["Time"] = time;
}
}
EntityWrapper aimSecondaryEntity = playerModel.FirstChildByName("AimSecondary");
if (aimSecondaryEntity.Valid()) {
if (aimSecondaryEntity.HasComponent("Animation")) {
float pitch = cameraOrientation.x + 0.2f;
double time = (pitch + glm::half_pi<float>()) / glm::pi<float>();
(double&)aimSecondaryEntity["Animation"]["Time"] = time;
}
}
}
}
@@ -213,7 +204,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.25;
aeb.NodeName = "StandCrouchBlend";
aeb.NodeName = "MovementBlend";
aeb.RootNode = playerModel;
aeb.Start = true;
aeb.Restart = false;
@@ -244,11 +235,11 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.25;
aeb.NodeName = "StandCrouchBlend";
aeb.NodeName = "MovementBlend";
aeb.RootNode = playerModel;
aeb.Start = true;
aeb.Restart = false;
aeb.AnimationEntity = playerModel.FirstChildByName("Jump");
aeb.AnimationEntity = playerModel.FirstChildByName("BlendTreeLower").FirstChildByName("Jump");
m_EventBroker->Publish(aeb);
}
}
@@ -377,12 +368,12 @@ void PlayerMovementSystem::spawnHexagon(EntityWrapper target)
bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
{
EntityWrapper player(m_World, e.Player);
if (!player.Valid() || !IsClient){// || player.ID == LocalPlayer.ID) {
if (!player.Valid()){// || !IsClient || player.ID == LocalPlayer.ID) {
return false;
}
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/DashEffect.xml");
EntityWrapper dashEffect = entityFile->MergeInto(m_World);
// auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/DashEffect.xml");
// EntityWrapper dashEffect = entityFile->MergeInto(m_World);
EntityWrapper playerModel = player.FirstChildByName("PlayerModel");
for (auto& kv : m_PlayerInputControllers) {
@@ -400,7 +391,7 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
if (controller->Movement().x > 0) {
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.3;
aeb.Duration = 0.1;
aeb.NodeName = "DashRight";
aeb.RootNode = playerModel;
aeb.Restart = true;
@@ -409,19 +400,18 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
}
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.3;
aeb.NodeName = "StandCrouchBlend";
aeb.Duration = 0.2;
aeb.NodeName = "MovementBlend";
aeb.RootNode = playerModel;
aeb.Delay = -0.3;
aeb.Start = true;
aeb.Restart = false;
aeb.AnimationEntity = playerModel.FirstChildByName("DashForward");
aeb.AnimationEntity = playerModel.FirstChildByName("DashRight");
m_EventBroker->Publish(aeb);
}
} else {
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.3;
aeb.Duration = 0.1;
aeb.NodeName = "DashLeft";
aeb.RootNode = playerModel;
aeb.Restart = true;
@@ -430,13 +420,12 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
}
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.3;
aeb.NodeName = "StandCrouchBlend";
aeb.Duration = 0.2;
aeb.NodeName = "MovementBlend";
aeb.RootNode = playerModel;
aeb.Delay = -0.3;
aeb.Start = true;
aeb.Restart = false;
aeb.AnimationEntity = playerModel.FirstChildByName("DashForward");
aeb.AnimationEntity = playerModel.FirstChildByName("DashLeft");
m_EventBroker->Publish(aeb);
}
}
@@ -444,7 +433,7 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
if (controller->Movement().z < 0) {
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.3;
aeb.Duration = 0.1;
aeb.NodeName = "DashForward";
aeb.RootNode = playerModel;
aeb.Restart = true;
@@ -453,10 +442,9 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
}
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.3;
aeb.NodeName = "StandCrouchBlend";
aeb.Duration = 0.2;
aeb.NodeName = "MovementBlend";
aeb.RootNode = playerModel;
aeb.Delay = -0.3;
aeb.Start = true;
aeb.Restart = false;
aeb.AnimationEntity = playerModel.FirstChildByName("DashForward");
@@ -465,7 +453,7 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
} else {
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.3;
aeb.Duration = 0.1;
aeb.NodeName = "DashBackward";
aeb.RootNode = playerModel;
aeb.Restart = true;
@@ -474,32 +462,41 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
}
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.3;
aeb.NodeName = "StandCrouchBlend";
aeb.Duration = 0.2;
aeb.NodeName = "MovementBlend";
aeb.RootNode = playerModel;
aeb.Delay = -0.3;
aeb.Start = true;
aeb.Restart = false;
aeb.AnimationEntity = playerModel.FirstChildByName("DashForward");
aeb.AnimationEntity = playerModel.FirstChildByName("DashBackward");
m_EventBroker->Publish(aeb);
}
}
}
}
}
}
/*
auto playerEntityAnimation = playerModel["Animation"];
playerEntityModel.Copy(dashEffect["Model"]);
playerEntityAnimation.Copy(dashEffect["Animation"]);
dashEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"];
((glm::vec4&)dashEffect["ExplosionEffect"]["EndColor"]).w = 0.f;
*/
EntityWrapper dashEffectModel;
dashEffectModel = playerModel.Clone();
player["Transform"].Copy(dashEffectModel["Transform"]);
dashEffectModel.AttachComponent("ExplosionEffect");
dashEffectModel["ExplosionEffect"]["EndColor"] = (glm::vec4)playerModel["Model"]["Color"];
((glm::vec4&)dashEffectModel["ExplosionEffect"]["EndColor"]).w = 0.f;
(double&)dashEffectModel["ExplosionEffect"]["ExplosionDuration"] = dashEffect["Lifetime"]["Lifetime"];
(glm::vec3&)dashEffectModel["ExplosionEffect"]["ExplosionOrigin"] = glm::vec3(0, 1, 0) + (0.2f * controller->Movement());
auto animationChildren = dashEffectModel.ChildrenWithComponent("Animation");
for (auto animationEntity : animationChildren) {
(bool&)animationEntity["Animation"]["Play"] = false;
}
*/
}
}
}
return true;
}
+61 -52
View File
@@ -1,4 +1,5 @@
#include "Systems/PlayerSpawnSystem.h"
#include "Core/ELockMouse.h"
PlayerSpawnSystem::PlayerSpawnSystem(SystemParams params)
: System(params)
@@ -59,7 +60,15 @@ void PlayerSpawnSystem::Update(double dt)
}
int numSpawnedPlayers = 0;
for (auto& req : m_SpawnRequests) {
int playersSpectating = 0;
const int numRequestsToHandle = (int)m_SpawnRequests.size();
for (auto it = m_SpawnRequests.begin(); it != m_SpawnRequests.end(); ++it) {
// It is valid if they didn't pick class yet
// but don't spawn anything, goto next spawnrequest.
if (it->Class == PlayerClass::None) {
++playersSpectating;
continue;
}
for (auto& cPlayerSpawn : *playerSpawns) {
EntityWrapper spawner(m_World, cPlayerSpawn.EntityID);
if (!spawner.HasComponent("Spawner")) {
@@ -69,43 +78,49 @@ void PlayerSpawnSystem::Update(double dt)
// If the spawner has a team affiliation, check it
if (spawner.HasComponent("Team")) {
auto cSpawnerTeam = spawner["Team"];
if ((int)cSpawnerTeam["Team"] != req.Team) {
// Increase num spawned players if someone picks spectator, since it is valid to pick spectator
// but don't spawn anything, goto next spawnrequest.
if (req.Team == (int)cSpawnerTeam["Team"].Enum("Spectator")) {
++numSpawnedPlayers;
if ((int)cSpawnerTeam["Team"] != it->Team) {
// If they somehow has a valid class as spectator, don't spawn them.
if (it->Team == cSpawnerTeam["Team"].Enum("Spectator")) {
++playersSpectating;
break;
}
continue;
}
}
// TODO: Choose a different spawner depending on class picked?
// Spawn the player!
EntityWrapper player = SpawnerSystem::Spawn(spawner, EntityWrapper::Invalid, "Player");
// Set the player team affiliation
player["Team"]["Team"] = req.Team;
player["Team"]["Team"] = it->Team;
// Publish a PlayerSpawned event
Events::PlayerSpawned e;
e.PlayerID = req.PlayerID;
e.PlayerID = it->PlayerID;
e.Player = player;
e.Spawner = spawner;
m_EventBroker->Publish(e);
++numSpawnedPlayers;
it = m_SpawnRequests.erase(it);
break;
}
if (it == m_SpawnRequests.end()) {
break;
}
}
if (numSpawnedPlayers != (int)m_SpawnRequests.size()) {
LOG_DEBUG("%i players were supposed to be spawned or set as spectator, but only %i was handled.", (int)m_SpawnRequests.size(), numSpawnedPlayers);
if (numSpawnedPlayers != numRequestsToHandle - playersSpectating) {
LOG_DEBUG("%i players were supposed to be spawned, but only %i was successfully.", numRequestsToHandle - playersSpectating, numSpawnedPlayers);
} else {
LOG_DEBUG("%i players were spawned or set as spectator.", numSpawnedPlayers);
std::string dbg = numSpawnedPlayers != 0 ? std::to_string(numSpawnedPlayers) + " players were spawned. " : "";
dbg += playersSpectating != 0 ? std::to_string(playersSpectating) + " players are spectating/picking class. " : "";
LOG_DEBUG(dbg.c_str());
}
m_SpawnRequests.clear();
}
bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
{
if (e.Command != "PickTeam" && e.Command != "SwapToClassPick") {
if (e.Command != "PickTeam" && e.Command != "PickClass" && e.Command != "SwapToTeamPick" && e.Command != "SwapToClassPick") {
return false;
}
@@ -113,19 +128,6 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
return false;
}
// A dead client should be able to swap to the overwatch camera.
if (IsClient && !LocalPlayer.Valid()) {
// Set the camera as active, if it exists.
// Find the respawn camera or class pick camera.
std::string camName = e.Command == "SwapToClassPick" ? "PickClassCamera" : "SpectatorCamera";
EntityWrapper spectatorCam = m_World->GetFirstEntityByName(camName);
if (spectatorCam.Valid() && spectatorCam.HasComponent("Camera")) {
Events::SetCamera eSetCamera;
eSetCamera.CameraEntity = spectatorCam;
m_EventBroker->Publish(eSetCamera);
}
}
// Team picks should be processed ONLY server-side!
// Don't make a spawn request if we're the client.
if (!IsServer && m_NetworkEnabled) {
@@ -136,27 +138,38 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
auto iter = m_SpawnRequests.begin();
for (; iter != m_SpawnRequests.end(); ++iter) {
if (iter->PlayerID == e.PlayerID) {
// If player wants to switch class, remove their spawn request.
if (e.Command == "SwapToClassPick") {
m_SpawnRequests.erase(iter);
// If player wants to switch team or class , remove their selected class so they don't spawn.
if (e.Command == "SwapToTeamPick" || e.Command == "SwapToClassPick") {
iter->Class = PlayerClass::None;
return true;
}
break;
}
}
if (e.Command == "SwapToClassPick") {
return true;
}
//If we get here we got a PickTeam or PickClass, so add or alter a spawn request.
if (iter != m_SpawnRequests.end()) {
// If player is in queue to spawn, then change their team affiliation in the request.
iter->Team = (ComponentInfo::EnumType)e.Value;
// If player is in queue to spawn, then change their team affiliation or class in the request.
if (e.Command == "PickTeam") {
iter->Team = (ComponentInfo::EnumType)e.Value;
} else {
iter->Class = static_cast<PlayerClass>((int)e.Value);
}
} else if (m_PlayerEntities.count(e.PlayerID) == 0 || !m_PlayerEntities[e.PlayerID].Valid()) {
// If player is not in queue to spawn, then create a spawn request,
// but only if they are spectating and/or just connected.
SpawnRequest req;
req.PlayerID = e.PlayerID;
req.Team = (ComponentInfo::EnumType)e.Value;
if (e.Command == "PickTeam") {
req.Team = (ComponentInfo::EnumType)e.Value;
req.Class = PlayerClass::None;
} else {
// Should never get here, since you should have picked a team before you ever get a chance to pick class.
LOG_WARNING("Sequence error: Should not be able to pick class before team");
req.Team = 1; // TODO: 1 Signifies spectator, should probably have real enum here later.
req.Class = static_cast<PlayerClass>((int)e.Value);
}
m_SpawnRequests.push_back(req);
} else {
return false;
@@ -191,18 +204,8 @@ bool PlayerSpawnSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
Events::SetCamera e;
e.CameraEntity = cameraEntity;
m_EventBroker->Publish(e);
}
// HACK: Set the player model color to team color
EntityWrapper playerModel = e.Player.FirstChildByName("PlayerModel");
if (playerModel.Valid() && e.Player.HasComponent("Team")) {
ComponentWrapper cTeam = e.Player["Team"];
ComponentWrapper cModel = playerModel["Model"];
if ((ComponentInfo::EnumType)cTeam["Team"] == cTeam["Team"].Enum("Red")) {
cModel["Color"] = glm::vec3(1.f, 0.f, 0.f);
} else if ((ComponentInfo::EnumType)cTeam["Team"] == cTeam["Team"].Enum("Blue")) {
cModel["Color"] = glm::vec3(0.f, 0.25f, 1.f);
}
Events::LockMouse lock;
m_EventBroker->Publish(lock);
}
return true;
@@ -210,7 +213,7 @@ bool PlayerSpawnSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
{
//Only spawn request if network is disabled or we are server.
// Only spawn request if network is disabled or we are server.
if (!IsServer && m_NetworkEnabled) {
return false;
}
@@ -218,10 +221,6 @@ bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
return false;
}
ComponentWrapper cTeam = e.Player["Team"];
//A spectator can't die anyway
if ((ComponentInfo::EnumType)cTeam["Team"] == cTeam["Team"].Enum("Spectator")) {
return false;
}
if (m_PlayerIDs.count(e.Player.ID) == 0) {
return false;
@@ -230,6 +229,16 @@ bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
SpawnRequest req;
req.PlayerID = m_PlayerIDs.at(e.Player.ID);
req.Team = cTeam["Team"];
// TODO: Something better than temp class state code, if we ever add class enums in .xml
if (e.Player.HasComponent("DashAbility")) {
req.Class = PlayerClass::Assault;
} else if (e.Player.HasComponent("SprintAbility")) {
req.Class = PlayerClass::Sniper;
} else if (e.Player.HasComponent("ShieldAbility")) {
req.Class = PlayerClass::Defender;
} else {
req.Class = PlayerClass::None;
}
m_SpawnRequests.push_back(req);
return true;
+53
View File
@@ -0,0 +1,53 @@
#include "../Game/Systems/ServerListSystem.h"
ServerListSystem::ServerListSystem(SystemParams params, IRenderer* renderer)
: System(params)
, PureSystem("ServerList")
, m_Renderer(renderer)
{
EVENT_SUBSCRIBE_MEMBER(m_EServerListRecieved, &ServerListSystem::OnServerListRecieved);
}
void ServerListSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cServerList, double dt)
{
}
void ServerListSystem::RefreshList()
{
Events::SearchForServers event;
m_EventBroker->Publish(event);
}
bool ServerListSystem::OnServerListRecieved(const Events::DisplayServerlist& e)
{
if (e.Serverlist.size() == 0) {
return 1;
}
auto serverLists = m_World->GetComponents("ServerList");
if (serverLists == nullptr)
return 1;
for (auto& cServerList : *serverLists) {
EntityWrapper serverListEntity = EntityWrapper(m_World, cServerList.EntityID);
EntityWrapper identitySpawner = serverListEntity.FirstChildByName("ServerIdentitySpawner");
identitySpawner.DeleteChildren();
(int&)cServerList["TotalIdentities"] = (int)e.Serverlist.size();
for (int i = 0; i < e.Serverlist.size(); i++) {
//Create Identities for each server and place them on the right position.
EntityWrapper newIdentity = SpawnerSystem::Spawn(identitySpawner, identitySpawner);
EntityWrapper serverIdentityEntity = newIdentity.FirstChildByName("ServerIdentity");
glm::vec3 offset = (glm::vec3)serverListEntity["ServerList"]["Offset"];
(glm::vec3&)serverIdentityEntity["Transform"]["Position"] = offset * (float)i;
auto& cIdentity = serverIdentityEntity["ServerIdentity"];
(std::string&)cIdentity["IP"] = e.Serverlist[i].Address;
(std::string&)cIdentity["ServerName"] = e.Serverlist[i].Name;
(int&)cIdentity["Port"] = e.Serverlist[i].Port;
(int&)cIdentity["PlayersConnected"] = e.Serverlist[i].PlayersConnected;
}
}
return 1;
}
@@ -0,0 +1,90 @@
#include "Systems/SpectatorCameraSystem.h"
#include "Rendering/ESetCamera.h"
#include "Core/ELockMouse.h"
SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params)
: System(params)
, m_CamSetToTeamPick(false)
, m_PickedTeam(-1)
{
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SpectatorCameraSystem::OnInputCommand);
}
void SpectatorCameraSystem::Update(double dt)
{
if (!m_CamSetToTeamPick && IsClient) {
// Find the class pick camera and set them to it, since they need to pick a team before they can leave the screen.
EntityWrapper spectatorCam = m_World->GetFirstEntityByName("PickTeamCamera");
if (spectatorCam.HasComponent("Camera")) {
m_CamSetToTeamPick = true;
Events::SetCamera eSetCamera;
eSetCamera.CameraEntity = spectatorCam;
m_EventBroker->Publish(eSetCamera);
Events::UnlockMouse unlock;
m_EventBroker->Publish(unlock);
}
}
}
bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e)
{
// Only the client should do this, and only if player is not spawned.
if (!IsClient || LocalPlayer.Valid()) {
return false;
}
bool swapToClass = e.Command == "PickTeam" || e.Command == "SwapToClassPick";
if (e.Value == 0 || !swapToClass && e.Command != "SwapToTeamPick" && e.Command != "PickClass") {
return false;
}
if (e.Command == "PickTeam") {
m_PickedTeam = e.Value;
}
// If a team has not been picked, they may not exit the pick team screen.
if (m_PickedTeam == -1) {
return false;
}
// A dead client should be able to swap to and between the overwatch cameras.
std::string camName;
// TODO: 1 Signifies spectator, should probably have real enum here later.
// Spectators should never end up at the class select, instead put them at the SpectatorCamera.
if (swapToClass && m_PickedTeam != 1) {
camName = "PickClassCamera";
} else if (e.Command == "SwapToTeamPick") {
camName = "PickTeamCamera";
} else {
camName = "SpectatorCamera";
}
EntityWrapper spectatorCam = m_World->GetFirstEntityByName(camName);
// Set the camera as active, if it exists.
if (spectatorCam.HasComponent("Camera")) {
// Set the class pick button visible if a blue or red team is picked, else invisible.
EntityWrapper HUD;
if (camName == "SpectatorCamera") {
HUD = spectatorCam.FirstChildByName("SpectatorHUD");
} else if (camName == "PickTeamCamera") {
HUD = spectatorCam.FirstChildByName("PickTeamHUD");
}
// If we are at the class pick already, or if HUD is invalid for any other reason, do nothing.
if (HUD.Valid()) {
EntityWrapper toClassButton = spectatorCam.FirstChildByName("ToClassPick");
if (toClassButton.Valid()) {
// Set ClassButton as invisible if spectator, else visible.
bool visible = m_PickedTeam != 1; // TODO: 1 Signifies spectator.
toClassButton["Sprite"]["Visible"] = visible;
for (auto& child : toClassButton.ChildrenWithComponent("Text")) {
child["Text"]["Visible"] = visible;
}
}
}
Events::SetCamera eSetCamera;
eSetCamera.CameraEntity = spectatorCam;
m_EventBroker->Publish(eSetCamera);
Events::UnlockMouse unlock;
m_EventBroker->Publish(unlock);
}
return true;
}
+33
View File
@@ -0,0 +1,33 @@
#include "../Game/Systems/StartSystem.h"
StartSystem::StartSystem(SystemParams params)
: System(params)
, ImpureSystem()
{
EVENT_SUBSCRIBE_MEMBER(m_ECameraActivated, &StartSystem::OnCameraActivated);
}
void StartSystem::Update(double dt)
{
auto cameras = m_World->GetComponents("Camera");
if(cameras == nullptr) {
return;
}
for(auto& cCamera: *cameras) {
EntityWrapper cameraEntity = EntityWrapper(m_World, cCamera.EntityID);
if(cameraEntity == m_ActiveCamera){
return;
}
if(cameraEntity.Name() == "Overview_Camera_Start_Menu") {
Events::SetCamera event;
event.CameraEntity = cameraEntity;
m_EventBroker->Publish(event);
}
}
}
bool StartSystem::OnCameraActivated(const Events::SetCamera& e)
{
m_ActiveCamera = e.CameraEntity;
return 1;
}
+10 -6
View File
@@ -7,17 +7,21 @@ void TextFieldReader::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
}
// Find the entity to read from
const std::string& parentEntityName = cAmmunitionHUD["ParentEntityName"];
const std::string& entityName = cAmmunitionHUD["ParentEntityName"];
const std::string& componentType = cAmmunitionHUD["ComponentType"];
EntityWrapper readEntity = entity;
if (!parentEntityName.empty()) {
readEntity = entity.FirstParentByName(parentEntityName);
if (!readEntity.Valid()) {
return;
if (entityName.empty()) {
if (!readEntity.HasComponent(componentType)) {
readEntity = readEntity.FirstParentWithComponent(componentType);
}
} else {
readEntity = entity.FirstParentByName(entityName);
}
if (!readEntity.Valid()) {
return;
}
// Find the component to read from
const std::string& componentType = cAmmunitionHUD["ComponentType"];
if (componentType.empty() || !readEntity.HasComponent(componentType)) {
return;
}
@@ -40,12 +40,16 @@ void AssaultWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo&
magAmmo = glm::min(magSize, ammo);
isReloading = false;
if (wi.FirstPersonEntity.Valid()) {
wi.FirstPersonEntity["Model"]["Visible"] = true;
wi.FirstPersonEntity.FirstChildByName("ViewModel")["Model"]["Visible"] = true;
}
if (wi.ThirdPersonEntity.Valid()) {
wi.ThirdPersonEntity["Model"]["Visible"] = true;
}
}
double reloadTime = cWeapon["ReloadTime"];
if (isReloading && reloadTimer <= reloadTime / 2) {
}
// Restore view angle
if (IsClient) {
@@ -68,7 +72,7 @@ void AssaultWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo&
const float& movementSpeed = cPlayer["MovementSpeed"];
float speed = glm::length((const glm::vec3&)cPhysics["Velocity"]);
float animationWeight = glm::min(speed, movementSpeed) / movementSpeed;
EntityWrapper rootNode = wi.FirstPersonEntity.FirstParentWithComponent("Model");
EntityWrapper rootNode = wi.FirstPersonEntity;
if (rootNode.Valid()) {
EntityWrapper blend = rootNode.FirstChildByName("MovementBlend");
if (blend.Valid()) {
@@ -121,19 +125,35 @@ void AssaultWeaponBehaviour::OnReload(ComponentWrapper cWeapon, WeaponInfo& wi)
reloadTimer = reloadTime;
// Play animation
playAnimationAndReturn(wi.FirstPersonEntity, "BlendTreeAssaultWeapon", "Reload");
if (IsClient) {
// Spawn explosion effect
EntityWrapper reloadEffectSpawner = wi.FirstPersonEntity.FirstChildByName("FirstPersonReloadSpawner");
if (reloadEffectSpawner.Valid()) {
SpawnerSystem::Spawn(reloadEffectSpawner, reloadEffectSpawner);
playAnimationAndReturn(wi.FirstPersonEntity, "ActionBlend", "Reload");
// Third person anim
Events::AutoAnimationBlend b1;
b1.RootNode = wi.ThirdPersonPlayerModel;
b1.NodeName = "Reload";
b1.Restart = true;
b1.Start = true;
m_EventBroker->Publish(b1);
// Spawn explosion effect
if (wi.FirstPersonEntity.Valid()) {
if (IsClient) {
EntityWrapper reloadEffectSpawner = wi.FirstPersonEntity.FirstChildByName("ReloadSpawner");
if (reloadEffectSpawner.Valid()) {
reloadEffectSpawner.DeleteChildren();
SpawnerSystem::Spawn(reloadEffectSpawner, reloadEffectSpawner);
}
}
if (wi.FirstPersonEntity.Valid()) {
wi.FirstPersonEntity["Model"]["Visible"] = false;
}
if (wi.ThirdPersonEntity.Valid()) {
wi.ThirdPersonEntity["Model"]["Visible"] = false;
wi.FirstPersonEntity.FirstChildByName("ViewModel")["Model"]["Visible"] = false;
}
if (wi.ThirdPersonEntity.Valid()) {
if (IsServer) {
EntityWrapper reloadEffectSpawner = wi.ThirdPersonEntity.FirstChildByName("ReloadSpawner");
if (reloadEffectSpawner.Valid()) {
reloadEffectSpawner.DeleteChildren();
SpawnerSystem::Spawn(reloadEffectSpawner, reloadEffectSpawner);
}
}
wi.ThirdPersonEntity["Model"]["Visible"] = false;
}
// Sound
@@ -190,7 +210,7 @@ void AssaultWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
}
// Get weapon model based on current person
EntityWrapper weaponModelEntity = getRelevantWeaponModelEntity(wi);
EntityWrapper weaponModelEntity = getRelevantWeaponEntity(wi);
if (!weaponModelEntity.Valid()) {
return;
}
@@ -221,7 +241,15 @@ void AssaultWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
}
// Play animation
playAnimationAndReturn(wi.FirstPersonEntity, "BlendTreeAssaultWeapon", "Fire");
playAnimationAndReturn(wi.FirstPersonEntity, "ActionBlend", "Fire");
// Third person anim
Events::AutoAnimationBlend b1;
b1.RootNode = wi.ThirdPersonPlayerModel;
b1.NodeName = "Fire";
b1.Restart = true;
b1.Start = true;
m_EventBroker->Publish(b1);
// Sound
Events::PlaySoundOnEntity e;
@@ -36,7 +36,7 @@ void DefenderWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo&
m_EventBroker->Publish(e);
} else {
isReloading = false;
playAnimationAndReturn(wi.FirstPersonEntity, "FinalBlend", "Idle");
playAnimationAndReturn(wi.FirstPersonEntity, "FinalBlend", "ReloadEnd");
}
}
@@ -99,7 +99,21 @@ void DefenderWeaponBehaviour::OnReload(ComponentWrapper cWeapon, WeaponInfo& wi)
reloadTimer = reloadTime;
// Play animation
playAnimationAndReturn(wi.FirstPersonEntity, "FinalBlend", "Reload");
if (wi.FirstPersonEntity.Valid()) {
Events::AutoAnimationBlend eBlendStart;
eBlendStart.RootNode = wi.FirstPersonEntity;
eBlendStart.NodeName = "ReloadStart";
eBlendStart.Restart = true;
eBlendStart.Start = true;
m_EventBroker->Publish(eBlendStart);
Events::AutoAnimationBlend eBlendLoop;
eBlendLoop.RootNode = wi.FirstPersonEntity;
eBlendLoop.NodeName = "ReloadLoop";
eBlendLoop.Restart = true;
eBlendLoop.Start = true;
eBlendLoop.AnimationEntity = wi.FirstPersonEntity.FirstChildByName("ReloadStart");
m_EventBroker->Publish(eBlendLoop);
}
}
void DefenderWeaponBehaviour::OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi)
@@ -114,17 +128,18 @@ void DefenderWeaponBehaviour::OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi
bool DefenderWeaponBehaviour::OnInputCommand(ComponentWrapper cWeapon, WeaponInfo& wi, const Events::InputCommand& e)
{
if (e.Command == "SpecialAbility" && IsServer) {
if (e.Command == "SpecialAbility") {
EntityWrapper attachment = wi.Player.FirstChildByName("ShieldAttachment");
if (attachment.Valid()) {
if (e.Value > 0) {
SpawnerSystem::Spawn(attachment, attachment);
if (IsServer) {
SpawnerSystem::Spawn(attachment, attachment);
}
EntityWrapper root = wi.FirstPersonEntity.FirstParentWithComponent("Model");
if (root.Valid()) {
EntityWrapper subTree = root.FirstChildByName("FinalBlend");
if (subTree.Valid()) {
EntityWrapper animationNode = subTree.FirstChildByName("Shield");
if (IsClient) {
EntityWrapper root = wi.FirstPersonEntity;
if (root.Valid()) {
EntityWrapper animationNode = root.FirstChildByName("Shield");
if (animationNode.Valid()) {
Events::AutoAnimationBlend eFireBlend;
eFireBlend.RootNode = root;
@@ -138,11 +153,10 @@ bool DefenderWeaponBehaviour::OnInputCommand(ComponentWrapper cWeapon, WeaponInf
} else {
attachment.DeleteChildren();
EntityWrapper root = wi.FirstPersonEntity.FirstParentWithComponent("Model");
if (root.Valid()) {
EntityWrapper subTree = root.FirstChildByName("FinalBlend");
if (subTree.Valid()) {
EntityWrapper animationNode = subTree.FirstChildByName("ActionBlend");
if (IsClient) {
EntityWrapper root = wi.FirstPersonEntity;
if (root.Valid()) {
EntityWrapper animationNode = root.FirstChildByName("ActionBlend");
if (animationNode.Valid()) {
Events::AutoAnimationBlend eFireBlend;
eFireBlend.RootNode = root;
@@ -232,7 +246,7 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
}
// Play animation
playAnimationAndReturn(wi.FirstPersonEntity, "BlendTreeDefenderWeapon", "Fire");
playAnimationAndReturn(wi.FirstPersonEntity, "FinalBlend", "Fire");
// Sound
Events::PlaySoundOnEntity e;
@@ -52,7 +52,7 @@ void SidearmWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
cWeapon["FireCooldown"] = 60.0 / (double)cWeapon["RPM"];
// Get weapon model based on current person
EntityWrapper weaponModelEntity = getRelevantWeaponModelEntity(wi);
EntityWrapper weaponModelEntity = getRelevantWeaponEntity(wi);
if (!weaponModelEntity.Valid()) {
return;
}