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
be6a14ed
Commit
be6a14ed
authored
May 03, 2019
by
chili
Browse files
pyramid and cylinder independent meshes
parent
3164667b
Changes
2
Show whitespace changes
Inline
Side-by-side
hw3d/Cylinder.cpp
View file @
be6a14ed
...
@@ -16,23 +16,12 @@ Cylinder::Cylinder( Graphics& gfx,std::mt19937& rng,
...
@@ -16,23 +16,12 @@ Cylinder::Cylinder( Graphics& gfx,std::mt19937& rng,
if
(
!
IsStaticInitialized
()
)
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
pvs
=
std
::
make_unique
<
VertexShader
>
(
gfx
,
L"PhongVS.cso"
);
auto
pvsbc
=
pvs
->
GetBytecode
();
auto
pvsbc
=
pvs
->
GetBytecode
();
AddStaticBind
(
std
::
move
(
pvs
)
);
AddStaticBind
(
std
::
move
(
pvs
)
);
AddStaticBind
(
std
::
make_unique
<
PixelShader
>
(
gfx
,
L"IndexedPhongPS.cso"
)
);
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
=
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
},
...
@@ -57,10 +46,15 @@ Cylinder::Cylinder( Graphics& gfx,std::mt19937& rng,
...
@@ -57,10 +46,15 @@ Cylinder::Cylinder( Graphics& gfx,std::mt19937& rng,
}
matConst
;
}
matConst
;
AddStaticBind
(
std
::
make_unique
<
PixelConstantBuffer
<
PSMaterialConstant
>>
(
gfx
,
matConst
,
1u
)
);
AddStaticBind
(
std
::
make_unique
<
PixelConstantBuffer
<
PSMaterialConstant
>>
(
gfx
,
matConst
,
1u
)
);
}
}
else
struct
Vertex
{
{
SetIndexFromStatic
();
dx
::
XMFLOAT3
pos
;
}
dx
::
XMFLOAT3
n
;
};
const
auto
model
=
Prism
::
MakeTesselatedIndependentCapNormals
<
Vertex
>
(
tdist
(
rng
)
);
AddBind
(
std
::
make_unique
<
VertexBuffer
>
(
gfx
,
model
.
vertices
)
);
AddIndexBuffer
(
std
::
make_unique
<
IndexBuffer
>
(
gfx
,
model
.
indices
)
);
AddBind
(
std
::
make_unique
<
TransformCbuf
>
(
gfx
,
*
this
)
);
AddBind
(
std
::
make_unique
<
TransformCbuf
>
(
gfx
,
*
this
)
);
}
}
hw3d/Pyramid.cpp
View file @
be6a14ed
...
@@ -18,39 +18,12 @@ Pyramid::Pyramid( Graphics& gfx,std::mt19937& rng,
...
@@ -18,39 +18,12 @@ Pyramid::Pyramid( Graphics& gfx,std::mt19937& rng,
if
(
!
IsStaticInitialized
()
)
if
(
!
IsStaticInitialized
()
)
{
{
struct
Vertex
{
dx
::
XMFLOAT3
pos
;
dx
::
XMFLOAT3
n
;
std
::
array
<
char
,
4
>
color
;
char
padding
;
};
const
auto
tesselation
=
tdist
(
rng
);
auto
model
=
Cone
::
MakeTesselatedIndependentFaces
<
Vertex
>
(
tesselation
);
// set vertex colors for mesh (tip red blending to blue base)
for
(
auto
&
v
:
model
.
vertices
)
{
v
.
color
=
{
(
char
)
10
,(
char
)
10
,(
char
)
255
};
}
for
(
int
i
=
0
;
i
<
tesselation
;
i
++
)
{
model
.
vertices
[
i
*
3
].
color
=
{
(
char
)
255
,(
char
)
10
,(
char
)
10
};
}
// squash mesh a bit in the z direction
model
.
Transform
(
dx
::
XMMatrixScaling
(
1.0
f
,
1.0
f
,
0.7
f
)
);
// add normals
model
.
SetNormalsIndependentFlat
();
AddStaticBind
(
std
::
make_unique
<
VertexBuffer
>
(
gfx
,
model
.
vertices
)
);
auto
pvs
=
std
::
make_unique
<
VertexShader
>
(
gfx
,
L"BlendedPhongVS.cso"
);
auto
pvs
=
std
::
make_unique
<
VertexShader
>
(
gfx
,
L"BlendedPhongVS.cso"
);
auto
pvsbc
=
pvs
->
GetBytecode
();
auto
pvsbc
=
pvs
->
GetBytecode
();
AddStaticBind
(
std
::
move
(
pvs
)
);
AddStaticBind
(
std
::
move
(
pvs
)
);
AddStaticBind
(
std
::
make_unique
<
PixelShader
>
(
gfx
,
L"BlendedPhongPS.cso"
)
);
AddStaticBind
(
std
::
make_unique
<
PixelShader
>
(
gfx
,
L"BlendedPhongPS.cso"
)
);
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
},
...
@@ -69,10 +42,32 @@ Pyramid::Pyramid( Graphics& gfx,std::mt19937& rng,
...
@@ -69,10 +42,32 @@ Pyramid::Pyramid( Graphics& gfx,std::mt19937& rng,
}
colorConst
;
}
colorConst
;
AddStaticBind
(
std
::
make_unique
<
PixelConstantBuffer
<
PSMaterialConstant
>>
(
gfx
,
colorConst
,
1u
)
);
AddStaticBind
(
std
::
make_unique
<
PixelConstantBuffer
<
PSMaterialConstant
>>
(
gfx
,
colorConst
,
1u
)
);
}
}
else
struct
Vertex
{
{
SetIndexFromStatic
();
dx
::
XMFLOAT3
pos
;
dx
::
XMFLOAT3
n
;
std
::
array
<
char
,
4
>
color
;
char
padding
;
};
const
auto
tesselation
=
tdist
(
rng
);
auto
model
=
Cone
::
MakeTesselatedIndependentFaces
<
Vertex
>
(
tesselation
);
// set vertex colors for mesh (tip red blending to blue base)
for
(
auto
&
v
:
model
.
vertices
)
{
v
.
color
=
{
(
char
)
10
,(
char
)
10
,(
char
)
255
};
}
for
(
int
i
=
0
;
i
<
tesselation
;
i
++
)
{
model
.
vertices
[
i
*
3
].
color
=
{
(
char
)
255
,(
char
)
10
,(
char
)
10
};
}
}
// squash mesh a bit in the z direction
model
.
Transform
(
dx
::
XMMatrixScaling
(
1.0
f
,
1.0
f
,
0.7
f
)
);
// add normals
model
.
SetNormalsIndependentFlat
();
AddBind
(
std
::
make_unique
<
VertexBuffer
>
(
gfx
,
model
.
vertices
)
);
AddIndexBuffer
(
std
::
make_unique
<
IndexBuffer
>
(
gfx
,
model
.
indices
)
);
AddBind
(
std
::
make_unique
<
TransformCbuf
>
(
gfx
,
*
this
)
);
AddBind
(
std
::
make_unique
<
TransformCbuf
>
(
gfx
,
*
this
)
);
}
}
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