add specular map support
This commit is contained in:
parent
29b3605cba
commit
149903c7d7
6 changed files with 51 additions and 7 deletions
BIN
Assets/Textures/HQGame/structure-endgame-deepfloor_specular.png
Normal file
BIN
Assets/Textures/HQGame/structure-endgame-deepfloor_specular.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 290 KiB |
BIN
Assets/Textures/HQGame/structure-endgame-floor_specular.png
Normal file
BIN
Assets/Textures/HQGame/structure-endgame-floor_specular.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 441 KiB |
|
@ -625,6 +625,36 @@
|
||||||
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)/Assets/Textures/HQGame</DestinationFolders>
|
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)/Assets/Textures/HQGame</DestinationFolders>
|
||||||
</CopyFileToFolders>
|
</CopyFileToFolders>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<CopyFileToFolders Include="Assets\Textures\HQGame\structure-endgame-deepfloor_specular.png">
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
|
||||||
|
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
|
||||||
|
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
|
||||||
|
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
|
||||||
|
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||||
|
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)/Assets/Textures/HQGame</DestinationFolders>
|
||||||
|
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)/Assets/Textures/HQGame</DestinationFolders>
|
||||||
|
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)/Assets/Textures/HQGame</DestinationFolders>
|
||||||
|
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)/Assets/Textures/HQGame</DestinationFolders>
|
||||||
|
</CopyFileToFolders>
|
||||||
|
<CopyFileToFolders Include="Assets\Textures\HQGame\structure-endgame-floor_specular.png">
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
|
||||||
|
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
|
||||||
|
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
|
||||||
|
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
|
||||||
|
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||||
|
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)/Assets/Textures/HQGame</DestinationFolders>
|
||||||
|
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)/Assets/Textures/HQGame</DestinationFolders>
|
||||||
|
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)/Assets/Textures/HQGame</DestinationFolders>
|
||||||
|
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)/Assets/Textures/HQGame</DestinationFolders>
|
||||||
|
</CopyFileToFolders>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
<Import Project="packages\Microsoft.XAudio2.Redist.1.2.8\build\native\Microsoft.XAudio2.Redist.targets" Condition="Exists('packages\Microsoft.XAudio2.Redist.1.2.8\build\native\Microsoft.XAudio2.Redist.targets')" />
|
<Import Project="packages\Microsoft.XAudio2.Redist.1.2.8\build\native\Microsoft.XAudio2.Redist.targets" Condition="Exists('packages\Microsoft.XAudio2.Redist.1.2.8\build\native\Microsoft.XAudio2.Redist.targets')" />
|
||||||
|
|
|
@ -198,6 +198,12 @@
|
||||||
<CopyFileToFolders Include="Assets\Textures\HQGame\structure-endgame-floor_bump.png">
|
<CopyFileToFolders Include="Assets\Textures\HQGame\structure-endgame-floor_bump.png">
|
||||||
<Filter>Assets\Textures\HQGame</Filter>
|
<Filter>Assets\Textures\HQGame</Filter>
|
||||||
</CopyFileToFolders>
|
</CopyFileToFolders>
|
||||||
|
<CopyFileToFolders Include="Assets\Textures\HQGame\structure-endgame-deepfloor_specular.png">
|
||||||
|
<Filter>Assets\Textures\HQGame</Filter>
|
||||||
|
</CopyFileToFolders>
|
||||||
|
<CopyFileToFolders Include="Assets\Textures\HQGame\structure-endgame-floor_specular.png">
|
||||||
|
<Filter>Assets\Textures\HQGame</Filter>
|
||||||
|
</CopyFileToFolders>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="Helpers.hlsli">
|
<None Include="Helpers.hlsli">
|
||||||
|
|
8
Game.cpp
8
Game.cpp
|
@ -106,19 +106,25 @@ void Game::LoadTextures()
|
||||||
device->CreateSamplerState(&sampDesc, sampler.GetAddressOf());
|
device->CreateSamplerState(&sampDesc, sampler.GetAddressOf());
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView>
|
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView>
|
||||||
|
deepFloorSpecular,
|
||||||
deepFloorAlbedo,
|
deepFloorAlbedo,
|
||||||
|
floorSpecular,
|
||||||
floorAlbedo;
|
floorAlbedo;
|
||||||
|
|
||||||
// taking the preprocessor macro from the demo because I don't like typing
|
// taking the preprocessor macro from the demo because I don't like typing
|
||||||
#define GetTex(pathToTexture, shaderResourceView) CreateWICTextureFromFile(device.Get(), context.Get(), GetFullPathTo_Wide(pathToTexture).c_str(), 0, shaderResourceView.GetAddressOf());
|
#define GetTex(pathToTexture, shaderResourceView) CreateWICTextureFromFile(device.Get(), context.Get(), GetFullPathTo_Wide(pathToTexture).c_str(), 0, shaderResourceView.GetAddressOf());
|
||||||
|
|
||||||
|
GetTex(L"Assets/Textures/HQGame/structure-endgame-deepfloor_specular.png", deepFloorSpecular);
|
||||||
GetTex(L"Assets/Textures/HQGame/structure-endgame-deepfloor_albedo.png", deepFloorAlbedo);
|
GetTex(L"Assets/Textures/HQGame/structure-endgame-deepfloor_albedo.png", deepFloorAlbedo);
|
||||||
|
GetTex(L"Assets/Textures/HQGame/structure-endgame-floor_specular.png", floorSpecular);
|
||||||
GetTex(L"Assets/Textures/HQGame/structure-endgame-floor_albedo.png", floorAlbedo);
|
GetTex(L"Assets/Textures/HQGame/structure-endgame-floor_albedo.png", floorAlbedo);
|
||||||
|
|
||||||
materials[0]->PushSampler("BasicSampler", sampler);
|
materials[0]->PushSampler("BasicSampler", sampler);
|
||||||
materials[0]->PushTexture("Albedo", deepFloorAlbedo);
|
materials[0]->PushTexture("Albedo", deepFloorAlbedo);
|
||||||
|
materials[0]->PushTexture("Specular", deepFloorSpecular);
|
||||||
materials[1]->PushSampler("BasicSampler", sampler);
|
materials[1]->PushSampler("BasicSampler", sampler);
|
||||||
materials[1]->PushTexture("Albedo", floorAlbedo);
|
materials[1]->PushTexture("Albedo", floorAlbedo);
|
||||||
|
materials[1]->PushTexture("Specular", floorSpecular);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::LoadLighting()
|
void Game::LoadLighting()
|
||||||
|
@ -238,7 +244,7 @@ void Game::Update(float deltaTime, float totalTime)
|
||||||
|
|
||||||
for (int i = 0; i < entities.size(); ++i)
|
for (int i = 0; i < entities.size(); ++i)
|
||||||
{
|
{
|
||||||
entities[i]->GetTransform()->SetRotation(sin(totalTime / 360) * 360, 0, 0);
|
entities[i]->GetTransform()->SetRotation(sin(totalTime / 720) * 360, 0, 0);
|
||||||
entities[i]->GetMaterial()->SetRoughness(sin(totalTime) * 0.5f + 0.49f);
|
entities[i]->GetMaterial()->SetRoughness(sin(totalTime) * 0.5f + 0.49f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ cbuffer ExternalData : register(b0)
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D Albedo : register(t0);
|
Texture2D Albedo : register(t0);
|
||||||
|
Texture2D Specular : register(t1);
|
||||||
SamplerState BasicSampler : register(s0);
|
SamplerState BasicSampler : register(s0);
|
||||||
|
|
||||||
// Gets the specular value for any light
|
// Gets the specular value for any light
|
||||||
|
@ -28,22 +29,22 @@ float calculateSpecular(float3 normal, float3 direction, float3 view, float roug
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the RGB value of a pixel with a directional light
|
// Gets the RGB value of a pixel with a directional light
|
||||||
float3 calculateDirectionalLight(Light light, float3 normal, float3 view, float roughness, float3 surfaceColor)
|
float3 calculateDirectionalLight(Light light, float3 normal, float3 view, float roughness, float3 surfaceColor, float specularValue)
|
||||||
{
|
{
|
||||||
float3 lightDirection = normalize(light.Direction);
|
float3 lightDirection = normalize(light.Direction);
|
||||||
float diffuse = getDiffuse(normal, -lightDirection);
|
float diffuse = getDiffuse(normal, -lightDirection);
|
||||||
float specular = calculateSpecular(normal, lightDirection, view, roughness);
|
float specular = calculateSpecular(normal, lightDirection, view, roughness) * specularValue;
|
||||||
|
|
||||||
return (diffuse * surfaceColor + specular) * light.Intensity * light.Color;
|
return (diffuse * surfaceColor + specular) * light.Intensity * light.Color;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the RGB value of a pixel with a point light
|
// Gets the RGB value of a pixel with a point light
|
||||||
float3 calculatePointLight(Light light, float3 normal, float3 view, float3 worldPosition, float roughness, float3 surfaceColor)
|
float3 calculatePointLight(Light light, float3 normal, float3 view, float3 worldPosition, float roughness, float3 surfaceColor, float specularValue)
|
||||||
{
|
{
|
||||||
float3 lightDirection = normalize(light.Position - worldPosition);
|
float3 lightDirection = normalize(light.Position - worldPosition);
|
||||||
float attenuation = getAttenuation(light.Position, worldPosition, light.Range);
|
float attenuation = getAttenuation(light.Position, worldPosition, light.Range);
|
||||||
float diffuse = getDiffuse(normal, lightDirection);
|
float diffuse = getDiffuse(normal, lightDirection);
|
||||||
float specular = calculateSpecular(normal, lightDirection, view, roughness);
|
float specular = calculateSpecular(normal, lightDirection, view, roughness) * specularValue;
|
||||||
|
|
||||||
return (diffuse * surfaceColor + specular) * attenuation * light.Intensity * light.Color;
|
return (diffuse * surfaceColor + specular) * attenuation * light.Intensity * light.Color;
|
||||||
}
|
}
|
||||||
|
@ -58,6 +59,7 @@ float4 main(VertexToPixel input) : SV_TARGET
|
||||||
float3 view = getView(cameraPosition, input.worldPosition);
|
float3 view = getView(cameraPosition, input.worldPosition);
|
||||||
|
|
||||||
float4 albedo = Albedo.Sample(BasicSampler, input.uv).rgba;
|
float4 albedo = Albedo.Sample(BasicSampler, input.uv).rgba;
|
||||||
|
float specular = Specular.Sample(BasicSampler, input.uv).r;
|
||||||
float3 surface = albedo.rgb * tint;
|
float3 surface = albedo.rgb * tint;
|
||||||
float3 light = ambient * surface;
|
float3 light = ambient * surface;
|
||||||
|
|
||||||
|
@ -67,10 +69,10 @@ float4 main(VertexToPixel input) : SV_TARGET
|
||||||
switch (lights[i].Type)
|
switch (lights[i].Type)
|
||||||
{
|
{
|
||||||
case LIGHT_TYPE_DIRECTIONAL:
|
case LIGHT_TYPE_DIRECTIONAL:
|
||||||
light += calculateDirectionalLight(lights[i], input.normal, view, roughness, surface);
|
light += calculateDirectionalLight(lights[i], input.normal, view, roughness, surface, specular);
|
||||||
break;
|
break;
|
||||||
case LIGHT_TYPE_POINT:
|
case LIGHT_TYPE_POINT:
|
||||||
light += calculatePointLight(lights[i], input.normal, view, input.worldPosition, roughness, surface);
|
light += calculatePointLight(lights[i], input.normal, view, input.worldPosition, roughness, surface, specular);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue