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
bfe02273
Commit
bfe02273
authored
Jul 27, 2019
by
chili
Browse files
fix the specular mapping (scaling alpha power, using light intensity)
parent
9beaef9a
Changes
1
Hide whitespace changes
Inline
Side-by-side
hw3d/PhongPSSpecMap.hlsl
View file @
bfe02273
...
...
@@ -14,6 +14,8 @@ Texture2D spec;
SamplerState
splr
;
static
const
float
specularPowerFactor
=
100
.
0
f
;
float4
main
(
float3
worldPos
:
Position
,
float3
n
:
Normal
,
float2
tc
:
Texcoord
)
:
SV_Target
{
...
...
@@ -30,9 +32,9 @@ float4 main(float3 worldPos : Position, float3 n : Normal, float2 tc : Texcoord)
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
float4
specularSample
=
spec
.
Sample
(
splr
,
tc
);
const
float3
specular
ColorIntensity
=
specularSample
.
rgb
;
const
float
specularPower
=
specularSample
.
a
;
const
float3
specular
=
att
*
specularColor
Intensity
*
pow
(
max
(
0
.
0
f
,
dot
(
normalize
(
-
r
),
normalize
(
worldPos
))),
specularPower
);
const
float3
specular
ReflectionColor
=
specularSample
.
rgb
;
const
float
specularPower
=
specularSample
.
a
*
specularPowerFactor
;
const
float3
specular
=
att
*
(
diffuseColor
*
diffuse
Intensity
)
*
pow
(
max
(
0
.
0
f
,
dot
(
normalize
(
-
r
),
normalize
(
worldPos
))),
specularPower
);
// final color
return
float4
(
saturate
(
diffuse
+
ambient
+
specular
),
1
.
0
f
)
*
tex
.
Sample
(
splr
,
tc
);
return
float4
(
saturate
(
(
diffuse
+
ambient
)
*
tex
.
Sample
(
splr
,
tc
)
.
rgb
+
specular
*
specularReflectionColor
),
1
.
0
f
)
;
}
\ 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