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
3fd3a302
Commit
3fd3a302
authored
Aug 06, 2019
by
chili
Browse files
rename worldPos => viewPos
parent
15e490b0
Changes
5
Hide whitespace changes
Inline
Side-by-side
hw3d/PhongPS.hlsl
View file @
3fd3a302
...
...
@@ -21,10 +21,10 @@ Texture2D tex;
SamplerState
splr
;
float4
main
(
float3
world
Pos
:
Position
,
float3
n
:
Normal
,
float2
tc
:
Texcoord
)
:
SV_Target
float4
main
(
float3
view
Pos
:
Position
,
float3
n
:
Normal
,
float2
tc
:
Texcoord
)
:
SV_Target
{
// fragment to light vector data
const
float3
vToL
=
lightPos
-
world
Pos
;
const
float3
vToL
=
lightPos
-
view
Pos
;
const
float
distToL
=
length
(
vToL
);
const
float3
dirToL
=
vToL
/
distToL
;
// attenuation
...
...
@@ -35,7 +35,7 @@ float4 main(float3 worldPos : Position, float3 n : Normal, float2 tc : Texcoord)
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
(
world
Pos
))),
specularPower
);
const
float3
specular
=
att
*
(
diffuseColor
*
diffuseIntensity
)
*
specularIntensity
*
pow
(
max
(
0
.
0
f
,
dot
(
normalize
(
-
r
),
normalize
(
view
Pos
))),
specularPower
);
// final color
return
float4
(
saturate
((
diffuse
+
ambient
)
*
tex
.
Sample
(
splr
,
tc
).
rgb
+
specular
),
1
.
0
f
);
}
\ No newline at end of file
hw3d/PhongPSNormalMap.hlsl
View file @
3fd3a302
...
...
@@ -23,7 +23,7 @@ Texture2D nmap : register(t2);
SamplerState
splr
;
float4
main
(
float3
world
Pos
:
Position
,
float3
n
:
Normal
,
float3
tan
:
Tangent
,
float3
bitan
:
Bitangent
,
float2
tc
:
Texcoord
)
:
SV_Target
float4
main
(
float3
view
Pos
:
Position
,
float3
n
:
Normal
,
float3
tan
:
Tangent
,
float3
bitan
:
Bitangent
,
float2
tc
:
Texcoord
)
:
SV_Target
{
// sample normal from map if normal mapping enabled
if
(
normalMapEnabled
)
...
...
@@ -43,7 +43,7 @@ float4 main(float3 worldPos : Position, float3 n : Normal, float3 tan : Tangent,
n
=
mul
(
n
,
tanToView
);
}
// fragment to light vector data
const
float3
vToL
=
lightPos
-
world
Pos
;
const
float3
vToL
=
lightPos
-
view
Pos
;
const
float
distToL
=
length
(
vToL
);
const
float3
dirToL
=
vToL
/
distToL
;
// attenuation
...
...
@@ -54,7 +54,7 @@ float4 main(float3 worldPos : Position, float3 n : Normal, float3 tan : Tangent,
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
(
world
Pos
))),
specularPower
);
const
float3
specular
=
att
*
(
diffuseColor
*
diffuseIntensity
)
*
specularIntensity
*
pow
(
max
(
0
.
0
f
,
dot
(
normalize
(
-
r
),
normalize
(
view
Pos
))),
specularPower
);
// final color
return
float4
(
saturate
((
diffuse
+
ambient
)
*
tex
.
Sample
(
splr
,
tc
).
rgb
+
specular
),
1
.
0
f
);
}
\ No newline at end of file
hw3d/PhongPSSpecNormalMap.hlsl
View file @
3fd3a302
...
...
@@ -22,7 +22,7 @@ Texture2D nmap;
SamplerState
splr
;
float4
main
(
float3
world
Pos
:
Position
,
float3
n
:
Normal
,
float3
tan
:
Tangent
,
float3
bitan
:
Bitangent
,
float2
tc
:
Texcoord
)
:
SV_Target
float4
main
(
float3
view
Pos
:
Position
,
float3
n
:
Normal
,
float3
tan
:
Tangent
,
float3
bitan
:
Bitangent
,
float2
tc
:
Texcoord
)
:
SV_Target
{
// sample normal from map if normal mapping enabled
if
(
normalMapEnabled
)
...
...
@@ -42,7 +42,7 @@ float4 main(float3 worldPos : Position, float3 n : Normal, float3 tan : Tangent,
n
=
mul
(
n
,
tanToView
);
}
// fragment to light vector data
const
float3
vToL
=
lightPos
-
world
Pos
;
const
float3
vToL
=
lightPos
-
view
Pos
;
const
float
distToL
=
length
(
vToL
);
const
float3
dirToL
=
vToL
/
distToL
;
// attenuation
...
...
@@ -56,7 +56,7 @@ float4 main(float3 worldPos : Position, float3 n : Normal, float3 tan : Tangent,
const
float4
specularSample
=
spec
.
Sample
(
splr
,
tc
);
const
float3
specularReflectionColor
=
specularSample
.
rgb
;
const
float
specularPower
=
pow
(
2
.
0
f
,
specularSample
.
a
*
13
.
0
f
);
const
float3
specular
=
att
*
(
diffuseColor
*
diffuseIntensity
)
*
pow
(
max
(
0
.
0
f
,
dot
(
normalize
(
-
r
),
normalize
(
world
Pos
))),
specularPower
);
const
float3
specular
=
att
*
(
diffuseColor
*
diffuseIntensity
)
*
pow
(
max
(
0
.
0
f
,
dot
(
normalize
(
-
r
),
normalize
(
view
Pos
))),
specularPower
);
// final color
return
float4
(
saturate
((
diffuse
+
ambient
)
*
tex
.
Sample
(
splr
,
tc
).
rgb
+
specular
*
specularReflectionColor
),
1
.
0
f
);
}
\ No newline at end of file
hw3d/PhongVS.hlsl
View file @
3fd3a302
...
...
@@ -6,7 +6,7 @@ cbuffer CBuf
struct
VSOut
{
float3
world
Pos
:
Position
;
float3
view
Pos
:
Position
;
float3
normal
:
Normal
;
float2
tc
:
Texcoord
;
float4
pos
:
SV_Position
;
...
...
@@ -15,7 +15,7 @@ struct VSOut
VSOut
main
(
float3
pos
:
Position
,
float3
n
:
Normal
,
float2
tc
:
Texcoord
)
{
VSOut
vso
;
vso
.
world
Pos
=
(
float3
)
mul
(
float4
(
pos
,
1
.
0
f
),
modelView
);
vso
.
view
Pos
=
(
float3
)
mul
(
float4
(
pos
,
1
.
0
f
),
modelView
);
vso
.
normal
=
mul
(
n
,
(
float3x3
)
modelView
);
vso
.
pos
=
mul
(
float4
(
pos
,
1
.
0
f
),
modelViewProj
);
vso
.
tc
=
tc
;
...
...
hw3d/PhongVSNormalMap.hlsl
View file @
3fd3a302
...
...
@@ -6,7 +6,7 @@ cbuffer CBuf
struct
VSOut
{
float3
world
Pos
:
Position
;
float3
view
Pos
:
Position
;
float3
normal
:
Normal
;
float3
tan
:
Tangent
;
float3
bitan
:
Bitangent
;
...
...
@@ -17,7 +17,7 @@ struct VSOut
VSOut
main
(
float3
pos
:
Position
,
float3
n
:
Normal
,
float3
tan
:
Tangent
,
float3
bitan
:
Bitangent
,
float2
tc
:
Texcoord
)
{
VSOut
vso
;
vso
.
world
Pos
=
(
float3
)
mul
(
float4
(
pos
,
1
.
0
f
),
modelView
);
vso
.
view
Pos
=
(
float3
)
mul
(
float4
(
pos
,
1
.
0
f
),
modelView
);
vso
.
normal
=
mul
(
n
,
(
float3x3
)
modelView
);
vso
.
tan
=
mul
(
tan
,
(
float3x3
)
modelView
);
vso
.
bitan
=
mul
(
bitan
,
(
float3x3
)
modelView
);
...
...
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