(def
advanced-fragment-shader
{:precision "mediump float",
:uniforms
'{u_lightColor vec4,
u_color vec4,
u_specular vec4,
u_shininess float,
u_specularFactor float},
:inputs
'{v_position vec4,
v_texCoord vec2,
v_normal vec3,
v_surfaceToLight vec3,
v_surfaceToView vec3},
:outputs '{outColor vec4},
:signatures '{lit ([float float float] vec4), main ([] void)},
:functions
'{lit
([l h m]
(vec4
"1.0"
(abs l)
(? (> l "0.0") (pow (max "0.0" h) m) "0.0")
"1.0")),
main
([]
(=vec3 a_normal (normalize v_normal))
(=vec3 surfaceToLight (normalize v_surfaceToLight))
(=vec3 surfaceToView (normalize v_surfaceToView))
(=vec3 halfVector (normalize (+ surfaceToLight surfaceToView)))
(=vec4
litR
(lit
(dot a_normal surfaceToLight)
(dot a_normal halfVector)
u_shininess))
(=
outColor
(vec4
(.rgb
(*
u_lightColor
(+
(* (.y litR) u_color)
(* u_specular (.z litR) u_specularFactor))))
1)))}})