bgfx/examples/36-sky/fs_sky.sc

27 lines
726 B
Python
Raw Normal View History

$input v_skyColor, v_screenPos, v_viewDir
/*
* Copyright 2017 Stanislav Pidhorskyi. All rights reserved.
2022-01-15 22:59:06 +03:00
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
*/
2017-10-04 06:48:45 +03:00
uniform vec4 u_parameters; // x - sun size, y - sun bloom, z - exposition, w - time
uniform vec4 u_sunDirection;
uniform vec4 u_sunLuminance;
#include "../common/common.sh"
void main()
{
float size2 = u_parameters.x * u_parameters.x;
2017-10-04 06:48:45 +03:00
vec3 lightDir = normalize(u_sunDirection.xyz);
2017-10-04 06:48:45 +03:00
float dist = 2.0 * (1.0 - dot(normalize(v_viewDir), lightDir));
float sun = exp(-dist/ u_parameters.y / size2) + step(dist, size2);
float sun2 = min(sun * sun, 1.0);
vec3 color = v_skyColor + sun2;
color = toGamma(color);
2017-10-04 06:48:45 +03:00
gl_FragColor = vec4(color, 1.0);
}