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
809cff33
Commit
809cff33
authored
Aug 04, 2019
by
chili
Browse files
create normal map shader
creepy normal map shitting the bed hard
parent
9f94557f
Changes
6
Show whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
809cff33
...
...
@@ -102,6 +102,7 @@ void App::DoFrame()
ShowImguiDemoWindow
();
nano
.
ShowWindow
(
"Model 1"
);
nano2
.
ShowWindow
(
"Model 2"
);
plane
.
SpawnControlWindow
(
wnd
.
Gfx
()
);
// present
wnd
.
Gfx
().
EndFrame
();
...
...
hw3d/PhongPSNormalMap.hlsl
0 → 100644
View file @
809cff33
cbuffer
LightCBuf
{
float3
lightPos
;
float3
ambient
;
float3
diffuseColor
;
float
diffuseIntensity
;
float
attConst
;
float
attLin
;
float
attQuad
;
};
cbuffer
ObjectCBuf
{
float
specularIntensity
;
float
specularPower
;
bool
normalMapEnabled
;
float
padding
[
1
];
};
Texture2D
tex
;
Texture2D
nmap
;
SamplerState
splr
;
float4
main
(
float3
worldPos
:
Position
,
float3
n
:
Normal
,
float2
tc
:
Texcoord
)
:
SV_Target
{
// sample normal from map if normal mapping enabled
if
(
normalMapEnabled
)
{
n
=
nmap
.
Sample
(
splr
,
tc
).
xyz
;
}
// 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
)
*
tex
.
Sample
(
splr
,
tc
).
rgb
+
specular
),
1
.
0
f
);
}
\ No newline at end of file
hw3d/TestPlane.cpp
View file @
809cff33
#include "TestPlane.h"
#include "Plane.h"
#include "BindableCommon.h"
#include "imgui/imgui.h"
TestPlane
::
TestPlane
(
Graphics
&
gfx
,
float
size
)
{
...
...
@@ -19,14 +20,8 @@ TestPlane::TestPlane( Graphics& gfx,float size )
auto
pvsbc
=
pvs
->
GetBytecode
();
AddBind
(
std
::
move
(
pvs
)
);
AddBind
(
PixelShader
::
Resolve
(
gfx
,
"PhongPS.cso"
)
);
AddBind
(
PixelShader
::
Resolve
(
gfx
,
"PhongPS
NormalMap
.cso"
)
);
struct
PSMaterialConstant
{
float
specularIntensity
=
0.1
f
;
float
specularPower
=
20.0
f
;
float
padding
[
2
];
}
pmc
;
AddBind
(
PixelConstantBuffer
<
PSMaterialConstant
>::
Resolve
(
gfx
,
pmc
,
1u
)
);
AddBind
(
InputLayout
::
Resolve
(
gfx
,
model
.
vertices
.
GetLayout
(),
pvsbc
)
);
...
...
@@ -53,3 +48,29 @@ DirectX::XMMATRIX TestPlane::GetTransformXM() const noexcept
return
DirectX
::
XMMatrixRotationRollPitchYaw
(
roll
,
pitch
,
yaw
)
*
DirectX
::
XMMatrixTranslation
(
pos
.
x
,
pos
.
y
,
pos
.
z
);
}
void
TestPlane
::
SpawnControlWindow
(
Graphics
&
gfx
)
noexcept
{
if
(
ImGui
::
Begin
(
"Plane"
)
)
{
ImGui
::
Text
(
"Position"
);
ImGui
::
SliderFloat
(
"X"
,
&
pos
.
x
,
-
80.0
f
,
80.0
f
,
"%.1f"
);
ImGui
::
SliderFloat
(
"Y"
,
&
pos
.
y
,
-
80.0
f
,
80.0
f
,
"%.1f"
);
ImGui
::
SliderFloat
(
"Z"
,
&
pos
.
z
,
-
80.0
f
,
80.0
f
,
"%.1f"
);
ImGui
::
Text
(
"Orientation"
);
ImGui
::
SliderAngle
(
"Roll"
,
&
roll
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Pitch"
,
&
pitch
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Yaw"
,
&
yaw
,
-
180.0
f
,
180.0
f
);
ImGui
::
Text
(
"Shading"
);
bool
changed0
=
ImGui
::
SliderFloat
(
"Spec. Int."
,
&
pmc
.
specularIntensity
,
0.0
f
,
1.0
f
);
bool
changed1
=
ImGui
::
SliderFloat
(
"Spec. Power"
,
&
pmc
.
specularPower
,
0.0
f
,
100.0
f
);
bool
checkState
=
pmc
.
normalMappingEnabled
==
TRUE
;
bool
changed2
=
ImGui
::
Checkbox
(
"Enable Normal Map"
,
&
checkState
);
pmc
.
normalMappingEnabled
=
checkState
?
TRUE
:
FALSE
;
if
(
changed0
||
changed1
||
changed2
)
{
QueryBindable
<
Bind
::
PixelConstantBuffer
<
PSMaterialConstant
>>
()
->
Update
(
gfx
,
pmc
);
}
}
ImGui
::
End
();
}
hw3d/TestPlane.h
View file @
809cff33
...
...
@@ -8,7 +8,15 @@ public:
void
SetPos
(
DirectX
::
XMFLOAT3
pos
)
noexcept
;
void
SetRotation
(
float
roll
,
float
pitch
,
float
yaw
)
noexcept
;
DirectX
::
XMMATRIX
GetTransformXM
()
const
noexcept
override
;
void
SpawnControlWindow
(
Graphics
&
gfx
)
noexcept
;
private:
struct
PSMaterialConstant
{
float
specularIntensity
=
0.1
f
;
float
specularPower
=
20.0
f
;
BOOL
normalMappingEnabled
=
TRUE
;
float
padding
[
1
];
}
pmc
;
DirectX
::
XMFLOAT3
pos
=
{
1.0
f
,
1.0
f
,
1.0
f
};
float
roll
=
0.0
f
;
float
pitch
=
0.0
f
;
...
...
hw3d/hw3d.vcxproj
View file @
809cff33
...
...
@@ -194,6 +194,14 @@
<None
Include=
"DXTrace.inl"
/>
</ItemGroup>
<ItemGroup>
<FxCompile
Include=
"PhongPSNormalMap.hlsl"
>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
Pixel
</ShaderType>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
4.0
</ShaderModel>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
Pixel
</ShaderType>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
4.0
</ShaderModel>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
</FxCompile>
<FxCompile
Include=
"PhongPSSpecMap.hlsl"
>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
Pixel
</ShaderType>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
4.0
</ShaderModel>
...
...
hw3d/hw3d.vcxproj.filters
View file @
809cff33
...
...
@@ -151,7 +151,7 @@
<Filter>
Source Files
</Filter>
</ClCompile>
<ClCompile
Include=
"TestPlane.cpp"
>
<Filter>
Source Files
</Filter>
<Filter>
Source Files
\Drawable
</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
...
...
@@ -346,5 +346,8 @@
<FxCompile
Include=
"PhongPSSpecMap.hlsl"
>
<Filter>
Shader
</Filter>
</FxCompile>
<FxCompile
Include=
"PhongPSNormalMap.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