Commit 617483fa authored by chili's avatar chili
Browse files

comparing object space / tangent space nmapping

parent 3fd3a302
......@@ -16,6 +16,8 @@ App::App()
wnd( 1280,720,"The Donkey Fart Box" ),
light( wnd.Gfx() )
{
wall.SetRootTransform( dx::XMMatrixTranslation( -1.5f,0.0f,0.0f ) );
tp.SetPos( { 1.5f,0.0f,0.0f } );
wnd.Gfx().SetProjection( dx::XMMatrixPerspectiveLH( 1.0f,9.0f / 16.0f,0.5f,40.0f ) );
}
......@@ -27,6 +29,7 @@ void App::DoFrame()
light.Bind( wnd.Gfx(),cam.GetMatrix() );
wall.Draw( wnd.Gfx() );
tp.Draw( wnd.Gfx() );
//nano.Draw( wnd.Gfx() );
light.Draw( wnd.Gfx() );
......@@ -98,6 +101,7 @@ void App::DoFrame()
light.SpawnControlWindow();
ShowImguiDemoWindow();
wall.ShowWindow( "Wall" );
tp.SpawnControlWindow( wnd.Gfx() );
//nano.ShowWindow( "Model 1" );
// present
......
......@@ -27,5 +27,6 @@ private:
Camera cam;
PointLight light;
Model wall{ wnd.Gfx(),"Models\\brick_wall\\brick_wall.obj" };
TestPlane tp{ wnd.Gfx(),1.0 };
//Model nano{ wnd.Gfx(),"Models\\nano_textured\\nanosuit.obj" };
};
\ No newline at end of file
......@@ -47,7 +47,7 @@ void Camera::SpawnControlWindow() noexcept
void Camera::Reset() noexcept
{
pos = { 0.0f,7.5f,-18.0f };
pos = { 0.0f,0.0f,-10.0f };
pitch = 0.0f;
yaw = 0.0f;
}
......
......@@ -224,6 +224,11 @@ void Model::ShowWindow( const char* windowName ) noexcept
pWindow->Show( windowName,*pRoot );
}
void Model::SetRootTransform( DirectX::FXMMATRIX tf ) noexcept
{
pRoot->SetAppliedTransform( tf );
}
Model::~Model() noexcept
{}
......@@ -326,7 +331,7 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
struct PSMaterialConstant
{
float specularIntensity = 0.8f;
float specularIntensity = 0.18f;
float specularPower;
BOOL normalMapEnabled = TRUE;
float padding[1];
......
......@@ -56,6 +56,7 @@ public:
Model( Graphics& gfx,const std::string fileName );
void Draw( Graphics& gfx ) const noxnd;
void ShowWindow( const char* windowName = nullptr ) noexcept;
void SetRootTransform( DirectX::FXMMATRIX tf ) noexcept;
~Model() noexcept;
private:
static std::unique_ptr<Mesh> ParseMesh( Graphics& gfx,const aiMesh& mesh,const aiMaterial* const* pMaterials );
......
cbuffer LightCBuf
{
float3 lightPos;
float3 ambient;
float3 diffuseColor;
float diffuseIntensity;
float attConst;
float attLin;
float attQuad;
};
cbuffer ObjectCBuf
{
float specularIntensity;
float specularPower;
bool normalMapEnabled;
float padding[1];
};
Texture2D tex;
Texture2D nmap : register(t2);
SamplerState splr;
float4 main( float3 viewPos : Position,float3 n : Normal,float2 tc : Texcoord ) : SV_Target
{
// sample normal from map if normal mapping enabled
if (normalMapEnabled)
{
// unpack normal data
const float3 normalSample = nmap.Sample(splr, tc).xyz;
n.x = normalSample.x * 2.0f - 1.0f;
n.y = -normalSample.y * 2.0f + 1.0f;
n.z = -normalSample.z;
}
// fragment to light vector data
const float3 vToL = lightPos - viewPos;
const float distToL = length( vToL );
const float3 dirToL = vToL / distToL;
// attenuation
const float att = 1.0f / (attConst + attLin * distToL + attQuad * (distToL * distToL));
// diffuse intensity
const float3 diffuse = diffuseColor * diffuseIntensity * att * max( 0.0f, dot( dirToL, n ) );
// reflected light vector
const float3 w = n * dot( vToL, n );
const float3 r = w * 2.0f - vToL;
// calculate specular intensity based on angle between viewing vector and reflection vector, narrow with power function
const float3 specular = att * (diffuseColor * diffuseIntensity) * specularIntensity * pow( max( 0.0f, dot( normalize( -r ), normalize( viewPos ) ) ), specularPower );
// final color
return float4( saturate( (diffuse + ambient) * tex.Sample( splr, tc ).rgb + specular ), 1.0f );
}
\ No newline at end of file
......@@ -39,7 +39,7 @@ void PointLight::SpawnControlWindow() noexcept
void PointLight::Reset() noexcept
{
cbData = {
{ 1.5f,14.0f,-4.5f },
{ 0.0f,4.0f,-4.5f },
{ 0.05f,0.05f,0.05f },
{ 1.0f,1.0f,1.0f },
1.0f,
......
......@@ -21,7 +21,7 @@ TestPlane::TestPlane( Graphics& gfx,float size )
auto pvsbc = pvs->GetBytecode();
AddBind( std::move( pvs ) );
AddBind( PixelShader::Resolve( gfx,"PhongPSNormalMap.cso" ) );
AddBind( PixelShader::Resolve( gfx,"PhongPSNormalMapObject.cso" ) );
AddBind( PixelConstantBuffer<PSMaterialConstant>::Resolve( gfx,pmc,1u ) );
......
......@@ -12,12 +12,12 @@ public:
private:
struct PSMaterialConstant
{
float specularIntensity = 0.1f;
float specularPower = 20.0f;
float specularIntensity = 0.18f;
float specularPower = 18.0f;
BOOL normalMappingEnabled = TRUE;
float padding[1];
} pmc;
DirectX::XMFLOAT3 pos = { 1.0f,1.0f,1.0f };
DirectX::XMFLOAT3 pos = { 0.0f,0.0f,0.0f };
float roll = 0.0f;
float pitch = 0.0f;
float yaw = 0.0f;
......
......@@ -112,6 +112,15 @@
<ClCompile Include="InputLayout.cpp" />
<ClCompile Include="Keyboard.cpp" />
<ClCompile Include="Mesh.cpp" />
<FxCompile Include="PhongPSNormalMapObject.hlsl">
<FileType>Document</FileType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4.0</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4.0</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir)%(Filename).cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir)%(Filename).cso</ObjectFileOutput>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
</FxCompile>
<ClCompile Include="PointLight.cpp" />
<ClCompile Include="Mouse.cpp" />
<ClCompile Include="PixelShader.cpp" />
......
......@@ -367,5 +367,8 @@
<FxCompile Include="PhongPSSpecNormalMap.hlsl">
<Filter>Shader</Filter>
</FxCompile>
<FxCompile Include="PhongPSNormalMapObject.hlsl">
<Filter>Shader</Filter>
</FxCompile>
</ItemGroup>
</Project>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment