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
3bff8c88
Commit
3bff8c88
authored
Apr 14, 2019
by
chili
Browse files
probably a good idea to attenuate the specular as well
parent
9c50145e
Changes
1
Hide whitespace changes
Inline
Side-by-side
hw3d/PhongPS.hlsl
View file @
3bff8c88
...
@@ -23,7 +23,7 @@ float4 main( float3 worldPos : Position,float3 n : Normal ) : SV_Target
...
@@ -23,7 +23,7 @@ float4 main( float3 worldPos : Position,float3 n : Normal ) : SV_Target
const
float3
vToL
=
lightPos
-
worldPos
;
const
float3
vToL
=
lightPos
-
worldPos
;
const
float
distToL
=
length
(
vToL
);
const
float
distToL
=
length
(
vToL
);
const
float3
dirToL
=
vToL
/
distToL
;
const
float3
dirToL
=
vToL
/
distToL
;
//
diffuse
attenuation
// attenuation
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
)
);
...
@@ -31,7 +31,7 @@ float4 main( float3 worldPos : Position,float3 n : Normal ) : SV_Target
...
@@ -31,7 +31,7 @@ float4 main( float3 worldPos : Position,float3 n : Normal ) : SV_Target
const
float3
w
=
n
*
dot
(
vToL
,
n
);
const
float3
w
=
n
*
dot
(
vToL
,
n
);
const
float3
r
=
w
*
2
.
0
f
-
vToL
;
const
float3
r
=
w
*
2
.
0
f
-
vToL
;
// 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
=
att
*
(
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
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