begin working on new pixel shader with roughness

This commit is contained in:
lightling 2022-03-19 14:32:21 -04:00
parent 6cbd6c5482
commit 15bf4521b4
Signed by: lightling
GPG key ID: 016F11E0AA296B67
6 changed files with 60 additions and 7 deletions

View file

@ -167,6 +167,12 @@
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.0</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel>
</FxCompile>
<FxCompile Include="SimplePixelShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="VertexShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>

View file

@ -97,6 +97,9 @@
<FxCompile Include="RandomPixelShader.hlsl">
<Filter>Shaders</Filter>
</FxCompile>
<FxCompile Include="SimplePixelShader.hlsl">
<Filter>Shaders</Filter>
</FxCompile>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="Assets\Models\cube.obj">

View file

@ -80,7 +80,8 @@ void Game::LoadShaders()
{
vertexShader = std::make_shared<SimpleVertexShader>(device, context, GetFullPathTo_Wide(L"VertexShader.cso").c_str());
pixelShader = //std::make_shared<SimplePixelShader>(device, context, GetFullPathTo_Wide(L"PixelShader.cso").c_str());
std::make_shared<SimplePixelShader>(device, context, GetFullPathTo_Wide(L"RandomPixelShader.cso").c_str());
//std::make_shared<SimplePixelShader>(device, context, GetFullPathTo_Wide(L"RandomPixelShader.cso").c_str());
std::make_shared<SimplePixelShader>(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<Material>(white, vertexShader, pixelShader),
std::make_shared<Material>(deeppink, vertexShader, pixelShader),
std::make_shared<Material>(deepcoral, vertexShader, pixelShader),
std::make_shared<Material>(white, 0, vertexShader, pixelShader),
std::make_shared<Material>(deeppink, 0, vertexShader, pixelShader),
std::make_shared<Material>(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<SimplePixelShader> 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();

View file

@ -1,8 +1,13 @@
#include "Material.h"
Material::Material(DirectX::XMFLOAT4 _tint, std::shared_ptr<SimpleVertexShader> _vertexShader, std::shared_ptr<SimplePixelShader> _pixelShader)
Material::Material(
DirectX::XMFLOAT4 _tint,
float _roughness,
std::shared_ptr<SimpleVertexShader> _vertexShader,
std::shared_ptr<SimplePixelShader> _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<SimpleVertexShader> 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<SimpleVertexShader> _vertexShader)
{
vertexShader = _vertexShader;

View file

@ -9,20 +9,24 @@ class Material
public:
Material(
DirectX::XMFLOAT4 _tint,
float _roughness,
std::shared_ptr<SimpleVertexShader> _vertexShader,
std::shared_ptr<SimplePixelShader> _pixelShader);
~Material();
DirectX::XMFLOAT4 GetTint();
float GetRoughness();
std::shared_ptr<SimpleVertexShader> GetVertexShader();
std::shared_ptr<SimplePixelShader> GetPixelShader();
void SetTint(DirectX::XMFLOAT4 _tint);
void SetRoughness(float _roughness);
void SetVertexShader(std::shared_ptr<SimpleVertexShader> _vertexShader);
void SetPixelShader(std::shared_ptr<SimplePixelShader> _pixelShader);
private:
DirectX::XMFLOAT4 tint;
float roughness;
std::shared_ptr<SimpleVertexShader> vertexShader;
std::shared_ptr<SimplePixelShader> pixelShader;
};

12
SimplePixelShader.hlsl Normal file
View file

@ -0,0 +1,12 @@
#include "Includes.hlsli"
cbuffer ExternalData : register(b0)
{
float3 cameraPosition;
float roughness;
}
float4 main() : SV_TARGET
{
return float4(roughness.rrr, 1);
}