bgfx/examples/21-deferred/fs_deferred_geom.sc

32 lines
767 B
Python
Raw Normal View History

2014-05-22 07:33:12 +04:00
$input v_wpos, v_view, v_normal, v_tangent, v_bitangent, v_texcoord0
/*
2017-01-01 11:18:41 +03:00
* Copyright 2011-2017 Branimir Karadzic. All rights reserved.
2016-01-01 11:11:04 +03:00
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
2014-05-22 07:33:12 +04:00
*/
#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);
}