1 uniform sampler2D uTexMain;
10 #include "light_clearskies_stddef.glsl"
11 #include "common_world.glsl"
12 #include "motion_vectors_fs.glsl"
13 #include "depth_compare.glsl"
15 vec3 character_clearskies_lighting( vec3 normal, float shadow, vec3 halfview )
17 float fresnel = 1.0 - abs(dot(normal,halfview));
19 vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb,
23 vec3 sky_reflection = 0.5 * fresnel * reflect_colour;
24 vec3 light_sun = max(0.0, dot(normal,g_sun_dir.xyz)*0.5+0.5)
25 * g_sun_colour.rgb * g_day_phase;
27 float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );
28 vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb,
31 return ambient + (light_sun + sky_reflection) * shadow;
34 vec3 character_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,
37 if( g_light_preview == 1 )
41 vec3 halfview = uCamera - co;
42 float fdist = length(halfview);
45 float world_shadow = newlight_compute_sun_shadow(
46 co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );
48 vec3 total_light = character_clearskies_lighting(
49 normal, min( light_mask, world_shadow ), halfview );
51 vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;
52 cube_coord = floor( cube_coord );
54 if( g_debug_indices == 1 )
56 return rand33(cube_coord);
59 if( g_debug_complexity == 1 )
61 ivec3 coord = ivec3( cube_coord );
62 uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );
64 uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);
65 return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );
68 // FIXME: this coord should absolutely must be clamped!
70 ivec3 coord = ivec3( cube_coord );
71 uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );
74 scene_calculate_packed_light_patch( index_sample.x,
75 halfview, co, normal )
78 scene_calculate_packed_light_patch( index_sample.y,
79 halfview, co, normal )
82 // Take a section of the sky function to give us a matching fog colour
84 vec3 fog_colour = clearskies_ambient( -halfview );
85 float sun_theta = dot( -halfview, g_sun_dir.xyz );
86 float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );
87 float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;
89 vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );
90 sun_colour *= sun_shape;
92 fog_colour += sun_colour;
93 return scene_apply_fog( diffuse * total_light, fog_colour, fdist );
97 depth_compare_dither();
98 compute_motion_vectors();
101 vec3 diffuse = texture( uTexMain, aUv ).rgb;
102 vec3 composite = character_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 );
104 float dist = distance( aWorldCo, uCamera ) - 0.08;
105 float opacity = clamp( dist*dist, 0.0, 1.0 );
107 oColour = vec4( composite, opacity );