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
fc18dc8b
Commit
fc18dc8b
authored
Jul 27, 2019
by
chili
Browse files
textured shading
parent
035f0975
Changes
3
Hide whitespace changes
Inline
Side-by-side
hw3d/Mesh.cpp
View file @
fc18dc8b
...
@@ -294,10 +294,9 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
...
@@ -294,10 +294,9 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
struct
PSMaterialConstant
struct
PSMaterialConstant
{
{
DirectX
::
XMFLOAT3
color
=
{
0.6
f
,
0.6
f
,
0.8
f
};
float
specularIntensity
=
0.6
f
;
float
specularIntensity
=
0.6
f
;
float
specularPower
=
30.0
f
;
float
specularPower
=
30.0
f
;
float
padding
[
3
];
float
padding
[
2
];
}
pmc
;
}
pmc
;
bindablePtrs
.
push_back
(
std
::
make_unique
<
Bind
::
PixelConstantBuffer
<
PSMaterialConstant
>>
(
gfx
,
pmc
,
1u
)
);
bindablePtrs
.
push_back
(
std
::
make_unique
<
Bind
::
PixelConstantBuffer
<
PSMaterialConstant
>>
(
gfx
,
pmc
,
1u
)
);
...
...
hw3d/PhongPS.hlsl
View file @
fc18dc8b
cbuffer
LightCBuf
cbuffer
LightCBuf
{
{
float3
lightPos
;
float3
lightPos
;
float3
ambient
;
float3
ambient
;
float3
diffuseColor
;
float3
diffuseColor
;
float
diffuseIntensity
;
float
diffuseIntensity
;
float
attConst
;
float
attConst
;
float
attLin
;
float
attLin
;
float
attQuad
;
float
attQuad
;
};
};
cbuffer
ObjectCBuf
cbuffer
ObjectCBuf
{
{
float
3
materialColor
;
float
specularIntensity
;
float
specular
Intensity
;
float
specular
Power
;
float
specularPower
;
float
padding
[
2
]
;
};
};
Texture2D
tex
;
float4
main
(
float3
worldPos
:
Position
,
float3
n
:
Normal
)
:
SV_Target
SamplerState
splr
;
float4
main
(
float3
worldPos
:
Position
,
float3
n
:
Normal
,
float2
tc
:
Texcoord
)
:
SV_Target
{
{
// fragment to light vector data
// fragment to light vector data
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
;
// 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
)
);
// reflected light vector
// reflected light vector
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
=
att
*
(
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
)
,
1
.
0
f
)
*
tex
.
Sample
(
splr
,
tc
);
}
}
\ No newline at end of file
hw3d/PhongVS.hlsl
View file @
fc18dc8b
cbuffer
CBuf
cbuffer
CBuf
{
{
matrix
modelView
;
matrix
modelView
;
matrix
modelViewProj
;
matrix
modelViewProj
;
};
};
struct
VSOut
struct
VSOut
{
{
float3
worldPos
:
Position
;
float3
worldPos
:
Position
;
float3
normal
:
Normal
;
float3
normal
:
Normal
;
float4
pos
:
SV_Position
;
float2
tc
:
Texcoord
;
float4
pos
:
SV_Position
;
};
};
VSOut
main
(
float3
pos
:
Position
,
float3
n
:
Normal
)
VSOut
main
(
float3
pos
:
Position
,
float3
n
:
Normal
,
float2
tc
:
Texcoord
)
{
{
VSOut
vso
;
VSOut
vso
;
vso
.
worldPos
=
(
float3
)
mul
(
float4
(
pos
,
1
.
0
f
),
modelView
);
vso
.
worldPos
=
(
float3
)
mul
(
float4
(
pos
,
1
.
0
f
),
modelView
);
vso
.
normal
=
mul
(
n
,(
float3x3
)
modelView
);
vso
.
normal
=
mul
(
n
,
(
float3x3
)
modelView
);
vso
.
pos
=
mul
(
float4
(
pos
,
1
.
0
f
),
modelViewProj
);
vso
.
pos
=
mul
(
float4
(
pos
,
1
.
0
f
),
modelViewProj
);
return
vso
;
vso
.
tc
=
tc
;
return
vso
;
}
}
\ 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