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
0e8bebbf
Commit
0e8bebbf
authored
May 02, 2019
by
chili
Browse files
cylindrical problems
parent
f61cdfde
Changes
8
Hide whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
0e8bebbf
#include "App.h"
#include "Box.h"
#include "Cylinder.h"
#include <memory>
#include <algorithm>
#include "ChiliMath.h"
...
...
@@ -26,20 +27,35 @@ App::App()
std
::
unique_ptr
<
Drawable
>
operator
()()
{
const
DirectX
::
XMFLOAT3
mat
=
{
cdist
(
rng
),
cdist
(
rng
),
cdist
(
rng
)
};
return
std
::
make_unique
<
Box
>
(
gfx
,
rng
,
adist
,
ddist
,
odist
,
rdist
,
bdist
,
mat
);
switch
(
sdist
(
rng
)
)
{
case
0
:
return
std
::
make_unique
<
Box
>
(
gfx
,
rng
,
adist
,
ddist
,
odist
,
rdist
,
bdist
,
mat
);
case
1
:
return
std
::
make_unique
<
Cylinder
>
(
gfx
,
rng
,
adist
,
ddist
,
odist
,
rdist
,
bdist
,
tdist
);
default:
assert
(
false
&&
"impossible drawable option in factory"
);
return
{};
}
}
private:
Graphics
&
gfx
;
std
::
mt19937
rng
{
std
::
random_device
{}()
};
std
::
uniform_int_distribution
<
int
>
sdist
{
0
,
1
};
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
>
odist
{
0.0
f
,
PI
*
0.08
f
};
std
::
uniform_real_distribution
<
float
>
rdist
{
6.0
f
,
20.0
f
};
std
::
uniform_real_distribution
<
float
>
bdist
{
0.4
f
,
3.0
f
};
std
::
uniform_real_distribution
<
float
>
cdist
{
0.0
f
,
1.0
f
};
std
::
uniform_int_distribution
<
int
>
tdist
{
3
,
30
};
};
drawables
.
reserve
(
nDrawables
);
...
...
hw3d/Cylinder.cpp
0 → 100644
View file @
0e8bebbf
#include "Cylinder.h"
#include "Prism.h"
#include "BindableBase.h"
Cylinder
::
Cylinder
(
Graphics
&
gfx
,
std
::
mt19937
&
rng
,
std
::
uniform_real_distribution
<
float
>&
adist
,
std
::
uniform_real_distribution
<
float
>&
ddist
,
std
::
uniform_real_distribution
<
float
>&
odist
,
std
::
uniform_real_distribution
<
float
>&
rdist
,
std
::
uniform_real_distribution
<
float
>&
bdist
,
std
::
uniform_int_distribution
<
int
>&
tdist
)
:
TestObject
(
gfx
,
rng
,
adist
,
ddist
,
odist
,
rdist
)
{
namespace
dx
=
DirectX
;
if
(
!
IsStaticInitialized
()
)
{
struct
Vertex
{
dx
::
XMFLOAT3
pos
;
dx
::
XMFLOAT3
n
;
};
auto
model
=
Prism
::
MakeTesselatedIndependentCapNormals
<
Vertex
>
(
tdist
(
rng
)
);
AddStaticBind
(
std
::
make_unique
<
VertexBuffer
>
(
gfx
,
model
.
vertices
)
);
auto
pvs
=
std
::
make_unique
<
VertexShader
>
(
gfx
,
L"PhongVS.cso"
);
auto
pvsbc
=
pvs
->
GetBytecode
();
AddStaticBind
(
std
::
move
(
pvs
)
);
AddStaticBind
(
std
::
make_unique
<
PixelShader
>
(
gfx
,
L"IndexedPhongPS.cso"
)
);
AddStaticIndexBuffer
(
std
::
make_unique
<
IndexBuffer
>
(
gfx
,
model
.
indices
)
);
const
std
::
vector
<
D3D11_INPUT_ELEMENT_DESC
>
ied
=
{
{
"Position"
,
0
,
DXGI_FORMAT_R32G32B32_FLOAT
,
0
,
0
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
{
"Normal"
,
0
,
DXGI_FORMAT_R32G32B32_FLOAT
,
0
,
12
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
};
AddStaticBind
(
std
::
make_unique
<
InputLayout
>
(
gfx
,
ied
,
pvsbc
)
);
AddStaticBind
(
std
::
make_unique
<
Topology
>
(
gfx
,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST
)
);
struct
PSMaterialConstant
{
alignas
(
16
)
dx
::
XMFLOAT3A
colors
[
6
]
=
{
{
1.0
f
,
0.0
f
,
0.0
f
},
{
0.0
f
,
1.0
f
,
0.0
f
},
{
0.0
f
,
0.0
f
,
1.0
f
},
{
1.0
f
,
1.0
f
,
0.0
f
},
{
1.0
f
,
0.0
f
,
1.0
f
},
{
0.0
f
,
1.0
f
,
1.0
f
},
};
float
specularIntensity
=
0.6
f
;
float
specularPower
=
30.0
f
;
}
matConst
;
AddStaticBind
(
std
::
make_unique
<
PixelConstantBuffer
<
PSMaterialConstant
>>
(
gfx
,
matConst
,
1u
)
);
}
else
{
SetIndexFromStatic
();
}
AddBind
(
std
::
make_unique
<
TransformCbuf
>
(
gfx
,
*
this
)
);
}
hw3d/Cylinder.h
0 → 100644
View file @
0e8bebbf
#pragma once
#include "TestObject.h"
class
Cylinder
:
public
TestObject
<
Cylinder
>
{
public:
Cylinder
(
Graphics
&
gfx
,
std
::
mt19937
&
rng
,
std
::
uniform_real_distribution
<
float
>&
adist
,
std
::
uniform_real_distribution
<
float
>&
ddist
,
std
::
uniform_real_distribution
<
float
>&
odist
,
std
::
uniform_real_distribution
<
float
>&
rdist
,
std
::
uniform_real_distribution
<
float
>&
bdist
,
std
::
uniform_int_distribution
<
int
>&
tdist
);
};
\ No newline at end of file
hw3d/Drawable.cpp
View file @
0e8bebbf
...
...
@@ -2,7 +2,6 @@
#include "GraphicsThrowMacros.h"
#include "IndexBuffer.h"
#include <cassert>
#include <typeinfo>
void
Drawable
::
Draw
(
Graphics
&
gfx
)
const
noexcept
(
!
IS_DEBUG
)
{
...
...
hw3d/IndexedPhongPS.hlsl
0 → 100644
View file @
0e8bebbf
cbuffer
LightCBuf
{
float3
lightPos
;
float3
ambient
;
float3
diffuseColor
;
float
diffuseIntensity
;
float
attConst
;
float
attLin
;
float
attQuad
;
};
cbuffer
ObjectCBuf
{
float3
materialColors
[
6
];
float
specularIntensity
;
float
specularPower
;
};
float4
main
(
float3
worldPos
:
Position
,
float3
n
:
Normal
,
uint
tid
:
SV_PrimitiveID
)
:
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
)
*
materialColors
[
tid
%
6
]
),
1
.
0
f
);
}
\ No newline at end of file
hw3d/Prism.h
View file @
0e8bebbf
...
...
@@ -80,6 +80,117 @@ public:
return
{
std
::
move
(
vertices
),
std
::
move
(
indices
)
};
}
template
<
class
V
>
static
IndexedTriangleList
<
V
>
MakeTesselatedIndependentCapNormals
(
int
longDiv
)
{
namespace
dx
=
DirectX
;
assert
(
longDiv
>=
3
);
const
auto
base
=
dx
::
XMVectorSet
(
1.0
f
,
0.0
f
,
-
1.0
f
,
0.0
f
);
const
auto
offset
=
dx
::
XMVectorSet
(
0.0
f
,
0.0
f
,
2.0
f
,
0.0
f
);
const
float
longitudeAngle
=
2.0
f
*
PI
/
longDiv
;
std
::
vector
<
V
>
vertices
;
// near center
const
auto
iCenterNear
=
(
unsigned
short
)
vertices
.
size
();
vertices
.
emplace_back
();
vertices
.
back
().
pos
=
{
0.0
f
,
0.0
f
,
-
1.0
f
};
vertices
.
back
().
n
=
{
0.0
f
,
0.0
f
,
-
1.0
f
};
// near base vertices
const
auto
iBaseNear
=
(
unsigned
short
)
vertices
.
size
();
for
(
int
iLong
=
0
;
iLong
<
longDiv
;
iLong
++
)
{
vertices
.
emplace_back
();
auto
v
=
dx
::
XMVector3Transform
(
base
,
dx
::
XMMatrixRotationZ
(
longitudeAngle
*
iLong
)
);
dx
::
XMStoreFloat3
(
&
vertices
.
back
().
pos
,
v
);
vertices
.
back
().
n
=
{
0.0
f
,
0.0
f
,
-
1.0
f
};
}
// far center
const
auto
iCenterFar
=
(
unsigned
short
)
vertices
.
size
();
vertices
.
emplace_back
();
vertices
.
back
().
pos
=
{
0.0
f
,
0.0
f
,
1.0
f
};
vertices
.
back
().
n
=
{
0.0
f
,
0.0
f
,
1.0
f
};
// far base vertices
const
auto
iBaseFar
=
(
unsigned
short
)
vertices
.
size
();
for
(
int
iLong
=
0
;
iLong
<
longDiv
;
iLong
++
)
{
vertices
.
emplace_back
();
auto
v
=
dx
::
XMVector3Transform
(
base
,
dx
::
XMMatrixRotationZ
(
longitudeAngle
*
iLong
)
);
v
=
dx
::
XMVectorAdd
(
v
,
offset
);
dx
::
XMStoreFloat3
(
&
vertices
.
back
().
pos
,
v
);
vertices
.
back
().
n
=
{
0.0
f
,
0.0
f
,
1.0
f
};
}
// fusilage vertices
const
auto
iFusilage
=
(
unsigned
short
)
vertices
.
size
();
for
(
int
iLong
=
0
;
iLong
<
longDiv
;
iLong
++
)
{
// near base
{
vertices
.
emplace_back
();
auto
v
=
dx
::
XMVector3Transform
(
base
,
dx
::
XMMatrixRotationZ
(
longitudeAngle
*
iLong
)
);
dx
::
XMStoreFloat3
(
&
vertices
.
back
().
pos
,
v
);
vertices
.
back
().
n
=
{
vertices
.
back
().
pos
.
x
,
vertices
.
back
().
pos
.
y
,
0.0
f
};
}
// far base
{
vertices
.
emplace_back
();
auto
v
=
dx
::
XMVector3Transform
(
base
,
dx
::
XMMatrixRotationZ
(
longitudeAngle
*
iLong
)
);
v
=
dx
::
XMVectorAdd
(
v
,
offset
);
dx
::
XMStoreFloat3
(
&
vertices
.
back
().
pos
,
v
);
vertices
.
back
().
n
=
{
vertices
.
back
().
pos
.
x
,
vertices
.
back
().
pos
.
y
,
0.0
f
};
}
}
std
::
vector
<
unsigned
short
>
indices
;
// near base indices
for
(
unsigned
short
iLong
=
0
;
iLong
<
longDiv
;
iLong
++
)
{
const
auto
i
=
iLong
*
2
;
const
auto
mod
=
longDiv
*
2
;
// near
indices
.
push_back
(
i
+
iBaseNear
);
indices
.
push_back
(
iCenterNear
);
indices
.
push_back
(
(
i
+
2
)
%
mod
+
iBaseNear
);
}
// far base indices
for
(
unsigned
short
iLong
=
0
;
iLong
<
longDiv
;
iLong
++
)
{
const
auto
i
=
iLong
*
2
;
const
auto
mod
=
longDiv
*
2
;
// far
indices
.
push_back
(
iCenterFar
);
indices
.
push_back
(
i
+
1
+
iBaseFar
);
indices
.
push_back
(
(
i
+
3
)
%
mod
+
iBaseFar
);
}
// fusilage indices
for
(
unsigned
short
iLong
=
0
;
iLong
<
longDiv
;
iLong
++
)
{
const
auto
i
=
iLong
*
2
;
const
auto
mod
=
longDiv
*
2
;
indices
.
push_back
(
i
+
iFusilage
);
indices
.
push_back
(
(
i
+
2
)
%
mod
+
iFusilage
);
indices
.
push_back
(
i
+
1
+
iFusilage
);
indices
.
push_back
(
(
i
+
2
)
%
mod
+
iFusilage
);
indices
.
push_back
(
(
i
+
3
)
%
mod
+
iFusilage
);
indices
.
push_back
(
i
+
1
+
iFusilage
);
}
return
{
std
::
move
(
vertices
),
std
::
move
(
indices
)
};
}
template
<
class
V
>
static
IndexedTriangleList
<
V
>
Make
()
{
return
MakeTesselated
<
V
>
(
24
);
...
...
hw3d/hw3d.vcxproj
View file @
0e8bebbf
...
...
@@ -153,6 +153,7 @@
<ClCompile
Include=
"Camera.cpp"
/>
<ClCompile
Include=
"ChiliException.cpp"
/>
<ClCompile
Include=
"ChiliTimer.cpp"
/>
<ClCompile
Include=
"Cylinder.cpp"
/>
<ClCompile
Include=
"Drawable.cpp"
/>
<ClCompile
Include=
"dxerr.cpp"
/>
<ClCompile
Include=
"DxgiInfoManager.cpp"
/>
...
...
@@ -199,6 +200,7 @@
<ClInclude
Include=
"Cone.h"
/>
<ClInclude
Include=
"ConstantBuffers.h"
/>
<ClInclude
Include=
"Cube.h"
/>
<ClInclude
Include=
"Cylinder.h"
/>
<ClInclude
Include=
"Drawable.h"
/>
<ClInclude
Include=
"DrawableBase.h"
/>
<ClInclude
Include=
"dxerr.h"
/>
...
...
@@ -280,6 +282,14 @@
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
</FxCompile>
<FxCompile
Include=
"IndexedPhongPS.hlsl"
>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
Pixel
</ShaderType>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
Pixel
</ShaderType>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
4.0
</ShaderModel>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
4.0
</ShaderModel>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
</FxCompile>
<FxCompile
Include=
"SolidPS.hlsl"
>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
Pixel
</ShaderType>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
4.0
</ShaderModel>
...
...
hw3d/hw3d.vcxproj.filters
View file @
0e8bebbf
...
...
@@ -156,6 +156,9 @@
<ClCompile
Include=
"TestObject.h"
>
<Filter>
Header Files\Drawable
</Filter>
</ClCompile>
<ClCompile
Include=
"Cylinder.cpp"
>
<Filter>
Source Files\Drawable
</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"WindowsMessageMap.h"
>
...
...
@@ -314,6 +317,9 @@
<ClInclude
Include=
"Pyramid.h"
>
<Filter>
Header Files\Drawable
</Filter>
</ClInclude>
<ClInclude
Include=
"Cylinder.h"
>
<Filter>
Header Files\Drawable
</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile
Include=
"hw3d.rc"
>
...
...
@@ -361,5 +367,8 @@
<FxCompile
Include=
"SolidVS.hlsl"
>
<Filter>
Shader
</Filter>
</FxCompile>
<FxCompile
Include=
"IndexedPhongPS.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