define bools for handling null texture maps

This commit is contained in:
lightling 2022-04-03 16:28:10 -04:00
parent f0ab528f13
commit 4a0dfebd60
Signed by: lightling
GPG key ID: 016F11E0AA296B67
3 changed files with 29 additions and 2 deletions

View file

@ -13,6 +13,10 @@ Material::Material(
uvOffset = DirectX::XMFLOAT2(0, 0);
uvScale = DirectX::XMFLOAT2(1, 1);
emitAmount = 0;
hasEmissiveMap = false;
hasSpecularMap = false;
hasNormalMap = false;
hasReflectionMap = false;
}
Material::~Material()
@ -36,6 +40,10 @@ void Material::Activate(Transform* _transform, std::shared_ptr<Camera> _camera,
pixelShader->SetFloat("emitAmount", GetEmitAmount());
pixelShader->SetFloat3("tint", GetTint());
pixelShader->SetFloat("lightCount", (int)_lights.size());
pixelShader->SetInt("hasEmissiveMap", (int)hasEmissiveMap);
pixelShader->SetInt("hasSpecularMap", (int)hasSpecularMap);
pixelShader->SetInt("hasNormalMap", (int)hasNormalMap);
pixelShader->SetInt("hasReflectionMap", (int)hasReflectionMap);
pixelShader->SetData("lights", &_lights[0], sizeof(Light) * (int)_lights.size());
pixelShader->CopyAllBufferData();
pixelShader->SetShader();
@ -136,6 +144,11 @@ void Material::LoadTexture(const wchar_t* _path, const char* _type, ID3D11Device
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> shaderResourceView;
DirectX::CreateWICTextureFromFile(_device, _context, DXCore::GetFullPathTo_Wide(_path).c_str(), 0, shaderResourceView.GetAddressOf());
PushTexture(_type, shaderResourceView);
if (_type == TEXTYPE_EMISSIVE) hasEmissiveMap = true;
else if (_type == TEXTYPE_SPECULAR) hasSpecularMap = true;
else if (_type == TEXTYPE_NORMAL) hasNormalMap = true;
else if (_type == TEXTYPE_REFLECTION) hasReflectionMap = true;
}
void Material::PushSampler(std::string _name, Microsoft::WRL::ComPtr<ID3D11SamplerState> _sampler)

View file

@ -13,6 +13,7 @@ constexpr auto TEXTYPE_ALBEDO = "Albedo";
constexpr auto TEXTYPE_NORMAL = "Normal";
constexpr auto TEXTYPE_EMISSIVE = "Emissive";
constexpr auto TEXTYPE_SPECULAR = "Specular";
constexpr auto TEXTYPE_REFLECTION = "Reflection";
class Material
{
@ -51,6 +52,10 @@ public:
void PushTexture(std::string _name, Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> _texture);
private:
bool hasEmissiveMap;
bool hasSpecularMap;
bool hasNormalMap;
bool hasReflectionMap;
DirectX::XMFLOAT3 tint;
float roughness;
float emitAmount;

View file

@ -18,12 +18,19 @@ cbuffer ExternalData : register(b0)
float3 tint;
float lightCount;
int hasEmissiveMap;
int hasSpecularMap;
int hasNormalMap;
int hasReflectionMap;
Light lights[MAX_LIGHTS];
}
Texture2D Albedo : register(t0);
Texture2D Specular : register(t1);
Texture2D Emissive : register(t2);
Texture2D Normal : register(t3);
TextureCube Reflection : register(t4);
SamplerState BasicSampler : register(s0);
// shader entry point
@ -37,8 +44,10 @@ float4 main(VertexToPixel input) : SV_TARGET
float3 view = getView(cameraPosition, input.worldPosition);
float4 albedo = Albedo.Sample(BasicSampler, input.uv).rgba;
float specular = Specular.Sample(BasicSampler, input.uv).r;
float3 emit = Emissive.Sample(BasicSampler, input.uv).rgb;
float specular = 1;
if (hasSpecularMap > 0) specular = Specular.Sample(BasicSampler, input.uv).r;
float3 emit = float3(1, 1, 1);
if (hasEmissiveMap > 0) emit = Emissive.Sample(BasicSampler, input.uv).rgb;
float3 surface = albedo.rgb * tint;
float3 light = ambient * surface;