Commit 51c06840 authored by chili's avatar chili
Browse files

specular is weird on this boi

parent e19c20dc
...@@ -270,6 +270,7 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a ...@@ -270,6 +270,7 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
std::vector<std::unique_ptr<Bind::Bindable>> bindablePtrs; std::vector<std::unique_ptr<Bind::Bindable>> bindablePtrs;
bool hasSpecularMap = false;
if( mesh.mMaterialIndex >= 0 ) if( mesh.mMaterialIndex >= 0 )
{ {
auto& material = *pMaterials[mesh.mMaterialIndex]; auto& material = *pMaterials[mesh.mMaterialIndex];
...@@ -284,6 +285,7 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a ...@@ -284,6 +285,7 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
if( material.GetTexture( aiTextureType_SPECULAR,0,&texFileName ) == aiReturn_SUCCESS ) if( material.GetTexture( aiTextureType_SPECULAR,0,&texFileName ) == aiReturn_SUCCESS )
{ {
bindablePtrs.push_back( std::make_unique<Bind::Texture>( gfx,Surface::FromFile( base + texFileName.C_Str() ),1 ) ); bindablePtrs.push_back( std::make_unique<Bind::Texture>( gfx,Surface::FromFile( base + texFileName.C_Str() ),1 ) );
hasSpecularMap = true;
} }
bindablePtrs.push_back( std::make_unique<Bind::Sampler>( gfx ) ); bindablePtrs.push_back( std::make_unique<Bind::Sampler>( gfx ) );
...@@ -297,17 +299,24 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a ...@@ -297,17 +299,24 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
auto pvsbc = pvs->GetBytecode(); auto pvsbc = pvs->GetBytecode();
bindablePtrs.push_back( std::move( pvs ) ); bindablePtrs.push_back( std::move( pvs ) );
bindablePtrs.push_back( std::make_unique<Bind::PixelShader>( gfx,L"PhongPS.cso" ) );
bindablePtrs.push_back( std::make_unique<Bind::InputLayout>( gfx,vbuf.GetLayout().GetD3DLayout(),pvsbc ) ); bindablePtrs.push_back( std::make_unique<Bind::InputLayout>( gfx,vbuf.GetLayout().GetD3DLayout(),pvsbc ) );
struct PSMaterialConstant if( hasSpecularMap )
{
bindablePtrs.push_back( std::make_unique<Bind::PixelShader>( gfx,L"PhongPSSpecMap.cso" ) );
}
else
{ {
float specularIntensity = 0.6f; bindablePtrs.push_back( std::make_unique<Bind::PixelShader>( gfx,L"PhongPS.cso" ) );
float specularPower = 30.0f;
float padding[2]; struct PSMaterialConstant
} pmc; {
bindablePtrs.push_back( std::make_unique<Bind::PixelConstantBuffer<PSMaterialConstant>>( gfx,pmc,1u ) ); float specularIntensity = 1.6f;
float specularPower = 50.0f;
float padding[2];
} pmc;
bindablePtrs.push_back( std::make_unique<Bind::PixelConstantBuffer<PSMaterialConstant>>( gfx,pmc,1u ) );
}
return std::make_unique<Mesh>( gfx,std::move( bindablePtrs ) ); return std::make_unique<Mesh>( gfx,std::move( bindablePtrs ) );
} }
......
...@@ -29,7 +29,10 @@ float4 main(float3 worldPos : Position, float3 n : Normal, float2 tc : Texcoord) ...@@ -29,7 +29,10 @@ float4 main(float3 worldPos : Position, float3 n : Normal, float2 tc : Texcoord)
const float3 w = n * dot(vToL, n); const float3 w = n * dot(vToL, n);
const float3 r = w * 2.0f - vToL; const float3 r = w * 2.0f - vToL;
// calculate specular intensity based on angle between viewing vector and reflection vector, narrow with power function // 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(worldPos))), specularPower); const float4 specularSample = spec.Sample(splr, tc);
const float3 specularColorIntensity = specularSample.rgb;
const float specularPower = specularSample.a;
const float3 specular = att * specularColorIntensity * pow(max(0.0f, dot(normalize(-r), normalize(worldPos))), specularPower);
// final color // final color
return float4(saturate(diffuse + ambient + specular), 1.0f) * tex.Sample(splr, tc); return float4(saturate(diffuse + ambient + specular), 1.0f) * tex.Sample(splr, tc);
} }
\ No newline at end of file
...@@ -191,6 +191,14 @@ ...@@ -191,6 +191,14 @@
<None Include="DXTrace.inl" /> <None Include="DXTrace.inl" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<FxCompile Include="PhongPSSpecMap.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<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>
</FxCompile>
<FxCompile Include="SolidPS.hlsl"> <FxCompile Include="SolidPS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4.0</ShaderModel> <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4.0</ShaderModel>
......
...@@ -334,5 +334,8 @@ ...@@ -334,5 +334,8 @@
<FxCompile Include="SolidVS.hlsl"> <FxCompile Include="SolidVS.hlsl">
<Filter>Shader</Filter> <Filter>Shader</Filter>
</FxCompile> </FxCompile>
<FxCompile Include="PhongPSSpecMap.hlsl">
<Filter>Shader</Filter>
</FxCompile>
</ItemGroup> </ItemGroup>
</Project> </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