Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1457450fef | |||
| 071caf51b6 | |||
| 8a3bf57d7e | |||
| 9805c7a2c1 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -26,4 +26,3 @@ bld/
|
||||
cmake-build-debug
|
||||
cmake-build-release
|
||||
cmake-build-debug-visual-studio
|
||||
cmake-**
|
||||
|
||||
@@ -13,37 +13,30 @@ set(SOURCES
|
||||
"src/Utils.cpp"
|
||||
"src/HitTest.cpp"
|
||||
"src/Material.cpp"
|
||||
"src/DirectionalLight.cpp"
|
||||
"src/Light.cpp"
|
||||
|
||||
"src/Math/Vector2.cpp"
|
||||
"src/Math/Vector3.cpp"
|
||||
"src/Math/Vector4.cpp"
|
||||
"src/Math/Matrix.cpp"
|
||||
|
||||
"src/BRDF.h"
|
||||
|
||||
"src/Effects/Effect.cpp"
|
||||
"src/Effects/BaseEffect.cpp"
|
||||
"src/Effects/FireEffect.cpp"
|
||||
"src/Effects/ShadowEffect.cpp"
|
||||
"src/Effects/ShadowDiffuse.cpp"
|
||||
|
||||
"src/Singleton.h"
|
||||
"src/RenderSettings.h"
|
||||
|
||||
"src/PerlinNoise.hpp"
|
||||
|
||||
"src/Buffers/DepthBuffer.cpp"
|
||||
"src/Buffers/SamplerState.cpp"
|
||||
"src/Buffers/ShadowMapBuffer.cpp"
|
||||
|
||||
"src/Scenes/BaseScene.cpp"
|
||||
"src/Scenes/MainScene.cpp"
|
||||
"src/Scenes/DioramaScene.cpp"
|
||||
"src/Scenes/InstancedScene.cpp"
|
||||
"src/Scenes/PlanetScene.cpp"
|
||||
"src/Scenes/ShadowTestScene.cpp"
|
||||
|
||||
"src/Buffers/ShadowMapBuffer.cpp"
|
||||
"src/Buffers/SamplerState.cpp"
|
||||
"src/Buffers/DepthBuffer.cpp"
|
||||
"src/Buffers/DX11Viewport.cpp"
|
||||
)
|
||||
|
||||
SET(INCLUDE_DIRS
|
||||
|
||||
@@ -1,42 +1,2 @@
|
||||
# Blender 4.3.2 MTL File: 'None'
|
||||
# www.blender.org
|
||||
|
||||
newmtl Material.001
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800119 0.001607 0.000000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.500000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl Material.002
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800149 0.000000 0.387990
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.500000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl Material.003
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.003822 0.800111 0.000000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.500000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl Material.004
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.500000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -116,6 +116,10 @@ float3 Shade(VS_OUTPUT input)
|
||||
}
|
||||
|
||||
float4 PS(VS_OUTPUT input) : SV_TARGET{
|
||||
//Check if gDiffuseMap sample has a valid value, otherwise render red
|
||||
if (gDiffuseMap.Sample(gSampleState, input.TexCoord).a == 0.f)
|
||||
return float4(1.f, 0.f, 0.f, 1.f);
|
||||
|
||||
return gDiffuseMap.Sample(gSampleState, input.TexCoord);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
|
||||
// Global parameters
|
||||
SamplerState gShadowSampler : ShadowSampler;
|
||||
SamplerState gShadowSampler2 : ShadowSampler {
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = CLAMP;
|
||||
AddressV = CLAMP;
|
||||
ComparisonFunc = LESS_EQUAL;
|
||||
};
|
||||
texture2D gShadowMap : ShadowMap;
|
||||
float4x4 gLightWorldViewProj : LightViewProjection;
|
||||
float4x4 gLightViewProj : LightViewProjection;
|
||||
|
||||
DepthStencilState ShadowDepthStencilState
|
||||
{
|
||||
@@ -10,16 +17,7 @@ DepthStencilState ShadowDepthStencilState
|
||||
StencilEnable = false; // We don't need stencil operations here
|
||||
};
|
||||
|
||||
SamplerState gShadowSampler2 : ShadowSampler {
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = CLAMP;
|
||||
AddressV = CLAMP;
|
||||
ComparisonFunc = LESS_EQUAL;
|
||||
};
|
||||
|
||||
|
||||
SamplerState gSampleState : SampleState;
|
||||
|
||||
RasterizerState gRasterizerState : RastState;
|
||||
|
||||
float4x4 gWorldViewProj : WorldViewProjection;
|
||||
@@ -68,89 +66,69 @@ VS_OUTPUT VS(VS_INPUT input) {
|
||||
|
||||
// Calculate shadow map coordinates
|
||||
// lightSpaceMatrix * vec4(vs_out.FragPos, 1.0);
|
||||
output.ShadowCoord = mul(float4(input.Position, 1.f) , gLightWorldViewProj);
|
||||
output.ShadowCoord = mul(float4(input.Position, 1.f) , gLightViewProj);
|
||||
return output;
|
||||
}
|
||||
|
||||
// Shadow sampling function
|
||||
float ShadowCalculation(float4 shadowCoord, float3 normal) {
|
||||
float ShadowCalculation(float4 shadowCoord) {
|
||||
// Normalize the depth by dividing by the w component
|
||||
float3 projCoord = shadowCoord.xyz / shadowCoord.w;
|
||||
|
||||
float shadow = 0.0;
|
||||
uint width, height;
|
||||
gShadowMap.GetDimensions(width, height);
|
||||
float2 texelSize = float2(1.f / width, 1.f / height);
|
||||
|
||||
// Convert from [-1, 1] to [0, 1]
|
||||
float2 UVCoords;
|
||||
UVCoords.x = 0.5f * projCoord.x + 0.5f;
|
||||
UVCoords.y = -0.5f * projCoord.y + 0.5f;
|
||||
// float z = 0.5 * projCoord.z + 0.5;
|
||||
float z = projCoord.z;
|
||||
// Sample the shadow map
|
||||
float shadowDepth = gShadowMap.Sample(gShadowSampler2, UVCoords.xy).r;
|
||||
|
||||
float bias = max(0.05 * (1.0 - dot(normal, -gLightDirection)), 0.005);
|
||||
float bias = 0.0025f;
|
||||
|
||||
for(int x = -1; x <= 1; ++x)
|
||||
{
|
||||
for(int y = -1; y <= 1; ++y)
|
||||
{
|
||||
float pcfDepth = gShadowMap.Sample(gShadowSampler2, UVCoords.xy + float2(x, y) * texelSize).r;
|
||||
shadow += z - bias > pcfDepth ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
// float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005);
|
||||
|
||||
shadow /= 9.0f;
|
||||
// return gShadowMap.Sample(gShadowSampler2, UVCoords.xy).r;
|
||||
// Check if the current fragment is in shadow
|
||||
if (shadowDepth + bias < z)
|
||||
return 0.5f;
|
||||
else
|
||||
return 1.0f;
|
||||
|
||||
|
||||
if(projCoord.z > 1.0)
|
||||
shadow = 0.0;
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
// Pixel shader
|
||||
// float4 PS(VS_OUTPUT input) : SV_TARGET {
|
||||
// float shadowFactor = ShadowCalculation(input.ShadowCoord, input.Normal);
|
||||
//
|
||||
// float3 diffuseColor = gDiffuseMap.Sample(gSampleState, input.TexCoord).rgb;
|
||||
//
|
||||
// float3 finalColor = diffuseColor * (1 - shadowFactor);
|
||||
// finalColor += gAmbient;
|
||||
//
|
||||
// return float4(finalColor, 1.0f);
|
||||
// }
|
||||
|
||||
float4 PS(VS_OUTPUT input) : SV_TARGET {
|
||||
float3 color = gDiffuseMap.Sample(gSampleState, input.TexCoord).rgb;
|
||||
float3 normal = normalize(input.Normal);
|
||||
// Check if gDiffuseMap sample has a valid value, otherwise render red
|
||||
// if (gDiffuseMap.Sample(gSampleState, input.TexCoord).a == 0.f)
|
||||
// return float4(1.f, 0.f, 0.f, 1.f);
|
||||
|
||||
float3 lightDir = normalize(-gLightDirection);
|
||||
float3 viewDir = normalize(gCameraPosition - input.WorldPosition.xyz);
|
||||
// return float4(Shade(input), 1.0f); // Use the shading function with shadow
|
||||
|
||||
float3 ambient = gAmbient;
|
||||
// return gShadowMap.Sample(gShadowSampler, input.ShadowCoord.xy / input.ShadowCoord.w); // Sample shadow map
|
||||
|
||||
float diff = max(dot(normal, lightDir), 0.0);
|
||||
float shadowFactor = ShadowCalculation(input.ShadowCoord);
|
||||
|
||||
float3 diffuse = gLightColor * diff * color;
|
||||
float3 diffuseColor = gDiffuseMap.Sample(gSampleState, input.TexCoord).rgb;
|
||||
|
||||
float3 reflectDir = reflect(-lightDir, normal);
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
|
||||
float3 specular = gLightColor * spec;
|
||||
float3 finalColor = float3(1.f, 1.f, 1.f) * shadowFactor;
|
||||
finalColor += gAmbient;
|
||||
|
||||
float shadow = ShadowCalculation(input.ShadowCoord, normal);
|
||||
float3 lighting = (ambient + (1.0 - shadow) * (diffuse + specular)) * color;
|
||||
|
||||
return float4(lighting, 1.0f);
|
||||
// return float4(shadowDepth,shadowDepth,shadowDepth, 1.0f);
|
||||
return float4(finalColor, 1.0f);
|
||||
// return gShadowMap.Sample(gShadowSampler, input.TexCoord); // Sample shadow map
|
||||
}
|
||||
|
||||
// DepthStencilState
|
||||
DepthStencilState gDepthStencilState {
|
||||
DepthStencilState gDepthStencilState
|
||||
{
|
||||
DepthEnable = true;
|
||||
DepthWriteMask = ALL;
|
||||
DepthFunc = LESS;
|
||||
StencilEnable = true;
|
||||
};
|
||||
|
||||
|
||||
// Technique
|
||||
technique11 DefaultTechnique {
|
||||
pass P0 {
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 133 KiB |
@@ -1,25 +0,0 @@
|
||||
//
|
||||
// Created by Bram on 17/01/2025.
|
||||
//
|
||||
|
||||
#ifndef GP1_DIRECTX_BRDF_H
|
||||
#define GP1_DIRECTX_BRDF_H
|
||||
|
||||
#include "ColorRGB.h"
|
||||
#include "./math/Vector3.h"
|
||||
|
||||
namespace dae{
|
||||
static ColorRGB Phong(const ColorRGB& specularReflectance, float exp, const Vector3& lightDir, const Vector3& viewDir, const Vector3& normal)
|
||||
{
|
||||
const Vector3 reflect{ Vector3::Reflect(lightDir, normal) };
|
||||
const float dot{ Saturate(Vector3::Dot(reflect, -viewDir)) };
|
||||
return specularReflectance * powf(dot, exp);
|
||||
}
|
||||
|
||||
static ColorRGB Lambert(float kd, const ColorRGB& diffuse)
|
||||
{
|
||||
return kd * diffuse;
|
||||
}
|
||||
}
|
||||
|
||||
#endif //GP1_DIRECTX_BRDF_H
|
||||
@@ -3,33 +3,3 @@
|
||||
//
|
||||
|
||||
#include "DX11Viewport.h"
|
||||
|
||||
DX11Viewport::DX11Viewport(float width, float height, float topLeftX, float topLeftY, float minDepth, float maxDepth) {
|
||||
viewport.Width = width;
|
||||
viewport.Height = height;
|
||||
viewport.TopLeftX = topLeftX;
|
||||
viewport.TopLeftY = topLeftY;
|
||||
viewport.MinDepth = minDepth;
|
||||
viewport.MaxDepth = maxDepth;
|
||||
}
|
||||
|
||||
void DX11Viewport::Apply(ID3D11DeviceContext *context) {
|
||||
if (context) {
|
||||
context->RSSetViewports(1, &viewport);
|
||||
}
|
||||
}
|
||||
|
||||
void DX11Viewport::SetDimensions(float width, float height) {
|
||||
viewport.Width = width;
|
||||
viewport.Height = height;
|
||||
}
|
||||
|
||||
void DX11Viewport::SetPosition(float topLeftX, float topLeftY) {
|
||||
viewport.TopLeftX = topLeftX;
|
||||
viewport.TopLeftY = topLeftY;
|
||||
}
|
||||
|
||||
void DX11Viewport::SetDepthRange(float minDepth, float maxDepth) {
|
||||
viewport.MinDepth = minDepth;
|
||||
viewport.MaxDepth = maxDepth;
|
||||
}
|
||||
|
||||
@@ -3,19 +3,46 @@
|
||||
|
||||
#include <d3d11.h>
|
||||
|
||||
class DX11Viewport {
|
||||
class DX11Viewport
|
||||
{
|
||||
public:
|
||||
DX11Viewport(float width, float height, float topLeftX = 0.0f, float topLeftY = 0.0f, float minDepth = 0.0f, float maxDepth = 1.0f);
|
||||
DX11Viewport(float width, float height, float topLeftX = 0.0f, float topLeftY = 0.0f, float minDepth = 0.0f, float maxDepth = 1.0f)
|
||||
{
|
||||
viewport.Width = width;
|
||||
viewport.Height = height;
|
||||
viewport.TopLeftX = topLeftX;
|
||||
viewport.TopLeftY = topLeftY;
|
||||
viewport.MinDepth = minDepth;
|
||||
viewport.MaxDepth = maxDepth;
|
||||
}
|
||||
|
||||
void Apply(ID3D11DeviceContext *context);
|
||||
void Apply(ID3D11DeviceContext* context)
|
||||
{
|
||||
if (context)
|
||||
{
|
||||
context->RSSetViewports(1, &viewport);
|
||||
}
|
||||
}
|
||||
|
||||
void SetDimensions(float width, float height);
|
||||
void SetDimensions(float width, float height)
|
||||
{
|
||||
viewport.Width = width;
|
||||
viewport.Height = height;
|
||||
}
|
||||
|
||||
void SetPosition(float topLeftX, float topLeftY);
|
||||
void SetPosition(float topLeftX, float topLeftY)
|
||||
{
|
||||
viewport.TopLeftX = topLeftX;
|
||||
viewport.TopLeftY = topLeftY;
|
||||
}
|
||||
|
||||
void SetDepthRange(float minDepth, float maxDepth);
|
||||
void SetDepthRange(float minDepth, float maxDepth)
|
||||
{
|
||||
viewport.MinDepth = minDepth;
|
||||
viewport.MaxDepth = maxDepth;
|
||||
}
|
||||
|
||||
const D3D11_VIEWPORT &GetViewport() const { return viewport; }
|
||||
const D3D11_VIEWPORT& GetViewport() const { return viewport; }
|
||||
|
||||
private:
|
||||
D3D11_VIEWPORT viewport;
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
#include "DepthBuffer.h"
|
||||
|
||||
DepthBuffer::DepthBuffer(ID3D11Device *device, UINT width, UINT height)
|
||||
: m_device(device), m_width(width), m_height(height), m_depthBuffer(nullptr), m_depthStencilView(nullptr) {
|
||||
DepthBuffer::DepthBuffer(ID3D11Device* device, UINT width, UINT height)
|
||||
: m_device(device), m_width(width), m_height(height), m_depthBuffer(nullptr), m_depthStencilView(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
DepthBuffer::~DepthBuffer() {
|
||||
DepthBuffer::~DepthBuffer()
|
||||
{
|
||||
if (m_depthStencilView) m_depthStencilView->Release();
|
||||
if (m_depthBuffer) m_depthBuffer->Release();
|
||||
}
|
||||
|
||||
bool DepthBuffer::Initialize() {
|
||||
bool DepthBuffer::Initialize()
|
||||
{
|
||||
// Create a depth buffer with a typeless format
|
||||
D3D11_TEXTURE2D_DESC desc = {};
|
||||
desc.Width = m_width;
|
||||
@@ -24,7 +27,8 @@ bool DepthBuffer::Initialize() {
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
HRESULT hr = m_device->CreateTexture2D(&desc, nullptr, &m_depthBuffer);
|
||||
if (FAILED(hr)) {
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -34,17 +38,20 @@ bool DepthBuffer::Initialize() {
|
||||
dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
|
||||
dsvDesc.Texture2D.MipSlice = 0;
|
||||
hr = m_device->CreateDepthStencilView(m_depthBuffer, &dsvDesc, &m_depthStencilView);
|
||||
if (FAILED(hr)) {
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ID3D11Texture2D *DepthBuffer::GetDepthBuffer() {
|
||||
ID3D11Texture2D* DepthBuffer::GetDepthBuffer()
|
||||
{
|
||||
return m_depthBuffer;
|
||||
}
|
||||
|
||||
ID3D11DepthStencilView *DepthBuffer::GetDepthStencilView() {
|
||||
ID3D11DepthStencilView* DepthBuffer::GetDepthStencilView()
|
||||
{
|
||||
return m_depthStencilView;
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ SamplerState::~SamplerState() {
|
||||
bool SamplerState::Initialize() {
|
||||
D3D11_SAMPLER_DESC samplerDesc = {};
|
||||
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
// samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
// samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
// samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
// samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
// samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
// samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
|
||||
samplerDesc.MinLOD = 0;
|
||||
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
|
||||
|
||||
@@ -8,6 +8,7 @@ ShadowMapBuffer::ShadowMapBuffer(ID3D11Device *device, UINT width, UINT height)
|
||||
ShadowMapBuffer::~ShadowMapBuffer() {
|
||||
if (m_shaderResourceView) m_shaderResourceView->Release();
|
||||
}
|
||||
|
||||
bool ShadowMapBuffer::Initialize() {
|
||||
if (!m_depthBuffer.Initialize()) {
|
||||
return false;
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
//
|
||||
// Created by Bram on 13/01/2025.
|
||||
//
|
||||
|
||||
#ifndef GP1_DIRECTX_SHADOWMAPBUFFER_H
|
||||
#define GP1_DIRECTX_SHADOWMAPBUFFER_H
|
||||
|
||||
@@ -18,6 +22,7 @@ public:
|
||||
|
||||
void ResetRenderTarget(ID3D11DeviceContext *deviceContext);
|
||||
|
||||
// Get the depth stencil view and the sampler state
|
||||
ID3D11ShaderResourceView *GetShaderResourceView() const { return m_shaderResourceView; }
|
||||
|
||||
ID3D11SamplerState *GetSamplerState() const { return m_samplerState.GetSamplerState(); }
|
||||
|
||||
@@ -60,11 +60,9 @@ void dae::Camera::Update(const dae::Timer *pTimer) {
|
||||
if (pKeyboardState[SDL_SCANCODE_LSHIFT]) {
|
||||
MovementSpeed *= 2;
|
||||
}
|
||||
|
||||
if (pKeyboardState[SDL_SCANCODE_W]) {
|
||||
origin += forward * deltaTime * MovementSpeed;
|
||||
}
|
||||
|
||||
if (pKeyboardState[SDL_SCANCODE_A]) {
|
||||
origin -= right * deltaTime * MovementSpeed;
|
||||
}
|
||||
@@ -193,7 +191,7 @@ const dae::Vector3 & dae::Camera::GetPosition() const {
|
||||
return origin;
|
||||
}
|
||||
|
||||
dae::Vector3 dae::Camera::GetRotation() const {
|
||||
const dae::Vector3 dae::Camera::GetRotation() const {
|
||||
return {totalPitch, totalYaw, 0.f};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "Math/Matrix.h"
|
||||
|
||||
namespace dae {
|
||||
class Camera final {
|
||||
class Camera {
|
||||
public:
|
||||
Camera() = default;
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace dae {
|
||||
const Vector3 & GetPosition() const;
|
||||
void SetPosition(const Vector3& position);
|
||||
|
||||
Vector3 GetRotation() const;
|
||||
const Vector3 GetRotation() const;
|
||||
void SetRotation(const Vector3& rotation);
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
#include "DirectionalLight.h"
|
||||
#include <cmath>
|
||||
|
||||
DirectionalLight::DirectionalLight()
|
||||
: m_Position(0.0f, 10.0f, 0.0f),
|
||||
m_Target(0.0f, 0.0f, 0.0f),
|
||||
m_Up(0.0f, 1.0f, 0.0f),
|
||||
m_ViewMatrix(dae::Matrix()),
|
||||
m_ProjectionMatrix(dae::Matrix()) {}
|
||||
|
||||
void DirectionalLight::SetPosition(const dae::Vector3 &position) {
|
||||
m_Position = position;
|
||||
}
|
||||
|
||||
void DirectionalLight::SetTarget(const dae::Vector3 &target) {
|
||||
m_Target = target;
|
||||
}
|
||||
|
||||
void DirectionalLight::SetUp(const dae::Vector3 &up) {
|
||||
m_Up = up;
|
||||
}
|
||||
|
||||
dae::Matrix DirectionalLight::GetViewMatrix() const {
|
||||
return dae::Matrix::CreateLookAtLH(m_Position, m_Target, m_Up);
|
||||
}
|
||||
|
||||
dae::Matrix DirectionalLight::GetProjectionMatrix(float nearPlane, float farPlane, float size) const {
|
||||
return dae::Matrix::CreateOrthographic(size, size, nearPlane, farPlane);
|
||||
}
|
||||
|
||||
dae::Matrix DirectionalLight::GetViewProjectionMatrix(float nearPlane, float farPlane, float size) const {
|
||||
return GetViewMatrix() * GetProjectionMatrix(nearPlane, farPlane, size);
|
||||
}
|
||||
|
||||
void DirectionalLight::Update() {
|
||||
// If the light position or target changes dynamically, this is where updates would be managed.
|
||||
// m_ViewMatrix = dae::Matrix::CreateLookAtLH(m_Position, m_Target, m_Up);
|
||||
// m_ProjectionMatrix = dae::Matrix::CreateOrthographic(size, size, nearPlane, farPlane);
|
||||
}
|
||||
|
||||
dae::Vector3 DirectionalLight::GetTarget() {
|
||||
return m_Target;
|
||||
}
|
||||
|
||||
dae::Vector3 DirectionalLight::GetPosition() {
|
||||
return m_Position;
|
||||
}
|
||||
|
||||
void DirectionalLight::SetColor(const dae::ColorRGB &color) { m_Color = color; }
|
||||
|
||||
dae::Vector3 DirectionalLight::GetDirection() const { return m_Target - m_Position; }
|
||||
|
||||
dae::ColorRGB DirectionalLight::GetColor() const { return m_Color; }
|
||||
@@ -9,13 +9,10 @@ BaseEffect::BaseEffect(ID3D11Device *devicePtr, const std::wstring &filePath) {
|
||||
const std::ifstream file(filePath);
|
||||
if (!file)
|
||||
std::wcout << L"File doesn't exist" << std::endl;
|
||||
|
||||
m_EffectPtr = LoadEffect(devicePtr, filePath);
|
||||
m_TechniquePtr = m_EffectPtr->GetTechniqueByName("DefaultTechnique");
|
||||
|
||||
if (!m_TechniquePtr->IsValid())
|
||||
std::wcout << L"Technique is not valid" << std::endl;
|
||||
|
||||
m_MatWorldViewProjVariablePtr = m_EffectPtr->GetVariableByName("gWorldViewProj")->AsMatrix();
|
||||
if (!m_MatWorldViewProjVariablePtr->IsValid())
|
||||
std::wcout << L"gWorldViewProj Matrix is not valid" << std::endl;
|
||||
@@ -54,11 +51,11 @@ ID3DX11Effect *BaseEffect::LoadEffect(ID3D11Device *devicePtr, const std::wstrin
|
||||
ss << errorsPtr[i];
|
||||
OutputDebugStringW(ss.str().c_str());
|
||||
|
||||
|
||||
errorBlobPtr->Release();
|
||||
errorBlobPtr = nullptr;
|
||||
return nullptr;
|
||||
} else {
|
||||
|
||||
std::wstringstream ss;
|
||||
ss << "EffectLoader: Failed to CreateEffectFromFile!\nPath: " << filePath;
|
||||
std::wcout << ss.str() << std::endl;
|
||||
@@ -73,6 +70,7 @@ void BaseEffect::SetWorldViewProjMatrix(const dae::Matrix &matrix) {
|
||||
}
|
||||
|
||||
void BaseEffect::NextSamplingState() {
|
||||
|
||||
}
|
||||
|
||||
void BaseEffect::SetCameraPos(const dae::Vector3 &vector3) const {
|
||||
@@ -80,7 +78,6 @@ void BaseEffect::SetCameraPos(const dae::Vector3 &vector3) const {
|
||||
}
|
||||
|
||||
void BaseEffect::SetMaterial(Material *material) {
|
||||
|
||||
}
|
||||
|
||||
void BaseEffect::SetWorldMatrix(const dae::Matrix& matrix) const {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
//
|
||||
// Created by Bram on 20/12/2024.
|
||||
//
|
||||
|
||||
#ifndef GP1_DIRECTX_BASEEFFECT_H
|
||||
#define GP1_DIRECTX_BASEEFFECT_H
|
||||
|
||||
@@ -24,6 +28,8 @@ public:
|
||||
|
||||
ID3DX11EffectTechnique* GetTechniquePtr() const { return m_TechniquePtr; }
|
||||
|
||||
|
||||
|
||||
void SetWorldViewProjMatrix(const dae::Matrix& matrix);
|
||||
|
||||
virtual void NextSamplingState();
|
||||
|
||||
@@ -40,6 +40,7 @@ Effect::Effect(ID3D11Device *devicePtr, const std::wstring &filePath)
|
||||
if(!m_CameraPosVariablePtr->IsValid())
|
||||
std::wcout << L"gCameraPos Vector is not valid" << std::endl;
|
||||
|
||||
|
||||
m_LightColorVariablePtr = m_EffectPtr->GetVariableByName("gLightColor")->AsVector();
|
||||
if(!m_LightColorVariablePtr->IsValid())
|
||||
std::wcout << L"gLightColor Vector is not valid" << std::endl;
|
||||
@@ -52,6 +53,17 @@ Effect::Effect(ID3D11Device *devicePtr, const std::wstring &filePath)
|
||||
if(!m_RasterizerVariablePtr->IsValid())
|
||||
std::wcout << L"gRasterizerState Rasterizer is not valid" << std::endl;
|
||||
|
||||
m_ShadowMapVariablePtr = m_EffectPtr->GetVariableByName("gShadowMap")->AsShaderResource();
|
||||
if(!m_ShadowMapVariablePtr->IsValid())
|
||||
std::wcout << L"gShadowMap ShaderResource is not valid" << std::endl;
|
||||
|
||||
m_ShadowMapSamplerVariablePtr = m_EffectPtr->GetVariableByName("gShadowSampler")->AsSampler();
|
||||
if(!m_ShadowMapSamplerVariablePtr->IsValid())
|
||||
std::wcout << L"gShadowSampler Sampler is not valid" << std::endl;
|
||||
|
||||
m_LightWorldViewProjVariablePtr = m_EffectPtr->GetVariableByName("gLightViewProj")->AsMatrix();
|
||||
if(!m_LightWorldViewProjVariablePtr->IsValid())
|
||||
std::wcout << L"gLightWorldViewProj Matrix is not valid" << std::endl;
|
||||
|
||||
m_UseNormalMapVariablePtr->SetBool(m_UseNormalMap);
|
||||
|
||||
@@ -66,6 +78,7 @@ Effect::Effect(ID3D11Device *devicePtr, const std::wstring &filePath)
|
||||
this->InitSamplers(devicePtr);
|
||||
this->InitRasterizer(devicePtr);
|
||||
|
||||
|
||||
m_SamplerVariablePtr->SetSampler(0,m_SamplerStates[static_cast<int>(m_TechniqueType)]);
|
||||
m_RasterizerVariablePtr->SetRasterizerState(0,m_RasterizerStates[static_cast<int>(m_CullMode)]);
|
||||
}
|
||||
@@ -203,3 +216,17 @@ void Effect::InitRasterizer(ID3D11Device *devicePtr) {
|
||||
|
||||
devicePtr->CreateRasterizerState(&rasterDesc, &m_RasterizerStates[static_cast<int>(CullMode::None)]);
|
||||
}
|
||||
|
||||
void Effect::SetShadowMapSampler(ID3D11SamplerState *pState) {
|
||||
|
||||
m_ShadowMapSamplerVariablePtr->SetSampler(0,pState);
|
||||
}
|
||||
|
||||
void Effect::SetShadowMap(ID3D11ShaderResourceView *pView) {
|
||||
m_ShadowMapVariablePtr->SetResource(pView);
|
||||
}
|
||||
|
||||
void Effect::SetLightViewProjMatrix(Matrix matrix) {
|
||||
m_LightWorldViewProjVariablePtr->SetMatrix(reinterpret_cast<const float*>(&matrix));
|
||||
|
||||
}
|
||||
|
||||
@@ -3,13 +3,16 @@
|
||||
#include "BaseEffect.h"
|
||||
#include <array>
|
||||
|
||||
|
||||
|
||||
enum class CullMode {
|
||||
None = 0,
|
||||
Front = 1,
|
||||
Back = 2
|
||||
};
|
||||
|
||||
class Effect final: public BaseEffect {
|
||||
|
||||
class Effect: public BaseEffect {
|
||||
public:
|
||||
Effect(ID3D11Device *devicePtr, const std::wstring &filePath);
|
||||
|
||||
@@ -27,6 +30,12 @@ public:
|
||||
|
||||
void NextCullMode() override;
|
||||
|
||||
void SetShadowMap(ID3D11ShaderResourceView *pView);
|
||||
|
||||
void SetShadowMapSampler(ID3D11SamplerState *pState);
|
||||
|
||||
void SetLightViewProjMatrix(Matrix matrix);
|
||||
|
||||
private:
|
||||
|
||||
void InitSamplers(ID3D11Device* devicePtr);
|
||||
@@ -49,6 +58,13 @@ private:
|
||||
|
||||
ID3DX11EffectRasterizerVariable* m_RasterizerVariablePtr{};
|
||||
|
||||
ID3DX11EffectShaderResourceVariable* m_ShadowMapVariablePtr{};
|
||||
|
||||
//m_LightWorldViewProjVariablePtr
|
||||
ID3DX11EffectMatrixVariable* m_LightWorldViewProjVariablePtr{};
|
||||
|
||||
ID3DX11EffectSamplerVariable* m_ShadowMapSamplerVariablePtr{};
|
||||
|
||||
TechniqueType m_TechniqueType{TechniqueType::Linear};
|
||||
|
||||
std::array<ID3D11SamplerState*, 3> m_SamplerStates{};
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <array>
|
||||
#include "BaseEffect.h"
|
||||
|
||||
class FireEffect final : public BaseEffect {
|
||||
class FireEffect: public BaseEffect {
|
||||
public:
|
||||
FireEffect(ID3D11Device *devicePtr, const std::wstring &filePath);
|
||||
|
||||
@@ -20,13 +20,14 @@ public:
|
||||
void NextSamplingState() override;
|
||||
|
||||
private:
|
||||
void InitSamplers(ID3D11Device *devicePtr);
|
||||
void InitSamplers(ID3D11Device* devicePtr);
|
||||
|
||||
|
||||
ID3DX11EffectShaderResourceVariable *m_DiffuseMapVariablePtr{};
|
||||
|
||||
ID3DX11EffectSamplerVariable *m_SamplerVariablePtr{};
|
||||
|
||||
std::array<ID3D11SamplerState *, 3> m_SamplerStates{};
|
||||
std::array<ID3D11SamplerState*, 3> m_SamplerStates{};
|
||||
|
||||
TechniqueType m_TechniqueType{TechniqueType::Linear};
|
||||
|
||||
|
||||
@@ -1,247 +0,0 @@
|
||||
#include "../pch.h"
|
||||
#include "ShadowDiffuse.h"
|
||||
#include "../Utils.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
ShadowDiffuse::ShadowDiffuse(ID3D11Device *devicePtr, const std::wstring &filePath)
|
||||
: BaseEffect(devicePtr, filePath) {
|
||||
|
||||
m_LightPosVariablePtr = m_EffectPtr->GetVariableByName("gLightDirection")->AsVector();
|
||||
if (!m_LightPosVariablePtr->IsValid())
|
||||
std::wcout << L"gLightDirection Vector is not valid" << std::endl;
|
||||
|
||||
|
||||
m_SamplerVariablePtr = m_EffectPtr->GetVariableByName("gSampleState")->AsSampler();
|
||||
if (!m_SamplerVariablePtr->IsValid())
|
||||
std::wcout << L"gSampleState Sampler is not valid" << std::endl;
|
||||
|
||||
m_MatWorldVariablePtr = m_EffectPtr->GetVariableByName("gWorldMatrix")->AsMatrix();
|
||||
if (!m_MatWorldVariablePtr->IsValid())
|
||||
std::wcout << L"gWorld Matrix is not valid" << std::endl;
|
||||
|
||||
m_DiffuseMapVariablePtr = m_EffectPtr->GetVariableByName("gDiffuseMap")->AsShaderResource();
|
||||
if (!m_DiffuseMapVariablePtr->IsValid())
|
||||
std::wcout << L"gDiffuseMap ShaderResource is not valid" << std::endl;
|
||||
|
||||
m_NormalMapVariablePtr = m_EffectPtr->GetVariableByName("gNormalMap")->AsShaderResource();
|
||||
if (!m_NormalMapVariablePtr->IsValid())
|
||||
std::wcout << L"gNormalMap ShaderResource is not valid" << std::endl;
|
||||
|
||||
m_SpecularMapVariablePtr = m_EffectPtr->GetVariableByName("gSpecularMap")->AsShaderResource();
|
||||
if (!m_SpecularMapVariablePtr->IsValid())
|
||||
std::wcout << L"gSpecularMap ShaderResource is not valid" << std::endl;
|
||||
|
||||
m_GlossMapVariablePtr = m_EffectPtr->GetVariableByName("gGlossMap")->AsShaderResource();
|
||||
if (!m_GlossMapVariablePtr->IsValid())
|
||||
std::wcout << L"gGlossMap ShaderResource is not valid" << std::endl;
|
||||
|
||||
m_CameraPosVariablePtr = m_EffectPtr->GetVariableByName("gCameraPosition")->AsVector();
|
||||
if (!m_CameraPosVariablePtr->IsValid())
|
||||
std::wcout << L"gCameraPos Vector is not valid" << std::endl;
|
||||
|
||||
m_LightColorVariablePtr = m_EffectPtr->GetVariableByName("gLightColor")->AsVector();
|
||||
if (!m_LightColorVariablePtr->IsValid())
|
||||
std::wcout << L"gLightColor Vector is not valid" << std::endl;
|
||||
|
||||
m_UseNormalMapVariablePtr = m_EffectPtr->GetVariableByName("gUseNormal")->AsScalar();
|
||||
if (!m_UseNormalMapVariablePtr->IsValid())
|
||||
std::wcout << L"gUseNormalMap Scalar is not valid" << std::endl;
|
||||
|
||||
m_RasterizerVariablePtr = m_EffectPtr->GetVariableByName("gRasterizerState")->AsRasterizer();
|
||||
if (!m_RasterizerVariablePtr->IsValid())
|
||||
std::wcout << L"gRasterizerState Rasterizer is not valid" << std::endl;
|
||||
|
||||
m_ShadowMapVariablePtr = m_EffectPtr->GetVariableByName("gShadowMap")->AsShaderResource();
|
||||
if (!m_ShadowMapVariablePtr->IsValid())
|
||||
std::wcout << L"gShadowMapSampler Sampler is not valid" << std::endl;
|
||||
|
||||
m_LightWorldViewProjVariablePtr = m_EffectPtr->GetVariableByName("gLightWorldViewProj")->AsMatrix();
|
||||
if (!m_LightWorldViewProjVariablePtr->IsValid())
|
||||
std::wcout << L"gLightWorldViewProj Matrix is not valid" << std::endl;
|
||||
|
||||
m_LightDirectionVariablePtr = m_EffectPtr->GetVariableByName("gLightDirection")->AsVector();
|
||||
if (!m_LightDirectionVariablePtr->IsValid())
|
||||
std::wcout << L"gLightDirection Vector is not valid" << std::endl;
|
||||
|
||||
m_LightColorVariablePtr = m_EffectPtr->GetVariableByName("gLightColor")->AsVector();
|
||||
if (!m_LightColorVariablePtr->IsValid())
|
||||
std::wcout << L"gLightColor Vector is not valid" << std::endl;
|
||||
|
||||
m_UseNormalMapVariablePtr->SetBool(m_UseNormalMap);
|
||||
|
||||
constexpr int vectorSize{4};
|
||||
constexpr float lightDirection[vectorSize]{.577f, -.577f, .577f, 0.f};
|
||||
m_LightPosVariablePtr->SetFloatVector(lightDirection);
|
||||
|
||||
constexpr float lightColor[vectorSize]{1.f, 1.f, 1.f, 1.f};
|
||||
m_LightColorVariablePtr->SetFloatVector(lightColor);
|
||||
|
||||
this->InitSamplers(devicePtr);
|
||||
this->InitRasterizer(devicePtr);
|
||||
|
||||
m_SamplerVariablePtr->SetSampler(0, m_SamplerStates[static_cast<int>(m_TechniqueType)]);
|
||||
m_RasterizerVariablePtr->SetRasterizerState(0, m_RasterizerStates[static_cast<int>(m_CullMode)]);
|
||||
}
|
||||
|
||||
ShadowDiffuse::~ShadowDiffuse() {
|
||||
m_MatWorldVariablePtr->Release();
|
||||
m_MatWorldVariablePtr = nullptr;
|
||||
|
||||
m_DiffuseMapVariablePtr->Release();
|
||||
m_DiffuseMapVariablePtr = nullptr;
|
||||
|
||||
m_NormalMapVariablePtr->Release();
|
||||
m_NormalMapVariablePtr = nullptr;
|
||||
|
||||
m_SpecularMapVariablePtr->Release();
|
||||
m_SpecularMapVariablePtr = nullptr;
|
||||
|
||||
m_GlossMapVariablePtr->Release();
|
||||
m_GlossMapVariablePtr = nullptr;
|
||||
|
||||
m_CameraPosVariablePtr->Release();
|
||||
m_CameraPosVariablePtr = nullptr;
|
||||
|
||||
m_LightPosVariablePtr->Release();
|
||||
m_LightPosVariablePtr = nullptr;
|
||||
|
||||
m_LightColorVariablePtr->Release();
|
||||
m_LightColorVariablePtr = nullptr;
|
||||
|
||||
m_UseNormalMapVariablePtr->Release();
|
||||
m_UseNormalMapVariablePtr = nullptr;
|
||||
|
||||
m_SamplerVariablePtr->Release();
|
||||
m_SamplerVariablePtr = nullptr;
|
||||
|
||||
m_RasterizerVariablePtr->Release();
|
||||
m_RasterizerVariablePtr = nullptr;
|
||||
|
||||
m_LightDirectionVariablePtr->Release();
|
||||
m_LightDirectionVariablePtr = nullptr;
|
||||
|
||||
if (m_ShadowMapVariablePtr) {
|
||||
m_ShadowMapVariablePtr->Release();
|
||||
m_ShadowMapVariablePtr = nullptr;
|
||||
}
|
||||
if (m_LightWorldViewProjVariablePtr) {
|
||||
m_LightWorldViewProjVariablePtr->Release();
|
||||
m_LightWorldViewProjVariablePtr = nullptr;
|
||||
}
|
||||
|
||||
|
||||
for (auto sampler: m_SamplerStates) {
|
||||
sampler->Release();
|
||||
}
|
||||
|
||||
for (auto rasterizer: m_RasterizerStates) {
|
||||
rasterizer->Release();
|
||||
}
|
||||
|
||||
m_EffectPtr->Release();
|
||||
m_EffectPtr = nullptr;
|
||||
}
|
||||
|
||||
void ShadowDiffuse::SetWorldMatrix(const dae::Matrix &world) const {
|
||||
m_MatWorldVariablePtr->SetMatrix(reinterpret_cast<const float *>(&world));
|
||||
}
|
||||
|
||||
void ShadowDiffuse::SetMaterial(Material *material) {
|
||||
if (material->diffuseTexturePtr)
|
||||
m_DiffuseMapVariablePtr->SetResource(material->diffuseTexturePtr->GetSrv());
|
||||
if (material->normalTexturePtr)
|
||||
m_NormalMapVariablePtr->SetResource(material->normalTexturePtr->GetSrv());
|
||||
if (material->specularTexturePtr)
|
||||
m_SpecularMapVariablePtr->SetResource(material->specularTexturePtr->GetSrv());
|
||||
if (material->glossTexturePtr)
|
||||
m_GlossMapVariablePtr->SetResource(material->glossTexturePtr->GetSrv());
|
||||
}
|
||||
|
||||
void ShadowDiffuse::SetCameraPos(const dae::Vector3 &pos) const {
|
||||
m_CameraPosVariablePtr->SetFloatVector(reinterpret_cast<const float *>(&pos));
|
||||
}
|
||||
|
||||
void ShadowDiffuse::NextSamplingState() {
|
||||
switch (m_TechniqueType) {
|
||||
case TechniqueType::Point:
|
||||
m_TechniqueType = TechniqueType::Linear;
|
||||
break;
|
||||
case TechniqueType::Linear:
|
||||
m_TechniqueType = TechniqueType::Anisotropic;
|
||||
break;
|
||||
case TechniqueType::Anisotropic:
|
||||
m_TechniqueType = TechniqueType::Point;
|
||||
break;
|
||||
}
|
||||
m_SamplerVariablePtr->SetSampler(0, m_SamplerStates[static_cast<int>(m_TechniqueType)]);
|
||||
}
|
||||
|
||||
void ShadowDiffuse::ToggleNormals() {
|
||||
m_UseNormalMap = !m_UseNormalMap;
|
||||
m_UseNormalMapVariablePtr->SetBool(m_UseNormalMap);
|
||||
}
|
||||
|
||||
void ShadowDiffuse::InitSamplers(ID3D11Device *devicePtr) {
|
||||
D3D11_SAMPLER_DESC samplerDesc{};
|
||||
samplerDesc.Filter = D3D11_FILTER_ANISOTROPIC;
|
||||
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
|
||||
|
||||
devicePtr->CreateSamplerState(&samplerDesc, &m_SamplerStates[static_cast<int>(TechniqueType::Anisotropic)]);
|
||||
|
||||
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
devicePtr->CreateSamplerState(&samplerDesc, &m_SamplerStates[static_cast<int>(TechniqueType::Linear)]);
|
||||
|
||||
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
|
||||
devicePtr->CreateSamplerState(&samplerDesc, &m_SamplerStates[static_cast<int>(TechniqueType::Point)]);
|
||||
|
||||
m_SamplerVariablePtr->SetSampler(0, m_SamplerStates[static_cast<int>(m_TechniqueType)]);
|
||||
}
|
||||
|
||||
void ShadowDiffuse::NextCullMode() {
|
||||
m_CullMode = static_cast<CullMode>((static_cast<int>(m_CullMode) + 1) % 3);
|
||||
m_RasterizerVariablePtr->SetRasterizerState(0, m_RasterizerStates[static_cast<int>(m_CullMode)]);
|
||||
}
|
||||
|
||||
void ShadowDiffuse::InitRasterizer(ID3D11Device *devicePtr) {
|
||||
D3D11_RASTERIZER_DESC rasterDesc = {};
|
||||
rasterDesc.FillMode = D3D11_FILL_SOLID; // Solid fill
|
||||
rasterDesc.FrontCounterClockwise = FALSE;
|
||||
rasterDesc.DepthBias = D3D11_DEFAULT_DEPTH_BIAS;
|
||||
rasterDesc.SlopeScaledDepthBias = D3D11_DEFAULT_SLOPE_SCALED_DEPTH_BIAS;
|
||||
rasterDesc.DepthClipEnable = TRUE;
|
||||
rasterDesc.ScissorEnable = FALSE;
|
||||
rasterDesc.MultisampleEnable = FALSE;
|
||||
rasterDesc.AntialiasedLineEnable = FALSE;
|
||||
|
||||
rasterDesc.CullMode = D3D11_CULL_BACK; // Cull back faces
|
||||
|
||||
devicePtr->CreateRasterizerState(&rasterDesc, &m_RasterizerStates[static_cast<int>(CullMode::Back)]);
|
||||
|
||||
rasterDesc.CullMode = D3D11_CULL_FRONT;
|
||||
|
||||
devicePtr->CreateRasterizerState(&rasterDesc, &m_RasterizerStates[static_cast<int>(CullMode::Front)]);
|
||||
|
||||
rasterDesc.CullMode = D3D11_CULL_NONE;
|
||||
|
||||
devicePtr->CreateRasterizerState(&rasterDesc, &m_RasterizerStates[static_cast<int>(CullMode::None)]);
|
||||
}
|
||||
|
||||
void ShadowDiffuse::SetShadowMap(ID3D11ShaderResourceView *shadowMapSRV) {
|
||||
m_ShadowMapVariablePtr->SetResource(shadowMapSRV);
|
||||
}
|
||||
|
||||
void ShadowDiffuse::SetLightViewProjMatrix(Matrix matrix) {
|
||||
m_LightWorldViewProjVariablePtr->SetMatrix(reinterpret_cast<const float *>(&matrix));
|
||||
}
|
||||
|
||||
void ShadowDiffuse::SetLightDirection(Vector3 direction) {
|
||||
m_LightDirectionVariablePtr->SetFloatVector(reinterpret_cast<const float *>(&direction));
|
||||
}
|
||||
|
||||
void ShadowDiffuse::SetLightColor(ColorRGB rgb) {
|
||||
m_LightColorVariablePtr->SetFloatVector(reinterpret_cast<const float *>(&rgb));
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseEffect.h"
|
||||
#include "Effect.h"
|
||||
#include <array>
|
||||
|
||||
class ShadowDiffuse final: public BaseEffect {
|
||||
public:
|
||||
ShadowDiffuse(ID3D11Device *devicePtr, const std::wstring &filePath);
|
||||
|
||||
virtual ~ShadowDiffuse() override;
|
||||
|
||||
void SetWorldMatrix(const dae::Matrix &world) const override;
|
||||
|
||||
void SetCameraPos(const dae::Vector3 &pos) const override;
|
||||
|
||||
void SetMaterial(Material *material) override;
|
||||
|
||||
void ToggleNormals() override;
|
||||
|
||||
void NextSamplingState() override;
|
||||
|
||||
void NextCullMode() override;
|
||||
|
||||
void SetShadowMap(ID3D11ShaderResourceView* shadowMapSRV);
|
||||
|
||||
void SetLightViewProjMatrix(Matrix matrix);
|
||||
|
||||
void SetLightDirection(Vector3 direction);
|
||||
|
||||
void SetLightColor(ColorRGB rgb);
|
||||
|
||||
private:
|
||||
void InitSamplers(ID3D11Device* devicePtr);
|
||||
void InitRasterizer(ID3D11Device* devicePtr);
|
||||
|
||||
ID3DX11EffectMatrixVariable *m_MatWorldVariablePtr{};
|
||||
|
||||
ID3DX11EffectShaderResourceVariable *m_DiffuseMapVariablePtr{};
|
||||
ID3DX11EffectShaderResourceVariable *m_NormalMapVariablePtr{};
|
||||
ID3DX11EffectShaderResourceVariable *m_SpecularMapVariablePtr{};
|
||||
ID3DX11EffectShaderResourceVariable *m_GlossMapVariablePtr{};
|
||||
|
||||
ID3DX11EffectVectorVariable *m_CameraPosVariablePtr{};
|
||||
ID3DX11EffectVectorVariable *m_LightPosVariablePtr{};
|
||||
ID3DX11EffectVectorVariable *m_LightColorVariablePtr{};
|
||||
ID3DX11EffectVectorVariable *m_LightDirectionVariablePtr{};
|
||||
|
||||
ID3DX11EffectScalarVariable *m_UseNormalMapVariablePtr{};
|
||||
|
||||
ID3DX11EffectSamplerVariable *m_SamplerVariablePtr{};
|
||||
|
||||
ID3DX11EffectRasterizerVariable* m_RasterizerVariablePtr{};
|
||||
|
||||
ID3DX11EffectMatrixVariable* m_LightWorldViewProjVariablePtr{};
|
||||
|
||||
ID3DX11EffectShaderResourceVariable* m_ShadowMapVariablePtr{};
|
||||
|
||||
TechniqueType m_TechniqueType{TechniqueType::Linear};
|
||||
|
||||
std::array<ID3D11SamplerState*, 3> m_SamplerStates{};
|
||||
std::array<ID3D11RasterizerState*, 3> m_RasterizerStates{};
|
||||
|
||||
CullMode m_CullMode{ CullMode::Back };
|
||||
|
||||
bool m_UseNormalMap{true};
|
||||
};
|
||||
@@ -42,23 +42,3 @@ void ShadowEffect::SetShadowMapSampler(ID3D11SamplerState *samplerState) {
|
||||
}
|
||||
}
|
||||
|
||||
ShadowEffect::~ShadowEffect() {
|
||||
if (m_LightWorldViewProjVariable) {
|
||||
m_LightWorldViewProjVariable->Release();
|
||||
m_LightWorldViewProjVariable = nullptr;
|
||||
}
|
||||
|
||||
if (m_ShadowMapVariable) {
|
||||
m_ShadowMapVariable->Release();
|
||||
m_ShadowMapVariable = nullptr;
|
||||
}
|
||||
|
||||
if (m_ShadowMapSamplerVariable) {
|
||||
m_ShadowMapSamplerVariable->Release();
|
||||
m_ShadowMapSamplerVariable = nullptr;
|
||||
}
|
||||
|
||||
m_EffectPtr->Release();
|
||||
m_EffectPtr = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,12 @@ class ShadowEffect : public BaseEffect {
|
||||
public:
|
||||
ShadowEffect(ID3D11Device* devicePtr, const std::wstring& filePath);
|
||||
|
||||
~ShadowEffect() override;
|
||||
~ShadowEffect() override = default;
|
||||
|
||||
void SetLightWorldViewProjMatrix(const dae::Matrix& matrix);
|
||||
|
||||
void SetShadowMap(ID3D11ShaderResourceView* shadowMapSRV);
|
||||
|
||||
void SetShadowMapSampler(ID3D11SamplerState* samplerState);
|
||||
|
||||
private:
|
||||
|
||||
@@ -2,17 +2,16 @@
|
||||
#define GP1_DIRECTX_GAMEPADCONTROLLER_H
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
#include "SDL_gamecontroller.h"
|
||||
#include "SDL.h"
|
||||
|
||||
|
||||
struct GamePad{
|
||||
std::array<bool, SDL_CONTROLLER_BUTTON_MAX> buttons{false};
|
||||
std::array<float, SDL_CONTROLLER_AXIS_MAX> axis{0.0f};
|
||||
bool buttons[SDL_CONTROLLER_BUTTON_MAX];
|
||||
float axis[SDL_CONTROLLER_AXIS_MAX];
|
||||
|
||||
std::array<bool, SDL_CONTROLLER_BUTTON_MAX> prevButtons{ false };
|
||||
bool prevButtons[SDL_CONTROLLER_BUTTON_MAX]{ false };
|
||||
};
|
||||
|
||||
enum class GamePadButton {
|
||||
@@ -43,7 +42,7 @@ enum class GamePadButton {
|
||||
|
||||
enum Controllers {PLAYER1, PLAYER2, PLAYER3, PLAYER4};
|
||||
|
||||
class GamePadController final {
|
||||
class GamePadController {
|
||||
public:
|
||||
|
||||
static GamePadController& GetInstance()
|
||||
@@ -67,6 +66,7 @@ private:
|
||||
GamePadController();
|
||||
std::vector<SDL_GameController*> m_pGameControllers;
|
||||
std::vector<GamePad> m_GamePads;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "HitTest.h"
|
||||
|
||||
|
||||
|
||||
float CrossZ(const Vector3& p0, const Vector3& p1, const Vector3& point)
|
||||
{
|
||||
return (p1.x - p0.x) * (point.y - p0.y)
|
||||
@@ -68,3 +70,4 @@ std::optional<Sample> TriangleHitTest(const Vector3& fragPos, const VertexOut& v
|
||||
.mesh = v0.mesh
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,11 @@
|
||||
#include "Math/Vector3.h"
|
||||
#include "Math/Vector2.h"
|
||||
#include "Mesh.h"
|
||||
#include "Effects/Effect.h"
|
||||
|
||||
using namespace dae;
|
||||
|
||||
|
||||
struct Sample final
|
||||
struct Sample
|
||||
{
|
||||
Vector2 uv{};
|
||||
Vector3 normal{};
|
||||
@@ -24,6 +23,6 @@ struct Sample final
|
||||
};
|
||||
|
||||
|
||||
std::optional<Sample> TriangleHitTest(const Vector3 &fragPos, const VertexOut &v0, const VertexOut &v1, const VertexOut &v2);
|
||||
std::optional<Sample> TriangleHitTest(const Vector3& fragPos, const VertexOut& v0, const VertexOut& v1, const VertexOut& v2);
|
||||
|
||||
#endif //GP1_DIRECTX_HITTEST_H
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include "InstancedMesh.h"
|
||||
|
||||
InstancedMesh::InstancedMesh(ID3D11Device *devicePtr, const std::vector<VertexIn> &verticesIn, const std::vector<Uint32> &indices,
|
||||
std::shared_ptr<Material> material, std::unique_ptr<BaseEffect> effectPtr, const std::vector<InstancedData> &instanceData)
|
||||
: m_EffectPtr(std::move(effectPtr)),
|
||||
std::shared_ptr<Material> material, BaseEffect *effectPtr, const std::vector<InstancedData> &instanceData)
|
||||
: m_EffectPtr(effectPtr),
|
||||
m_InputLayoutPtr(nullptr),
|
||||
m_VertexBufferPtr(nullptr),
|
||||
m_IndexBufferPtr(nullptr),
|
||||
@@ -152,6 +152,9 @@ InstancedMesh::~InstancedMesh() {
|
||||
m_InstanceBufferPtr = nullptr;
|
||||
}
|
||||
|
||||
delete m_EffectPtr;
|
||||
m_EffectPtr = nullptr;
|
||||
|
||||
m_Material.reset();
|
||||
|
||||
m_InstancedData.clear();
|
||||
|
||||
@@ -13,10 +13,10 @@ struct alignas(16) InstancedData {
|
||||
Vector4 color;
|
||||
};
|
||||
|
||||
class InstancedMesh final {
|
||||
class InstancedMesh {
|
||||
public:
|
||||
InstancedMesh(ID3D11Device *devicePtr, const std::vector<VertexIn> &verticesIn, const std::vector<Uint32> &indices,
|
||||
std::shared_ptr<Material> material, std::unique_ptr<BaseEffect> effectPtr, const std::vector<InstancedData>& instanceData);
|
||||
std::shared_ptr<Material> material, BaseEffect* effectPtr, const std::vector<InstancedData>& instanceData);
|
||||
|
||||
~InstancedMesh();
|
||||
|
||||
@@ -26,6 +26,7 @@ public:
|
||||
|
||||
Matrix GetWorldMatrix() const;
|
||||
|
||||
|
||||
Material* GetMaterial() const;
|
||||
|
||||
void SetWorldMatrix(const Matrix &matrix);
|
||||
@@ -39,7 +40,7 @@ public:
|
||||
void UpdateInstanceData(ID3D11DeviceContext* deviceContextPtr, const std::vector<InstancedData>& instanceData);
|
||||
|
||||
private:
|
||||
std::unique_ptr<BaseEffect> m_EffectPtr;
|
||||
BaseEffect *m_EffectPtr;
|
||||
|
||||
Matrix m_WorldMatrix{};
|
||||
|
||||
|
||||
45
project/src/Light.cpp
Normal file
45
project/src/Light.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "Light.h"
|
||||
#include <cmath>
|
||||
|
||||
Light::Light()
|
||||
: m_Position(0.0f, 10.0f, 0.0f),
|
||||
m_Target(0.0f, 0.0f, 0.0f),
|
||||
m_Up(0.0f, 1.0f, 0.0f),
|
||||
m_ViewMatrix(dae::Matrix()),
|
||||
m_ProjectionMatrix(dae::Matrix()) {}
|
||||
|
||||
void Light::SetPosition(const dae::Vector3 &position) {
|
||||
m_Position = position;
|
||||
}
|
||||
|
||||
void Light::SetTarget(const dae::Vector3 &target) {
|
||||
m_Target = target;
|
||||
}
|
||||
|
||||
void Light::SetUp(const dae::Vector3 &up) {
|
||||
m_Up = up;
|
||||
}
|
||||
|
||||
dae::Matrix Light::GetViewMatrix() const {
|
||||
return dae::Matrix::CreateLookAtLH(m_Position, m_Target, m_Up);
|
||||
}
|
||||
|
||||
dae::Matrix Light::GetProjectionMatrix(float nearPlane, float farPlane, float size) const {
|
||||
return dae::Matrix::CreateOrthographic(size, size, nearPlane, farPlane);
|
||||
}
|
||||
dae::Matrix Light::GetViewProjectionMatrix(float nearPlane, float farPlane, float size) const {
|
||||
return GetViewMatrix() * GetProjectionMatrix(nearPlane, farPlane, size);
|
||||
}
|
||||
void Light::Update() {
|
||||
// If the light position or target changes dynamically, this is where updates would be managed.
|
||||
// m_ViewMatrix = dae::Matrix::CreateLookAtLH(m_Position, m_Target, m_Up);
|
||||
// m_ProjectionMatrix = dae::Matrix::CreateOrthographic(size, size, nearPlane, farPlane);
|
||||
}
|
||||
|
||||
dae::Vector3 Light::GetTarget() {
|
||||
return m_Target;
|
||||
}
|
||||
|
||||
dae::Vector3 Light::GetPosition() {
|
||||
return m_Position;
|
||||
}
|
||||
@@ -1,20 +1,18 @@
|
||||
#ifndef GP1_DIRECTX_DIRECTIONALLIGHT_H
|
||||
#define GP1_DIRECTX_DIRECTIONALLIGHT_H
|
||||
#ifndef GP1_DIRECTX_LIGHT_H
|
||||
#define GP1_DIRECTX_LIGHT_H
|
||||
|
||||
|
||||
#include "Math/Vector3.h"
|
||||
#include "Math/Matrix.h"
|
||||
#include "ColorRGB.h"
|
||||
|
||||
class DirectionalLight {
|
||||
class Light {
|
||||
public:
|
||||
DirectionalLight();
|
||||
~DirectionalLight() = default;
|
||||
Light();
|
||||
~Light() = default;
|
||||
|
||||
void SetPosition(const dae::Vector3 &position);
|
||||
void SetTarget(const dae::Vector3 &target);
|
||||
void SetUp(const dae::Vector3 &up);
|
||||
void SetColor(const dae::ColorRGB &color);
|
||||
|
||||
dae::Matrix GetViewMatrix() const;
|
||||
dae::Matrix GetProjectionMatrix(float nearPlane = 0.1f, float farPlane = 100.0f, float size = 50.0f) const;
|
||||
@@ -24,17 +22,13 @@ public:
|
||||
|
||||
dae::Vector3 GetTarget();
|
||||
dae::Vector3 GetPosition();
|
||||
dae::Vector3 GetDirection() const;
|
||||
dae::ColorRGB GetColor() const;
|
||||
private:
|
||||
dae::Vector3 m_Position;
|
||||
dae::Vector3 m_Target;
|
||||
dae::Vector3 m_Up;
|
||||
|
||||
dae::ColorRGB m_Color{1.f, 1.f, 1.f};
|
||||
|
||||
dae::Matrix m_ViewMatrix;
|
||||
dae::Matrix m_ProjectionMatrix;
|
||||
};
|
||||
|
||||
#endif //GP1_DIRECTX_DIRECTIONALLIGHT_H
|
||||
#endif //GP1_DIRECTX_LIGHT_H
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "Texture.h"
|
||||
|
||||
struct Material final {
|
||||
struct Material {
|
||||
Texture *diffuseTexturePtr{nullptr};
|
||||
Texture *normalTexturePtr{nullptr};
|
||||
Texture *specularTexturePtr{nullptr};
|
||||
|
||||
@@ -282,6 +282,7 @@ namespace dae {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
const Matrix& Matrix::operator*=(const Matrix& m)
|
||||
{
|
||||
Matrix copy{ *this };
|
||||
@@ -302,12 +303,12 @@ namespace dae {
|
||||
data[3] = {vector3, 1};
|
||||
}
|
||||
|
||||
Matrix Matrix::CreateOrthographic(float width, float height, float zn, float zf) {
|
||||
Matrix Matrix::CreateOrthographic(float size, float size1, float nearPlane, float farPlane) {
|
||||
return Matrix(
|
||||
{2.f / width, 0, 0, 0},
|
||||
{0, 2.f / height, 0, 0},
|
||||
{0, 0, 1.f / (zf - zn), 0},
|
||||
{0, 0, -zn / (zf - zn), 1}
|
||||
{2.f / size, 0, 0, 0},
|
||||
{0, 2.f / size1, 0, 0},
|
||||
{0, 0, 1.f / (farPlane - nearPlane), 0},
|
||||
{0, 0, -nearPlane / (farPlane - nearPlane), 1}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,9 @@ namespace dae {
|
||||
|
||||
static Matrix CreateLookAtLH(const Vector3& origin, const Vector3& forward, const Vector3& up);
|
||||
static Matrix CreatePerspectiveFovLH(float fovy, float aspect, float zn, float zf);
|
||||
static Matrix CreateOrthographic(float width, float height, float zn, float zf);
|
||||
|
||||
|
||||
|
||||
Vector4& operator[](int index);
|
||||
Vector4 operator[](int index) const;
|
||||
Matrix operator*(const Matrix& m) const;
|
||||
@@ -58,6 +60,8 @@ namespace dae {
|
||||
|
||||
void SetTranslation(Vector3 vector3);
|
||||
|
||||
static dae::Matrix CreateOrthographic(float size, float size1, float plane, float plane1);
|
||||
|
||||
private:
|
||||
|
||||
//Row-Major Matrix
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
#include "Effects/Effect.h"
|
||||
|
||||
Mesh::Mesh(ID3D11Device *devicePtr, const std::vector<VertexIn> &verticesIn, const std::vector<Uint32> &indices, std::shared_ptr<Material> material, std::unique_ptr<BaseEffect> effectPtr) :
|
||||
m_EffectPtr(std::move(effectPtr)),
|
||||
Mesh::Mesh(ID3D11Device *devicePtr, const std::vector<VertexIn> &verticesIn, const std::vector<Uint32> &indices, std::shared_ptr<Material> material, BaseEffect* effectPtr) :
|
||||
m_EffectPtr(effectPtr),
|
||||
m_InputLayoutPtr(nullptr),
|
||||
m_VertexBufferPtr(nullptr),
|
||||
m_IndexBufferPtr(nullptr),
|
||||
@@ -91,6 +91,8 @@ Mesh::~Mesh() {
|
||||
m_IndexBufferPtr->Release();
|
||||
m_IndexBufferPtr = nullptr;
|
||||
|
||||
delete m_EffectPtr;
|
||||
m_EffectPtr = nullptr;
|
||||
}
|
||||
|
||||
void Mesh::Render(ID3D11DeviceContext *deviceContextPtr, const Matrix &worldViewProj) const {
|
||||
@@ -139,3 +141,7 @@ void Mesh::SetMaterial(Material *pMaterial) {
|
||||
void Mesh::CycleCullMode() {
|
||||
m_EffectPtr->NextCullMode();
|
||||
}
|
||||
|
||||
BaseEffect *Mesh::GetEffect() {
|
||||
return m_EffectPtr;
|
||||
}
|
||||
|
||||
@@ -19,10 +19,12 @@ enum class PrimitiveTopology {
|
||||
};
|
||||
|
||||
|
||||
class Mesh final {
|
||||
|
||||
|
||||
class Mesh {
|
||||
public:
|
||||
Mesh(ID3D11Device *devicePtr, const std::vector<VertexIn> &verticesIn, const std::vector<Uint32> &indices,
|
||||
std::shared_ptr<Material> material, std::unique_ptr<BaseEffect> effectPtr);
|
||||
std::shared_ptr<Material> material, BaseEffect* effectPtr);
|
||||
|
||||
~Mesh();
|
||||
|
||||
@@ -51,8 +53,10 @@ public:
|
||||
void SetShouldRender(bool shouldRender) { m_ShouldRender = shouldRender; }
|
||||
bool GetShouldRender() const { return m_ShouldRender; }
|
||||
|
||||
BaseEffect *GetEffect();
|
||||
|
||||
private:
|
||||
std::unique_ptr<BaseEffect> m_EffectPtr;
|
||||
BaseEffect *m_EffectPtr;
|
||||
|
||||
Matrix m_WorldMatrix{};
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
//
|
||||
// Created by Bram on 16/01/2025.
|
||||
//
|
||||
|
||||
#ifndef GP1_DIRECTX_RENDERSETTINGS_H
|
||||
#define GP1_DIRECTX_RENDERSETTINGS_H
|
||||
|
||||
#include "Singleton.h"
|
||||
|
||||
class RenderSettings : public Singleton<RenderSettings> {
|
||||
public:
|
||||
void setWidth(int w) { width = w; }
|
||||
void setHeight(int h) { height = h; }
|
||||
int getWidth() const { return width; }
|
||||
int getHeight() const { return height; }
|
||||
|
||||
private:
|
||||
friend class Singleton<RenderSettings>;
|
||||
RenderSettings() : width(1920), height(1080) {} // Default values
|
||||
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
|
||||
#endif //GP1_DIRECTX_RENDERSETTINGS_H
|
||||
@@ -4,13 +4,13 @@
|
||||
#include "Utils.h"
|
||||
#include "Texture.h"
|
||||
#include "Effects/Effect.h"
|
||||
#include "Effects/FireEffect.h"
|
||||
#include "HitTest.h"
|
||||
#include "Scenes/MainScene.h"
|
||||
#include "Scenes/DioramaScene.h"
|
||||
#include "Scenes/InstancedScene.h"
|
||||
#include "Scenes/PlanetScene.h"
|
||||
#include "Scenes/ShadowTestScene.h"
|
||||
#include "BRDF.h"
|
||||
|
||||
|
||||
namespace dae {
|
||||
@@ -37,14 +37,14 @@ namespace dae {
|
||||
|
||||
InitializeSDLRasterizer();
|
||||
|
||||
m_pScene = std::make_unique<ShadowTestScene>();
|
||||
m_pScene = new ShadowTestScene();
|
||||
m_pScene->Initialize(m_DevicePtr, m_DeviceContextPtr, nullptr);
|
||||
|
||||
if (!m_pScene->GetMeshes().empty()) {
|
||||
m_pFireMesh = m_pScene->GetMeshes().back().get();
|
||||
m_pFireMesh = m_pScene->GetMeshes().back();
|
||||
}
|
||||
|
||||
const float aspectRatio = static_cast<float>(m_Width) / static_cast<float>(m_Height);
|
||||
float aspectRatio = static_cast<float>(m_Width) / static_cast<float>(m_Height);
|
||||
m_Camera = Camera({.0f, .0f, .0f}, 45.f);
|
||||
m_Camera.Initialize(45.f, {.0f, .0f, .0f}, aspectRatio);
|
||||
}
|
||||
@@ -67,6 +67,7 @@ namespace dae {
|
||||
m_DevicePtr->Release();
|
||||
|
||||
m_pScene->Cleanup();
|
||||
delete m_pScene;
|
||||
//SDL
|
||||
|
||||
SDL_FreeSurface(m_pBackBuffer);
|
||||
@@ -79,7 +80,7 @@ namespace dae {
|
||||
void Renderer::Update(const Timer *pTimer) {
|
||||
m_Camera.Update(pTimer);
|
||||
|
||||
for (auto& mesh: m_pScene->GetMeshes()) {
|
||||
for (auto mesh: m_pScene->GetMeshes()) {
|
||||
mesh->SetCameraPos(m_Camera.GetPosition());
|
||||
}
|
||||
if (m_Rotating) {
|
||||
@@ -89,7 +90,7 @@ namespace dae {
|
||||
|
||||
Matrix rotationMatrix = Matrix::CreateRotationY(rotationThisFrame);
|
||||
|
||||
for (auto& mesh: m_pScene->GetMeshes()) {
|
||||
for (auto mesh: m_pScene->GetMeshes()) {
|
||||
Matrix originalWorldMatrix = mesh->GetWorldMatrix();
|
||||
Matrix world = rotationMatrix * originalWorldMatrix;
|
||||
|
||||
@@ -112,30 +113,52 @@ namespace dae {
|
||||
}
|
||||
|
||||
void Renderer::RenderDirectX() const {
|
||||
//Clear back buffer
|
||||
ColorRGB ChosenClearColor = m_UseUniformClearColor ? m_UniformClearColor : DirectXClearColor;
|
||||
const float clearColor[] = {static_cast<float>(ChosenClearColor.r) / 255.f, static_cast<float>(ChosenClearColor.g) / 255.f,
|
||||
static_cast<float>(ChosenClearColor.b) / 255.f, 1.f};
|
||||
// Clear back buffer
|
||||
ColorRGB chosenClearColor = m_UseUniformClearColor ? m_UniformClearColor : DirectXClearColor;
|
||||
const float clearColor[] = {
|
||||
static_cast<float>(chosenClearColor.r) / 255.f,
|
||||
static_cast<float>(chosenClearColor.g) / 255.f,
|
||||
static_cast<float>(chosenClearColor.b) / 255.f,
|
||||
1.0f
|
||||
};
|
||||
|
||||
m_DeviceContextPtr->ClearRenderTargetView(m_RenderTargetViewPtr, clearColor);
|
||||
|
||||
// Clear depth and stencil buffer
|
||||
m_DeviceContextPtr->ClearDepthStencilView(m_DepthStencilViewPtr, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
|
||||
|
||||
// Set viewport
|
||||
D3D11_VIEWPORT viewport = {};
|
||||
viewport.TopLeftX = 0.0f;
|
||||
viewport.TopLeftY = 0.0f;
|
||||
viewport.Width = static_cast<float>(m_Width);
|
||||
viewport.Height = static_cast<float>(m_Height);
|
||||
viewport.MinDepth = 0.0f;
|
||||
viewport.MaxDepth = 1.0f;
|
||||
m_DeviceContextPtr->RSSetViewports(1, &viewport);
|
||||
|
||||
// Set camera matrix
|
||||
Matrix viewProjMatrix = m_Camera.GetViewProjectionMatrix();
|
||||
for (auto& mesh: m_pScene->GetMeshes()) {
|
||||
if (mesh->GetShouldRender()) {
|
||||
Matrix modelMatrix = mesh->GetWorldMatrix();
|
||||
Matrix worldViewProjMatrix = modelMatrix * viewProjMatrix;
|
||||
|
||||
mesh->Render(m_DeviceContextPtr, worldViewProjMatrix);
|
||||
}
|
||||
}
|
||||
// Render all meshes in the scene
|
||||
// for (auto mesh : m_pScene->GetMeshes()) {
|
||||
// if (mesh->GetShouldRender()) {
|
||||
// Matrix modelMatrix = mesh->GetWorldMatrix();
|
||||
// Matrix worldViewProjMatrix = modelMatrix * viewProjMatrix;
|
||||
//
|
||||
// mesh->Render(m_DeviceContextPtr, worldViewProjMatrix);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Call additional scene render logic (e.g., shadow rendering or post-processing)
|
||||
m_pScene->Render(m_DeviceContextPtr, m_RenderTargetViewPtr, m_DepthStencilViewPtr, m_Camera);
|
||||
|
||||
//Present
|
||||
m_SwapChainPtr->Present(0, 0);
|
||||
// Present the rendered frame
|
||||
HRESULT result = m_SwapChainPtr->Present(0, 0);
|
||||
assert(SUCCEEDED(result) && "SwapChain Present failed");
|
||||
}
|
||||
|
||||
|
||||
void Renderer::RenderSDL() {
|
||||
ColorRGB ChosenClearColor = m_UseUniformClearColor ? m_UniformClearColor : m_ClearColorSoftware;
|
||||
SDL_FillRect(m_pBackBuffer, nullptr, SDL_MapRGB(m_pBackBuffer->format, ChosenClearColor.r, ChosenClearColor.g, ChosenClearColor.b));
|
||||
@@ -149,8 +172,8 @@ namespace dae {
|
||||
m_VerticiesScreenSpace.clear();
|
||||
|
||||
|
||||
for (auto& currentMeshUP: m_pScene->GetMeshes()) {
|
||||
Mesh* currentMesh = currentMeshUP.get();
|
||||
for (auto *currentMesh: m_pScene->GetMeshes()) {
|
||||
|
||||
if (!currentMesh->GetShouldRender()) {
|
||||
continue;
|
||||
}
|
||||
@@ -200,12 +223,14 @@ namespace dae {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
const float minX{std::min(vertex0.position.x, std::min(vertex1.position.x, vertex2.position.x))};
|
||||
const float minY{std::min(vertex0.position.y, std::min(vertex1.position.y, vertex2.position.y))};
|
||||
|
||||
const float maxX{std::max(vertex0.position.x, std::max(vertex1.position.x, vertex2.position.x))};
|
||||
const float maxY{std::max(vertex0.position.y, std::max(vertex1.position.y, vertex2.position.y))};
|
||||
|
||||
|
||||
const Vector3 side1{vertex1.position - vertex0.position};
|
||||
const Vector3 side2{vertex2.position - vertex0.position};
|
||||
|
||||
@@ -281,7 +306,6 @@ namespace dae {
|
||||
SDL_UpdateWindowSurface(m_pWindow);
|
||||
}
|
||||
|
||||
|
||||
HRESULT Renderer::InitializeDirectX() {
|
||||
//1. Create device & deviceContext
|
||||
//=====
|
||||
@@ -441,7 +465,6 @@ namespace dae {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Renderer::ToggleDepthBuffer() {
|
||||
m_isDepthBuffer = !m_isDepthBuffer;
|
||||
|
||||
@@ -534,10 +557,8 @@ namespace dae {
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Renderer::CycleCullMode() {
|
||||
for (auto& mesh: m_pScene->GetMeshes()) {
|
||||
for (auto mesh: m_pScene->GetMeshes()) {
|
||||
mesh->CycleCullMode();
|
||||
}
|
||||
|
||||
@@ -606,7 +627,7 @@ namespace dae {
|
||||
}
|
||||
|
||||
void Renderer::NextSamplingState() {
|
||||
for (auto& mesh: m_pScene->GetMeshes()) {
|
||||
for (auto mesh: m_pScene->GetMeshes()) {
|
||||
mesh->NextSamplingState();
|
||||
}
|
||||
|
||||
@@ -631,7 +652,7 @@ namespace dae {
|
||||
|
||||
void Renderer::ToggleNormals() {
|
||||
m_useNormals = !m_useNormals;
|
||||
for (auto& mesh: m_pScene->GetMeshes()) {
|
||||
for (auto mesh: m_pScene->GetMeshes()) {
|
||||
mesh->ToggleNormals();
|
||||
}
|
||||
std::string mode = m_useNormals ? "ON" : "OFF";
|
||||
@@ -660,6 +681,7 @@ namespace dae {
|
||||
|
||||
void Renderer::NextScene() {
|
||||
m_pScene->Cleanup();
|
||||
delete m_pScene;
|
||||
|
||||
//Calculate the next scene
|
||||
int index = static_cast<int>(m_CurrentScene);
|
||||
@@ -668,38 +690,32 @@ namespace dae {
|
||||
|
||||
switch (m_CurrentScene) {
|
||||
case SceneNames::Main:
|
||||
m_pScene = std::make_unique<MainScene>();
|
||||
m_pScene = new MainScene();
|
||||
m_pFireMesh = nullptr;
|
||||
|
||||
std::cout << MAGENTA << "[SHARED]" << BLUE << " Scene = Main" << RESET << std::endl;
|
||||
std::cout << MAGENTA << "This could take a second" << RESET << std::endl;
|
||||
break;
|
||||
case SceneNames::Diorama:
|
||||
m_pScene = std::make_unique<DioramaScene>();
|
||||
m_pScene = new DioramaScene();
|
||||
|
||||
std::cout << MAGENTA << "[SHARED]" << BLUE << " Scene = Diorama" << RESET << std::endl;
|
||||
std::cout << MAGENTA << "This could take a second" << RESET << std::endl;
|
||||
break;
|
||||
case SceneNames::Instanced:
|
||||
m_pScene = std::make_unique<InstancedScene>();
|
||||
m_pScene = new InstancedScene();
|
||||
|
||||
std::cout << MAGENTA << "[SHARED]" << BLUE << " Scene = Instanced" << RESET << std::endl;
|
||||
std::cout << MAGENTA << "This could take a second" << RESET << std::endl;
|
||||
break;
|
||||
|
||||
case SceneNames::Planet:
|
||||
m_pScene = std::make_unique<PlanetScene>();
|
||||
m_pScene = new PlanetScene();
|
||||
|
||||
std::cout << MAGENTA << "[SHARED]" << BLUE << " Scene = Planet" << RESET << std::endl;
|
||||
std::cout << MAGENTA << "This could take a second" << RESET << std::endl;
|
||||
break;
|
||||
|
||||
case SceneNames::ShadowTest:
|
||||
m_pScene = std::make_unique<ShadowTestScene>();
|
||||
|
||||
std::cout << MAGENTA << "[SHARED]" << BLUE << " Scene = ShadowTest" << RESET << std::endl;
|
||||
std::cout << MAGENTA << "This could take a second" << RESET << std::endl;
|
||||
|
||||
case SceneNames::Count:
|
||||
break;
|
||||
}
|
||||
@@ -712,7 +728,7 @@ namespace dae {
|
||||
|
||||
if (m_CurrentScene == SceneNames::Main) {
|
||||
//Kind of sloppy fix but hey :p
|
||||
m_pFireMesh = m_pScene->GetMeshes().back().get();
|
||||
m_pFireMesh = m_pScene->GetMeshes().back();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "HitTest.h"
|
||||
#include "Scenes/BaseScene.h"
|
||||
#include "Effects/Effect.h"
|
||||
#include "Buffers/ShadowMapBuffer.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -28,7 +29,6 @@ enum class SceneNames{
|
||||
Diorama,
|
||||
Instanced,
|
||||
Planet,
|
||||
ShadowTest,
|
||||
|
||||
Count
|
||||
};
|
||||
@@ -80,7 +80,7 @@ namespace dae
|
||||
|
||||
Backendtype m_backendType{ Backendtype::DirectX };
|
||||
|
||||
std::unique_ptr<BaseScene> m_pScene{};
|
||||
BaseScene* m_pScene{};
|
||||
SceneNames m_CurrentScene{ SceneNames::Main };
|
||||
//Pos rot
|
||||
std::unordered_map<SceneNames, std::pair<Vector3, Vector3>> m_SceneCameraPositions{};
|
||||
@@ -91,7 +91,10 @@ namespace dae
|
||||
float m_currentRotation{};
|
||||
bool m_UseUniformClearColor{ false };
|
||||
|
||||
const ColorRGB m_UniformClearColor{ ColorRGB{0.1f * 255.f, 0.1f * 255.f, 0.1 * 255.f} };
|
||||
ColorRGB m_UniformClearColor{ ColorRGB{0.1f * 255.f, 0.1f * 255.f, 0.1 * 255.f} };
|
||||
|
||||
ShadowMapBuffer* m_pShadowMapBuffer{};
|
||||
dae::Matrix m_LightViewProjectionMatrix{};
|
||||
|
||||
|
||||
//DirectX vars
|
||||
@@ -101,7 +104,7 @@ namespace dae
|
||||
HRESULT InitializeDirectX();
|
||||
void RenderDirectX() const;
|
||||
|
||||
const ColorRGB DirectXClearColor{ .39f * 255.f, .59f * 255.f, .93f * 255.f };
|
||||
ColorRGB DirectXClearColor{ .39f * 255.f, .59f * 255.f, .93f * 255.f };
|
||||
|
||||
//Storing the mesh so i can deactivate it;
|
||||
Mesh* m_pFireMesh{};
|
||||
@@ -135,7 +138,7 @@ namespace dae
|
||||
bool m_isDepthBuffer{ false };
|
||||
|
||||
|
||||
const ColorRGB m_ClearColorSoftware{ .39f * 255.f, .39f * 255.f, .39f * 255.f };
|
||||
ColorRGB m_ClearColorSoftware{ .39f * 255.f, .39f * 255.f, .39f * 255.f };
|
||||
|
||||
float* m_pDepthBufferPixels{};
|
||||
|
||||
|
||||
@@ -25,8 +25,9 @@ public:
|
||||
|
||||
virtual void Cleanup() = 0;
|
||||
|
||||
virtual std::vector<std::unique_ptr<Mesh>>& GetMeshes() = 0;
|
||||
virtual std::vector<Mesh*>& GetMeshes() = 0;
|
||||
virtual std::vector<std::shared_ptr<Material>>& GetMaterials() = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -15,20 +15,19 @@ void DioramaScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *Devi
|
||||
std::vector<std::unique_ptr<Utils::MaterialMesh>> materialMeshes;
|
||||
Utils::LoadObjWithMaterials("resources/scene.obj", materialMeshes, true, DevicePtr);
|
||||
for (const auto &mesh: materialMeshes) {
|
||||
if (!mesh->vertices.empty()) {
|
||||
if (mesh->vertices.size() > 0) {
|
||||
std::shared_ptr<Material> material = std::make_shared<Material>();
|
||||
std::unique_ptr<BaseEffect> effect{};
|
||||
BaseEffect *effect{nullptr};
|
||||
|
||||
if (!mesh->opacity_map.empty()) {
|
||||
effect = std::make_unique<FireEffect>(DevicePtr, L"resources/Fire.fx");
|
||||
if (mesh->opacity_map != "") {
|
||||
effect = new FireEffect(DevicePtr, L"resources/Fire.fx");
|
||||
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/diorama/" + mesh->diffuse_texture, DevicePtr);
|
||||
} else {
|
||||
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/diorama/" + mesh->diffuse_texture, DevicePtr);
|
||||
effect = std::make_unique<Effect>(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||
effect = new Effect(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||
}
|
||||
auto newMesh = std::make_unique<Mesh>(DevicePtr, mesh->vertices, mesh->indices, material, std::move(effect));
|
||||
m_meshes.push_back(std::move(newMesh));
|
||||
|
||||
m_meshes.push_back(new Mesh(DevicePtr, mesh->vertices, mesh->indices, material, effect));
|
||||
|
||||
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||
worldMatrix *= Matrix::CreateScale(2.f, 2.f, 2.f);
|
||||
@@ -43,15 +42,13 @@ void DioramaScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *Devi
|
||||
for (const auto &mesh: materialMeshes) {
|
||||
if (!mesh->vertices.empty()) {
|
||||
std::shared_ptr<Material> material = std::make_shared<Material>();
|
||||
auto effect = std::make_unique<Effect>(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||
BaseEffect *effect{nullptr};
|
||||
|
||||
effect = new Effect(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/brok/" + mesh->diffuse_texture, DevicePtr);
|
||||
|
||||
|
||||
auto brokMesh = std::make_unique<Mesh>(DevicePtr, mesh->vertices, mesh->indices, material, std::move(effect));
|
||||
m_brokMeshses.push_back(brokMesh.get());
|
||||
m_meshes.push_back(std::move(brokMesh));
|
||||
|
||||
m_meshes.push_back(new Mesh(DevicePtr, mesh->vertices, mesh->indices, material, effect));
|
||||
m_brokMeshses.push_back(m_meshes.back());
|
||||
|
||||
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||
worldMatrix *= Matrix::CreateRotationY(3.14f / 2.f);
|
||||
@@ -84,7 +81,7 @@ void DioramaScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView
|
||||
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Mesh>> &DioramaScene::GetMeshes() {
|
||||
std::vector<Mesh *> &DioramaScene::GetMeshes() {
|
||||
return m_meshes;
|
||||
}
|
||||
|
||||
@@ -93,6 +90,9 @@ std::vector<std::shared_ptr<Material>> &DioramaScene::GetMaterials() {
|
||||
}
|
||||
|
||||
void DioramaScene::Cleanup() {
|
||||
for (Mesh *mesh: m_meshes) {
|
||||
delete mesh;
|
||||
}
|
||||
m_meshes.clear();
|
||||
m_materials.clear();
|
||||
}
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
#include "BaseScene.h"
|
||||
|
||||
class DioramaScene final : public BaseScene {
|
||||
class DioramaScene : public BaseScene {
|
||||
public:
|
||||
void Cleanup() override;
|
||||
|
||||
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) override;
|
||||
|
||||
std::vector<std::unique_ptr<Mesh>> &GetMeshes() override;
|
||||
std::vector<Mesh *> &GetMeshes() override;
|
||||
|
||||
std::vector<std::shared_ptr<Material>> &GetMaterials() override;
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
void Render(ID3D11DeviceContext* devicePtr, ID3D11RenderTargetView *renderTargetViewPtr, ID3D11DepthStencilView *depthStencilViewPtr, const Camera& camera) override;
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<Mesh>> m_meshes{};
|
||||
std::vector<Mesh *> m_meshes{};
|
||||
std::vector<std::shared_ptr<Material>> m_materials{};
|
||||
|
||||
std::vector<Mesh*> m_brokMeshses{ nullptr };
|
||||
|
||||
@@ -43,9 +43,7 @@ void InstancedScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *De
|
||||
float scale = 2;
|
||||
|
||||
//use the perlin noise to generate the YOffset
|
||||
float currentTick = static_cast<float>(SDL_GetTicks());
|
||||
|
||||
float YOffset = sin(x * 0.5f +currentTick * 0.001f) + cos(y * 0.5f + currentTick * 0.001f);
|
||||
float YOffset = sin(x * 0.5f + SDL_GetTicks() * 0.001f) + cos(y * 0.5f + SDL_GetTicks() * 0.001f);
|
||||
data.worldMatrix = Matrix::CreateTranslation(x * scale, YOffset, y * scale);
|
||||
data.worldMatrix *= Matrix::CreateScale(0.5f, 0.5f, 0.5f);
|
||||
data.color = Vector4(float(x) / 255.f, float(y) / 255.f, 1.f, 1.0f);
|
||||
@@ -53,20 +51,26 @@ void InstancedScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *De
|
||||
}
|
||||
}
|
||||
|
||||
auto effect = std::make_unique<Effect>(DevicePtr, L"resources/InstancedSimpleDiffuse.fx");
|
||||
auto *effect = new Effect(DevicePtr, L"resources/InstancedSimpleDiffuse.fx");
|
||||
effect->NextSamplingState();
|
||||
effect->NextSamplingState(); //Dirty hack
|
||||
|
||||
auto cubeMesh = std::make_unique<InstancedMesh>(DevicePtr, vertices, indices, cubeMaterial, std::move(effect), instanceData);
|
||||
m_instancedMeshes.push_back(std::move(cubeMesh));
|
||||
m_instancedMeshes.push_back(new InstancedMesh(DevicePtr, vertices, indices, cubeMaterial, effect, instanceData));
|
||||
}
|
||||
|
||||
void InstancedScene::Cleanup() {
|
||||
for (auto mesh: m_instancedMeshes) {
|
||||
delete mesh;
|
||||
}
|
||||
m_instancedMeshes.clear();
|
||||
|
||||
for (auto mesh: m_meshes) {
|
||||
delete mesh;
|
||||
}
|
||||
|
||||
m_meshes.clear();
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Mesh>> &InstancedScene::GetMeshes() {
|
||||
std::vector<Mesh *> &InstancedScene::GetMeshes() {
|
||||
return m_meshes;
|
||||
}
|
||||
|
||||
@@ -77,7 +81,7 @@ std::vector<std::shared_ptr<Material>> &InstancedScene::GetMaterials() {
|
||||
void InstancedScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView *renderTargetViewPtr,
|
||||
ID3D11DepthStencilView *depthStencilViewPtr, const Camera &camera) {
|
||||
Matrix viewProjMatrix = camera.GetViewProjectionMatrix();
|
||||
for (auto& mesh: m_instancedMeshes) {
|
||||
for (auto mesh: m_instancedMeshes) {
|
||||
Matrix modelMatrix = mesh->GetWorldMatrix();
|
||||
Matrix worldViewProjMatrix = modelMatrix * viewProjMatrix;
|
||||
mesh->Render(devicePtr, worldViewProjMatrix);
|
||||
@@ -92,9 +96,8 @@ void InstancedScene::Update() {
|
||||
InstancedData data;
|
||||
float scale = 2;
|
||||
//Generate sine wave based on x and y and the SDL_GetTicks
|
||||
float currentTick = static_cast<float>(SDL_GetTicks());
|
||||
float YOffset = sin(static_cast<float>(x) * 0.5f + currentTick * 0.001f) + cos(static_cast<float>(y) * 0.5f + currentTick * 0.001f);
|
||||
YOffset += (static_cast<float>(x) * 0.1f + static_cast<float>(y) * 0.1f) * 0.1f;
|
||||
float YOffset = sin(x * 0.5f + SDL_GetTicks() * 0.001f) + cos(y * 0.5f + SDL_GetTicks() * 0.001f);
|
||||
YOffset += (x * 0.1f + y * 0.1f) * 0.1f;
|
||||
|
||||
data.worldMatrix = Matrix::CreateTranslation(x * scale, YOffset, y * scale);
|
||||
data.worldMatrix *= Matrix::CreateScale(0.5f, 0.5f, 0.5f);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "../InstancedMesh.h"
|
||||
#include "../PerlinNoise.hpp"
|
||||
|
||||
class InstancedScene final : public BaseScene {
|
||||
class InstancedScene : public BaseScene {
|
||||
public:
|
||||
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) override;
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
|
||||
void Cleanup() override;
|
||||
|
||||
std::vector<std::unique_ptr<Mesh>> &GetMeshes() override;
|
||||
std::vector<Mesh *> &GetMeshes() override;
|
||||
|
||||
std::vector<std::shared_ptr<Material>> &GetMaterials() override;
|
||||
|
||||
@@ -24,9 +24,9 @@ private:
|
||||
|
||||
ID3D11DeviceContext* m_DeviceContextPtr{};
|
||||
|
||||
std::vector<std::unique_ptr<Mesh>> m_meshes;
|
||||
std::vector<Mesh*> m_meshes;
|
||||
//Kind of hack since InstancedMesh doesnt extend mesh
|
||||
std::vector<std::unique_ptr<InstancedMesh>> m_instancedMeshes;
|
||||
std::vector<InstancedMesh*> m_instancedMeshes;
|
||||
std::vector<std::shared_ptr<Material>> m_materials;
|
||||
|
||||
const siv::PerlinNoise::seed_type seed = 123456u;
|
||||
|
||||
@@ -26,9 +26,8 @@ void MainScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceC
|
||||
vehicleMaterial->specularTexturePtr = Texture::LoadFromFile("resources/vehicle_specular.png", DevicePtr);
|
||||
vehicleMaterial->glossTexturePtr = Texture::LoadFromFile("resources/vehicle_gloss.png", DevicePtr);
|
||||
|
||||
auto effect = std::make_unique<Effect>(DevicePtr, L"resources/PosCol3D.fx");
|
||||
auto vehicleMesh = std::make_unique<Mesh>(DevicePtr, vertices, indices, vehicleMaterial, std::move(effect));
|
||||
m_meshes.push_back(std::move(vehicleMesh));
|
||||
auto* effect = new Effect(DevicePtr, L"resources/PosCol3D.fx");
|
||||
m_meshes.push_back(new Mesh(DevicePtr, vertices, indices, vehicleMaterial, effect));
|
||||
|
||||
|
||||
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||
@@ -46,9 +45,8 @@ void MainScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceC
|
||||
std::shared_ptr<Material> FireMaterial = std::make_shared<Material>();
|
||||
FireMaterial->diffuseTexturePtr = Texture::LoadFromFile("resources/fireFX_diffuse.png", DevicePtr);
|
||||
|
||||
auto fireEffect = std::make_unique<FireEffect>(DevicePtr, L"resources/Fire.fx");
|
||||
auto fireMesh = std::make_unique<Mesh>(DevicePtr, vertices, indices, FireMaterial, std::move(fireEffect));
|
||||
m_meshes.push_back(std::move(fireMesh));
|
||||
auto* fireEffect = new FireEffect(DevicePtr, L"resources/Fire.fx");
|
||||
m_meshes.push_back(new Mesh(DevicePtr, vertices, indices, FireMaterial, fireEffect));
|
||||
|
||||
worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||
worldMatrix *= Matrix::CreateTranslation(0, 0, 50.f);
|
||||
@@ -57,10 +55,13 @@ void MainScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceC
|
||||
|
||||
|
||||
void MainScene::Cleanup() {
|
||||
for (Mesh* mesh : m_meshes) {
|
||||
delete mesh;
|
||||
}
|
||||
m_meshes.clear();
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Mesh>> &MainScene::GetMeshes() {
|
||||
std::vector<Mesh *> &MainScene::GetMeshes() {
|
||||
return m_meshes;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class MainScene final : public BaseScene {
|
||||
class MainScene : public BaseScene {
|
||||
public:
|
||||
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) override;
|
||||
|
||||
void Cleanup() override;
|
||||
|
||||
std::vector<std::unique_ptr<Mesh>> &GetMeshes() override;
|
||||
std::vector<Mesh *> &GetMeshes() override;
|
||||
|
||||
std::vector<std::shared_ptr<Material>> &GetMaterials() override;
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
std::vector<std::unique_ptr<Mesh>> m_meshes{};
|
||||
std::vector<Mesh*> m_meshes{};
|
||||
std::vector<std::shared_ptr<Material>> m_materials{};
|
||||
|
||||
};
|
||||
|
||||
@@ -60,9 +60,8 @@ void PlanetScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *Devic
|
||||
m_InstancedData.push_back(data);
|
||||
}
|
||||
|
||||
auto rockEffect = std::make_unique<Effect>(DevicePtr, L"resources/InstancedSimpleDiffuse.fx");
|
||||
auto rockMesh = std::make_unique<InstancedMesh>(DevicePtr, vertices, indices, rockMaterial, std::move(rockEffect), m_InstancedData);
|
||||
m_instancedMeshes.push_back(std::move(rockMesh));
|
||||
auto *rockEffect = new Effect(DevicePtr, L"resources/InstancedSimpleDiffuse.fx");
|
||||
m_instancedMeshes.push_back(new InstancedMesh(DevicePtr, vertices, indices, rockMaterial, rockEffect, m_InstancedData));
|
||||
|
||||
indices.clear();
|
||||
vertices.clear();
|
||||
@@ -75,10 +74,8 @@ void PlanetScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *Devic
|
||||
std::shared_ptr<Material> planetMaterial = std::make_shared<Material>();
|
||||
planetMaterial->diffuseTexturePtr = Texture::LoadFromFile("resources/planet/mars.png", DevicePtr);
|
||||
|
||||
auto planetEffect = std::make_unique<Effect>(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||
auto planetMesh = std::make_unique<Mesh>(DevicePtr, vertices, indices, planetMaterial, std::move(planetEffect));
|
||||
m_planetMesh = planetMesh.get();
|
||||
m_meshes.push_back(std::move(planetMesh));
|
||||
auto* planetEffect = new Effect(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||
m_meshes.push_back(new Mesh(DevicePtr, vertices, indices, planetMaterial, planetEffect));
|
||||
|
||||
indices.clear();
|
||||
vertices.clear();
|
||||
@@ -91,10 +88,9 @@ void PlanetScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *Devic
|
||||
std::shared_ptr<Material> skyboxMaterial = std::make_shared<Material>();
|
||||
skyboxMaterial->diffuseTexturePtr = Texture::LoadFromFile("resources/planet/skybox/space_nebula_6k.png", DevicePtr);
|
||||
|
||||
auto skyboxEffect = std::make_unique<Effect>(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||
auto skyBoxMesh = std::make_unique<Mesh>(DevicePtr, vertices, indices, skyboxMaterial, std::move(skyboxEffect));
|
||||
m_meshes.push_back(std::move(skyBoxMesh));
|
||||
m_skyboxMesh = m_meshes.back().get();
|
||||
auto* skyboxEffect = new Effect(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||
m_meshes.push_back(new Mesh(DevicePtr, vertices, indices, skyboxMaterial, skyboxEffect));
|
||||
m_skyboxMesh = m_meshes.back();
|
||||
|
||||
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||
worldMatrix *= Matrix::CreateScale(0.1f, 0.1f, 0.1f);
|
||||
@@ -102,12 +98,19 @@ void PlanetScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *Devic
|
||||
}
|
||||
|
||||
void PlanetScene::Cleanup() {
|
||||
for (auto mesh: m_instancedMeshes) {
|
||||
delete mesh;
|
||||
}
|
||||
m_instancedMeshes.clear();
|
||||
|
||||
for (auto mesh: m_meshes) {
|
||||
delete mesh;
|
||||
}
|
||||
|
||||
m_meshes.clear();
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Mesh>> &PlanetScene::GetMeshes() {
|
||||
std::vector<Mesh *> &PlanetScene::GetMeshes() {
|
||||
return m_meshes;
|
||||
}
|
||||
|
||||
@@ -118,7 +121,7 @@ std::vector<std::shared_ptr<Material>> &PlanetScene::GetMaterials() {
|
||||
void PlanetScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView *renderTargetViewPtr,
|
||||
ID3D11DepthStencilView *depthStencilViewPtr, const Camera &camera) {
|
||||
Matrix viewProjMatrix = camera.GetViewProjectionMatrix();
|
||||
for (auto& mesh: m_instancedMeshes) {
|
||||
for (auto mesh: m_instancedMeshes) {
|
||||
Matrix modelMatrix = mesh->GetWorldMatrix();
|
||||
Matrix worldViewProjMatrix = modelMatrix * viewProjMatrix;
|
||||
mesh->Render(devicePtr, worldViewProjMatrix);
|
||||
@@ -134,13 +137,8 @@ void PlanetScene::Update() {
|
||||
|
||||
//set the skybox to the camera
|
||||
Matrix skyboxMatrix = m_skyboxMesh->GetWorldMatrix();
|
||||
|
||||
Vector3 cameraPos = m_Camera->GetPosition();
|
||||
skyboxMatrix.SetTranslation(cameraPos);
|
||||
m_skyboxMesh->SetWorldMatrix(skyboxMatrix);
|
||||
|
||||
//Rotate the planet slowly
|
||||
Matrix planetMatrix = m_planetMesh->GetWorldMatrix();
|
||||
planetMatrix *= Matrix::CreateRotationY(-0.0001f);
|
||||
m_planetMesh->SetWorldMatrix(planetMatrix);
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "BaseScene.h"
|
||||
#include "../InstancedMesh.h"
|
||||
|
||||
class PlanetScene final : public BaseScene {
|
||||
class PlanetScene : public BaseScene {
|
||||
public:
|
||||
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) override;
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
|
||||
void Cleanup() override;
|
||||
|
||||
std::vector<std::unique_ptr<Mesh>> &GetMeshes() override;
|
||||
std::vector<Mesh *> &GetMeshes() override;
|
||||
|
||||
std::vector<std::shared_ptr<Material>> &GetMaterials() override;
|
||||
|
||||
@@ -24,14 +24,13 @@ private:
|
||||
|
||||
ID3D11DeviceContext* m_DeviceContextPtr{};
|
||||
|
||||
std::vector<std::unique_ptr<Mesh>> m_meshes;
|
||||
std::vector<Mesh*> m_meshes;
|
||||
//Kind of hack since InstancedMesh doesnt extend mesh
|
||||
std::vector<std::unique_ptr<InstancedMesh>> m_instancedMeshes;
|
||||
std::vector<InstancedMesh*> m_instancedMeshes;
|
||||
std::vector<InstancedData> m_InstancedData;
|
||||
std::vector<std::shared_ptr<Material>> m_materials;
|
||||
|
||||
Mesh* m_skyboxMesh;
|
||||
Mesh* m_planetMesh;
|
||||
|
||||
Camera* m_Camera;
|
||||
};
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "../Effects/ShadowEffect.h"
|
||||
#include "../Effects/Effect.h"
|
||||
#include "../Buffers/DX11Viewport.h"
|
||||
#include "../RenderSettings.h"
|
||||
|
||||
void ShadowTestScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) {
|
||||
// Initialize shadow map buffer
|
||||
@@ -16,49 +15,31 @@ void ShadowTestScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *D
|
||||
assert(true && "Shadow map buffer failed to initialize");
|
||||
}
|
||||
// Initialize light source
|
||||
m_Light.SetPosition({-20.0f, 60.0f, 0.0f});
|
||||
m_Light.SetPosition({-20.0f, 30.0f, 0.0f});
|
||||
m_Light.SetTarget({0, -5, 40});
|
||||
m_Light.SetUp({0.0f, 1.0f, 0.0f});
|
||||
|
||||
std::vector<VertexIn> vertices{};
|
||||
std::vector<uint32_t> indices{};
|
||||
|
||||
if(!Utils::ParseOBJNew("resources/ShadingDemo.obj", vertices, indices, true)){
|
||||
assert(true && "Model failed to load");
|
||||
}
|
||||
|
||||
auto material = std::make_shared<Material>();
|
||||
material->diffuseTexturePtr = Texture::LoadFromFile("resources/shadowTestTexture.png", DevicePtr);
|
||||
// material->diffuseTexturePtr = Texture::LoadFromFile("resources/vehicle_diffuse.png", DevicePtr);
|
||||
|
||||
auto shadowEffect = new ShadowEffect(DevicePtr, L"resources/shadowEffect.fx");
|
||||
auto otherEffect = new ShadowDiffuse(DevicePtr, L"resources/SuperSimpleDiffuse.fx");
|
||||
auto otherEffect = new Effect(DevicePtr, L"resources/SuperSimpleDiffuse.fx");
|
||||
|
||||
auto shadowMesh = new ShadowMesh(DevicePtr, vertices, indices, material, shadowEffect, otherEffect);
|
||||
|
||||
|
||||
if(!Utils::ParseOBJNew("resources/tuktuk.obj", vertices, indices, true)){
|
||||
assert(true && "Model failed to load");
|
||||
}
|
||||
|
||||
material = std::make_shared<Material>();
|
||||
material->diffuseTexturePtr = Texture::LoadFromFile("resources/tuktuk.png", DevicePtr);
|
||||
|
||||
shadowEffect = new ShadowEffect(DevicePtr, L"resources/shadowEffect.fx");
|
||||
otherEffect = new ShadowDiffuse(DevicePtr, L"resources/SuperSimpleDiffuse.fx");
|
||||
|
||||
auto shadowMesh2 = new ShadowMesh(DevicePtr, vertices, indices, material, shadowEffect, otherEffect);
|
||||
|
||||
shadowMesh2->SetWorldMatrix(Matrix::CreateTranslation(Vector3(0, -5, 40)));
|
||||
m_tuktukMesh = shadowMesh2;
|
||||
m_shadowMeshes.push_back(shadowMesh2);
|
||||
//
|
||||
|
||||
// std::vector<std::unique_ptr<Utils::MaterialMesh>> materialMeshes;
|
||||
// Utils::LoadObjWithMaterials("resources/scene.obj", materialMeshes, true, DevicePtr);
|
||||
// for (const auto &mesh: materialMeshes) {
|
||||
// if (mesh->vertices.size() > 0) {
|
||||
// std::shared_ptr<Material> material = std::make_shared<Material>();
|
||||
// auto* effect = new ShadowDiffuse(DevicePtr, L"resources/SuperSimpleDiffuse.fx");
|
||||
// BaseEffect *effect = new Effect(DevicePtr, L"resources/SuperSimpleDiffuse.fx");
|
||||
// ShadowEffect* shadowEffect = new ShadowEffect(DevicePtr, L"resources/shadowEffect.fx");
|
||||
// material->diffuseTexturePtr = Texture::LoadFromFile("./resources/diorama/" + mesh->diffuse_texture, DevicePtr);
|
||||
//
|
||||
@@ -87,20 +68,14 @@ void ShadowTestScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *D
|
||||
}
|
||||
|
||||
void ShadowTestScene::Update() {
|
||||
|
||||
// m_Light.SetTarget(lightTarget);
|
||||
Vector3 pos = m_Light.GetPosition();
|
||||
pos.y = sin(SDL_GetTicks() / 1000.f) * 10.f + 10.f;
|
||||
m_Light.SetPosition(pos);
|
||||
|
||||
|
||||
m_Light.Update();
|
||||
|
||||
|
||||
//rotate tutkuk
|
||||
|
||||
Matrix newOne;
|
||||
newOne *= Matrix::CreateRotationY(0.001f * SDL_GetTicks());
|
||||
newOne *= Matrix::CreateTranslation(Vector3(20, -5, 40));
|
||||
m_tuktukMesh->SetWorldMatrix(newOne);
|
||||
|
||||
}
|
||||
|
||||
void ShadowTestScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView *renderTargetViewPtr,
|
||||
@@ -133,7 +108,7 @@ void ShadowTestScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetV
|
||||
|
||||
// Set the depthmap correctly
|
||||
|
||||
DX11Viewport ColorViewport(RenderSettings::GetInstance().getWidth(), RenderSettings::GetInstance().getHeight());
|
||||
DX11Viewport ColorViewport(640, 480);
|
||||
ColorViewport.Apply(devicePtr);
|
||||
|
||||
|
||||
@@ -154,18 +129,24 @@ void ShadowTestScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetV
|
||||
|
||||
auto* effect = dynamic_cast<ShadowMesh*>(mesh)->GetColorEffectPtr() ;
|
||||
|
||||
effect->SetWorldViewProjMatrix(worldViewProj);
|
||||
effect->SetWorldMatrix(mesh->GetWorldMatrix());
|
||||
effect->SetShadowMap(shadowMap);
|
||||
effect->SetLightViewProjMatrix(lightWorldViewProj);
|
||||
effect->SetLightDirection(m_Light.GetDirection());
|
||||
effect->SetLightColor(m_Light.GetColor());
|
||||
dynamic_cast<Effect*>(effect)->SetWorldViewProjMatrix(worldViewProj);
|
||||
dynamic_cast<Effect*>(effect)->SetWorldMatrix(mesh->GetWorldMatrix());
|
||||
dynamic_cast<Effect*>(effect)->SetShadowMapSampler(shadowSampler);
|
||||
dynamic_cast<Effect*>(effect)->SetShadowMap(shadowMap);
|
||||
dynamic_cast<Effect*>(effect)->SetLightViewProjMatrix(lightWorldViewProj);
|
||||
|
||||
|
||||
dynamic_cast<ShadowMesh*>(mesh)->RenderFinal(devicePtr, worldViewProj);
|
||||
}
|
||||
}
|
||||
|
||||
void ShadowTestScene::Cleanup() {
|
||||
|
||||
for (auto *mesh : m_Meshes) {
|
||||
delete mesh;
|
||||
}
|
||||
|
||||
m_Meshes.clear();
|
||||
|
||||
for (auto *mesh : m_shadowMeshes) {
|
||||
delete mesh;
|
||||
@@ -177,7 +158,7 @@ void ShadowTestScene::Cleanup() {
|
||||
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Mesh>> & ShadowTestScene::GetMeshes() {
|
||||
std::vector<Mesh *> &ShadowTestScene::GetMeshes() {
|
||||
return m_Meshes;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "BaseScene.h"
|
||||
#include "../Buffers/ShadowMapBuffer.h"
|
||||
#include "../DirectionalLight.h"
|
||||
#include "../Light.h"
|
||||
#include "../ShadowMesh.h"
|
||||
|
||||
class ShadowTestScene: public BaseScene {
|
||||
@@ -17,25 +17,24 @@ public:
|
||||
|
||||
void Cleanup() override;
|
||||
|
||||
std::vector<std::unique_ptr<Mesh>>& GetMeshes() override;
|
||||
std::vector<Mesh *> &GetMeshes() override;
|
||||
|
||||
std::vector<std::shared_ptr<Material>> &GetMaterials() override;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
std::vector<std::unique_ptr<Mesh>> m_Meshes;
|
||||
std::vector<Mesh *> m_Meshes;
|
||||
std::vector<std::shared_ptr<Material>> m_Materials;
|
||||
|
||||
std::vector<ShadowMesh *> m_shadowMeshes;
|
||||
std::vector<std::shared_ptr<Material>> m_shadowMaterials;
|
||||
|
||||
ShadowMapBuffer *m_ShadowMapBuffer{nullptr};
|
||||
DirectionalLight m_Light;
|
||||
Light m_Light;
|
||||
|
||||
float angle = 0.0f;
|
||||
|
||||
ShadowMesh* m_tuktukMesh;
|
||||
|
||||
void RenderShadowMapToScreen(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView *renderTargetViewPtr);
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ ShadowMesh::ShadowMesh(ID3D11Device* devicePtr,
|
||||
const std::vector<Uint32>& indices,
|
||||
std::shared_ptr<Material> material,
|
||||
ShadowEffect* shadowEffectPtr,
|
||||
ShadowDiffuse* colorEffectPtr)
|
||||
BaseEffect* colorEffectPtr)
|
||||
: m_ShadowEffectPtr(shadowEffectPtr),
|
||||
m_ColorEffectPtr(colorEffectPtr),
|
||||
m_VerticesIn(verticesIn),
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "Effects/ShadowEffect.h"
|
||||
#include "Material.h"
|
||||
#include "Mesh.h"
|
||||
#include "Effects/ShadowDiffuse.h"
|
||||
|
||||
class ShadowMesh {
|
||||
public:
|
||||
@@ -16,7 +15,7 @@ public:
|
||||
const std::vector<Uint32>& indices,
|
||||
std::shared_ptr<Material> material,
|
||||
ShadowEffect* shadowEffectPtr,
|
||||
ShadowDiffuse* colorEffectPtr);
|
||||
BaseEffect* colorEffectPtr);
|
||||
|
||||
~ShadowMesh();
|
||||
|
||||
@@ -27,7 +26,7 @@ public:
|
||||
Matrix GetWorldMatrix() const;
|
||||
|
||||
ShadowEffect* GetShadowEffectPtr(){ return m_ShadowEffectPtr; }
|
||||
ShadowDiffuse* GetColorEffectPtr(){ return m_ColorEffectPtr; }
|
||||
BaseEffect* GetColorEffectPtr(){ return m_ColorEffectPtr; }
|
||||
|
||||
|
||||
private:
|
||||
@@ -35,7 +34,7 @@ private:
|
||||
ShadowEffect* m_ShadowEffectPtr;
|
||||
|
||||
// Color effect for final render
|
||||
ShadowDiffuse* m_ColorEffectPtr;
|
||||
BaseEffect* m_ColorEffectPtr;
|
||||
|
||||
// Buffers
|
||||
ID3D11InputLayout* m_InputLayoutPtr;
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
//
|
||||
// Created by Bram on 16/01/2025.
|
||||
//
|
||||
|
||||
#ifndef GP1_DIRECTX_SINGLETON_H
|
||||
#define GP1_DIRECTX_SINGLETON_H
|
||||
|
||||
template<typename T>
|
||||
class Singleton {
|
||||
public:
|
||||
static T &GetInstance() {
|
||||
static T instance{};
|
||||
return instance;
|
||||
}
|
||||
|
||||
virtual ~Singleton() = default;
|
||||
|
||||
Singleton(Singleton &&other) = delete;
|
||||
|
||||
Singleton(const Singleton &other) = delete;
|
||||
|
||||
Singleton &operator=(Singleton &&other) = delete;
|
||||
|
||||
Singleton &operator=(const Singleton &other) = delete;
|
||||
|
||||
protected:
|
||||
Singleton() = default;
|
||||
};
|
||||
|
||||
#endif //GP1_DIRECTX_SINGLETON_H
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
using namespace dae;
|
||||
|
||||
class Texture final {
|
||||
class Texture {
|
||||
public:
|
||||
~Texture();
|
||||
|
||||
@@ -28,7 +28,7 @@ private:
|
||||
ID3D11ShaderResourceView* m_TextureResourceViewPtr{};
|
||||
ID3D11Texture2D* m_TexturePtr{};
|
||||
|
||||
const SDL_Surface* m_SurfacePtr{ nullptr };
|
||||
SDL_Surface* m_SurfacePtr{ nullptr };
|
||||
uint32_t* m_pSurfacePixels{ nullptr };
|
||||
};
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace dae
|
||||
{
|
||||
class Timer final
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
Timer();
|
||||
|
||||
@@ -396,13 +396,3 @@ namespace dae {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class DirectXDeleter
|
||||
{
|
||||
public:
|
||||
void operator()(T* p)
|
||||
{
|
||||
p->Release();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "Renderer.h"
|
||||
#include "GamePadController.h"
|
||||
#include "Utils.h"
|
||||
#include "RenderSettings.h"
|
||||
|
||||
using namespace dae;
|
||||
|
||||
@@ -120,7 +119,6 @@ void CheckController(Renderer* pRenderer, bool& printFPS){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *args[]) {
|
||||
//Unreferenced parameters
|
||||
(void) argc;
|
||||
@@ -130,19 +128,10 @@ int main(int argc, char *args[]) {
|
||||
|
||||
//Create window + surfaces
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
|
||||
//
|
||||
// const uint32_t width = 640;
|
||||
// const uint32_t height = 480;
|
||||
|
||||
const uint32_t width = 640;
|
||||
const uint32_t height = 480;
|
||||
|
||||
const uint32_t width = 900;
|
||||
const uint32_t height = 600;
|
||||
|
||||
RenderSettings::GetInstance().setHeight(height);
|
||||
RenderSettings::GetInstance().setWidth(width);
|
||||
|
||||
//// const uint32_t width = 640;
|
||||
//// const uint32_t height = 480;
|
||||
|
||||
|
||||
SDL_Window *pWindow = SDL_CreateWindow(
|
||||
|
||||
Reference in New Issue
Block a user