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
f0ac931f
Commit
f0ac931f
authored
Apr 14, 2019
by
chili
Browse files
need to work in camera's frame of reference for specular code to work
parent
92780ee3
Changes
4
Hide whitespace changes
Inline
Side-by-side
hw3d/PhongPS.hlsl
View file @
f0ac931f
...
@@ -28,10 +28,10 @@ float4 main( float3 worldPos : Position,float3 n : Normal ) : SV_Target
...
@@ -28,10 +28,10 @@ float4 main( float3 worldPos : Position,float3 n : Normal ) : SV_Target
// 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
// reflected light vector
const
float3
w
=
n
*
dot
(
dir
ToL
,
n
);
const
float3
w
=
n
*
dot
(
v
ToL
,
n
);
const
float3
r
=
w
*
2
.
0
f
-
dir
ToL
;
const
float3
r
=
w
*
2
.
0
f
-
v
ToL
;
// calculate specular intensity based on angle between viewing vector and reflection vector, narrow with power function
// 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
);
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
+
specular
)
*
materialColor
),
1
.
0
f
);
return
float4
(
saturate
(
(
diffuse
+
ambient
+
specular
)
*
materialColor
),
1
.
0
f
);
}
}
\ No newline at end of file
hw3d/PhongVS.hlsl
View file @
f0ac931f
cbuffer
CBuf
cbuffer
CBuf
{
{
matrix
model
;
matrix
model
View
;
matrix
modelViewProj
;
matrix
modelViewProj
;
};
};
...
@@ -14,8 +14,8 @@ struct VSOut
...
@@ -14,8 +14,8 @@ struct VSOut
VSOut
main
(
float3
pos
:
Position
,
float3
n
:
Normal
)
VSOut
main
(
float3
pos
:
Position
,
float3
n
:
Normal
)
{
{
VSOut
vso
;
VSOut
vso
;
vso
.
worldPos
=
(
float3
)
mul
(
float4
(
pos
,
1
.
0
f
),
model
);
vso
.
worldPos
=
(
float3
)
mul
(
float4
(
pos
,
1
.
0
f
),
model
View
);
vso
.
normal
=
mul
(
n
,(
float3x3
)
model
);
vso
.
normal
=
mul
(
n
,(
float3x3
)
model
View
);
vso
.
pos
=
mul
(
float4
(
pos
,
1
.
0
f
),
modelViewProj
);
vso
.
pos
=
mul
(
float4
(
pos
,
1
.
0
f
),
modelViewProj
);
return
vso
;
return
vso
;
}
}
\ No newline at end of file
hw3d/SolidVS.hlsl
View file @
f0ac931f
cbuffer
CBuf
cbuffer
CBuf
{
{
matrix
model
;
matrix
model
View
;
matrix
modelViewProj
;
matrix
modelViewProj
;
};
};
...
...
hw3d/TransformCbuf.cpp
View file @
f0ac931f
...
@@ -12,13 +12,12 @@ TransformCbuf::TransformCbuf( Graphics& gfx,const Drawable& parent,UINT slot )
...
@@ -12,13 +12,12 @@ TransformCbuf::TransformCbuf( Graphics& gfx,const Drawable& parent,UINT slot )
void
TransformCbuf
::
Bind
(
Graphics
&
gfx
)
noexcept
void
TransformCbuf
::
Bind
(
Graphics
&
gfx
)
noexcept
{
{
const
auto
model
=
parent
.
GetTransformXM
();
const
auto
model
View
=
parent
.
GetTransformXM
()
*
gfx
.
GetCamera
()
;
const
Transforms
tf
=
const
Transforms
tf
=
{
{
DirectX
::
XMMatrixTranspose
(
model
),
DirectX
::
XMMatrixTranspose
(
model
View
),
DirectX
::
XMMatrixTranspose
(
DirectX
::
XMMatrixTranspose
(
model
*
modelView
*
gfx
.
GetCamera
()
*
gfx
.
GetProjection
()
gfx
.
GetProjection
()
)
)
};
};
...
...
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