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
ffb174ec
Commit
ffb174ec
authored
Apr 14, 2019
by
chili
Browse files
multiple slots
parent
dac6adaf
Changes
9
Hide whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
ffb174ec
...
@@ -25,9 +25,10 @@ App::App()
...
@@ -25,9 +25,10 @@ App::App()
{}
{}
std
::
unique_ptr
<
Drawable
>
operator
()()
std
::
unique_ptr
<
Drawable
>
operator
()()
{
{
const
DirectX
::
XMFLOAT3
mat
=
{
cdist
(
rng
),
cdist
(
rng
),
cdist
(
rng
)
};
return
std
::
make_unique
<
Box
>
(
return
std
::
make_unique
<
Box
>
(
gfx
,
rng
,
adist
,
ddist
,
gfx
,
rng
,
adist
,
ddist
,
odist
,
rdist
,
bdist
odist
,
rdist
,
bdist
,
mat
);
);
}
}
private:
private:
...
@@ -38,6 +39,7 @@ App::App()
...
@@ -38,6 +39,7 @@ App::App()
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
};
std
::
uniform_real_distribution
<
float
>
rdist
{
6.0
f
,
20.0
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
>
bdist
{
0.4
f
,
3.0
f
};
std
::
uniform_real_distribution
<
float
>
cdist
{
0.0
f
,
1.0
f
};
};
};
drawables
.
reserve
(
nDrawables
);
drawables
.
reserve
(
nDrawables
);
...
...
hw3d/Box.cpp
View file @
ffb174ec
...
@@ -10,7 +10,8 @@ Box::Box( Graphics& gfx,
...
@@ -10,7 +10,8 @@ Box::Box( Graphics& gfx,
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
,
std
::
uniform_real_distribution
<
float
>&
bdist
)
std
::
uniform_real_distribution
<
float
>&
bdist
,
DirectX
::
XMFLOAT3
material
)
:
:
r
(
rdist
(
rng
)
),
r
(
rdist
(
rng
)
),
droll
(
ddist
(
rng
)
),
droll
(
ddist
(
rng
)
),
...
@@ -61,6 +62,14 @@ Box::Box( Graphics& gfx,
...
@@ -61,6 +62,14 @@ Box::Box( Graphics& gfx,
AddBind
(
std
::
make_unique
<
TransformCbuf
>
(
gfx
,
*
this
)
);
AddBind
(
std
::
make_unique
<
TransformCbuf
>
(
gfx
,
*
this
)
);
struct
PSMaterialConstant
{
dx
::
XMFLOAT3
color
;
float
padding
;
}
colorConst
;
colorConst
.
color
=
material
;
AddBind
(
std
::
make_unique
<
PixelConstantBuffer
<
PSMaterialConstant
>>
(
gfx
,
colorConst
,
1u
)
);
// model deformation transform (per instance, not stored as bind)
// model deformation transform (per instance, not stored as bind)
dx
::
XMStoreFloat3x3
(
dx
::
XMStoreFloat3x3
(
&
mt
,
&
mt
,
...
...
hw3d/Box.h
View file @
ffb174ec
...
@@ -9,7 +9,8 @@ public:
...
@@ -9,7 +9,8 @@ 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
,
std
::
uniform_real_distribution
<
float
>&
bdist
);
std
::
uniform_real_distribution
<
float
>&
bdist
,
DirectX
::
XMFLOAT3
material
);
void
Update
(
float
dt
)
noexcept
override
;
void
Update
(
float
dt
)
noexcept
override
;
DirectX
::
XMMATRIX
GetTransformXM
()
const
noexcept
override
;
DirectX
::
XMMATRIX
GetTransformXM
()
const
noexcept
override
;
private:
private:
...
...
hw3d/ConstantBuffers.h
View file @
ffb174ec
...
@@ -19,7 +19,9 @@ public:
...
@@ -19,7 +19,9 @@ public:
memcpy
(
msr
.
pData
,
&
consts
,
sizeof
(
consts
)
);
memcpy
(
msr
.
pData
,
&
consts
,
sizeof
(
consts
)
);
GetContext
(
gfx
)
->
Unmap
(
pConstantBuffer
.
Get
(),
0u
);
GetContext
(
gfx
)
->
Unmap
(
pConstantBuffer
.
Get
(),
0u
);
}
}
ConstantBuffer
(
Graphics
&
gfx
,
const
C
&
consts
)
ConstantBuffer
(
Graphics
&
gfx
,
const
C
&
consts
,
UINT
slot
=
0u
)
:
slot
(
slot
)
{
{
INFOMAN
(
gfx
);
INFOMAN
(
gfx
);
...
@@ -35,7 +37,9 @@ public:
...
@@ -35,7 +37,9 @@ public:
csd
.
pSysMem
=
&
consts
;
csd
.
pSysMem
=
&
consts
;
GFX_THROW_INFO
(
GetDevice
(
gfx
)
->
CreateBuffer
(
&
cbd
,
&
csd
,
&
pConstantBuffer
)
);
GFX_THROW_INFO
(
GetDevice
(
gfx
)
->
CreateBuffer
(
&
cbd
,
&
csd
,
&
pConstantBuffer
)
);
}
}
ConstantBuffer
(
Graphics
&
gfx
)
ConstantBuffer
(
Graphics
&
gfx
,
UINT
slot
=
0u
)
:
slot
(
slot
)
{
{
INFOMAN
(
gfx
);
INFOMAN
(
gfx
);
...
@@ -50,18 +54,20 @@ public:
...
@@ -50,18 +54,20 @@ public:
}
}
protected:
protected:
Microsoft
::
WRL
::
ComPtr
<
ID3D11Buffer
>
pConstantBuffer
;
Microsoft
::
WRL
::
ComPtr
<
ID3D11Buffer
>
pConstantBuffer
;
UINT
slot
;
};
};
template
<
typename
C
>
template
<
typename
C
>
class
VertexConstantBuffer
:
public
ConstantBuffer
<
C
>
class
VertexConstantBuffer
:
public
ConstantBuffer
<
C
>
{
{
using
ConstantBuffer
<
C
>::
pConstantBuffer
;
using
ConstantBuffer
<
C
>::
pConstantBuffer
;
using
ConstantBuffer
<
C
>::
slot
;
using
Bindable
::
GetContext
;
using
Bindable
::
GetContext
;
public:
public:
using
ConstantBuffer
<
C
>::
ConstantBuffer
;
using
ConstantBuffer
<
C
>::
ConstantBuffer
;
void
Bind
(
Graphics
&
gfx
)
noexcept
override
void
Bind
(
Graphics
&
gfx
)
noexcept
override
{
{
GetContext
(
gfx
)
->
VSSetConstantBuffers
(
0u
,
1u
,
pConstantBuffer
.
GetAddressOf
()
);
GetContext
(
gfx
)
->
VSSetConstantBuffers
(
slot
,
1u
,
pConstantBuffer
.
GetAddressOf
()
);
}
}
};
};
...
@@ -69,11 +75,12 @@ template<typename C>
...
@@ -69,11 +75,12 @@ template<typename C>
class
PixelConstantBuffer
:
public
ConstantBuffer
<
C
>
class
PixelConstantBuffer
:
public
ConstantBuffer
<
C
>
{
{
using
ConstantBuffer
<
C
>::
pConstantBuffer
;
using
ConstantBuffer
<
C
>::
pConstantBuffer
;
using
ConstantBuffer
<
C
>::
slot
;
using
Bindable
::
GetContext
;
using
Bindable
::
GetContext
;
public:
public:
using
ConstantBuffer
<
C
>::
ConstantBuffer
;
using
ConstantBuffer
<
C
>::
ConstantBuffer
;
void
Bind
(
Graphics
&
gfx
)
noexcept
override
void
Bind
(
Graphics
&
gfx
)
noexcept
override
{
{
GetContext
(
gfx
)
->
PSSetConstantBuffers
(
0u
,
1u
,
pConstantBuffer
.
GetAddressOf
()
);
GetContext
(
gfx
)
->
PSSetConstantBuffers
(
slot
,
1u
,
pConstantBuffer
.
GetAddressOf
()
);
}
}
};
};
\ No newline at end of file
hw3d/PhongPS.hlsl
View file @
ffb174ec
cbuffer
LightCBuf
cbuffer
LightCBuf
{
{
float3
lightPos
;
float3
lightPos
;
float3
materialColor
;
float3
ambient
;
float3
ambient
;
float3
diffuseColor
;
float3
diffuseColor
;
float
diffuseIntensity
;
float
diffuseIntensity
;
...
@@ -10,6 +9,11 @@ cbuffer LightCBuf
...
@@ -10,6 +9,11 @@ cbuffer LightCBuf
float
attQuad
;
float
attQuad
;
};
};
cbuffer
ObjectCBuf
{
float3
materialColor
;
};
float4
main
(
float3
worldPos
:
Position
,
float3
n
:
Normal
)
:
SV_Target
float4
main
(
float3
worldPos
:
Position
,
float3
n
:
Normal
)
:
SV_Target
{
{
...
...
hw3d/PointLight.cpp
View file @
ffb174ec
...
@@ -22,7 +22,6 @@ void PointLight::SpawnControlWindow() noexcept
...
@@ -22,7 +22,6 @@ void PointLight::SpawnControlWindow() noexcept
ImGui
::
SliderFloat
(
"Intensity"
,
&
cbData
.
diffuseIntensity
,
0.01
f
,
2.0
f
,
"%.2f"
,
2
);
ImGui
::
SliderFloat
(
"Intensity"
,
&
cbData
.
diffuseIntensity
,
0.01
f
,
2.0
f
,
"%.2f"
,
2
);
ImGui
::
ColorEdit3
(
"Diffuse Color"
,
&
cbData
.
diffuseColor
.
x
);
ImGui
::
ColorEdit3
(
"Diffuse Color"
,
&
cbData
.
diffuseColor
.
x
);
ImGui
::
ColorEdit3
(
"Ambient"
,
&
cbData
.
ambient
.
x
);
ImGui
::
ColorEdit3
(
"Ambient"
,
&
cbData
.
ambient
.
x
);
ImGui
::
ColorEdit3
(
"Material"
,
&
cbData
.
materialColor
.
x
);
ImGui
::
Text
(
"Falloff"
);
ImGui
::
Text
(
"Falloff"
);
ImGui
::
SliderFloat
(
"Constant"
,
&
cbData
.
attConst
,
0.05
f
,
10.0
f
,
"%.2f"
,
4
);
ImGui
::
SliderFloat
(
"Constant"
,
&
cbData
.
attConst
,
0.05
f
,
10.0
f
,
"%.2f"
,
4
);
...
@@ -41,7 +40,6 @@ void PointLight::Reset() noexcept
...
@@ -41,7 +40,6 @@ void PointLight::Reset() noexcept
{
{
cbData
=
{
cbData
=
{
{
0.0
f
,
0.0
f
,
0.0
f
},
{
0.0
f
,
0.0
f
,
0.0
f
},
{
0.7
f
,
0.7
f
,
0.9
f
},
{
0.05
f
,
0.05
f
,
0.05
f
},
{
0.05
f
,
0.05
f
,
0.05
f
},
{
1.0
f
,
1.0
f
,
1.0
f
},
{
1.0
f
,
1.0
f
,
1.0
f
},
1.0
f
,
1.0
f
,
...
...
hw3d/PointLight.h
View file @
ffb174ec
...
@@ -15,7 +15,6 @@ private:
...
@@ -15,7 +15,6 @@ private:
struct
PointLightCBuf
struct
PointLightCBuf
{
{
alignas
(
16
)
DirectX
::
XMFLOAT3
pos
;
alignas
(
16
)
DirectX
::
XMFLOAT3
pos
;
alignas
(
16
)
DirectX
::
XMFLOAT3
materialColor
;
alignas
(
16
)
DirectX
::
XMFLOAT3
ambient
;
alignas
(
16
)
DirectX
::
XMFLOAT3
ambient
;
alignas
(
16
)
DirectX
::
XMFLOAT3
diffuseColor
;
alignas
(
16
)
DirectX
::
XMFLOAT3
diffuseColor
;
float
diffuseIntensity
;
float
diffuseIntensity
;
...
...
hw3d/TransformCbuf.cpp
View file @
ffb174ec
#include "TransformCbuf.h"
#include "TransformCbuf.h"
TransformCbuf
::
TransformCbuf
(
Graphics
&
gfx
,
const
Drawable
&
parent
)
TransformCbuf
::
TransformCbuf
(
Graphics
&
gfx
,
const
Drawable
&
parent
,
UINT
slot
)
:
:
parent
(
parent
)
parent
(
parent
)
{
{
if
(
!
pVcbuf
)
if
(
!
pVcbuf
)
{
{
pVcbuf
=
std
::
make_unique
<
VertexConstantBuffer
<
Transforms
>>
(
gfx
);
pVcbuf
=
std
::
make_unique
<
VertexConstantBuffer
<
Transforms
>>
(
gfx
,
slot
);
}
}
}
}
...
...
hw3d/TransformCbuf.h
View file @
ffb174ec
...
@@ -12,7 +12,7 @@ private:
...
@@ -12,7 +12,7 @@ private:
DirectX
::
XMMATRIX
model
;
DirectX
::
XMMATRIX
model
;
};
};
public:
public:
TransformCbuf
(
Graphics
&
gfx
,
const
Drawable
&
parent
);
TransformCbuf
(
Graphics
&
gfx
,
const
Drawable
&
parent
,
UINT
slot
=
0u
);
void
Bind
(
Graphics
&
gfx
)
noexcept
override
;
void
Bind
(
Graphics
&
gfx
)
noexcept
override
;
private:
private:
static
std
::
unique_ptr
<
VertexConstantBuffer
<
Transforms
>>
pVcbuf
;
static
std
::
unique_ptr
<
VertexConstantBuffer
<
Transforms
>>
pVcbuf
;
...
...
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