-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhemisphere-steps.frag.glsl
52 lines (40 loc) · 1.51 KB
/
hemisphere-steps.frag.glsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
uniform float halfSkylightLength;
uniform float halfSkylightWidth;
uniform sampler2D texture;
uniform vec3 skyColor;
uniform vec2 repeat;
varying vec3 sunLight;
varying float albedo;
varying vec2 vCeilingLoc;
varying float fSunBlur;
varying vec2 vUV;
varying vec3 vPosition;
varying vec3 vNormal;
#pragma glslify: orenNayar = require(glsl-diffuse-oren-nayar)
void main( void ) {
float fDirect = 0.0;
if (sunLight.r > 0.0) {
// Sun is shining
// Distance from origin to point on ceiling along sunlight path. If this is inside the skylight, then sun can see this point.
float xDist = abs(vCeilingLoc.x);
float zDist = abs(vCeilingLoc.y);
if ((xDist < halfSkylightWidth + fSunBlur) && (zDist < halfSkylightLength + fSunBlur)) {
if (xDist < halfSkylightWidth) {
fDirect = 1.0;
} else {
fDirect = 1.0 - (xDist - halfSkylightWidth) / fSunBlur;
}
if (zDist > halfSkylightLength) {
fDirect *= 1.0 - (zDist - halfSkylightLength) / fSunBlur;
}
}
}
// Remap 0.9-1 to 1-0.5.
//float aoStrength = vColor.g >= 0.9 ? -5.0 * vColor.g + 5.5 : 1.0;
// orenNayar( lightDir, viewDir, surfaceNormal, roughness (0 - pi/2?), albedo)
float ambientStrength = orenNayar( -normalize(vPosition), normalize(cameraPosition - vPosition), vNormal, 0.6, albedo );
gl_FragColor = vec4( ambientStrength * skyColor * texture2D(texture, vec2(vUV.x * repeat.x, vUV.y * repeat.y)).rgb + (sunLight * fDirect * fDirect * fDirect), 1.0 );
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
}