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
15e490b0
Commit
15e490b0
authored
Aug 06, 2019
by
chili
Browse files
1st try tan-space nmap, obj file for brick wall
parent
86aac23a
Changes
15
Show whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
15e490b0
...
...
@@ -14,10 +14,8 @@ GDIPlusManager gdipm;
App
::
App
()
:
wnd
(
1280
,
720
,
"The Donkey Fart Box"
),
light
(
wnd
.
Gfx
()
),
plane
(
wnd
.
Gfx
(),
3.0
f
)
light
(
wnd
.
Gfx
()
)
{
plane
.
SetPos
(
{
1.0
f
,
17.0
f
,
-
1.0
f
}
);
wnd
.
Gfx
().
SetProjection
(
dx
::
XMMatrixPerspectiveLH
(
1.0
f
,
9.0
f
/
16.0
f
,
0.5
f
,
40.0
f
)
);
}
...
...
@@ -28,10 +26,9 @@ void App::DoFrame()
wnd
.
Gfx
().
SetCamera
(
cam
.
GetMatrix
()
);
light
.
Bind
(
wnd
.
Gfx
(),
cam
.
GetMatrix
()
);
nano
.
Draw
(
wnd
.
Gfx
()
);
nano
2
.
Draw
(
wnd
.
Gfx
()
);
wall
.
Draw
(
wnd
.
Gfx
()
);
//
nano.Draw( wnd.Gfx() );
light
.
Draw
(
wnd
.
Gfx
()
);
plane
.
Draw
(
wnd
.
Gfx
()
);
while
(
const
auto
e
=
wnd
.
kbd
.
ReadKey
()
)
{
...
...
@@ -100,9 +97,8 @@ void App::DoFrame()
cam
.
SpawnControlWindow
();
light
.
SpawnControlWindow
();
ShowImguiDemoWindow
();
nano
.
ShowWindow
(
"Model 1"
);
nano2
.
ShowWindow
(
"Model 2"
);
plane
.
SpawnControlWindow
(
wnd
.
Gfx
()
);
wall
.
ShowWindow
(
"Wall"
);
//nano.ShowWindow( "Model 1" );
// present
wnd
.
Gfx
().
EndFrame
();
...
...
hw3d/App.h
View file @
15e490b0
...
...
@@ -26,7 +26,6 @@ private:
float
speed_factor
=
1.0
f
;
Camera
cam
;
PointLight
light
;
Model
nano
{
wnd
.
Gfx
(),
"Models
\\
nano_textured
\\
nanosuit.obj"
};
Model
nano2
{
wnd
.
Gfx
(),
"Models
\\
nano_textured
\\
nanosuit.obj"
};
TestPlane
plane
;
Model
wall
{
wnd
.
Gfx
(),
"Models
\\
brick_wall
\\
brick_wall.obj"
};
//Model nano{ wnd.Gfx(),"Models\\nano_textured\\nanosuit.obj" };
};
\ No newline at end of file
hw3d/Mesh.cpp
View file @
15e490b0
...
...
@@ -192,7 +192,8 @@ Model::Model( Graphics& gfx,const std::string fileName )
aiProcess_Triangulate
|
aiProcess_JoinIdenticalVertices
|
aiProcess_ConvertToLeftHanded
|
aiProcess_GenNormals
aiProcess_GenNormals
|
aiProcess_CalcTangentSpace
);
if
(
pScene
==
nullptr
)
...
...
@@ -235,6 +236,8 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
VertexLayout
{}
.
Append
(
VertexLayout
::
Position3D
)
.
Append
(
VertexLayout
::
Normal
)
.
Append
(
VertexLayout
::
Tangent
)
.
Append
(
VertexLayout
::
Bitangent
)
.
Append
(
VertexLayout
::
Texture2D
)
)
);
...
...
@@ -243,6 +246,8 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
vbuf
.
EmplaceBack
(
*
reinterpret_cast
<
dx
::
XMFLOAT3
*>
(
&
mesh
.
mVertices
[
i
]),
*
reinterpret_cast
<
dx
::
XMFLOAT3
*>
(
&
mesh
.
mNormals
[
i
]),
*
reinterpret_cast
<
dx
::
XMFLOAT3
*>
(
&
mesh
.
mTangents
[
i
]),
*
reinterpret_cast
<
dx
::
XMFLOAT3
*>
(
&
mesh
.
mBitangents
[
i
]),
*
reinterpret_cast
<
dx
::
XMFLOAT2
*>
(
&
mesh
.
mTextureCoords
[
0
][
i
])
);
}
...
...
@@ -261,7 +266,7 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
std
::
vector
<
std
::
shared_ptr
<
Bindable
>>
bindablePtrs
;
using
namespace
std
::
string_literals
;
const
auto
base
=
"Models
\\
nano_textured
\\
"
s
;
const
auto
base
=
"Models
\\
brick_wall
\\
"
s
;
bool
hasSpecularMap
=
false
;
float
shininess
=
35.0
f
;
...
...
@@ -284,6 +289,9 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
material
.
Get
(
AI_MATKEY_SHININESS
,
shininess
);
}
material
.
GetTexture
(
aiTextureType_NORMALS
,
0
,
&
texFileName
);
bindablePtrs
.
push_back
(
Texture
::
Resolve
(
gfx
,
base
+
texFileName
.
C_Str
(),
2
)
);
bindablePtrs
.
push_back
(
Bind
::
Sampler
::
Resolve
(
gfx
)
);
}
...
...
@@ -293,7 +301,7 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
bindablePtrs
.
push_back
(
IndexBuffer
::
Resolve
(
gfx
,
meshTag
,
indices
)
);
auto
pvs
=
VertexShader
::
Resolve
(
gfx
,
"PhongVS.cso"
);
auto
pvs
=
VertexShader
::
Resolve
(
gfx
,
"PhongVS
NormalMap
.cso"
);
auto
pvsbc
=
pvs
->
GetBytecode
();
bindablePtrs
.
push_back
(
std
::
move
(
pvs
)
);
...
...
@@ -301,17 +309,27 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
if
(
hasSpecularMap
)
{
bindablePtrs
.
push_back
(
PixelShader
::
Resolve
(
gfx
,
"PhongPSSpecMap.cso"
)
);
bindablePtrs
.
push_back
(
PixelShader
::
Resolve
(
gfx
,
"PhongPSSpecNormalMap.cso"
)
);
struct
PSMaterialConstant
{
BOOL
normalMapEnabled
=
TRUE
;
float
padding
[
3
];
}
pmc
;
// this is CLEARLY an issue... all meshes will share same mat const, but may have different
// Ns (specular power) specified for each in the material properties... bad conflict
bindablePtrs
.
push_back
(
PixelConstantBuffer
<
PSMaterialConstant
>::
Resolve
(
gfx
,
pmc
,
1u
)
);
}
else
{
bindablePtrs
.
push_back
(
PixelShader
::
Resolve
(
gfx
,
"PhongPS.cso"
)
);
bindablePtrs
.
push_back
(
PixelShader
::
Resolve
(
gfx
,
"PhongPS
NormalMap
.cso"
)
);
struct
PSMaterialConstant
{
float
specularIntensity
=
0.8
f
;
float
specularPower
;
float
padding
[
2
];
BOOL
normalMapEnabled
=
TRUE
;
float
padding
[
1
];
}
pmc
;
pmc
.
specularPower
=
shininess
;
// this is CLEARLY an issue... all meshes will share same mat const, but may have different
...
...
hw3d/Models/brick_wall/brick_wall.mtl
0 → 100644
View file @
15e490b0
newmtl Brick
Ns 18.0000
illum 2
Ka 0.0000 0.0000 0.0000
Kd 0.5880 0.5880 0.5880
Ks 0.1800 0.1800 0.1800
map_Kd brick_wall_diffuse.jpg
map_Kn brick_wall_normal.jpg
\ No newline at end of file
hw3d/Models/brick_wall/brick_wall.obj
0 → 100644
View file @
15e490b0
mtllib brick_wall.mtl
o BrickWall
v 1.000000 -1.000000 0.000000
v 1.000000 1.000000 0.000000
v -1.000000 1.000000 0.000000
v -1.000000 -1.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
usemtl Brick
s off
f 1/1 2/2 3/3
f 1/1 3/3 4/4
hw3d/Models/brick_wall/brick_wall_diffuse.jpg
0 → 100644
View file @
15e490b0
194 KB
hw3d/Models/brick_wall/brick_wall_normal.jpg
0 → 100644
View file @
15e490b0
559 KB
hw3d/Models/nano_textured/nanosuit.mtl
View file @
15e490b0
...
...
@@ -9,7 +9,7 @@ Ni 1.000000
d 1.000000
illum 2
map_Kd arm_dif.png
map_
Bump
arm_showroom_ddn.png
map_
Kn
arm_showroom_ddn.png
map_Ks arm_showroom_spec.png
...
...
@@ -22,7 +22,7 @@ Ni 1.000000
d 1.000000
illum 2
map_Kd body_dif.png
map_
Bump
body_showroom_ddn.png
map_
Kn
body_showroom_ddn.png
map_Ks body_showroom_spec.png
...
...
@@ -35,7 +35,7 @@ Ni 1.000000
d 1.000000
illum 2
map_Kd glass_dif.png
map_
Bump
glass_ddn.png
map_
Kn
glass_ddn.png
newmtl Hand
...
...
@@ -47,7 +47,7 @@ Ni 1.000000
d 1.000000
illum 2
map_Kd hand_dif.png
map_
Bump
hand_showroom_ddn.png
map_
Kn
hand_showroom_ddn.png
map_Ks hand_showroom_spec.png
...
...
@@ -60,7 +60,7 @@ Ni 1.000000
d 1.000000
illum 2
map_Kd helmet_diff.png
map_
Bump
helmet_showroom_ddn.png
map_
Kn
helmet_showroom_ddn.png
map_Ks helmet_showroom_spec.png
...
...
@@ -73,7 +73,7 @@ Ni 1.000000
d 1.000000
illum 2
map_Kd leg_dif.png
map_
Bump
leg_showroom_ddn.png
map_
Kn
leg_showroom_ddn.png
map_Ks leg_showroom_spec.png
hw3d/PhongPSNormalMap.hlsl
View file @
15e490b0
...
...
@@ -18,20 +18,29 @@ cbuffer ObjectCBuf
};
Texture2D
tex
;
Texture2D
nmap
;
Texture2D
nmap
:
register
(
t2
)
;
SamplerState
splr
;
float4
main
(
float3
worldPos
:
Position
,
float3
n
:
Normal
,
float2
tc
:
Texcoord
)
:
SV_Target
float4
main
(
float3
worldPos
:
Position
,
float3
n
:
Normal
,
float3
tan
:
Tangent
,
float3
bitan
:
Bitangent
,
float2
tc
:
Texcoord
)
:
SV_Target
{
// sample normal from map if normal mapping enabled
if
(
normalMapEnabled
)
{
// build the tranform (rotation) into tangent space
const
float3x3
tanToView
=
float3x3
(
normalize
(
tan
),
normalize
(
bitan
),
normalize
(
n
)
);
// unpack the normal from map into tangent space
const
float3
normalSample
=
nmap
.
Sample
(
splr
,
tc
).
xyz
;
n
.
x
=
normalSample
.
x
*
2
.
0
f
-
1
.
0
f
;
n
.
y
=
-
normalSample
.
y
*
2
.
0
f
+
1
.
0
f
;
n
.
z
=
-
normalSample
.
z
;
n
.
z
=
normalSample
.
z
;
// bring normal from tanspace into view space
n
=
mul
(
n
,
tanToView
);
}
// fragment to light vector data
const
float3
vToL
=
lightPos
-
worldPos
;
...
...
hw3d/PhongPSSpecMap.hlsl
→
hw3d/PhongPSSpec
Normal
Map.hlsl
View file @
15e490b0
...
...
@@ -9,14 +9,38 @@ cbuffer LightCBuf
float
attQuad
;
};
cbuffer
ObjectCBuf
{
bool
normalMapEnabled
;
float
padding
[
3
];
};
Texture2D
tex
;
Texture2D
spec
;
Texture2D
nmap
;
SamplerState
splr
;
float4
main
(
float3
worldPos
:
Position
,
float3
n
:
Normal
,
float2
tc
:
Texcoord
)
:
SV_Target
float4
main
(
float3
worldPos
:
Position
,
float3
n
:
Normal
,
float3
tan
:
Tangent
,
float3
bitan
:
Bitangent
,
float2
tc
:
Texcoord
)
:
SV_Target
{
// sample normal from map if normal mapping enabled
if
(
normalMapEnabled
)
{
// build the tranform (rotation) into tangent space
const
float3x3
tanToView
=
float3x3
(
normalize
(
tan
),
normalize
(
bitan
),
normalize
(
n
)
);
// unpack normal data
const
float3
normalSample
=
nmap
.
Sample
(
splr
,
tc
).
xyz
;
n
.
x
=
normalSample
.
x
*
2
.
0
f
-
1
.
0
f
;
n
.
y
=
-
normalSample
.
y
*
2
.
0
f
+
1
.
0
f
;
n
.
z
=
normalSample
.
z
;
// bring normal from tanspace into view space
n
=
mul
(
n
,
tanToView
);
}
// fragment to light vector data
const
float3
vToL
=
lightPos
-
worldPos
;
const
float
distToL
=
length
(
vToL
);
...
...
hw3d/PhongVSNormalMap.hlsl
0 → 100644
View file @
15e490b0
cbuffer
CBuf
{
matrix
modelView
;
matrix
modelViewProj
;
};
struct
VSOut
{
float3
worldPos
:
Position
;
float3
normal
:
Normal
;
float3
tan
:
Tangent
;
float3
bitan
:
Bitangent
;
float2
tc
:
Texcoord
;
float4
pos
:
SV_Position
;
};
VSOut
main
(
float3
pos
:
Position
,
float3
n
:
Normal
,
float3
tan
:
Tangent
,
float3
bitan
:
Bitangent
,
float2
tc
:
Texcoord
)
{
VSOut
vso
;
vso
.
worldPos
=
(
float3
)
mul
(
float4
(
pos
,
1
.
0
f
),
modelView
);
vso
.
normal
=
mul
(
n
,
(
float3x3
)
modelView
);
vso
.
tan
=
mul
(
tan
,
(
float3x3
)
modelView
);
vso
.
bitan
=
mul
(
bitan
,
(
float3x3
)
modelView
);
vso
.
pos
=
mul
(
float4
(
pos
,
1
.
0
f
),
modelViewProj
);
vso
.
tc
=
tc
;
return
vso
;
}
\ No newline at end of file
hw3d/Vertex.cpp
View file @
15e490b0
...
...
@@ -71,6 +71,10 @@ namespace Dvtx
return
sizeof
(
Map
<
Texture2D
>::
SysType
);
case
Normal
:
return
sizeof
(
Map
<
Normal
>::
SysType
);
case
Tangent
:
return
sizeof
(
Map
<
Tangent
>::
SysType
);
case
Bitangent
:
return
sizeof
(
Map
<
Bitangent
>::
SysType
);
case
Float3Color
:
return
sizeof
(
Map
<
Float3Color
>::
SysType
);
case
Float4Color
:
...
...
@@ -97,6 +101,10 @@ namespace Dvtx
return
Map
<
Texture2D
>::
code
;
case
Normal
:
return
Map
<
Normal
>::
code
;
case
Tangent
:
return
Map
<
Tangent
>::
code
;
case
Bitangent
:
return
Map
<
Bitangent
>::
code
;
case
Float3Color
:
return
Map
<
Float3Color
>::
code
;
case
Float4Color
:
...
...
@@ -119,6 +127,10 @@ namespace Dvtx
return
GenerateDesc
<
Texture2D
>
(
GetOffset
()
);
case
Normal
:
return
GenerateDesc
<
Normal
>
(
GetOffset
()
);
case
Tangent
:
return
GenerateDesc
<
Tangent
>
(
GetOffset
()
);
case
Bitangent
:
return
GenerateDesc
<
Bitangent
>
(
GetOffset
()
);
case
Float3Color
:
return
GenerateDesc
<
Float3Color
>
(
GetOffset
()
);
case
Float4Color
:
...
...
hw3d/Vertex.h
View file @
15e490b0
...
...
@@ -16,6 +16,8 @@ namespace Dvtx
Position3D
,
Texture2D
,
Normal
,
Tangent
,
Bitangent
,
Float3Color
,
Float4Color
,
BGRAColor
,
...
...
@@ -50,6 +52,20 @@ namespace Dvtx
static
constexpr
const
char
*
semantic
=
"Normal"
;
static
constexpr
const
char
*
code
=
"N"
;
};
template
<
>
struct
Map
<
Tangent
>
{
using
SysType
=
DirectX
::
XMFLOAT3
;
static
constexpr
DXGI_FORMAT
dxgiFormat
=
DXGI_FORMAT_R32G32B32_FLOAT
;
static
constexpr
const
char
*
semantic
=
"Tangent"
;
static
constexpr
const
char
*
code
=
"Nt"
;
};
template
<
>
struct
Map
<
Bitangent
>
{
using
SysType
=
DirectX
::
XMFLOAT3
;
static
constexpr
DXGI_FORMAT
dxgiFormat
=
DXGI_FORMAT_R32G32B32_FLOAT
;
static
constexpr
const
char
*
semantic
=
"Bitangent"
;
static
constexpr
const
char
*
code
=
"Nb"
;
};
template
<
>
struct
Map
<
Float3Color
>
{
using
SysType
=
DirectX
::
XMFLOAT3
;
...
...
@@ -146,6 +162,12 @@ namespace Dvtx
case
VertexLayout
::
Normal
:
SetAttribute
<
VertexLayout
::
Normal
>
(
pAttribute
,
std
::
forward
<
T
>
(
val
)
);
break
;
case
VertexLayout
::
Tangent
:
SetAttribute
<
VertexLayout
::
Tangent
>
(
pAttribute
,
std
::
forward
<
T
>
(
val
)
);
break
;
case
VertexLayout
::
Bitangent
:
SetAttribute
<
VertexLayout
::
Bitangent
>
(
pAttribute
,
std
::
forward
<
T
>
(
val
)
);
break
;
case
VertexLayout
::
Float3Color
:
SetAttribute
<
VertexLayout
::
Float3Color
>
(
pAttribute
,
std
::
forward
<
T
>
(
val
)
);
break
;
...
...
hw3d/hw3d.vcxproj
View file @
15e490b0
...
...
@@ -207,7 +207,7 @@
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
</FxCompile>
<FxCompile
Include=
"PhongPSSpecMap.hlsl"
>
<FxCompile
Include=
"PhongPSSpec
Normal
Map.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>
...
...
@@ -215,6 +215,14 @@
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
</FxCompile>
<FxCompile
Include=
"PhongVSNormalMap.hlsl"
>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
4.0
</ShaderModel>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
4.0
</ShaderModel>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
Vertex
</ShaderType>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
Vertex
</ShaderType>
<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 @
15e490b0
...
...
@@ -358,10 +358,13 @@
<FxCompile
Include=
"SolidVS.hlsl"
>
<Filter>
Shader
</Filter>
</FxCompile>
<FxCompile
Include=
"PhongPS
Spec
Map.hlsl"
>
<FxCompile
Include=
"PhongPS
Normal
Map.hlsl"
>
<Filter>
Shader
</Filter>
</FxCompile>
<FxCompile
Include=
"PhongPSNormalMap.hlsl"
>
<FxCompile
Include=
"PhongVSNormalMap.hlsl"
>
<Filter>
Shader
</Filter>
</FxCompile>
<FxCompile
Include=
"PhongPSSpecNormalMap.hlsl"
>
<Filter>
Shader
</Filter>
</FxCompile>
</ItemGroup>
...
...
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