Bigger
This commit is contained in:
@@ -14,9 +14,13 @@
|
||||
#include "texturesmanager.h"
|
||||
#include "iqm.h"
|
||||
#include "debugrender.h"
|
||||
#include "scenemanager.h"
|
||||
#include "camera.h"
|
||||
|
||||
extern Shader* g_unlitShader;
|
||||
extern Shader* g_unlitSkinnedShader;
|
||||
extern Shader* g_litShader;
|
||||
extern Shader* g_litSkinnedShader;
|
||||
|
||||
static std::string getFileNameWithoutExtension(const std::string& filename)
|
||||
{
|
||||
@@ -285,7 +289,7 @@ void Model::LoadIqm(const char* filename)
|
||||
//mesh.m_indices = indices;
|
||||
mesh.vb = g_renderDevice->CreateVertexBuffer(vertices.data(), pMesh->num_vertexes * sizeof(SkinnedMeshVertex), true);
|
||||
mesh.vbcount = pMesh->num_vertexes;
|
||||
mesh.ib = g_renderDevice->CreateIndexBuffer(indices.data(), pMesh->num_triangles * sizeof(iqmtriangle), false);
|
||||
mesh.ib = g_renderDevice->CreateIndexBuffer(indices.data(), pMesh->num_triangles * 3 * sizeof(uint), false);
|
||||
mesh.ibcount = pMesh->num_triangles * 3;
|
||||
|
||||
|
||||
@@ -611,8 +615,28 @@ void Model::Draw(const glm::mat4& model, SkeletonInstance* instance /*= nullptr*
|
||||
{
|
||||
SDL_assert(g_unlitShader);
|
||||
|
||||
glm::vec3 pos = model[3];
|
||||
|
||||
Shader* shader = instance ? g_unlitSkinnedShader : g_unlitShader;
|
||||
|
||||
DLight* light = nullptr;
|
||||
|
||||
float lastDistSq = FLT_MAX;
|
||||
|
||||
for (int i = 0; i < DLightManager::GetInstance()->GetNumLights(); i++)
|
||||
{
|
||||
float distSq = glm::length2(pos - DLightManager::GetInstance()->GetDLight(i)->position );
|
||||
|
||||
if (distSq <= lastDistSq)
|
||||
{
|
||||
lastDistSq = distSq;
|
||||
light = DLightManager::GetInstance()->GetDLight(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (light)
|
||||
shader = instance ? g_litSkinnedShader : g_litShader;
|
||||
|
||||
for (int i = 0; i < m_meshes.size(); i++)
|
||||
{
|
||||
ModelData_t& m_data = m_meshes[i];
|
||||
@@ -624,23 +648,7 @@ void Model::Draw(const glm::mat4& model, SkeletonInstance* instance /*= nullptr*
|
||||
g_renderDevice->SetDepthTest(true);
|
||||
g_renderDevice->SetDepthWrite(true);
|
||||
|
||||
bool isTransparent = false;
|
||||
if (isTransparent)
|
||||
{
|
||||
// Enable blending
|
||||
g_renderDevice->SetBlending(true);
|
||||
g_renderDevice->SetBlendingFunction(BF_SRC_ALPHA, BF_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glm::vec4 color = glm::vec4(1.f, 1.f, 1.f, .5f);
|
||||
g_shaderSystem->SetUniformFloat4(shader, UNIFORM_CUSTOM_COLOR, glm::value_ptr(color));
|
||||
}
|
||||
else
|
||||
{
|
||||
g_renderDevice->SetBlending(false);
|
||||
|
||||
//glm::vec4 color = glm::vec4(1.f, 1.f, 1.f, 1.f);
|
||||
//g_shaderSystem->SetUniformFloat4(shader, UNIFORM_CUSTOM_COLOR, glm::value_ptr(color));
|
||||
}
|
||||
g_renderDevice->SetBlending(false);
|
||||
|
||||
g_renderDevice->SetVerticesBuffer(m_data.vb);
|
||||
if (m_data.ib)
|
||||
@@ -657,6 +665,37 @@ void Model::Draw(const glm::mat4& model, SkeletonInstance* instance /*= nullptr*
|
||||
g_shaderSystem->SetUniformMatrix(shader, UNIFORM_MVP_MATRIX, &mvp[0]);
|
||||
|
||||
|
||||
Camera* camera = g_cameraManager.GetActiveCamera();
|
||||
if (camera && shader->HasUniform(UNIFORM_CAMERA_POS))
|
||||
{
|
||||
glm::vec4 campos = glm::vec4(camera->GetPosition(), 1.0f);
|
||||
g_shaderSystem->SetUniformFloat4(shader, UNIFORM_CAMERA_POS, &campos);
|
||||
}
|
||||
|
||||
if (shader->HasUniform(UNIFORM_SUN_DIRECTION))
|
||||
{
|
||||
glm::vec4 lightPos = glm::vec4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
if (light)
|
||||
lightPos = glm::vec4(light->position, light->radius);
|
||||
|
||||
g_shaderSystem->SetUniformFloat4(shader, UNIFORM_SUN_DIRECTION, &lightPos);
|
||||
}
|
||||
|
||||
if (shader->HasUniform(UNIFORM_SUN_COLOR))
|
||||
{
|
||||
glm::vec4 lightColor = glm::vec4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
if (light)
|
||||
lightColor = glm::vec4(light->color, 1.0f);
|
||||
|
||||
g_shaderSystem->SetUniformFloat4(shader, UNIFORM_SUN_COLOR, &lightColor);
|
||||
}
|
||||
|
||||
if (shader->HasUniform(UNIFORM_SUN_AMBIENT))
|
||||
{
|
||||
glm::vec4 lightColor = glm::vec4(0.1f);
|
||||
g_shaderSystem->SetUniformFloat4(shader, UNIFORM_SUN_AMBIENT, &lightColor);
|
||||
}
|
||||
|
||||
if (!m_data.m_AlbedoTexture)
|
||||
m_data.m_AlbedoTexture = g_texturesManager->LoadTexture2D("MustBeEvilHackButDontCare");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user