bgfx/examples/21-deferred/fs_deferred_geom.sc
Бранимир Караџић 4581f14cd4 Happy New Year!
2022-01-15 11:59:06 -08:00

32 lines
766 B
Scala

$input v_wpos, v_view, v_normal, v_tangent, v_bitangent, v_texcoord0
/*
* Copyright 2011-2022 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
*/
#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);
}