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
8e18159c
Commit
8e18159c
authored
May 03, 2019
by
chili
Browse files
controlling box material attributes
parent
be6a14ed
Changes
5
Show whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
8e18159c
...
...
@@ -73,6 +73,15 @@ App::App()
drawables
.
reserve
(
nDrawables
);
std
::
generate_n
(
std
::
back_inserter
(
drawables
),
nDrawables
,
Factory
{
wnd
.
Gfx
()
}
);
// init box pointers for editing instance parameters
for
(
auto
&
pd
:
drawables
)
{
if
(
auto
pb
=
dynamic_cast
<
Box
*>
(
pd
.
get
())
)
{
boxes
.
push_back
(
pb
);
}
}
wnd
.
Gfx
().
SetProjection
(
dx
::
XMMatrixPerspectiveLH
(
1.0
f
,
3.0
f
/
4.0
f
,
0.5
f
,
40.0
f
)
);
}
...
...
@@ -101,6 +110,8 @@ void App::DoFrame()
// imgui windows to control camera and light
cam
.
SpawnControlWindow
();
light
.
SpawnControlWindow
();
// imgui window to adjust box instance parameters
boxes
.
front
()
->
SpawnControlWindow
(
69
,
wnd
.
Gfx
()
);
// present
wnd
.
Gfx
().
EndFrame
();
...
...
hw3d/App.h
View file @
8e18159c
...
...
@@ -19,6 +19,7 @@ private:
Window
wnd
;
ChiliTimer
timer
;
std
::
vector
<
std
::
unique_ptr
<
class
Drawable
>>
drawables
;
std
::
vector
<
class
Box
*>
boxes
;
float
speed_factor
=
1.0
f
;
Camera
cam
;
PointLight
light
;
...
...
hw3d/Box.cpp
View file @
8e18159c
...
...
@@ -2,7 +2,7 @@
#include "BindableBase.h"
#include "GraphicsThrowMacros.h"
#include "Cube.h"
#include "imgui/imgui.h"
Box
::
Box
(
Graphics
&
gfx
,
std
::
mt19937
&
rng
,
...
...
@@ -53,15 +53,8 @@ Box::Box( Graphics& gfx,
AddBind
(
std
::
make_unique
<
TransformCbuf
>
(
gfx
,
*
this
)
);
struct
PSMaterialConstant
{
dx
::
XMFLOAT3
color
;
float
specularIntensity
=
0.6
f
;
float
specularPower
=
30.0
f
;
float
padding
[
3
];
}
colorConst
;
colorConst
.
color
=
material
;
AddBind
(
std
::
make_unique
<
PixelConstantBuffer
<
PSMaterialConstant
>>
(
gfx
,
colorConst
,
1u
)
);
materialConstants
.
color
=
material
;
AddBind
(
std
::
make_unique
<
MaterialCbuf
>
(
gfx
,
materialConstants
,
1u
)
);
// model deformation transform (per instance, not stored as bind)
dx
::
XMStoreFloat3x3
(
...
...
@@ -75,3 +68,29 @@ DirectX::XMMATRIX Box::GetTransformXM() const noexcept
namespace
dx
=
DirectX
;
return
dx
::
XMLoadFloat3x3
(
&
mt
)
*
TestObject
::
GetTransformXM
();
}
void
Box
::
SpawnControlWindow
(
int
id
,
Graphics
&
gfx
)
noexcept
{
using
namespace
std
::
string_literals
;
bool
dirty
=
false
;
if
(
ImGui
::
Begin
(
(
"Box "
s
+
std
::
to_string
(
id
)).
c_str
()
)
)
{
dirty
=
dirty
||
ImGui
::
ColorEdit3
(
"Material Color"
,
&
materialConstants
.
color
.
x
);
dirty
=
dirty
||
ImGui
::
SliderFloat
(
"Specular Intensity"
,
&
materialConstants
.
specularIntensity
,
0.05
f
,
4.0
f
,
"%.2f"
,
2
);
dirty
=
dirty
||
ImGui
::
SliderFloat
(
"Specular Power"
,
&
materialConstants
.
specularPower
,
1.0
f
,
200.0
f
,
"%.2f"
,
2
);
}
ImGui
::
End
();
if
(
dirty
)
{
SyncMaterial
(
gfx
);
}
}
void
Box
::
SyncMaterial
(
Graphics
&
gfx
)
noexcept
(
!
IS_DEBUG
)
{
auto
pConstPS
=
QueryBindable
<
MaterialCbuf
>
();
assert
(
pConstPS
!=
nullptr
);
pConstPS
->
Update
(
gfx
,
materialConstants
);
}
hw3d/Box.h
View file @
8e18159c
#pragma once
#include "TestObject.h"
#include "ConstantBuffers.h"
class
Box
:
public
TestObject
<
Box
>
{
...
...
@@ -12,6 +13,18 @@ public:
std
::
uniform_real_distribution
<
float
>&
bdist
,
DirectX
::
XMFLOAT3
material
);
DirectX
::
XMMATRIX
GetTransformXM
()
const
noexcept
override
;
void
SpawnControlWindow
(
int
id
,
Graphics
&
gfx
)
noexcept
;
private:
void
SyncMaterial
(
Graphics
&
gfx
)
noexcept
(
!
IS_DEBUG
);
private:
struct
PSMaterialConstant
{
DirectX
::
XMFLOAT3
color
;
float
specularIntensity
=
0.6
f
;
float
specularPower
=
30.0
f
;
float
padding
[
3
];
}
materialConstants
;
using
MaterialCbuf
=
PixelConstantBuffer
<
PSMaterialConstant
>
;
private:
// model transform
DirectX
::
XMFLOAT3X3
mt
;
...
...
hw3d/Drawable.h
View file @
8e18159c
...
...
@@ -16,6 +16,18 @@ public:
virtual
void
Update
(
float
dt
)
noexcept
=
0
;
virtual
~
Drawable
()
=
default
;
protected:
template
<
class
T
>
T
*
QueryBindable
()
noexcept
{
for
(
auto
&
pb
:
binds
)
{
if
(
auto
pt
=
dynamic_cast
<
T
*>
(
pb
.
get
())
)
{
return
pt
;
}
}
return
nullptr
;
}
void
AddBind
(
std
::
unique_ptr
<
Bindable
>
bind
)
noexcept
(
!
IS_DEBUG
);
void
AddIndexBuffer
(
std
::
unique_ptr
<
class
IndexBuffer
>
ibuf
)
noexcept
(
!
IS_DEBUG
);
private:
...
...
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