mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-12-11 00:31:28 -05:00
31 lines
760 B
Scala
31 lines
760 B
Scala
$input v_wpos, v_view, v_normal, v_tangent, v_bitangent, v_texcoord0
|
|
|
|
/*
|
|
* Copyright 2011-2015 Branimir Karadzic. All rights reserved.
|
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
|
*/
|
|
|
|
#include "../common/common.sh"
|
|
|
|
SAMPLER2D(s_texColor, 0);
|
|
SAMPLER2D(s_texNormal, 1);
|
|
|
|
void main()
|
|
{
|
|
vec3 normal;
|
|
normal.xy = texture2D(s_texNormal, v_texcoord0).xy * 2.0 - 1.0;
|
|
normal.z = sqrt(1.0 - dot(normal.xy, normal.xy) );
|
|
|
|
mat3 tbn = mat3(
|
|
normalize(v_tangent),
|
|
normalize(v_bitangent),
|
|
normalize(v_normal)
|
|
);
|
|
|
|
normal = normalize(mul(tbn, normal) );
|
|
|
|
vec3 wnormal = normalize(mul(u_invView, vec4(normal, 0.0) ).xyz);
|
|
|
|
gl_FragData[0] = texture2D(s_texColor, v_texcoord0);
|
|
gl_FragData[1] = vec4(encodeNormalUint(wnormal), 1.0);
|
|
}
|