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
92780ee3
Commit
92780ee3
authored
Apr 14, 2019
by
chili
Browse files
problem with specular
parent
ffb174ec
Changes
6
Show whitespace changes
Inline
Side-by-side
hw3d/Box.cpp
View file @
92780ee3
...
@@ -64,8 +64,10 @@ Box::Box( Graphics& gfx,
...
@@ -64,8 +64,10 @@ Box::Box( Graphics& gfx,
struct
PSMaterialConstant
struct
PSMaterialConstant
{
{
dx
::
XMFLOAT3
color
;
alignas
(
16
)
dx
::
XMFLOAT3
color
;
float
padding
;
float
specularIntensity
=
0.6
f
;
float
specularPower
=
30.0
f
;
float
padding
[
2
];
}
colorConst
;
}
colorConst
;
colorConst
.
color
=
material
;
colorConst
.
color
=
material
;
AddBind
(
std
::
make_unique
<
PixelConstantBuffer
<
PSMaterialConstant
>>
(
gfx
,
colorConst
,
1u
)
);
AddBind
(
std
::
make_unique
<
PixelConstantBuffer
<
PSMaterialConstant
>>
(
gfx
,
colorConst
,
1u
)
);
...
...
hw3d/PhongPS.hlsl
View file @
92780ee3
...
@@ -12,6 +12,8 @@ cbuffer LightCBuf
...
@@ -12,6 +12,8 @@ cbuffer LightCBuf
cbuffer
ObjectCBuf
cbuffer
ObjectCBuf
{
{
float3
materialColor
;
float3
materialColor
;
float
specularIntensity
;
float
specularPower
;
};
};
...
@@ -25,6 +27,11 @@ float4 main( float3 worldPos : Position,float3 n : Normal ) : SV_Target
...
@@ -25,6 +27,11 @@ float4 main( float3 worldPos : Position,float3 n : Normal ) : SV_Target
const
float
att
=
1
.
0
f
/
(
attConst
+
attLin
*
distToL
+
attQuad
*
(
distToL
*
distToL
));
const
float
att
=
1
.
0
f
/
(
attConst
+
attLin
*
distToL
+
attQuad
*
(
distToL
*
distToL
));
// diffuse intensity
// diffuse intensity
const
float3
diffuse
=
diffuseColor
*
diffuseIntensity
*
att
*
max
(
0
.
0
f
,
dot
(
dirToL
,
n
)
);
const
float3
diffuse
=
diffuseColor
*
diffuseIntensity
*
att
*
max
(
0
.
0
f
,
dot
(
dirToL
,
n
)
);
// reflected light vector
const
float3
w
=
n
*
dot
(
dirToL
,
n
);
const
float3
r
=
w
*
2
.
0
f
-
dirToL
;
// calculate specular intensity based on angle between viewing vector and reflection vector, narrow with power function
const
float3
specular
=
(
diffuseColor
*
diffuseIntensity
)
*
specularIntensity
*
pow
(
max
(
0
.
0
f
,
dot
(
normalize
(
r
),
normalize
(
worldPos
)
)
),
specularPower
);
// final color
// final color
return
float4
(
saturate
(
(
diffuse
+
ambient
)
*
materialColor
),
1
.
0
f
);
return
float4
(
saturate
(
(
diffuse
+
ambient
+
specular
)
*
materialColor
),
1
.
0
f
);
}
}
\ No newline at end of file
hw3d/Sheet.cpp
deleted
100644 → 0
View file @
ffb174ec
#include "Sheet.h"
#include "BindableBase.h"
#include "GraphicsThrowMacros.h"
#include "Plane.h"
#include "Surface.h"
#include "Texture.h"
#include "Sampler.h"
Sheet
::
Sheet
(
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
)
:
r
(
rdist
(
rng
)
),
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
;
if
(
!
IsStaticInitialized
()
)
{
struct
Vertex
{
dx
::
XMFLOAT3
pos
;
struct
{
float
u
;
float
v
;
}
tex
;
};
auto
model
=
Plane
::
Make
<
Vertex
>
();
model
.
vertices
[
0
].
tex
=
{
0.0
f
,
0.0
f
};
model
.
vertices
[
1
].
tex
=
{
1.0
f
,
0.0
f
};
model
.
vertices
[
2
].
tex
=
{
0.0
f
,
1.0
f
};
model
.
vertices
[
3
].
tex
=
{
1.0
f
,
1.0
f
};
AddStaticBind
(
std
::
make_unique
<
Texture
>
(
gfx
,
Surface
::
FromFile
(
"Images
\\
kappa50.png"
)
)
);
AddStaticBind
(
std
::
make_unique
<
VertexBuffer
>
(
gfx
,
model
.
vertices
)
);
AddStaticBind
(
std
::
make_unique
<
Sampler
>
(
gfx
)
);
auto
pvs
=
std
::
make_unique
<
VertexShader
>
(
gfx
,
L"TextureVS.cso"
);
auto
pvsbc
=
pvs
->
GetBytecode
();
AddStaticBind
(
std
::
move
(
pvs
)
);
AddStaticBind
(
std
::
make_unique
<
PixelShader
>
(
gfx
,
L"TexturePS.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
},
{
"TexCoord"
,
0
,
DXGI_FORMAT_R32G32_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
)
);
}
else
{
SetIndexFromStatic
();
}
AddBind
(
std
::
make_unique
<
TransformCbuf
>
(
gfx
,
*
this
)
);
}
void
Sheet
::
Update
(
float
dt
)
noexcept
{
roll
+=
droll
*
dt
;
pitch
+=
dpitch
*
dt
;
yaw
+=
dyaw
*
dt
;
theta
+=
dtheta
*
dt
;
phi
+=
dphi
*
dt
;
chi
+=
dchi
*
dt
;
}
DirectX
::
XMMATRIX
Sheet
::
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/Sheet.h
deleted
100644 → 0
View file @
ffb174ec
#pragma once
#include "DrawableBase.h"
class
Sheet
:
public
DrawableBase
<
Sheet
>
{
public:
Sheet
(
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
);
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/hw3d.vcxproj
View file @
92780ee3
...
@@ -174,7 +174,6 @@
...
@@ -174,7 +174,6 @@
<ClCompile
Include=
"PixelShader.cpp"
/>
<ClCompile
Include=
"PixelShader.cpp"
/>
<ClCompile
Include=
"Pyramid.cpp"
/>
<ClCompile
Include=
"Pyramid.cpp"
/>
<ClCompile
Include=
"Sampler.cpp"
/>
<ClCompile
Include=
"Sampler.cpp"
/>
<ClCompile
Include=
"Sheet.cpp"
/>
<ClCompile
Include=
"SkinnedBox.cpp"
/>
<ClCompile
Include=
"SkinnedBox.cpp"
/>
<ClCompile
Include=
"Surface.cpp"
/>
<ClCompile
Include=
"Surface.cpp"
/>
<ClCompile
Include=
"Texture.cpp"
/>
<ClCompile
Include=
"Texture.cpp"
/>
...
@@ -220,15 +219,14 @@
...
@@ -220,15 +219,14 @@
<ClInclude
Include=
"InputLayout.h"
/>
<ClInclude
Include=
"InputLayout.h"
/>
<ClInclude
Include=
"Keyboard.h"
/>
<ClInclude
Include=
"Keyboard.h"
/>
<ClInclude
Include=
"PointLight.h"
/>
<ClInclude
Include=
"PointLight.h"
/>
<ClInclude
Include=
"Pyramid.h"
/>
<ClInclude
Include=
"SolidSphere.h"
/>
<ClInclude
Include=
"SolidSphere.h"
/>
<ClInclude
Include=
"Mouse.h"
/>
<ClInclude
Include=
"Mouse.h"
/>
<ClInclude
Include=
"PixelShader.h"
/>
<ClInclude
Include=
"PixelShader.h"
/>
<ClInclude
Include=
"Plane.h"
/>
<ClInclude
Include=
"Plane.h"
/>
<ClInclude
Include=
"Prism.h"
/>
<ClInclude
Include=
"Prism.h"
/>
<ClInclude
Include=
"Pyramid.h"
/>
<ClInclude
Include=
"resource.h"
/>
<ClInclude
Include=
"resource.h"
/>
<ClInclude
Include=
"Sampler.h"
/>
<ClInclude
Include=
"Sampler.h"
/>
<ClInclude
Include=
"Sheet.h"
/>
<ClInclude
Include=
"SkinnedBox.h"
/>
<ClInclude
Include=
"SkinnedBox.h"
/>
<ClInclude
Include=
"Sphere.h"
/>
<ClInclude
Include=
"Sphere.h"
/>
<ClInclude
Include=
"Surface.h"
/>
<ClInclude
Include=
"Surface.h"
/>
...
...
hw3d/hw3d.vcxproj.filters
View file @
92780ee3
...
@@ -114,9 +114,6 @@
...
@@ -114,9 +114,6 @@
<ClCompile
Include=
"GDIPlusManager.cpp"
>
<ClCompile
Include=
"GDIPlusManager.cpp"
>
<Filter>
Source Files
</Filter>
<Filter>
Source Files
</Filter>
</ClCompile>
</ClCompile>
<ClCompile
Include=
"Sheet.cpp"
>
<Filter>
Source Files\Drawable
</Filter>
</ClCompile>
<ClCompile
Include=
"Texture.cpp"
>
<ClCompile
Include=
"Texture.cpp"
>
<Filter>
Source Files\Bindable
</Filter>
<Filter>
Source Files\Bindable
</Filter>
</ClCompile>
</ClCompile>
...
@@ -260,9 +257,6 @@
...
@@ -260,9 +257,6 @@
<ClInclude
Include=
"Prism.h"
>
<ClInclude
Include=
"Prism.h"
>
<Filter>
Header Files\Geometry
</Filter>
<Filter>
Header Files\Geometry
</Filter>
</ClInclude>
</ClInclude>
<ClInclude
Include=
"Pyramid.h"
>
<Filter>
Header Files\Drawable
</Filter>
</ClInclude>
<ClInclude
Include=
"Surface.h"
>
<ClInclude
Include=
"Surface.h"
>
<Filter>
Header Files
</Filter>
<Filter>
Header Files
</Filter>
</ClInclude>
</ClInclude>
...
@@ -272,9 +266,6 @@
...
@@ -272,9 +266,6 @@
<ClInclude
Include=
"Texture.h"
>
<ClInclude
Include=
"Texture.h"
>
<Filter>
Header Files\Bindable
</Filter>
<Filter>
Header Files\Bindable
</Filter>
</ClInclude>
</ClInclude>
<ClInclude
Include=
"Sheet.h"
>
<Filter>
Header Files\Drawable
</Filter>
</ClInclude>
<ClInclude
Include=
"Sampler.h"
>
<ClInclude
Include=
"Sampler.h"
>
<Filter>
Header Files\Bindable
</Filter>
<Filter>
Header Files\Bindable
</Filter>
</ClInclude>
</ClInclude>
...
@@ -317,6 +308,9 @@
...
@@ -317,6 +308,9 @@
<ClInclude
Include=
"PointLight.h"
>
<ClInclude
Include=
"PointLight.h"
>
<Filter>
Header Files
</Filter>
<Filter>
Header Files
</Filter>
</ClInclude>
</ClInclude>
<ClInclude
Include=
"Pyramid.h"
>
<Filter>
Header Files\Drawable
</Filter>
</ClInclude>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ResourceCompile
Include=
"hw3d.rc"
>
<ResourceCompile
Include=
"hw3d.rc"
>
...
...
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