Merge remote-tracking branch 'origin/master' into LevelSystemAndSuch
This commit is contained in:
+41
-20
@@ -53,6 +53,16 @@ file(GLOB SOURCE_FILES_Rendering
|
||||
"Rendering/*.cpp"
|
||||
)
|
||||
source_group(Rendering FILES ${SOURCE_FILES_Rendering})
|
||||
file(GLOB SOURCE_FILES_Rendering_OpenGL
|
||||
"${INCLUDE_PATH}/Rendering/OpenGL/Rendering/*.h"
|
||||
"Rendering/OpenGL/*.cpp"
|
||||
)
|
||||
source_group(Rendering\\OpenGL FILES ${SOURCE_FILES_Rendering_OpenGL})
|
||||
file(GLOB SOURCE_FILES_Rendering_DirectX
|
||||
"${INCLUDE_PATH}/Rendering/DirectX/Rendering/*.h"
|
||||
"Rendering/DirectX/*.cpp"
|
||||
)
|
||||
source_group(Rendering\\DirectX FILES ${SOURCE_FILES_Rendering_DirectX})
|
||||
|
||||
file(GLOB SOURCE_FILES_Transform
|
||||
"${INCLUDE_PATH}/Transform/*.h"
|
||||
@@ -61,8 +71,8 @@ file(GLOB SOURCE_FILES_Transform
|
||||
source_group(Transform FILES ${SOURCE_FILES_Transform})
|
||||
|
||||
file(GLOB SOURCE_FILES_Physics
|
||||
"${INCLUDE_PATH}/Physics/*.h"
|
||||
"Physics/*.cpp"
|
||||
"${INCLUDE_PATH}/Physics/*.h"
|
||||
"Physics/*.cpp"
|
||||
)
|
||||
source_group(Physics FILES ${SOURCE_FILES_Physics})
|
||||
|
||||
@@ -102,14 +112,7 @@ set(SOURCE_FILES
|
||||
${SOURCE_FILES_GUI}
|
||||
)
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
|
||||
set(STATIC_LIBRARY_FLAGS "${STATIC_LIBRARY_FLAGS}")
|
||||
endif()
|
||||
|
||||
add_library(game ${SOURCE_FILES})
|
||||
target_link_libraries(game
|
||||
set(LIBRARIES
|
||||
${OPENGL_LIBRARIES}
|
||||
${GLEW_LIBRARIES}
|
||||
${GLFW_LIBRARIES}
|
||||
@@ -118,7 +121,33 @@ target_link_libraries(game
|
||||
${PNG_LIBRARIES}
|
||||
${X11_LIBRARIES}
|
||||
${OPENAL_LIBRARY}
|
||||
${liquidfun_LIBRARIES}
|
||||
${liquidfun_LIBRARIES}
|
||||
)
|
||||
|
||||
if(BUILD_RENDERER_OPENGL)
|
||||
set(SOURCE_FILES ${SOURCE_FILES}
|
||||
${SOURCE_FILES_Rendering_OpenGL}
|
||||
)
|
||||
endif()
|
||||
# Compiling for DirectX target
|
||||
if(BUILD_RENDERER_DIRECTX)
|
||||
set(SOURCE_FILES ${SOURCE_FILES}
|
||||
${SOURCE_FILES_Rendering_DirectX}
|
||||
)
|
||||
set(LIBRARIES ${LIBRARIES}
|
||||
${CMAKE_LIBRARY_PATH}/DirectXTK.lib
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
|
||||
set(STATIC_LIBRARY_FLAGS "${STATIC_LIBRARY_FLAGS}")
|
||||
endif()
|
||||
|
||||
add_library(game ${SOURCE_FILES})
|
||||
target_link_libraries(game
|
||||
${LIBRARIES}
|
||||
)
|
||||
|
||||
add_executable(breakout
|
||||
@@ -126,14 +155,6 @@ add_executable(breakout
|
||||
)
|
||||
target_link_libraries(breakout
|
||||
game
|
||||
${OPENGL_LIBRARIES}
|
||||
${GLEW_LIBRARIES}
|
||||
${GLFW_LIBRARIES}
|
||||
${Boost_LIBRARIES}
|
||||
${assimp_LIBRARIES}
|
||||
${PNG_LIBRARIES}
|
||||
${X11_LIBRARIES}
|
||||
${OPENAL_LIBRARY}
|
||||
${liquidfun_LIBRARIES}
|
||||
${LIBRARIES}
|
||||
)
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/BGFXRenderer.h"
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/StaticSystem.h"
|
||||
|
||||
std::unordered_map<size_t, void*> dd::StaticSystem::Instances;
|
||||
@@ -62,7 +62,7 @@ void dd::Systems::LevelSystem::Initialize()
|
||||
travels->CurrentlyTraveling = false;
|
||||
auto model = m_World->AddComponent<Components::Model>(t_halfPipe);
|
||||
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
|
||||
model->Color = glm::vec4(0.8f, 0.8f, 0.8f, 0.3f);
|
||||
model->Color = glm::vec4(0.8f, 0.8f, 0.8f, 1.f);
|
||||
m_World->CommitEntity(t_halfPipe);
|
||||
|
||||
auto t_halfPipe2 = m_World->CloneEntity(t_halfPipe);
|
||||
@@ -107,7 +107,7 @@ void dd::Systems::LevelSystem::Initialize()
|
||||
particleEmitter->Spread = glm::pi<float>()*2;
|
||||
particleEmitter->EmittingAngle = glm::pi<float>();
|
||||
particleEmitter->LifeTime = 50;
|
||||
|
||||
|
||||
{
|
||||
auto Pt = m_World->CreateEntity(Pe);
|
||||
auto PtTransform = m_World->AddComponent<Components::Transform>(Pt);
|
||||
@@ -443,7 +443,7 @@ EntityID dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spac
|
||||
} else if (typeInt == KrakenAttackBrick) {
|
||||
cBrick->Type = KrakenAttackBrick;
|
||||
auto type = m_World->AddComponent<Components::KrakenAttackBrick>(brick);
|
||||
model->Color = glm::vec4(0.f, 0.5f, 1.0f, .0f);
|
||||
model->Color = glm::vec4(0.f, 0.5f, 1.0f, 1.0f);
|
||||
} else if (typeInt == Kraken) {
|
||||
Events::KrakenAppear e;
|
||||
e.Position = transform->Position;
|
||||
@@ -524,14 +524,14 @@ void dd::Systems::LevelSystem::GetBrickSet(int set) // These are sets the Kraken
|
||||
// m is magenta.
|
||||
// d is dark.
|
||||
// Feel free to make your own.
|
||||
glm::vec4 w = glm::vec4(1, 1, 1, 0);
|
||||
glm::vec4 r = glm::vec4(1, 0, 0, 0);
|
||||
glm::vec4 g = glm::vec4(0, 1, 0, 0);
|
||||
glm::vec4 b = glm::vec4(0, 0, 1, 0);
|
||||
glm::vec4 y = glm::vec4(1, 1, 0, 0);
|
||||
glm::vec4 c = glm::vec4(0, 1, 1, 0);
|
||||
glm::vec4 m = glm::vec4(1, 0, 1, 0);
|
||||
glm::vec4 d = glm::vec4(0, 0, 0, 0);
|
||||
glm::vec4 w = glm::vec4(1, 1, 1, 1);
|
||||
glm::vec4 r = glm::vec4(1, 0, 0, 1);
|
||||
glm::vec4 g = glm::vec4(0, 1, 0, 1);
|
||||
glm::vec4 b = glm::vec4(0, 0, 1, 1);
|
||||
glm::vec4 y = glm::vec4(1, 1, 0, 1);
|
||||
glm::vec4 c = glm::vec4(0, 1, 1, 1);
|
||||
glm::vec4 m = glm::vec4(1, 0, 1, 1);
|
||||
glm::vec4 d = glm::vec4(0, 0, 0, 1);
|
||||
|
||||
if (set == 1) {
|
||||
level =
|
||||
@@ -975,14 +975,14 @@ void dd::Systems::LevelSystem::GetNextLevel()
|
||||
// m is magenta.
|
||||
// d is dark.
|
||||
// Feel free to make your own.
|
||||
glm::vec4 w = glm::vec4(1, 1, 1, 0);
|
||||
glm::vec4 r = glm::vec4(1, 0, 0, 0);
|
||||
glm::vec4 g = glm::vec4(0, 1, 0, 0);
|
||||
glm::vec4 b = glm::vec4(0, 0, 1, 0);
|
||||
glm::vec4 y = glm::vec4(1, 1, 0, 0);
|
||||
glm::vec4 c = glm::vec4(0, 1, 1, 0);
|
||||
glm::vec4 m = glm::vec4(1, 0, 1, 0);
|
||||
glm::vec4 d = glm::vec4(0, 0, 0, 0);
|
||||
glm::vec4 w = glm::vec4(1, 1, 1, 1);
|
||||
glm::vec4 r = glm::vec4(1, 0, 0, 1);
|
||||
glm::vec4 g = glm::vec4(0, 1, 0, 1);
|
||||
glm::vec4 b = glm::vec4(0, 0, 1, 1);
|
||||
glm::vec4 y = glm::vec4(1, 1, 0, 1);
|
||||
glm::vec4 c = glm::vec4(0, 1, 1, 1);
|
||||
glm::vec4 m = glm::vec4(1, 0, 1, 1);
|
||||
glm::vec4 d = glm::vec4(0, 0, 0, 1);
|
||||
|
||||
//glm::vec4 p4 = glm::vec4(asd.f / 255.f, asd.f / 255.f, sad.f / 255.f, 1.f);
|
||||
glm::vec4 br = glm::vec4(143.f / 255.f, 98.f / 255.f, 0.f / 255.f, 1.f);
|
||||
|
||||
Executable → Regular
+3
-7
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/Camera.h"
|
||||
#include "Rendering/Camera.h"
|
||||
|
||||
dd::Camera::Camera(float aspectRatio, float yFOV, float nearClip, float farClip)
|
||||
{
|
||||
@@ -85,12 +85,8 @@ void dd::Camera::UpdateProjectionMatrix()
|
||||
// m_NearClip,
|
||||
// m_FarClip
|
||||
// );
|
||||
m_ProjectionMatrix = glm::perspective(
|
||||
m_FOV,
|
||||
m_AspectRatio,
|
||||
m_NearClip,
|
||||
m_FarClip
|
||||
);
|
||||
|
||||
m_ProjectionMatrix = glm::perspective(m_FOV, m_AspectRatio, m_NearClip, m_FarClip);
|
||||
}
|
||||
|
||||
void dd::Camera::UpdateViewMatrix()
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Rendering/Model.h"
|
||||
|
||||
dd::Model::Model(std::string fileName)
|
||||
: dd::RawModel(fileName)
|
||||
{
|
||||
D3D11_BUFFER_DESC vbd = { 0 };
|
||||
vbd.ByteWidth = sizeof(RawModel::Vertex) * m_Vertices.size();
|
||||
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
D3D11_SUBRESOURCE_DATA vsrd = { m_Vertices.data(), 0, 0 };
|
||||
StaticSystem::Get<Renderer>()->m_Device->CreateBuffer(&vbd, &vsrd, &VertexBuffer);
|
||||
|
||||
D3D11_BUFFER_DESC ibd = { 0 };
|
||||
ibd.ByteWidth = sizeof(unsigned int) * m_Indices.size();
|
||||
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
D3D11_SUBRESOURCE_DATA idata = { 0 };
|
||||
idata.pSysMem = m_Indices.data();
|
||||
StaticSystem::Get<Renderer>()->m_Device->CreateBuffer(&ibd, &idata, &IndexBuffer);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,429 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Rendering/Renderer.h"
|
||||
|
||||
#include "Rendering/Model.h"
|
||||
#include "Rendering/Skeleton.h"
|
||||
#include "Rendering/ShaderProgram.h"
|
||||
|
||||
void dd::Renderer::Initialize()
|
||||
{
|
||||
StaticSystem::Set(this);
|
||||
|
||||
// Initialize GLFW
|
||||
if (!glfwInit()) {
|
||||
LOG_ERROR("GLFW: Initialization failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Create a window
|
||||
GLFWmonitor* monitor = nullptr;
|
||||
if (m_Fullscreen) {
|
||||
monitor = glfwGetPrimaryMonitor();
|
||||
}
|
||||
glfwWindowHint(GLFW_SAMPLES, 8);
|
||||
m_Window = glfwCreateWindow(m_Resolution.Width, m_Resolution.Height, "Squidout! (DirectX 11)", monitor, nullptr);
|
||||
if (!m_Window) {
|
||||
LOG_ERROR("GLFW: Failed to create window");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
//glfwMakeContextCurrent(m_Window);
|
||||
|
||||
// Create default camera
|
||||
m_DefaultCamera = std::unique_ptr<dd::Camera>(new dd::Camera((float)m_Resolution.Width / m_Resolution.Height, 45.f, 0.01f, 5000.f));
|
||||
m_DefaultCamera->SetPosition(glm::vec3(0, 0, 0));
|
||||
if (m_Camera == nullptr) {
|
||||
m_Camera = m_DefaultCamera.get();
|
||||
}
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC scd = { 0 };
|
||||
scd.BufferCount = 1;
|
||||
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
scd.OutputWindow = glfwGetWin32Window(m_Window);
|
||||
scd.SampleDesc.Count = 4;
|
||||
scd.Windowed = TRUE;
|
||||
scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
|
||||
|
||||
D3D11CreateDeviceAndSwapChain(
|
||||
NULL,
|
||||
D3D_DRIVER_TYPE_HARDWARE,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
D3D11_SDK_VERSION,
|
||||
&scd,
|
||||
&m_SwapChain,
|
||||
&m_Device,
|
||||
NULL,
|
||||
&m_DeviceContext);
|
||||
|
||||
// Set the back buffer render target
|
||||
ID3D11Texture2D* pBackBuffer;
|
||||
m_SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pBackBuffer);
|
||||
m_Device->CreateRenderTargetView(pBackBuffer, NULL, &m_BackBuffer);
|
||||
pBackBuffer->Release();
|
||||
// Depth buffer
|
||||
D3D11_TEXTURE2D_DESC texd = { };
|
||||
texd.Width = m_Resolution.Width;
|
||||
texd.Height = m_Resolution.Height;
|
||||
texd.ArraySize = 1;
|
||||
texd.MipLevels = 1;
|
||||
texd.SampleDesc.Count = 4;
|
||||
texd.Format = DXGI_FORMAT_D32_FLOAT;
|
||||
texd.BindFlags = D3D11_BIND_DEPTH_STENCIL;
|
||||
ID3D11Texture2D* pDepthBuffer;
|
||||
m_Device->CreateTexture2D(&texd, NULL, &pDepthBuffer);
|
||||
D3D11_DEPTH_STENCIL_VIEW_DESC dsvd = { };
|
||||
dsvd.Format = DXGI_FORMAT_D32_FLOAT;
|
||||
dsvd.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
|
||||
m_Device->CreateDepthStencilView(pDepthBuffer, &dsvd, &m_DepthBuffer);
|
||||
pDepthBuffer->Release();
|
||||
// Set back and depth buffer
|
||||
m_DeviceContext->OMSetRenderTargets(1, &m_BackBuffer, m_DepthBuffer);
|
||||
|
||||
// Rasterizer settings
|
||||
setDefaultRasterState();
|
||||
|
||||
D3D11_BLEND_DESC blend = { 0 };
|
||||
for (int i = 0; i < 1; i++) {
|
||||
blend.RenderTarget[i].BlendEnable = true;
|
||||
blend.RenderTarget[i].BlendOp = D3D11_BLEND_OP_ADD;
|
||||
blend.RenderTarget[i].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
||||
blend.RenderTarget[i].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
blend.RenderTarget[i].BlendOpAlpha = D3D11_BLEND_OP_ADD;
|
||||
blend.RenderTarget[i].SrcBlendAlpha = D3D11_BLEND_ONE;
|
||||
blend.RenderTarget[i].DestBlendAlpha = D3D11_BLEND_ZERO;
|
||||
blend.RenderTarget[i].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
|
||||
}
|
||||
ID3D11BlendState* blendState;
|
||||
m_Device->CreateBlendState(&blend, &blendState);
|
||||
m_DeviceContext->OMSetBlendState(blendState, nullptr, 0xffffffff);
|
||||
|
||||
|
||||
D3D11_INPUT_ELEMENT_DESC VertexIED[] = {
|
||||
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"TANGENT", 1, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"COLOR", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"BLENDINDICES", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"BLENDINDICES", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"BLENDWEIGHT", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"BLENDWEIGHT", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
|
||||
};
|
||||
m_ForwardShaderProgram = new ShaderProgram();
|
||||
m_ForwardShaderProgram->CompileVertexShader(L"Shaders/DirectX/vertex.hlsl");
|
||||
m_ForwardShaderProgram->CompilePixelShader(L"Shaders/DirectX/pixel.hlsl");
|
||||
m_ForwardShaderProgram->CreateInputLayout(VertexIED, sizeof(VertexIED) / sizeof(VertexIED[0]));
|
||||
m_GUIShaderProgram = new ShaderProgram();
|
||||
m_GUIShaderProgram->CompileVertexShader(L"Shaders/DirectX/vertex.hlsl");
|
||||
m_GUIShaderProgram->CompilePixelShader(L"Shaders/DirectX/Flat.pixel.hlsl");
|
||||
m_GUIShaderProgram->CreateInputLayout(VertexIED, sizeof(VertexIED) / sizeof(VertexIED[0]));
|
||||
|
||||
// Create constant buffer
|
||||
// TODO: Put this in shader
|
||||
D3D11_BUFFER_DESC bd = { };
|
||||
bd.ByteWidth = sizeof(ConstantBufferStruct);
|
||||
bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
||||
m_Device->CreateBuffer(&bd, NULL, &constantBuffer);
|
||||
m_DeviceContext->VSSetConstantBuffers(0, 1, &constantBuffer);
|
||||
m_DeviceContext->PSSetConstantBuffers(0, 1, &constantBuffer);
|
||||
|
||||
D3D11_SAMPLER_DESC samplerDesc;
|
||||
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.MipLODBias = 0.0f;
|
||||
samplerDesc.MaxAnisotropy = 1;
|
||||
samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
|
||||
samplerDesc.BorderColor[0] = 1.f;
|
||||
samplerDesc.BorderColor[1] = 0;
|
||||
samplerDesc.BorderColor[2] = 1.f;
|
||||
samplerDesc.BorderColor[3] = 0;
|
||||
samplerDesc.MinLOD = 0;
|
||||
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
|
||||
m_Device->CreateSamplerState(&samplerDesc, &m_SamplerState);
|
||||
|
||||
m_UnitQuad = ResourceManager::Load<Model>("Models/Core/UnitQuad.obj");
|
||||
m_WhiteSphereTexture = ResourceManager::Load<Texture>("Textures/Test/Water.png");
|
||||
}
|
||||
|
||||
void dd::Renderer::Draw(RenderQueueCollection& rq)
|
||||
{
|
||||
using namespace DirectX::SimpleMath;
|
||||
|
||||
rq.Forward.Jobs.sort(dd::Renderer::DepthSort);
|
||||
|
||||
m_DeviceContext->OMSetRenderTargets(1, &m_BackBuffer, m_DepthBuffer);
|
||||
float color[] = { 0.f, 0.f, 0.f, 1.f };
|
||||
m_DeviceContext->ClearRenderTargetView(m_BackBuffer, color);
|
||||
m_DeviceContext->ClearDepthStencilView(m_DepthBuffer, D3D11_CLEAR_DEPTH, 1.0f, 0);
|
||||
|
||||
// Set the viewport
|
||||
D3D11_VIEWPORT viewport = { 0 };
|
||||
viewport.TopLeftX = 0;
|
||||
viewport.TopLeftY = 0;
|
||||
viewport.Width = m_Resolution.Width;
|
||||
viewport.Height = m_Resolution.Height;
|
||||
viewport.MinDepth = 0;
|
||||
viewport.MaxDepth = 1;
|
||||
m_DeviceContext->RSSetViewports(1, &viewport);
|
||||
|
||||
m_ForwardShaderProgram->Bind();
|
||||
|
||||
Matrix proj = DirectX::SimpleMath::Matrix::CreatePerspectiveFieldOfView(m_Camera->m_FOV, m_Camera->m_AspectRatio, m_Camera->m_NearClip, m_Camera->m_FarClip); // Right-handed
|
||||
Matrix view = Matrix::CreateTranslation(Vector3(m_Camera->Position().x, m_Camera->Position().y, -m_Camera->Position().z));
|
||||
|
||||
int i = 0;
|
||||
constantBufferStruct.NumLights = 0;
|
||||
for (auto &job : rq.Lights) {
|
||||
auto pointLightJob = std::dynamic_pointer_cast<PointLightJob>(job);
|
||||
if (pointLightJob) {
|
||||
glm::vec3 p = pointLightJob->Position;
|
||||
constantBufferStruct.LightPositions[i] = Vector4(p.r, p.g, p.b, 0.f);
|
||||
glm::vec3 c = pointLightJob->DiffuseColor;
|
||||
constantBufferStruct.LightColors[i] = Vector4(c.r, c.g, c.b, 1.f);
|
||||
constantBufferStruct.LightRadii[i] = pointLightJob->Radius;
|
||||
constantBufferStruct.NumLights++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &job : rq.Deferred) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
if (modelJob) {
|
||||
constantBufferStruct.MVP = Matrix(glm::value_ptr(modelJob->ModelMatrix)) * view * proj;
|
||||
constantBufferStruct.InverseTransposeViewModel = (Matrix(glm::value_ptr(modelJob->ModelMatrix)) * view).Transpose().Invert();
|
||||
constantBufferStruct.Color = Vector4(modelJob->Color.r, modelJob->Color.g, modelJob->Color.b, modelJob->Color.a);
|
||||
|
||||
m_DeviceContext->UpdateSubresource(constantBuffer, 0, 0, &constantBufferStruct, 0, 0);
|
||||
m_DeviceContext->PSSetSamplers(0, 1, &m_SamplerState);
|
||||
|
||||
m_DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
UINT stride = sizeof(Model::Vertex);
|
||||
UINT offset = 0;
|
||||
m_DeviceContext->IASetVertexBuffers(0, 1, &modelJob->Model->VertexBuffer, &stride, &offset);
|
||||
m_DeviceContext->IASetIndexBuffer(modelJob->Model->IndexBuffer, DXGI_FORMAT_R32_UINT, 0);
|
||||
|
||||
if (modelJob->DiffuseTexture != nullptr) {
|
||||
m_DeviceContext->PSSetShaderResources(0, 1, &modelJob->DiffuseTexture->m_ShaderResourceView);
|
||||
}
|
||||
//m_DeviceContext->Draw(modelJob->EndIndex - modelJob->StartIndex + 1, modelJob->StartIndex);
|
||||
m_DeviceContext->DrawIndexed(modelJob->EndIndex - modelJob->StartIndex + 1, modelJob->StartIndex, 0);
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &job : rq.Forward) {
|
||||
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
|
||||
if (spriteJob) {
|
||||
constantBufferStruct.MVP = Matrix(glm::value_ptr(spriteJob->ModelMatrix)) * view * proj;
|
||||
constantBufferStruct.InverseTransposeViewModel = (Matrix(glm::value_ptr(spriteJob->ModelMatrix)) * view).Transpose().Invert();
|
||||
constantBufferStruct.Color = Vector4(glm::value_ptr(spriteJob->Color));
|
||||
|
||||
m_DeviceContext->UpdateSubresource(constantBuffer, 0, 0, &constantBufferStruct, 0, 0);
|
||||
m_DeviceContext->PSSetSamplers(0, 1, &m_SamplerState);
|
||||
|
||||
m_DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
UINT stride = sizeof(Model::Vertex);
|
||||
UINT offset = 0;
|
||||
m_DeviceContext->IASetVertexBuffers(0, 1, &m_UnitQuad->VertexBuffer, &stride, &offset);
|
||||
m_DeviceContext->IASetIndexBuffer(m_UnitQuad->IndexBuffer, DXGI_FORMAT_R32_UINT, 0);
|
||||
|
||||
if (spriteJob->DiffuseTexture != nullptr) {
|
||||
m_DeviceContext->PSSetShaderResources(0, 1, &spriteJob->DiffuseTexture->m_ShaderResourceView);
|
||||
}
|
||||
//m_DeviceContext->Draw(modelJob->EndIndex - modelJob->StartIndex + 1, modelJob->StartIndex);
|
||||
m_DeviceContext->DrawIndexed(m_UnitQuad->m_Indices.size(), 0, 0);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
auto waterJob = std::dynamic_pointer_cast<WaterParticleJob>(job);
|
||||
if (waterJob) {
|
||||
constantBufferStruct.MVP = Matrix(glm::value_ptr(waterJob->ModelMatrix)) * view * proj;
|
||||
constantBufferStruct.InverseTransposeViewModel = (Matrix(glm::value_ptr(waterJob->ModelMatrix)) * view).Transpose().Invert();
|
||||
constantBufferStruct.Color = Vector4(glm::value_ptr(waterJob->Color));
|
||||
|
||||
m_DeviceContext->UpdateSubresource(constantBuffer, 0, 0, &constantBufferStruct, 0, 0);
|
||||
m_DeviceContext->PSSetSamplers(0, 1, &m_SamplerState);
|
||||
|
||||
m_DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
UINT stride = sizeof(Model::Vertex);
|
||||
UINT offset = 0;
|
||||
m_DeviceContext->IASetVertexBuffers(0, 1, &m_UnitQuad->VertexBuffer, &stride, &offset);
|
||||
m_DeviceContext->IASetIndexBuffer(m_UnitQuad->IndexBuffer, DXGI_FORMAT_R32_UINT, 0);
|
||||
|
||||
m_DeviceContext->PSSetShaderResources(0, 1, &m_WhiteSphereTexture->m_ShaderResourceView);
|
||||
//m_DeviceContext->Draw(modelJob->EndIndex - modelJob->StartIndex + 1, modelJob->StartIndex);
|
||||
m_DeviceContext->DrawIndexed(m_UnitQuad->m_Indices.size(), 0, 0);
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
m_DeviceContext->OMSetRenderTargets(1, &m_BackBuffer, nullptr);
|
||||
m_GUIShaderProgram->Bind();
|
||||
|
||||
for (auto &job : rq.GUI) {
|
||||
auto frameJob = std::dynamic_pointer_cast<FrameJob>(job);
|
||||
if (frameJob) {
|
||||
Rectangle& vp = frameJob->Viewport;
|
||||
glViewport(vp.X, m_Resolution.Height - vp.Y - vp.Height, vp.Width, vp.Height);
|
||||
Rectangle& sc = frameJob->Scissor;
|
||||
if (sc == Rectangle()) {
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
} else {
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(sc.X, m_Resolution.Height - sc.Y - sc.Height, sc.Width, sc.Height);
|
||||
}
|
||||
|
||||
D3D11_VIEWPORT viewport = { 0 };
|
||||
viewport.TopLeftX = vp.X;
|
||||
viewport.TopLeftY = vp.Y;
|
||||
viewport.Width = vp.Width;
|
||||
viewport.Height = vp.Height;
|
||||
viewport.MinDepth = 0;
|
||||
viewport.MaxDepth = 1;
|
||||
m_DeviceContext->RSSetViewports(1, &viewport);
|
||||
|
||||
proj = Matrix::Identity;
|
||||
view = Matrix::Identity;
|
||||
Matrix model = Matrix::CreateScale(2.f);
|
||||
constantBufferStruct.MVP = model * view * proj;
|
||||
constantBufferStruct.InverseTransposeViewModel = (model * view).Transpose().Invert();
|
||||
constantBufferStruct.Color = Vector4(glm::value_ptr(frameJob->Color));
|
||||
|
||||
m_DeviceContext->UpdateSubresource(constantBuffer, 0, 0, &constantBufferStruct, 0, 0);
|
||||
m_DeviceContext->PSSetSamplers(0, 1, &m_SamplerState);
|
||||
|
||||
m_DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
UINT stride = sizeof(Model::Vertex);
|
||||
UINT offset = 0;
|
||||
m_DeviceContext->IASetVertexBuffers(0, 1, &m_UnitQuad->VertexBuffer, &stride, &offset);
|
||||
m_DeviceContext->IASetIndexBuffer(m_UnitQuad->IndexBuffer, DXGI_FORMAT_R32_UINT, 0);
|
||||
|
||||
if (frameJob->DiffuseTexture != nullptr) {
|
||||
m_DeviceContext->PSSetShaderResources(0, 1, &frameJob->DiffuseTexture->m_ShaderResourceView);
|
||||
}
|
||||
//m_DeviceContext->Draw(modelJob->EndIndex - modelJob->StartIndex + 1, modelJob->StartIndex);
|
||||
m_DeviceContext->DrawIndexed(m_UnitQuad->m_Indices.size(), 0, 0);
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//constantBufferStruct.ModelMatrix = GLMtoDX(glm::mat4(1.f));
|
||||
//constantBufferStruct.ViewMatrix = GLMtoDX(m_Camera->ViewMatrix());
|
||||
//constantBufferStruct.ProjectionMatrix = proj;
|
||||
//constantBufferStruct.InverseTransposeViewModel = GLMtoDX(glm::mat4(1.f));
|
||||
|
||||
m_SwapChain->Present(0, 0);
|
||||
//glfwSwapBuffers(m_Window);
|
||||
}
|
||||
|
||||
//void dd::Renderer::Resize(int width, int height)
|
||||
//{
|
||||
// m_DeviceContext->OMSetRenderTargets(0, 0, 0);
|
||||
// m_BackBuffer->Release();
|
||||
//
|
||||
// HRESULT hr; // TODO: Error handling
|
||||
// // Preserve the existing buffer count and format.
|
||||
// hr = m_SwapChain->ResizeBuffers(0, width, height, DXGI_FORMAT_UNKNOWN, 0);
|
||||
//
|
||||
// ID3D11Texture2D* pBuffer;
|
||||
// hr = m_SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pBuffer);
|
||||
// hr = m_Device->CreateRenderTargetView(pBuffer, NULL, &m_BackBuffer);
|
||||
// pBuffer->Release();
|
||||
// m_DeviceContext->OMSetRenderTargets(1, &BackBuffer, NULL);
|
||||
//
|
||||
// // Set the viewport
|
||||
// D3D11_VIEWPORT viewport = { 0 };
|
||||
// viewport.TopLeftX = 0;
|
||||
// viewport.TopLeftY = 0;
|
||||
// viewport.Width = width;
|
||||
// viewport.Height = height;
|
||||
// m_DeviceContext->RSSetViewports(1, &viewport);
|
||||
//}
|
||||
|
||||
dd::Renderer::~Renderer()
|
||||
{
|
||||
m_SwapChain->Release();
|
||||
m_BackBuffer->Release();
|
||||
m_Device->Release();
|
||||
m_DeviceContext->Release();
|
||||
}
|
||||
|
||||
DirectX::SimpleMath::Matrix dd::Renderer::GLMtoDXModelView(glm::mat4 gm)
|
||||
{
|
||||
gm = glm::transpose(gm);
|
||||
DirectX::SimpleMath::Matrix dm(
|
||||
gm[0][0], gm[0][1], -gm[0][2], gm[0][3],
|
||||
gm[1][0], gm[1][1], -gm[1][2], gm[1][3],
|
||||
-gm[2][0], -gm[2][1], gm[2][2], gm[2][3],
|
||||
gm[3][0], gm[3][1], -gm[3][2], gm[3][3]
|
||||
);
|
||||
return dm;
|
||||
}
|
||||
|
||||
DirectX::SimpleMath::Matrix dd::Renderer::GLMtoDXProjection(glm::mat4 gm)
|
||||
{
|
||||
gm = glm::transpose(gm);
|
||||
DirectX::SimpleMath::Matrix dm(
|
||||
gm[0][0], gm[0][1], gm[0][2], gm[0][3],
|
||||
gm[1][0], gm[1][1], gm[1][2], gm[1][3],
|
||||
-gm[2][0], -gm[2][1], -gm[2][2], -gm[2][3],
|
||||
gm[3][0], gm[3][1], gm[3][2], gm[3][3]
|
||||
);
|
||||
return dm;
|
||||
}
|
||||
|
||||
void dd::Renderer::setDefaultRasterState()
|
||||
{
|
||||
if (m_RasterState != nullptr) {
|
||||
m_RasterState->Release();
|
||||
m_RasterState = nullptr;
|
||||
}
|
||||
|
||||
D3D11_RASTERIZER_DESC rd;
|
||||
memset(&rd, 0, sizeof(D3D11_RASTERIZER_DESC));
|
||||
rd.AntialiasedLineEnable = false;
|
||||
rd.CullMode = D3D11_CULL_BACK;
|
||||
rd.DepthBias = 0;
|
||||
rd.DepthBiasClamp = 0.0f;
|
||||
rd.DepthClipEnable = true;
|
||||
rd.FillMode = D3D11_FILL_SOLID;
|
||||
rd.FrontCounterClockwise = true;
|
||||
rd.MultisampleEnable = false;
|
||||
rd.ScissorEnable = false;
|
||||
rd.SlopeScaledDepthBias = 0.0f;
|
||||
m_Device->CreateRasterizerState(&rd, &m_RasterState);
|
||||
m_DeviceContext->RSSetState(m_RasterState);
|
||||
}
|
||||
|
||||
void dd::Renderer::setGUIRasterState()
|
||||
{
|
||||
if (m_RasterState != nullptr) {
|
||||
m_RasterState->Release();
|
||||
m_RasterState = nullptr;
|
||||
}
|
||||
|
||||
D3D11_RASTERIZER_DESC rd;
|
||||
memset(&rd, 0, sizeof(D3D11_RASTERIZER_DESC));
|
||||
rd.AntialiasedLineEnable = false;
|
||||
rd.CullMode = D3D11_CULL_BACK;
|
||||
rd.DepthBias = 0;
|
||||
rd.DepthBiasClamp = 0.0f;
|
||||
rd.DepthClipEnable = false;
|
||||
rd.FillMode = D3D11_FILL_SOLID;
|
||||
rd.FrontCounterClockwise = true;
|
||||
rd.MultisampleEnable = false;
|
||||
rd.ScissorEnable = false;
|
||||
rd.SlopeScaledDepthBias = 0.0f;
|
||||
m_Device->CreateRasterizerState(&rd, &m_RasterState);
|
||||
m_DeviceContext->RSSetState(m_RasterState);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Rendering/ShaderProgram.h"
|
||||
|
||||
dd::ShaderProgram::ShaderProgram()
|
||||
{
|
||||
m_VertexShaderBlob = nullptr;
|
||||
m_VertexShader = nullptr;
|
||||
m_PixelShaderBlob = nullptr;
|
||||
m_PixelShader = nullptr;
|
||||
m_InputLayout = nullptr;
|
||||
}
|
||||
|
||||
dd::ShaderProgram::~ShaderProgram()
|
||||
{
|
||||
if (m_VertexShader != nullptr)
|
||||
m_VertexShader->Release();
|
||||
if (m_VertexShaderBlob != nullptr)
|
||||
m_VertexShaderBlob->Release();
|
||||
if (m_PixelShader != nullptr)
|
||||
m_PixelShader->Release();
|
||||
if (m_PixelShaderBlob != nullptr)
|
||||
m_PixelShaderBlob->Release();
|
||||
if (m_InputLayout != nullptr)
|
||||
m_InputLayout->Release();
|
||||
}
|
||||
|
||||
void dd::ShaderProgram::CompileVertexShader(std::wstring filename)
|
||||
{
|
||||
//D3DX11CompileFromFile(filename.c_str(), 0, 0, "main", "vs_5_0", 0, 0, 0, &m_VertexShaderBlob, 0, 0);
|
||||
ID3DBlob* blob = nullptr;
|
||||
HRESULT result = D3DCompileFromFile(filename.c_str(), nullptr, nullptr, "main", "vs_5_0", 0, 0, &m_VertexShaderBlob, &blob);
|
||||
if (result != S_OK) {
|
||||
std::wstring blobString((wchar_t*)blob->GetBufferPointer(), blob->GetBufferSize());
|
||||
LOG_ERROR("Failed to compile vertex shader!\n\n%s", blobString.c_str());
|
||||
return;
|
||||
}
|
||||
StaticSystem::Get<Renderer>()->m_Device->CreateVertexShader(m_VertexShaderBlob->GetBufferPointer(), m_VertexShaderBlob->GetBufferSize(), NULL, &m_VertexShader);
|
||||
}
|
||||
|
||||
void dd::ShaderProgram::CompilePixelShader(std::wstring filename)
|
||||
{
|
||||
//D3DX11CompileFromFile(filename.c_str(), 0, 0, "main", "ps_5_0", 0, 0, 0, &m_PixelShaderBlob, 0, 0);
|
||||
ID3DBlob* blob = nullptr;
|
||||
HRESULT result = D3DCompileFromFile(filename.c_str(), nullptr, nullptr, "main", "ps_5_0", 0, 0, &m_PixelShaderBlob, &blob);
|
||||
if (result != S_OK) {
|
||||
std::wstring blobString((wchar_t*)blob->GetBufferPointer(), blob->GetBufferSize());
|
||||
LOG_ERROR("Failed to compile pixel shader!\n\n%s", blobString.c_str());
|
||||
return;
|
||||
}
|
||||
StaticSystem::Get<Renderer>()->m_Device->CreatePixelShader(m_PixelShaderBlob->GetBufferPointer(), m_PixelShaderBlob->GetBufferSize(), NULL, &m_PixelShader);
|
||||
}
|
||||
|
||||
void dd::ShaderProgram::Bind()
|
||||
{
|
||||
if (m_VertexShader != nullptr)
|
||||
StaticSystem::Get<Renderer>()->m_DeviceContext->VSSetShader(m_VertexShader, 0, 0);
|
||||
if (m_PixelShader != nullptr)
|
||||
StaticSystem::Get<Renderer>()->m_DeviceContext->PSSetShader(m_PixelShader, 0, 0);
|
||||
if (m_InputLayout != nullptr)
|
||||
StaticSystem::Get<Renderer>()->m_DeviceContext->IASetInputLayout(m_InputLayout);
|
||||
}
|
||||
|
||||
void dd::ShaderProgram::Unbind()
|
||||
{
|
||||
if (m_VertexShader != nullptr) {
|
||||
StaticSystem::Get<Renderer>()->m_DeviceContext->VSSetShader(NULL, 0, 0);
|
||||
}
|
||||
if (m_PixelShader != nullptr) {
|
||||
StaticSystem::Get<Renderer>()->m_DeviceContext->PSSetShader(NULL, 0, 0);
|
||||
}
|
||||
//if (m_InputLayout != nullptr)
|
||||
// dd::RENDERER->DeviceContext->IASetInputLayout(NULL);
|
||||
}
|
||||
|
||||
HRESULT dd::ShaderProgram::CreateInputLayout(D3D11_INPUT_ELEMENT_DESC* ied, UINT numElements)
|
||||
{
|
||||
return StaticSystem::Get<Renderer>()->m_Device->CreateInputLayout(ied, numElements, m_VertexShaderBlob->GetBufferPointer(), m_VertexShaderBlob->GetBufferSize(), &m_InputLayout);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
cbuffer ConstantBuffer
|
||||
{
|
||||
float4x4 MVP;
|
||||
float4x4 ModelMatrix;
|
||||
float4x4 ViewMatrix;
|
||||
float4x4 ProjectionMatrix;
|
||||
float4x4 InverseTransposeViewModel;
|
||||
float4 Color;
|
||||
float4 LightPositions[10];
|
||||
float4 LightColors[10];
|
||||
float LightRadii[10];
|
||||
uint NumLights;
|
||||
}
|
||||
|
||||
Texture2D Texture;
|
||||
SamplerState samplerState;
|
||||
|
||||
struct VOut
|
||||
{
|
||||
float4 PixelPosition : SV_POSITION;
|
||||
float4 Position : POSITION;
|
||||
float4 Normal : NORMAL;
|
||||
float4 Tangent : TANGENT0;
|
||||
float4 BiTangent : TANGENT1;
|
||||
float2 TextureCoord : TEXCOORD;
|
||||
float4 DiffuseColor : COLOR0;
|
||||
float4 SpecularColor : COLOR1;
|
||||
float4 BoneIndices1 : BLENDINDICES0;
|
||||
float4 BoneIndices2 : BLENDINDICES1;
|
||||
float4 BoneWeights1 : BLENDWEIGHT0;
|
||||
float4 BoneWeights2 : BLENDWEIGHT1;
|
||||
};
|
||||
|
||||
float4 main(VOut input) : SV_TARGET
|
||||
{
|
||||
float4 diffuseTexture = Texture.Sample(samplerState, input.TextureCoord) * Color;
|
||||
return diffuseTexture;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
cbuffer ConstantBuffer
|
||||
{
|
||||
float4x4 MVP;
|
||||
float4x4 ModelMatrix;
|
||||
float4x4 ViewMatrix;
|
||||
float4x4 ProjectionMatrix;
|
||||
float4x4 InverseTransposeViewModel;
|
||||
float4 Color;
|
||||
float4 LightPositions[10];
|
||||
float4 LightColors[10];
|
||||
float LightRadii[10];
|
||||
uint NumLights;
|
||||
}
|
||||
|
||||
Texture2D Texture;
|
||||
SamplerState samplerState;
|
||||
|
||||
struct VOut
|
||||
{
|
||||
float4 PixelPosition : SV_POSITION;
|
||||
float4 Position : POSITION;
|
||||
float4 Normal : NORMAL;
|
||||
float4 Tangent : TANGENT0;
|
||||
float4 BiTangent : TANGENT1;
|
||||
float2 TextureCoord : TEXCOORD;
|
||||
float4 DiffuseColor : COLOR0;
|
||||
float4 SpecularColor : COLOR1;
|
||||
float4 BoneIndices1 : BLENDINDICES0;
|
||||
float4 BoneIndices2 : BLENDINDICES1;
|
||||
float4 BoneWeights1 : BLENDWEIGHT0;
|
||||
float4 BoneWeights2 : BLENDWEIGHT1;
|
||||
};
|
||||
|
||||
float4 phong(float3 lightPos, float lightRadius, float3 lightColor, float3 position, float3 normal, float3 specular, float specularExponent)
|
||||
{
|
||||
float3 LightSpecular = float3(1.0f, 1.0f, 1.0f) * 0.5f;
|
||||
|
||||
// Diffuse
|
||||
lightPos = mul(ViewMatrix, float4(lightPos, 1.0f)).xyz;
|
||||
float3 distanceToLight = lightPos - position;
|
||||
float3 directionToLight = normalize(distanceToLight);
|
||||
float dotProd = dot(directionToLight, normal);
|
||||
float3 Idiffuse = lightColor * dotProd;
|
||||
|
||||
// Specular
|
||||
float3 surfaceToViewer = normalize(-position);
|
||||
float3 halfWay = normalize(surfaceToViewer + directionToLight);
|
||||
float dotSpecular = max(dot(halfWay, normal), 0.0f);
|
||||
float specularFactor = pow(dotSpecular, specularExponent);
|
||||
float3 Ispecular = specular * LightSpecular * specularFactor;
|
||||
|
||||
// Attenuation
|
||||
float dist = distance(lightPos, position);
|
||||
float attenuation = pow(max(0.0f, 1.0f - (dist / lightRadius)), 2.0f);
|
||||
|
||||
return float4((Idiffuse + Ispecular) * attenuation, 1.0f);
|
||||
}
|
||||
|
||||
float4 main(VOut input) : SV_TARGET
|
||||
{
|
||||
//float4 ambientLight = float4(1.0f, 1.0f, 1.0f, 1.0f) * 0.1f;
|
||||
//float4 lightColor = float4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
//float3 lightToPixel = normalize(LightPosition - mul(input.Position, transpose(ModelMatrix)));
|
||||
//float diffuseBrightness = saturate(dot(lightToPixel, normalize(mul(input.Normal, transpose(ModelMatrix)))));
|
||||
|
||||
float4 diffuseTexture = Texture.Sample(samplerState, input.TextureCoord) * Color;
|
||||
float4 lights = float4(1.f, 1.f, 1.f, 1.f);
|
||||
|
||||
for (uint i = 0; i < NumLights; i++) {
|
||||
float4 light = phong(LightPositions[i], LightRadii[i], LightColors[i].rgb, input.Position, normalize(input.Normal.xyz), float3(1.0f, 1.0f, 1.0f), 1.0f);
|
||||
lights = lights + light;
|
||||
}
|
||||
|
||||
//return float4(1.f, 0.f, 0.f, 1.f);
|
||||
return float4(diffuseTexture.rgb * 0.8f, diffuseTexture.a) * lights;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
cbuffer ConstantBuffer
|
||||
{
|
||||
float4x4 MVP;
|
||||
float4x4 ModelMatrix;
|
||||
float4x4 ViewMatrix;
|
||||
float4x4 ProjectionMatrix;
|
||||
float4x4 InverseTransposeViewModel;
|
||||
float4 Color;
|
||||
float4 LightPositions[2];
|
||||
}
|
||||
|
||||
struct VIn
|
||||
{
|
||||
float4 Position : POSITION;
|
||||
float4 Normal : NORMAL;
|
||||
float4 Tangent : TANGENT0;
|
||||
float4 BiTangent : TANGENT1;
|
||||
float2 TextureCoord : TEXCOORD;
|
||||
float4 DiffuseColor : COLOR0;
|
||||
float4 SpecularColor : COLOR1;
|
||||
float4 BoneIndices1 : BLENDINDICES0;
|
||||
float4 BoneIndices2 : BLENDINDICES1;
|
||||
float4 BoneWeights1 : BLENDWEIGHT0;
|
||||
float4 BoneWeights2 : BLENDWEIGHT1;
|
||||
};
|
||||
|
||||
struct VOut
|
||||
{
|
||||
float4 PixelPosition : SV_POSITION;
|
||||
float4 Position : POSITION;
|
||||
float4 Normal : NORMAL;
|
||||
float4 Tangent : TANGENT0;
|
||||
float4 BiTangent : TANGENT1;
|
||||
float2 TextureCoord : TEXCOORD;
|
||||
float4 DiffuseColor : COLOR0;
|
||||
float4 SpecularColor : COLOR1;
|
||||
float4 BoneIndices1 : BLENDINDICES0;
|
||||
float4 BoneIndices2 : BLENDINDICES1;
|
||||
float4 BoneWeights1 : BLENDWEIGHT0;
|
||||
float4 BoneWeights2 : BLENDWEIGHT1;
|
||||
};
|
||||
|
||||
VOut main(VIn input)
|
||||
{
|
||||
/*float4 ambientLight = float4(1.0f, 1.0f, 1.0f, 1.0f) * 0.1f;
|
||||
float4 lightPos = float4(0.0f, 0.0f, 8.0f, 0.0f);
|
||||
float4 lightColor = float4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
float diffuseBrightness = saturate(dot(normal, lightPos));*/
|
||||
|
||||
VOut output;
|
||||
|
||||
output.PixelPosition = mul(MVP, input.Position);
|
||||
//TODO: Make sure that boneTransform works here.
|
||||
output.Position = mul(ModelMatrix * ViewMatrix, float4(input.Position.xyz, 1.0f));
|
||||
output.Normal = mul(InverseTransposeViewModel, float4(input.Normal.xyz, 0.0f));
|
||||
output.Tangent = input.Tangent;
|
||||
output.BiTangent = input.BiTangent;
|
||||
output.TextureCoord = input.TextureCoord;
|
||||
output.DiffuseColor = input.DiffuseColor;
|
||||
output.SpecularColor = input.SpecularColor;
|
||||
output.BoneIndices1 = input.BoneIndices1;
|
||||
output.BoneIndices2 = input.BoneIndices2;
|
||||
output.BoneWeights1 = input.BoneWeights1;
|
||||
output.BoneWeights2 = input.BoneWeights2;
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Rendering/Texture.h"
|
||||
|
||||
dd::Texture::Texture(std::string path)
|
||||
{
|
||||
std::unique_ptr<Image> image = std::make_unique<PNG>(path);
|
||||
|
||||
if (image->Width == 0 && image->Height == 0 || image->Format == Image::ImageFormat::Unknown) {
|
||||
image = std::make_unique<PNG>("Textures/Core/ErrorTexture.png");
|
||||
if (image->Width == 0 && image->Height == 0 || image->Format == Image::ImageFormat::Unknown) {
|
||||
LOG_ERROR("Couldn't even load the error texture. This is a dark day indeed.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this->Width = image->Width;
|
||||
this->Height = image->Height;
|
||||
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
desc.Width = this->Width;
|
||||
desc.Height = this->Height;
|
||||
desc.MipLevels = 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.SampleDesc.Quality = 0;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
D3D11_SUBRESOURCE_DATA data;
|
||||
data.pSysMem = image->Data;
|
||||
data.SysMemPitch = image->Width * 4;
|
||||
data.SysMemSlicePitch = image->Width * image->Height * 4;
|
||||
|
||||
HRESULT result;
|
||||
result = StaticSystem::Get<Renderer>()->m_Device->CreateTexture2D(&desc, &data, &m_Texture);
|
||||
if (result != S_OK) {
|
||||
LOG_ERROR("DirectX failed to create texture \"%s\"", path.c_str());
|
||||
}
|
||||
result = StaticSystem::Get<Renderer>()->m_Device->CreateShaderResourceView(m_Texture, nullptr, &m_ShaderResourceView);
|
||||
if (result != S_OK) {
|
||||
LOG_ERROR("DirectX failed to create shader resource view for texture \"%s\"", path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
dd::Texture::~Texture()
|
||||
{
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/OBJ.h"
|
||||
#include "Rendering/OBJ.h"
|
||||
|
||||
bool dd::OBJ::LoadFromFile(std::string filename)
|
||||
{
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Rendering/Model.h"
|
||||
|
||||
dd::Model::Model(std::string fileName)
|
||||
: RawModel(fileName)
|
||||
{
|
||||
// Generate GL buffers
|
||||
GLuint buffer;
|
||||
glGenBuffers(1, &buffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, m_Vertices.size() * sizeof(Vertex), &m_Vertices[0], GL_STATIC_DRAW);
|
||||
|
||||
glGenBuffers(1, &ElementBuffer);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_Indices.size() * sizeof(unsigned int), &m_Indices[0], GL_STATIC_DRAW);
|
||||
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glBindVertexArray(VAO);
|
||||
GLERROR("GLEW: BufferFail4");
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
std::vector<int> structSizes = { 3, 3, 3, 3, 2, 4, 4, 4, 4, 4, 4 };
|
||||
int stride = 0;
|
||||
for (int size : structSizes)
|
||||
stride += size;
|
||||
stride *= sizeof(GLfloat);
|
||||
int offset = 0;
|
||||
{
|
||||
int element = 0;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * offset)); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
}
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
glEnableVertexAttribArray(3);
|
||||
glEnableVertexAttribArray(4);
|
||||
glEnableVertexAttribArray(5);
|
||||
glEnableVertexAttribArray(6);
|
||||
glEnableVertexAttribArray(7);
|
||||
glEnableVertexAttribArray(8);
|
||||
glEnableVertexAttribArray(9);
|
||||
glEnableVertexAttribArray(10);
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
//CreateBuffers();
|
||||
}
|
||||
|
||||
dd::Model::~Model()
|
||||
{
|
||||
|
||||
}
|
||||
Executable → Regular
+33
-26
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/Renderer.h"
|
||||
#include "Rendering/Renderer.h"
|
||||
|
||||
void dd::Renderer::Initialize()
|
||||
{
|
||||
@@ -45,7 +45,7 @@ void dd::Renderer::Initialize()
|
||||
glGetIntegerv(GL_MINOR_VERSION, &m_GLVersion[1]);
|
||||
m_GLVendor = (GLchar*)glGetString(GL_VENDOR);
|
||||
std::stringstream ss;
|
||||
ss << m_GLVendor << " OpenGL " << m_GLVersion[0] << "." << m_GLVersion[1];
|
||||
ss << "Squidout! (" << m_GLVendor << " OpenGL " << m_GLVersion[0] << "." << m_GLVersion[1] << ")";
|
||||
#ifdef DEBUG
|
||||
ss << " DEBUG";
|
||||
#endif
|
||||
@@ -80,7 +80,7 @@ void dd::Renderer::LoadShaders()
|
||||
*/
|
||||
|
||||
// Pass #1: Fill G-buffers
|
||||
m_SpDeferred1 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/1/");
|
||||
m_SpDeferred1 = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Deferred/1/");
|
||||
m_SpDeferred1->BindFragDataLocation(0, "GDiffuse");
|
||||
m_SpDeferred1->BindFragDataLocation(1, "GPosition");
|
||||
m_SpDeferred1->BindFragDataLocation(2, "GNormal");
|
||||
@@ -88,30 +88,30 @@ void dd::Renderer::LoadShaders()
|
||||
m_SpDeferred1->Link();
|
||||
|
||||
// Pass #2: Lighting
|
||||
m_SpDeferred2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/2/");
|
||||
m_SpDeferred2 = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Deferred/2/");
|
||||
//glBindFragDataLocation(m_SPDeferred2, 0, "FragmentLighting");
|
||||
m_SpDeferred2->Link();
|
||||
|
||||
//Water Pass
|
||||
m_SpWater = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water/");
|
||||
m_SpWater = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Deferred/water/");
|
||||
m_SpWater->Link();
|
||||
m_SpWater2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water2/");
|
||||
m_SpWater2 = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Deferred/water2/");
|
||||
m_SpWater2->Link();
|
||||
|
||||
// Pass #3: Combining into final image
|
||||
m_SpDeferred3 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/3/");
|
||||
m_SpDeferred3 = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Deferred/3/");
|
||||
m_SpDeferred3->Link();
|
||||
|
||||
/*
|
||||
Forward rendering
|
||||
*/
|
||||
m_SpForward = ResourceManager::Load<ShaderProgram>("Shaders/Forward/");
|
||||
m_SpForward = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Forward/");
|
||||
m_SpForward->Link();
|
||||
|
||||
/*
|
||||
Screen draw
|
||||
*/
|
||||
m_SpScreen = ResourceManager::Load<ShaderProgram>("Shaders/Screen/");
|
||||
m_SpScreen = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Screen/");
|
||||
m_SpScreen->Link();
|
||||
}
|
||||
|
||||
@@ -121,6 +121,7 @@ void dd::Renderer::CreateBuffers()
|
||||
m_ScreenQuad = CreateQuad();
|
||||
m_UnitQuad = ResourceManager::Load<Model>("Models/Core/UnitQuad.obj");
|
||||
m_UnitSphere = ResourceManager::Load<Model>("Models/Core/UnitSphere.obj");
|
||||
m_ErrorTexture = ResourceManager::Load<Texture>("Textures/Core/ErrorTexture.png");
|
||||
m_StandardNormal = ResourceManager::Load<Texture>("Textures/Core/NeutralNormalMap.png");
|
||||
m_StandardSpecular = ResourceManager::Load<Texture>("Textures/Core/NeutralSpecularMap.png");
|
||||
//m_WhiteSphereTexture = ResourceManager::Load<Texture>("Textures/Test/Water.png");
|
||||
@@ -414,22 +415,28 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "LightRadius"), 40.0f);
|
||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "MaterialShininess"), modelJob->Shininess);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture);
|
||||
if (modelJob->NormalTexture != 0) {
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture);
|
||||
if (modelJob->DiffuseTexture != nullptr) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture);
|
||||
} else {
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, *m_StandardNormal);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_ErrorTexture->m_Texture);
|
||||
}
|
||||
|
||||
if (modelJob->SpecularTexture != 0) {
|
||||
if (modelJob->NormalTexture != nullptr) {
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture->m_Texture);
|
||||
} else {
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, m_StandardNormal->m_Texture);
|
||||
}
|
||||
|
||||
if (modelJob->SpecularTexture != nullptr) {
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture->m_Texture);
|
||||
} else {
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, *m_StandardSpecular);
|
||||
glBindTexture(GL_TEXTURE_2D, m_StandardSpecular->m_Texture);
|
||||
}
|
||||
|
||||
if (modelJob->Skeleton != nullptr) {
|
||||
@@ -446,8 +453,8 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
||||
}
|
||||
}
|
||||
|
||||
glBindVertexArray(modelJob->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->ElementBuffer);
|
||||
glBindVertexArray(modelJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
|
||||
|
||||
continue;
|
||||
@@ -464,11 +471,11 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
||||
glUniform4fv(glGetUniformLocation(shaderProgramHandle, "Color"), 1, glm::value_ptr(spriteJob->Color));
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture->m_Texture);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, spriteJob->NormalTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, spriteJob->NormalTexture->m_Texture);
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, spriteJob->SpecularTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, spriteJob->SpecularTexture->m_Texture);
|
||||
|
||||
glBindVertexArray(m_UnitQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_UnitQuad->ElementBuffer);
|
||||
@@ -536,7 +543,7 @@ void dd::Renderer::DrawWater(RenderQueue &rq)
|
||||
glm::value_ptr(viewMatrix));
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, *m_WhiteSphereTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, m_WhiteSphereTexture->m_Texture);
|
||||
|
||||
glBindVertexArray(m_UnitQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_UnitQuad->ElementBuffer);
|
||||
@@ -691,7 +698,7 @@ void dd::Renderer::DrawGUI(dd::RenderQueue& rq)
|
||||
glUniform4fv(glGetUniformLocation(*m_SpScreen, "Color"), 1, glm::value_ptr(frameJob->Color));
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, frameJob->DiffuseTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, frameJob->DiffuseTexture->m_Texture);
|
||||
//glActiveTexture(GL_TEXTURE1);
|
||||
//glBindTexture(GL_TEXTURE_2D, frameJob->NormalTexture);
|
||||
//glActiveTexture(GL_TEXTURE2);
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/ShaderProgram.h"
|
||||
#include "Rendering/ShaderProgram.h"
|
||||
|
||||
void dd::Shader::Compile()
|
||||
{
|
||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
+1
-1
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/Texture.h"
|
||||
#include "Rendering/Texture.h"
|
||||
|
||||
dd::Texture::Texture(std::string path)
|
||||
{
|
||||
Executable → Regular
+9
-4
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/PNG.h"
|
||||
#include "Rendering/PNG.h"
|
||||
|
||||
dd::PNG::PNG(std::string path)
|
||||
{
|
||||
@@ -75,8 +75,6 @@ dd::PNG::PNG(std::string path)
|
||||
}
|
||||
switch (color_type) {
|
||||
case PNG_COLOR_TYPE_RGB:
|
||||
Format = Image::ImageFormat::RGB;
|
||||
break;
|
||||
case PNG_COLOR_TYPE_RGBA:
|
||||
Format = Image::ImageFormat::RGBA;
|
||||
break;
|
||||
@@ -84,8 +82,15 @@ dd::PNG::PNG(std::string path)
|
||||
LOG_ERROR("libpng: Unsupported color format \"%i\" of image \"%s\"", color_type, path.c_str());
|
||||
return;
|
||||
}
|
||||
unsigned int row_bytes = png_get_rowbytes(png_ptr, info_ptr);
|
||||
|
||||
// Convert RGB to RGBA, since DirectX rather treat them all the same way
|
||||
if (color_type == PNG_COLOR_TYPE_RGB) {
|
||||
LOG_DEBUG("Converting RGB to RGBA for \"%s\"", path.c_str());
|
||||
png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
|
||||
png_read_update_info(png_ptr, info_ptr);
|
||||
}
|
||||
|
||||
unsigned int row_bytes = png_get_rowbytes(png_ptr, info_ptr);
|
||||
this->Data = new unsigned char[height * row_bytes];
|
||||
png_bytep* row_pointers = new png_bytep[height];
|
||||
|
||||
Executable → Regular
+5
-57
@@ -17,9 +17,9 @@
|
||||
*/
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/Model.h"
|
||||
#include "Rendering/RawModel.h"
|
||||
|
||||
dd::Model::Model(std::string fileName)
|
||||
dd::RawModel::RawModel(std::string fileName)
|
||||
{
|
||||
Assimp::Importer importer;
|
||||
const aiScene* scene = importer.ReadFile(fileName, aiProcess_CalcTangentSpace | aiProcess_Triangulate);
|
||||
@@ -29,7 +29,7 @@ dd::Model::Model(std::string fileName)
|
||||
LOG_ERROR("Assimp error: %s", importer.GetErrorString());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
auto m = scene->mRootNode->mTransformation;
|
||||
m_Matrix = glm::mat4(
|
||||
m.a1, m.a2, m.a3, m.a4,
|
||||
@@ -303,68 +303,16 @@ dd::Model::Model(std::string fileName)
|
||||
|
||||
m_Skeleton->Animations[animationName] = skelAnim;
|
||||
}
|
||||
|
||||
// Generate GL buffers
|
||||
GLuint buffer;
|
||||
glGenBuffers(1, &buffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, m_Vertices.size() * sizeof(Vertex), &m_Vertices[0], GL_STATIC_DRAW);
|
||||
|
||||
glGenBuffers(1, &ElementBuffer);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_Indices.size() * sizeof(unsigned int), &m_Indices[0], GL_STATIC_DRAW);
|
||||
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glBindVertexArray(VAO);
|
||||
GLERROR("GLEW: BufferFail4");
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
std::vector<int> structSizes = { 3, 3, 3, 3, 2, 4, 4, 4, 4, 4, 4 };
|
||||
int stride = 0;
|
||||
for (int size : structSizes)
|
||||
stride += size;
|
||||
stride *= sizeof(GLfloat);
|
||||
int offset = 0;
|
||||
{
|
||||
int element = 0;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * offset)); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
}
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
glEnableVertexAttribArray(3);
|
||||
glEnableVertexAttribArray(4);
|
||||
glEnableVertexAttribArray(5);
|
||||
glEnableVertexAttribArray(6);
|
||||
glEnableVertexAttribArray(7);
|
||||
glEnableVertexAttribArray(8);
|
||||
glEnableVertexAttribArray(9);
|
||||
glEnableVertexAttribArray(10);
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
//CreateBuffers();
|
||||
}
|
||||
|
||||
dd::Model::~Model()
|
||||
dd::RawModel::~RawModel()
|
||||
{
|
||||
if (m_Skeleton) {
|
||||
delete m_Skeleton;
|
||||
}
|
||||
}
|
||||
|
||||
void dd::Model::CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID)
|
||||
void dd::RawModel::CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID)
|
||||
{
|
||||
std::string nodeName = node->mName.C_Str();
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/Skeleton.h"
|
||||
#include "Rendering/Skeleton.h"
|
||||
|
||||
int dd::Skeleton::CreateBone(int ID, int parentID, std::string name, glm::mat4 offsetMatrix)
|
||||
{
|
||||
Reference in New Issue
Block a user