//- Channels needed for metal/rough workflow are bound here.
//: param auto channel_basecolor
uniform
sampler2D
basecolor_tex;
//: param auto channel_roughness
uniform
sampler2D
roughness_tex;
//: param auto channel_metallic
uniform
sampler2D
metallic_tex;
//: param auto channel_specularlevel
uniform
sampler2D
specularlevel_tex;
//: param auto environment_rotation
uniform
float
cubemap_rotation;
//- Shader entry point.
vec4
shade
(V2F inputs)
{
vec4
OUT
=
vec4
(
0.0
f,
0.0
f,
0.0
f,
1.0
f);
vec3
light_pos
=
vec3
(
10.0
*
cos
(cubemap_rotation
*
2.0
*
M_PI),
10.0
,
10.0
*
sin
(cubemap_rotation
*
2.0
*
M_PI));
// Apply parallax occlusion mapping if possible
vec3
viewTS
=
worldSpaceToTangentSpace
(
getEyeVec
(inputs.
position
), inputs);
inputs.
tex_coord
+=
getParallaxOffset
(inputs.
tex_coord
, viewTS);
vec2
UV
=
inputs.
tex_coord
;
vec3
N
=
normalize
(inputs.
normal
);
vec3
T
=
inputs.
tangent
;
vec3
B
=
inputs.
bitangent
;
vec3
V
=
getEyeVec
(inputs.
position
);
vec3
L
=
normalize
(light_pos
-
inputs.
position
);
vec3
H
=
normalize
(V
+
L);
float
NoV
=
clamp
(
0
,
1
,
dot
(N,V));
float
NoL
=
dot
(N,L);
float
NoH
=
dot
(N,H);
// Fetch material parameters, and conversion to the specular/glossiness model
float
glossiness
=
1.0
-
getRoughness
(roughness_tex, inputs.
tex_coord
);
vec3
baseColor
=
getBaseColor
(basecolor_tex, inputs.
tex_coord
);
float
metallic
=
getMetallic
(metallic_tex, inputs.
tex_coord
);
float
specularLevel
=
getSpecularLevel
(specularlevel_tex, inputs.
tex_coord
);
vec3
diffColor
=
generateDiffuseColor
(baseColor, metallic);
vec3
specColor
=
generateSpecularColor
(specularLevel, baseColor, metallic);
// Get detail (ambient occlusion) and global (shadow) occlusion factors
float
AO
=
getAO
(inputs.
tex_coord
)
*
getShadowFactor
();
vec3
TTex
=
baseColor;
vec3
Tweight
=
(TTex
-
vec3
(
0.5
,
0.5
,
0.5
))
*
2
;
vec3
BaseT
=
normalize
(Tweight.
x
*
T
+
Tweight.
y
*
B);
T
=
normalize
(BaseT
+
N
*
(Tweight.
z
*
5
));
float
ToH
=
dot
(T,H);
float
ToH2
=
ToH
*
ToH;
float
TsH
=
sqrt
(
1
-
ToH2);
float
parm
=
pow
(TsH ,
100
);
vec3
spec
=
parm.
xxx
;
OUT.
rgb
=
NoL.
xxx
+
spec;
// Feed parameters for a physically based BRDF integration
return
OUT;
}
//- Entry point of the shadow pass.
void
shadeShadow
(V2F inputs)
{
}