Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
hw3d
Commits
51c06840
Commit
51c06840
authored
Jul 27, 2019
by
chili
Browse files
specular is weird on this boi
parent
e19c20dc
Changes
4
Show whitespace changes
Inline
Side-by-side
hw3d/Mesh.cpp
View file @
51c06840
...
...
@@ -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
;
bool
hasSpecularMap
=
false
;
if
(
mesh
.
mMaterialIndex
>=
0
)
{
auto
&
material
=
*
pMaterials
[
mesh
.
mMaterialIndex
];
...
...
@@ -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
)
{
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
)
);
...
...
@@ -297,17 +299,24 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
auto
pvsbc
=
pvs
->
GetBytecode
();
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
)
);
if
(
hasSpecularMap
)
{
bindablePtrs
.
push_back
(
std
::
make_unique
<
Bind
::
PixelShader
>
(
gfx
,
L"PhongPSSpecMap.cso"
)
);
}
else
{
bindablePtrs
.
push_back
(
std
::
make_unique
<
Bind
::
PixelShader
>
(
gfx
,
L"PhongPS.cso"
)
);
struct
PSMaterialConstant
{
float
specularIntensity
=
0
.6
f
;
float
specularPower
=
3
0.0
f
;
float
specularIntensity
=
1
.6
f
;
float
specularPower
=
5
0.0
f
;
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
)
);
}
...
...
hw3d/PhongPSSpecMap.hlsl
View file @
51c06840
...
...
@@ -29,7 +29,10 @@ float4 main(float3 worldPos : Position, float3 n : Normal, float2 tc : Texcoord)
const
float3
w
=
n
*
dot
(
vToL
,
n
);
const
float3
r
=
w
*
2
.
0
f
-
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
.
0
f
,
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
.
0
f
,
dot
(
normalize
(
-
r
),
normalize
(
worldPos
))),
specularPower
);
// final color
return
float4
(
saturate
(
diffuse
+
ambient
+
specular
),
1
.
0
f
)
*
tex
.
Sample
(
splr
,
tc
);
}
\ No newline at end of file
hw3d/hw3d.vcxproj
View file @
51c06840
...
...
@@ -191,6 +191,14 @@
<None
Include=
"DXTrace.inl"
/>
</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"
>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
Pixel
</ShaderType>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
4.0
</ShaderModel>
...
...
hw3d/hw3d.vcxproj.filters
View file @
51c06840
...
...
@@ -334,5 +334,8 @@
<FxCompile
Include=
"SolidVS.hlsl"
>
<Filter>
Shader
</Filter>
</FxCompile>
<FxCompile
Include=
"PhongPSSpecMap.hlsl"
>
<Filter>
Shader
</Filter>
</FxCompile>
</ItemGroup>
</Project>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment