diff --git a/DX11Starter.vcxproj b/DX11Starter.vcxproj
index 17469ca..a2e915d 100644
--- a/DX11Starter.vcxproj
+++ b/DX11Starter.vcxproj
@@ -167,6 +167,12 @@
5.0
5.0
+
+ Pixel
+ Pixel
+ Pixel
+ Pixel
+
Vertex
5.0
diff --git a/DX11Starter.vcxproj.filters b/DX11Starter.vcxproj.filters
index 1959b75..da4fb1a 100644
--- a/DX11Starter.vcxproj.filters
+++ b/DX11Starter.vcxproj.filters
@@ -97,6 +97,9 @@
Shaders
+
+ Shaders
+
diff --git a/Game.cpp b/Game.cpp
index 278fa0a..0c01a7c 100644
--- a/Game.cpp
+++ b/Game.cpp
@@ -80,7 +80,8 @@ void Game::LoadShaders()
{
vertexShader = std::make_shared(device, context, GetFullPathTo_Wide(L"VertexShader.cso").c_str());
pixelShader = //std::make_shared(device, context, GetFullPathTo_Wide(L"PixelShader.cso").c_str());
- std::make_shared(device, context, GetFullPathTo_Wide(L"RandomPixelShader.cso").c_str());
+ //std::make_shared(device, context, GetFullPathTo_Wide(L"RandomPixelShader.cso").c_str());
+ std::make_shared(device, context, GetFullPathTo_Wide(L"SimplePixelShader.cso").c_str());
// thanks to https://harry7557558.github.io/tools/colorpicker.html for having the only 0f-1f picker i could find
XMFLOAT4 white = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
@@ -88,9 +89,9 @@ void Game::LoadShaders()
XMFLOAT4 deepcoral = XMFLOAT4(1.0f, 0.39f, 0.22f, 1.0f);
materials = {
- std::make_shared(white, vertexShader, pixelShader),
- std::make_shared(deeppink, vertexShader, pixelShader),
- std::make_shared(deepcoral, vertexShader, pixelShader),
+ std::make_shared(white, 0, vertexShader, pixelShader),
+ std::make_shared(deeppink, 0, vertexShader, pixelShader),
+ std::make_shared(deepcoral, 0, vertexShader, pixelShader),
};
}
@@ -168,6 +169,7 @@ void Game::Update(float deltaTime, float totalTime)
for (int i = 0; i < entities.size(); ++i)
{
entities[i]->GetTransform()->SetRotation(1.0f * (i + 1) * sin(totalTime), 1.0f * (i + 1) * sin(totalTime), 1.0f * (i + 1) * sin(totalTime));
+ entities[i]->GetMaterial()->SetRoughness(sin(totalTime) * 0.5f + 0.5f);
}
}
@@ -198,8 +200,8 @@ void Game::Draw(float deltaTime, float totalTime)
vs->CopyAllBufferData();
std::shared_ptr ps = entity->GetMaterial()->GetPixelShader();
- ps->SetFloat4("tint", entity->GetMaterial()->GetTint());
- ps->SetFloat("noise", 2.5f + cos(totalTime));
+ ps->SetFloat3("cameraPosition", camera->GetTransform()->GetPosition());
+ ps->SetFloat("roughness", entity->GetMaterial()->GetRoughness());
ps->CopyAllBufferData();
entity->GetMaterial()->GetVertexShader()->SetShader();
diff --git a/Material.cpp b/Material.cpp
index 0c328e0..2d6ad6a 100644
--- a/Material.cpp
+++ b/Material.cpp
@@ -1,8 +1,13 @@
#include "Material.h"
-Material::Material(DirectX::XMFLOAT4 _tint, std::shared_ptr _vertexShader, std::shared_ptr _pixelShader)
+Material::Material(
+ DirectX::XMFLOAT4 _tint,
+ float _roughness,
+ std::shared_ptr _vertexShader,
+ std::shared_ptr _pixelShader)
{
tint = _tint;
+ roughness = _roughness;
vertexShader = _vertexShader;
pixelShader = _pixelShader;
}
@@ -16,6 +21,11 @@ DirectX::XMFLOAT4 Material::GetTint()
return tint;
}
+float Material::GetRoughness()
+{
+ return roughness;
+}
+
std::shared_ptr Material::GetVertexShader()
{
return vertexShader;
@@ -31,6 +41,22 @@ void Material::SetTint(DirectX::XMFLOAT4 _tint)
tint = _tint;
}
+void Material::SetRoughness(float _roughness)
+{
+ if (_roughness > 1)
+ {
+ roughness = 1;
+ }
+ else if (_roughness < 0)
+ {
+ roughness = 0;
+ }
+ else
+ {
+ roughness = _roughness;
+ }
+}
+
void Material::SetVertexShader(std::shared_ptr _vertexShader)
{
vertexShader = _vertexShader;
diff --git a/Material.h b/Material.h
index b04804d..03d2616 100644
--- a/Material.h
+++ b/Material.h
@@ -9,20 +9,24 @@ class Material
public:
Material(
DirectX::XMFLOAT4 _tint,
+ float _roughness,
std::shared_ptr _vertexShader,
std::shared_ptr _pixelShader);
~Material();
DirectX::XMFLOAT4 GetTint();
+ float GetRoughness();
std::shared_ptr GetVertexShader();
std::shared_ptr GetPixelShader();
void SetTint(DirectX::XMFLOAT4 _tint);
+ void SetRoughness(float _roughness);
void SetVertexShader(std::shared_ptr _vertexShader);
void SetPixelShader(std::shared_ptr _pixelShader);
private:
DirectX::XMFLOAT4 tint;
+ float roughness;
std::shared_ptr vertexShader;
std::shared_ptr pixelShader;
};
diff --git a/SimplePixelShader.hlsl b/SimplePixelShader.hlsl
new file mode 100644
index 0000000..3829b3c
--- /dev/null
+++ b/SimplePixelShader.hlsl
@@ -0,0 +1,12 @@
+#include "Includes.hlsli"
+
+cbuffer ExternalData : register(b0)
+{
+ float3 cameraPosition;
+ float roughness;
+}
+
+float4 main() : SV_TARGET
+{
+ return float4(roughness.rrr, 1);
+}