stk-code_catmod/data/shaders/utils/SunMRP.frag
Vincent Lejeune d8b3cf9c8f Factorise MRP
2014-12-27 03:22:06 +01:00

14 lines
552 B
GLSL

// Sun Most Representative Point (used for MRP area lighting method)
// From "Frostbite going PBR" paper
vec3 SunMRP(vec3 normal, vec3 eyedir)
{
vec3 local_sundir = normalize((transpose(InverseViewMatrix) * vec4(sun_direction, 0.)).xyz);
vec3 R = reflect(-eyedir, normal);
float angularRadius = 3.14 * sun_angle / 180.;
vec3 D = local_sundir;
float d = cos(angularRadius);
float r = sin(angularRadius);
float DdotR = dot(D, R);
vec3 S = R - DdotR * D;
return (DdotR < d) ? normalize(d * D + normalize (S) * r) : R;
}