2014-05-22 07:33:12 +04:00
|
|
|
$input v_texcoord0
|
|
|
|
|
|
|
|
/*
|
2023-01-14 21:05:12 +03:00
|
|
|
* Copyright 2011-2023 Branimir Karadzic. All rights reserved.
|
2022-01-15 22:59:06 +03:00
|
|
|
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
|
2014-05-22 07:33:12 +04:00
|
|
|
*/
|
|
|
|
|
2019-02-17 18:50:26 +03:00
|
|
|
#include "common.sh"
|
2014-05-22 07:33:12 +04:00
|
|
|
|
|
|
|
SAMPLER2D(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(texture2D(s_normal, v_texcoord0).xyz);
|
2016-04-02 08:48:57 +03:00
|
|
|
float deviceDepth = texture2D(s_depth, v_texcoord0).x;
|
2014-05-22 07:33:12 +04:00
|
|
|
float depth = toClipSpaceDepth(deviceDepth);
|
|
|
|
|
|
|
|
vec3 clip = vec3(v_texcoord0 * 2.0 - 1.0, depth);
|
2019-02-19 00:40:41 +03:00
|
|
|
#if !BGFX_SHADER_LANGUAGE_GLSL
|
2014-05-22 07:33:12 +04:00
|
|
|
clip.y = -clip.y;
|
2019-02-19 00:40:41 +03:00
|
|
|
#endif // !BGFX_SHADER_LANGUAGE_GLSL
|
2014-05-22 07:33:12 +04:00
|
|
|
vec3 wpos = clipToWorld(u_mtx, clip);
|
|
|
|
|
|
|
|
vec3 view = mul(u_view, vec4(wpos, 0.0) ).xyz;
|
|
|
|
view = -normalize(view);
|
|
|
|
|
2019-02-17 18:50:26 +03:00
|
|
|
vec3 lightColor = calcLight(wpos, normal, view, u_lightPosRadius[0].xyz, u_lightPosRadius[0].w, u_lightRgbInnerR[0].xyz, u_lightRgbInnerR[0].w);
|
2014-05-22 07:33:12 +04:00
|
|
|
gl_FragColor.xyz = toGamma(lightColor.xyz);
|
|
|
|
gl_FragColor.w = 1.0;
|
|
|
|
}
|