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
617483fa
Commit
617483fa
authored
Aug 06, 2019
by
chili
Browse files
comparing object space / tangent space nmapping
parent
3fd3a302
Changes
11
Show whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
617483fa
...
@@ -16,6 +16,8 @@ App::App()
...
@@ -16,6 +16,8 @@ App::App()
wnd
(
1280
,
720
,
"The Donkey Fart Box"
),
wnd
(
1280
,
720
,
"The Donkey Fart Box"
),
light
(
wnd
.
Gfx
()
)
light
(
wnd
.
Gfx
()
)
{
{
wall
.
SetRootTransform
(
dx
::
XMMatrixTranslation
(
-
1.5
f
,
0.0
f
,
0.0
f
)
);
tp
.
SetPos
(
{
1.5
f
,
0.0
f
,
0.0
f
}
);
wnd
.
Gfx
().
SetProjection
(
dx
::
XMMatrixPerspectiveLH
(
1.0
f
,
9.0
f
/
16.0
f
,
0.5
f
,
40.0
f
)
);
wnd
.
Gfx
().
SetProjection
(
dx
::
XMMatrixPerspectiveLH
(
1.0
f
,
9.0
f
/
16.0
f
,
0.5
f
,
40.0
f
)
);
}
}
...
@@ -27,6 +29,7 @@ void App::DoFrame()
...
@@ -27,6 +29,7 @@ void App::DoFrame()
light
.
Bind
(
wnd
.
Gfx
(),
cam
.
GetMatrix
()
);
light
.
Bind
(
wnd
.
Gfx
(),
cam
.
GetMatrix
()
);
wall
.
Draw
(
wnd
.
Gfx
()
);
wall
.
Draw
(
wnd
.
Gfx
()
);
tp
.
Draw
(
wnd
.
Gfx
()
);
//nano.Draw( wnd.Gfx() );
//nano.Draw( wnd.Gfx() );
light
.
Draw
(
wnd
.
Gfx
()
);
light
.
Draw
(
wnd
.
Gfx
()
);
...
@@ -98,6 +101,7 @@ void App::DoFrame()
...
@@ -98,6 +101,7 @@ void App::DoFrame()
light
.
SpawnControlWindow
();
light
.
SpawnControlWindow
();
ShowImguiDemoWindow
();
ShowImguiDemoWindow
();
wall
.
ShowWindow
(
"Wall"
);
wall
.
ShowWindow
(
"Wall"
);
tp
.
SpawnControlWindow
(
wnd
.
Gfx
()
);
//nano.ShowWindow( "Model 1" );
//nano.ShowWindow( "Model 1" );
// present
// present
...
...
hw3d/App.h
View file @
617483fa
...
@@ -27,5 +27,6 @@ private:
...
@@ -27,5 +27,6 @@ private:
Camera
cam
;
Camera
cam
;
PointLight
light
;
PointLight
light
;
Model
wall
{
wnd
.
Gfx
(),
"Models
\\
brick_wall
\\
brick_wall.obj"
};
Model
wall
{
wnd
.
Gfx
(),
"Models
\\
brick_wall
\\
brick_wall.obj"
};
TestPlane
tp
{
wnd
.
Gfx
(),
1.0
};
//Model nano{ wnd.Gfx(),"Models\\nano_textured\\nanosuit.obj" };
//Model nano{ wnd.Gfx(),"Models\\nano_textured\\nanosuit.obj" };
};
};
\ No newline at end of file
hw3d/Camera.cpp
View file @
617483fa
...
@@ -47,7 +47,7 @@ void Camera::SpawnControlWindow() noexcept
...
@@ -47,7 +47,7 @@ void Camera::SpawnControlWindow() noexcept
void
Camera
::
Reset
()
noexcept
void
Camera
::
Reset
()
noexcept
{
{
pos
=
{
0.0
f
,
7.5
f
,
-
1
8
.0
f
};
pos
=
{
0.0
f
,
0.0
f
,
-
1
0
.0
f
};
pitch
=
0.0
f
;
pitch
=
0.0
f
;
yaw
=
0.0
f
;
yaw
=
0.0
f
;
}
}
...
...
hw3d/Mesh.cpp
View file @
617483fa
...
@@ -224,6 +224,11 @@ void Model::ShowWindow( const char* windowName ) noexcept
...
@@ -224,6 +224,11 @@ void Model::ShowWindow( const char* windowName ) noexcept
pWindow
->
Show
(
windowName
,
*
pRoot
);
pWindow
->
Show
(
windowName
,
*
pRoot
);
}
}
void
Model
::
SetRootTransform
(
DirectX
::
FXMMATRIX
tf
)
noexcept
{
pRoot
->
SetAppliedTransform
(
tf
);
}
Model
::~
Model
()
noexcept
Model
::~
Model
()
noexcept
{}
{}
...
@@ -326,7 +331,7 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
...
@@ -326,7 +331,7 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
struct
PSMaterialConstant
struct
PSMaterialConstant
{
{
float
specularIntensity
=
0.8
f
;
float
specularIntensity
=
0.
1
8
f
;
float
specularPower
;
float
specularPower
;
BOOL
normalMapEnabled
=
TRUE
;
BOOL
normalMapEnabled
=
TRUE
;
float
padding
[
1
];
float
padding
[
1
];
...
...
hw3d/Mesh.h
View file @
617483fa
...
@@ -56,6 +56,7 @@ public:
...
@@ -56,6 +56,7 @@ public:
Model
(
Graphics
&
gfx
,
const
std
::
string
fileName
);
Model
(
Graphics
&
gfx
,
const
std
::
string
fileName
);
void
Draw
(
Graphics
&
gfx
)
const
noxnd
;
void
Draw
(
Graphics
&
gfx
)
const
noxnd
;
void
ShowWindow
(
const
char
*
windowName
=
nullptr
)
noexcept
;
void
ShowWindow
(
const
char
*
windowName
=
nullptr
)
noexcept
;
void
SetRootTransform
(
DirectX
::
FXMMATRIX
tf
)
noexcept
;
~
Model
()
noexcept
;
~
Model
()
noexcept
;
private:
private:
static
std
::
unique_ptr
<
Mesh
>
ParseMesh
(
Graphics
&
gfx
,
const
aiMesh
&
mesh
,
const
aiMaterial
*
const
*
pMaterials
);
static
std
::
unique_ptr
<
Mesh
>
ParseMesh
(
Graphics
&
gfx
,
const
aiMesh
&
mesh
,
const
aiMaterial
*
const
*
pMaterials
);
...
...
hw3d/PhongPSNormalMapObject.hlsl
0 → 100644
View file @
617483fa
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
:
register
(
t2
);
SamplerState
splr
;
float4
main
(
float3
viewPos
:
Position
,
float3
n
:
Normal
,
float2
tc
:
Texcoord
)
:
SV_Target
{
// sample normal from map if normal mapping enabled
if
(
normalMapEnabled
)
{
// unpack normal data
const
float3
normalSample
=
nmap
.
Sample
(
splr
,
tc
).
xyz
;
n
.
x
=
normalSample
.
x
*
2
.
0
f
-
1
.
0
f
;
n
.
y
=
-
normalSample
.
y
*
2
.
0
f
+
1
.
0
f
;
n
.
z
=
-
normalSample
.
z
;
}
// fragment to light vector data
const
float3
vToL
=
lightPos
-
viewPos
;
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
(
viewPos
)
)
),
specularPower
);
// final color
return
float4
(
saturate
(
(
diffuse
+
ambient
)
*
tex
.
Sample
(
splr
,
tc
).
rgb
+
specular
),
1
.
0
f
);
}
\ No newline at end of file
hw3d/PointLight.cpp
View file @
617483fa
...
@@ -39,7 +39,7 @@ void PointLight::SpawnControlWindow() noexcept
...
@@ -39,7 +39,7 @@ void PointLight::SpawnControlWindow() noexcept
void
PointLight
::
Reset
()
noexcept
void
PointLight
::
Reset
()
noexcept
{
{
cbData
=
{
cbData
=
{
{
1.5
f
,
1
4.0
f
,
-
4.5
f
},
{
0.0
f
,
4.0
f
,
-
4.5
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/TestPlane.cpp
View file @
617483fa
...
@@ -21,7 +21,7 @@ TestPlane::TestPlane( Graphics& gfx,float size )
...
@@ -21,7 +21,7 @@ TestPlane::TestPlane( Graphics& gfx,float size )
auto
pvsbc
=
pvs
->
GetBytecode
();
auto
pvsbc
=
pvs
->
GetBytecode
();
AddBind
(
std
::
move
(
pvs
)
);
AddBind
(
std
::
move
(
pvs
)
);
AddBind
(
PixelShader
::
Resolve
(
gfx
,
"PhongPSNormalMap.cso"
)
);
AddBind
(
PixelShader
::
Resolve
(
gfx
,
"PhongPSNormalMap
Object
.cso"
)
);
AddBind
(
PixelConstantBuffer
<
PSMaterialConstant
>::
Resolve
(
gfx
,
pmc
,
1u
)
);
AddBind
(
PixelConstantBuffer
<
PSMaterialConstant
>::
Resolve
(
gfx
,
pmc
,
1u
)
);
...
...
hw3d/TestPlane.h
View file @
617483fa
...
@@ -12,12 +12,12 @@ public:
...
@@ -12,12 +12,12 @@ public:
private:
private:
struct
PSMaterialConstant
struct
PSMaterialConstant
{
{
float
specularIntensity
=
0.1
f
;
float
specularIntensity
=
0.1
8
f
;
float
specularPower
=
20
.0
f
;
float
specularPower
=
18
.0
f
;
BOOL
normalMappingEnabled
=
TRUE
;
BOOL
normalMappingEnabled
=
TRUE
;
float
padding
[
1
];
float
padding
[
1
];
}
pmc
;
}
pmc
;
DirectX
::
XMFLOAT3
pos
=
{
1
.0
f
,
1
.0
f
,
1
.0
f
};
DirectX
::
XMFLOAT3
pos
=
{
0
.0
f
,
0
.0
f
,
0
.0
f
};
float
roll
=
0.0
f
;
float
roll
=
0.0
f
;
float
pitch
=
0.0
f
;
float
pitch
=
0.0
f
;
float
yaw
=
0.0
f
;
float
yaw
=
0.0
f
;
...
...
hw3d/hw3d.vcxproj
View file @
617483fa
...
@@ -112,6 +112,15 @@
...
@@ -112,6 +112,15 @@
<ClCompile
Include=
"InputLayout.cpp"
/>
<ClCompile
Include=
"InputLayout.cpp"
/>
<ClCompile
Include=
"Keyboard.cpp"
/>
<ClCompile
Include=
"Keyboard.cpp"
/>
<ClCompile
Include=
"Mesh.cpp"
/>
<ClCompile
Include=
"Mesh.cpp"
/>
<FxCompile
Include=
"PhongPSNormalMapObject.hlsl"
>
<FileType>
Document
</FileType>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
4.0
</ShaderModel>
<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>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
Pixel
</ShaderType>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
Pixel
</ShaderType>
</FxCompile>
<ClCompile
Include=
"PointLight.cpp"
/>
<ClCompile
Include=
"PointLight.cpp"
/>
<ClCompile
Include=
"Mouse.cpp"
/>
<ClCompile
Include=
"Mouse.cpp"
/>
<ClCompile
Include=
"PixelShader.cpp"
/>
<ClCompile
Include=
"PixelShader.cpp"
/>
...
...
hw3d/hw3d.vcxproj.filters
View file @
617483fa
...
@@ -367,5 +367,8 @@
...
@@ -367,5 +367,8 @@
<FxCompile
Include=
"PhongPSSpecNormalMap.hlsl"
>
<FxCompile
Include=
"PhongPSSpecNormalMap.hlsl"
>
<Filter>
Shader
</Filter>
<Filter>
Shader
</Filter>
</FxCompile>
</FxCompile>
<FxCompile
Include=
"PhongPSNormalMapObject.hlsl"
>
<Filter>
Shader
</Filter>
</FxCompile>
</ItemGroup>
</ItemGroup>
</Project>
</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