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
3164667b
Commit
3164667b
authored
May 03, 2019
by
chili
Browse files
textured cube added
parent
85e7ba5b
Changes
8
Hide whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
3164667b
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#include "Box.h"
#include "Box.h"
#include "Cylinder.h"
#include "Cylinder.h"
#include "Pyramid.h"
#include "Pyramid.h"
#include "SkinnedBox.h"
#include <memory>
#include <memory>
#include <algorithm>
#include <algorithm>
#include "ChiliMath.h"
#include "ChiliMath.h"
...
@@ -46,6 +47,11 @@ App::App()
...
@@ -46,6 +47,11 @@ App::App()
gfx
,
rng
,
adist
,
ddist
,
odist
,
gfx
,
rng
,
adist
,
ddist
,
odist
,
rdist
,
tdist
rdist
,
tdist
);
);
case
3
:
return
std
::
make_unique
<
SkinnedBox
>
(
gfx
,
rng
,
adist
,
ddist
,
odist
,
rdist
);
default:
default:
assert
(
false
&&
"impossible drawable option in factory"
);
assert
(
false
&&
"impossible drawable option in factory"
);
return
{};
return
{};
...
@@ -54,7 +60,7 @@ App::App()
...
@@ -54,7 +60,7 @@ App::App()
private:
private:
Graphics
&
gfx
;
Graphics
&
gfx
;
std
::
mt19937
rng
{
std
::
random_device
{}()
};
std
::
mt19937
rng
{
std
::
random_device
{}()
};
std
::
uniform_int_distribution
<
int
>
sdist
{
0
,
2
};
std
::
uniform_int_distribution
<
int
>
sdist
{
0
,
3
};
std
::
uniform_real_distribution
<
float
>
adist
{
0.0
f
,
PI
*
2.0
f
};
std
::
uniform_real_distribution
<
float
>
adist
{
0.0
f
,
PI
*
2.0
f
};
std
::
uniform_real_distribution
<
float
>
ddist
{
0.0
f
,
PI
*
0.5
f
};
std
::
uniform_real_distribution
<
float
>
ddist
{
0.0
f
,
PI
*
0.5
f
};
std
::
uniform_real_distribution
<
float
>
odist
{
0.0
f
,
PI
*
0.08
f
};
std
::
uniform_real_distribution
<
float
>
odist
{
0.0
f
,
PI
*
0.08
f
};
...
...
hw3d/Cube.h
View file @
3164667b
...
@@ -125,4 +125,36 @@ public:
...
@@ -125,4 +125,36 @@ public:
}
}
};
};
}
}
template
<
class
V
>
static
IndexedTriangleList
<
V
>
MakeIndependentTextured
()
{
auto
itl
=
MakeIndependent
<
V
>
();
itl
.
vertices
[
0
].
tc
=
{
0.0
f
,
0.0
f
};
itl
.
vertices
[
1
].
tc
=
{
1.0
f
,
0.0
f
};
itl
.
vertices
[
2
].
tc
=
{
0.0
f
,
1.0
f
};
itl
.
vertices
[
3
].
tc
=
{
1.0
f
,
1.0
f
};
itl
.
vertices
[
4
].
tc
=
{
0.0
f
,
0.0
f
};
itl
.
vertices
[
5
].
tc
=
{
1.0
f
,
0.0
f
};
itl
.
vertices
[
6
].
tc
=
{
0.0
f
,
1.0
f
};
itl
.
vertices
[
7
].
tc
=
{
1.0
f
,
1.0
f
};
itl
.
vertices
[
8
].
tc
=
{
0.0
f
,
0.0
f
};
itl
.
vertices
[
9
].
tc
=
{
1.0
f
,
0.0
f
};
itl
.
vertices
[
10
].
tc
=
{
0.0
f
,
1.0
f
};
itl
.
vertices
[
11
].
tc
=
{
1.0
f
,
1.0
f
};
itl
.
vertices
[
12
].
tc
=
{
0.0
f
,
0.0
f
};
itl
.
vertices
[
13
].
tc
=
{
1.0
f
,
0.0
f
};
itl
.
vertices
[
14
].
tc
=
{
0.0
f
,
1.0
f
};
itl
.
vertices
[
15
].
tc
=
{
1.0
f
,
1.0
f
};
itl
.
vertices
[
16
].
tc
=
{
0.0
f
,
0.0
f
};
itl
.
vertices
[
17
].
tc
=
{
1.0
f
,
0.0
f
};
itl
.
vertices
[
18
].
tc
=
{
0.0
f
,
1.0
f
};
itl
.
vertices
[
19
].
tc
=
{
1.0
f
,
1.0
f
};
itl
.
vertices
[
20
].
tc
=
{
0.0
f
,
0.0
f
};
itl
.
vertices
[
21
].
tc
=
{
1.0
f
,
0.0
f
};
itl
.
vertices
[
22
].
tc
=
{
0.0
f
,
1.0
f
};
itl
.
vertices
[
23
].
tc
=
{
1.0
f
,
1.0
f
};
return
itl
;
}
};
};
\ No newline at end of file
hw3d/SkinnedBox.cpp
View file @
3164667b
...
@@ -4,25 +4,16 @@
...
@@ -4,25 +4,16 @@
#include "Cube.h"
#include "Cube.h"
#include "Surface.h"
#include "Surface.h"
#include "Texture.h"
#include "Texture.h"
#include "Sampler.h"
SkinnedBox
::
SkinnedBox
(
Graphics
&
gfx
,
SkinnedBox
::
SkinnedBox
(
Graphics
&
gfx
,
std
::
mt19937
&
rng
,
std
::
mt19937
&
rng
,
std
::
uniform_real_distribution
<
float
>&
adist
,
std
::
uniform_real_distribution
<
float
>&
adist
,
std
::
uniform_real_distribution
<
float
>&
ddist
,
std
::
uniform_real_distribution
<
float
>&
ddist
,
std
::
uniform_real_distribution
<
float
>&
odist
,
std
::
uniform_real_distribution
<
float
>&
odist
,
std
::
uniform_real_distribution
<
float
>&
rdist
)
std
::
uniform_real_distribution
<
float
>&
rdist
)
:
:
r
(
rdist
(
rng
)
),
TestObject
(
gfx
,
rng
,
adist
,
ddist
,
odist
,
rdist
)
droll
(
ddist
(
rng
)
),
dpitch
(
ddist
(
rng
)
),
dyaw
(
ddist
(
rng
)
),
dphi
(
odist
(
rng
)
),
dtheta
(
odist
(
rng
)
),
dchi
(
odist
(
rng
)
),
chi
(
adist
(
rng
)
),
theta
(
adist
(
rng
)
),
phi
(
adist
(
rng
)
)
{
{
namespace
dx
=
DirectX
;
namespace
dx
=
DirectX
;
...
@@ -31,34 +22,43 @@ SkinnedBox::SkinnedBox( Graphics& gfx,
...
@@ -31,34 +22,43 @@ SkinnedBox::SkinnedBox( Graphics& gfx,
struct
Vertex
struct
Vertex
{
{
dx
::
XMFLOAT3
pos
;
dx
::
XMFLOAT3
pos
;
struct
dx
::
XMFLOAT3
n
;
{
dx
::
XMFLOAT2
tc
;
float
u
;
float
v
;
}
tex
;
};
};
const
auto
model
=
Cube
::
MakeSkinned
<
Vertex
>
();
auto
model
=
Cube
::
MakeIndependentTextured
<
Vertex
>
();
model
.
SetNormalsIndependentFlat
();
AddStaticBind
(
std
::
make_unique
<
VertexBuffer
>
(
gfx
,
model
.
vertices
)
);
AddStaticBind
(
std
::
make_unique
<
VertexBuffer
>
(
gfx
,
model
.
vertices
)
);
AddStaticBind
(
std
::
make_unique
<
Texture
>
(
gfx
,
Surface
::
FromFile
(
"Images
\\
cube
.png"
)
)
);
AddStaticBind
(
std
::
make_unique
<
Texture
>
(
gfx
,
Surface
::
FromFile
(
"Images
\\
kappa50
.png"
)
)
);
auto
pvs
=
std
::
make_unique
<
VertexShader
>
(
gfx
,
L"TextureVS.cso"
);
AddStaticBind
(
std
::
make_unique
<
Sampler
>
(
gfx
)
);
auto
pvs
=
std
::
make_unique
<
VertexShader
>
(
gfx
,
L"TexturedPhongVS.cso"
);
auto
pvsbc
=
pvs
->
GetBytecode
();
auto
pvsbc
=
pvs
->
GetBytecode
();
AddStaticBind
(
std
::
move
(
pvs
)
);
AddStaticBind
(
std
::
move
(
pvs
)
);
AddStaticBind
(
std
::
make_unique
<
PixelShader
>
(
gfx
,
L"TexturePS.cso"
)
);
AddStaticBind
(
std
::
make_unique
<
PixelShader
>
(
gfx
,
L"Texture
dPhong
PS.cso"
)
);
AddStaticIndexBuffer
(
std
::
make_unique
<
IndexBuffer
>
(
gfx
,
model
.
indices
)
);
AddStaticIndexBuffer
(
std
::
make_unique
<
IndexBuffer
>
(
gfx
,
model
.
indices
)
);
const
std
::
vector
<
D3D11_INPUT_ELEMENT_DESC
>
ied
=
const
std
::
vector
<
D3D11_INPUT_ELEMENT_DESC
>
ied
=
{
{
{
"Position"
,
0
,
DXGI_FORMAT_R32G32B32_FLOAT
,
0
,
0
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
{
"Position"
,
0
,
DXGI_FORMAT_R32G32B32_FLOAT
,
0
,
0
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
{
"TexCoord"
,
0
,
DXGI_FORMAT_R32G32_FLOAT
,
0
,
12
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
{
"Normal"
,
0
,
DXGI_FORMAT_R32G32B32_FLOAT
,
0
,
12
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
{
"TexCoord"
,
0
,
DXGI_FORMAT_R32G32_FLOAT
,
0
,
24
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
};
};
AddStaticBind
(
std
::
make_unique
<
InputLayout
>
(
gfx
,
ied
,
pvsbc
)
);
AddStaticBind
(
std
::
make_unique
<
InputLayout
>
(
gfx
,
ied
,
pvsbc
)
);
AddStaticBind
(
std
::
make_unique
<
Topology
>
(
gfx
,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST
)
);
AddStaticBind
(
std
::
make_unique
<
Topology
>
(
gfx
,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST
)
);
struct
PSMaterialConstant
{
float
specularIntensity
=
0.6
f
;
float
specularPower
=
30.0
f
;
float
padding
[
2
];
}
colorConst
;
AddStaticBind
(
std
::
make_unique
<
PixelConstantBuffer
<
PSMaterialConstant
>>
(
gfx
,
colorConst
,
1u
)
);
}
}
else
else
{
{
...
@@ -67,21 +67,3 @@ SkinnedBox::SkinnedBox( Graphics& gfx,
...
@@ -67,21 +67,3 @@ SkinnedBox::SkinnedBox( Graphics& gfx,
AddBind
(
std
::
make_unique
<
TransformCbuf
>
(
gfx
,
*
this
)
);
AddBind
(
std
::
make_unique
<
TransformCbuf
>
(
gfx
,
*
this
)
);
}
}
void
SkinnedBox
::
Update
(
float
dt
)
noexcept
{
roll
+=
droll
*
dt
;
pitch
+=
dpitch
*
dt
;
yaw
+=
dyaw
*
dt
;
theta
+=
dtheta
*
dt
;
phi
+=
dphi
*
dt
;
chi
+=
dchi
*
dt
;
}
DirectX
::
XMMATRIX
SkinnedBox
::
GetTransformXM
()
const
noexcept
{
namespace
dx
=
DirectX
;
return
dx
::
XMMatrixRotationRollPitchYaw
(
pitch
,
yaw
,
roll
)
*
dx
::
XMMatrixTranslation
(
r
,
0.0
f
,
0.0
f
)
*
dx
::
XMMatrixRotationRollPitchYaw
(
theta
,
phi
,
chi
);
}
hw3d/SkinnedBox.h
View file @
3164667b
#pragma once
#pragma once
#include "
DrawableBase
.h"
#include "
TestObject
.h"
class
SkinnedBox
:
public
DrawableBase
<
SkinnedBox
>
class
SkinnedBox
:
public
TestObject
<
SkinnedBox
>
{
{
public:
public:
SkinnedBox
(
Graphics
&
gfx
,
std
::
mt19937
&
rng
,
SkinnedBox
(
Graphics
&
gfx
,
std
::
mt19937
&
rng
,
...
@@ -9,22 +9,4 @@ public:
...
@@ -9,22 +9,4 @@ public:
std
::
uniform_real_distribution
<
float
>&
ddist
,
std
::
uniform_real_distribution
<
float
>&
ddist
,
std
::
uniform_real_distribution
<
float
>&
odist
,
std
::
uniform_real_distribution
<
float
>&
odist
,
std
::
uniform_real_distribution
<
float
>&
rdist
);
std
::
uniform_real_distribution
<
float
>&
rdist
);
void
Update
(
float
dt
)
noexcept
override
;
DirectX
::
XMMATRIX
GetTransformXM
()
const
noexcept
override
;
private:
// positional
float
r
;
float
roll
=
0.0
f
;
float
pitch
=
0.0
f
;
float
yaw
=
0.0
f
;
float
theta
;
float
phi
;
float
chi
;
// speed (delta/s)
float
droll
;
float
dpitch
;
float
dyaw
;
float
dtheta
;
float
dphi
;
float
dchi
;
};
};
\ No newline at end of file
hw3d/TexturedPhongPS.hlsl
0 → 100644
View file @
3164667b
cbuffer
LightCBuf
{
float3
lightPos
;
float3
ambient
;
float3
diffuseColor
;
float
diffuseIntensity
;
float
attConst
;
float
attLin
;
float
attQuad
;
};
cbuffer
ObjectCBuf
{
float
specularIntensity
;
float
specularPower
;
float
padding
[
2
];
};
Texture2D
tex
;
SamplerState
splr
;
float4
main
(
float3
worldPos
:
Position
,
float3
n
:
Normal
,
float2
tc
:
Texcoord
)
:
SV_Target
{
// fragment to light vector data
const
float3
vToL
=
lightPos
-
worldPos
;
const
float
distToL
=
length
(
vToL
);
const
float3
dirToL
=
vToL
/
distToL
;
// attenuation
const
float
att
=
1
.
0
f
/
(
attConst
+
attLin
*
distToL
+
attQuad
*
(
distToL
*
distToL
));
// diffuse intensity
const
float3
diffuse
=
diffuseColor
*
diffuseIntensity
*
att
*
max
(
0
.
0
f
,
dot
(
dirToL
,
n
)
);
// reflected light vector
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
);
// final color
return
float4
(
saturate
(
diffuse
+
ambient
+
specular
),
1
.
0
f
)
*
tex
.
Sample
(
splr
,
tc
);
}
\ No newline at end of file
hw3d/TexturedPhongVS.hlsl
0 → 100644
View file @
3164667b
cbuffer
CBuf
{
matrix
modelView
;
matrix
modelViewProj
;
};
struct
VSOut
{
float3
worldPos
:
Position
;
float3
normal
:
Normal
;
float2
tc
:
Texcoord
;
float4
pos
:
SV_Position
;
};
VSOut
main
(
float3
pos
:
Position
,
float3
n
:
Normal
,
float2
tc
:
Texcoord
)
{
VSOut
vso
;
vso
.
worldPos
=
(
float3
)
mul
(
float4
(
pos
,
1
.
0
f
),
modelView
);
vso
.
normal
=
mul
(
n
,(
float3x3
)
modelView
);
vso
.
pos
=
mul
(
float4
(
pos
,
1
.
0
f
),
modelViewProj
);
vso
.
tc
=
tc
;
return
vso
;
}
\ No newline at end of file
hw3d/hw3d.vcxproj
View file @
3164667b
...
@@ -372,6 +372,34 @@
...
@@ -372,6 +372,34 @@
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
</FxCompile>
</FxCompile>
<FxCompile
Include=
"TexturedPhongPS.hlsl"
>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
Pixel
</ShaderType>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
4.0
</ShaderModel>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
Pixel
</ShaderType>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
4.0
</ShaderModel>
<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|Win32'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
</FxCompile>
<FxCompile
Include=
"TexturedPhongVS.hlsl"
>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
Vertex
</ShaderType>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
4.0
</ShaderModel>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
Vertex
</ShaderType>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
4.0
</ShaderModel>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
Vertex
</ShaderType>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
4.0
</ShaderModel>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
Vertex
</ShaderType>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
4.0
</ShaderModel>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
</FxCompile>
<FxCompile
Include=
"TexturePS.hlsl"
>
<FxCompile
Include=
"TexturePS.hlsl"
>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
...
...
hw3d/hw3d.vcxproj.filters
View file @
3164667b
...
@@ -376,5 +376,11 @@
...
@@ -376,5 +376,11 @@
<FxCompile
Include=
"BlendedPhongVS.hlsl"
>
<FxCompile
Include=
"BlendedPhongVS.hlsl"
>
<Filter>
Shader
</Filter>
<Filter>
Shader
</Filter>
</FxCompile>
</FxCompile>
<FxCompile
Include=
"TexturedPhongPS.hlsl"
>
<Filter>
Shader
</Filter>
</FxCompile>
<FxCompile
Include=
"TexturedPhongVS.hlsl"
>
<Filter>
Shader
</Filter>
</FxCompile>
</ItemGroup>
</ItemGroup>
</Project>
</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