bgfx/examples/21-deferred/fs_deferred_light_ta.sc
Бранимир Караџић 82f56b5987 Happy New Year!
2020-01-14 21:37:06 -08:00

36 lines
1009 B
Python

$input v_texcoord0
/*
* Copyright 2011-2020 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
#include "common.sh"
SAMPLER2DARRAY(s_normal, 0);
SAMPLER2D(s_depth, 1);
uniform vec4 u_lightPosRadius[1];
uniform vec4 u_lightRgbInnerR[1];
uniform mat4 u_mtx;
void main()
{
vec3 normal = decodeNormalUint(texture2DArray(s_normal, vec3(v_texcoord0, 1.0) ).xyz);
float deviceDepth = texture2D(s_depth, v_texcoord0).x;
float depth = toClipSpaceDepth(deviceDepth);
vec3 clip = vec3(v_texcoord0 * 2.0 - 1.0, depth);
#if !BGFX_SHADER_LANGUAGE_GLSL
clip.y = -clip.y;
#endif // !BGFX_SHADER_LANGUAGE_GLSL
vec3 wpos = clipToWorld(u_mtx, clip);
vec3 view = mul(u_view, vec4(wpos, 0.0) ).xyz;
view = -normalize(view);
vec3 lightColor = calcLight(wpos, normal, view, u_lightPosRadius[0].xyz, u_lightPosRadius[0].w, u_lightRgbInnerR[0].xyz, u_lightRgbInnerR[0].w);
gl_FragColor.xyz = toGamma(lightColor.xyz);
gl_FragColor.w = 1.0;
}