shader_model_character_view_uPv( cam->mtx.pv );
world_instance *world = get_active_world();
- world_link_lighting_ub( world, _shader_model_character_view.id, 2 );
+ world_link_lighting_ub( world, _shader_model_character_view.id );
+ world_bind_position_texture( world, _shader_model_character_view.id,
+ _uniform_model_character_view_g_world_depth, 2 );
glUniformMatrix4x3fv( _uniform_model_character_view_uTransforms,
player->playeravatar->sk.bone_count,
#pragma pack(push,1)
-/* 28 byte vertexs, we don't care about the normals too much,
+/* 32 byte vertexs, we don't care about the normals too much,
* maybe possible to bring down uv to i16s too */
struct scene_vert
{
v3f co; /* 3*32 */
v2f uv; /* 2*32 */
i8 norm[4]; /* 4*8 */
- u8 lights[4]; /* 4*8 */
+ u16 lights[4]; /* 4*16 */
};
#pragma pack(pop)
glEnableVertexAttribArray( 2 );
/* 3: light cluster */
- glVertexAttribIPointer( 3, 4, GL_UNSIGNED_BYTE,
+ glVertexAttribIPointer( 3, 4, GL_UNSIGNED_SHORT,
stride, (void *)offsetof(scene_vert, lights) );
glEnableVertexAttribArray( 3 );
// :D
+in vec2 aUv;
+in vec4 aNorm;
+in vec3 aCo;
+in vec3 aWorldCo;
+flat in vec4 light_colours[3];
+flat in vec4 light_positions[3];
+
#include "common_world.glsl"
+float sdLine( vec3 p, vec3 a, vec3 b )
+{
+ vec3 pa = p - a;
+ vec3 ba = b - a;
+
+ float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
+ return length( pa - ba*h );
+}
+
+float compute_board_shadow()
+{
+ // player shadow
+ float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );
+ float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );
+ player_shadow *= player_shadow*player_shadow*player_shadow;
+
+ return 1.0 - player_shadow*0.8;
+}
+
vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )
{
// Lighting
world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );
float world_shadow = newlight_compute_sun_shadow();
+ float board_shadow = compute_board_shadow();
- total_light += world_light * world_shadow;
+ total_light += world_light * min( board_shadow, world_shadow );
// Compute the other lights that exist in the map, not effected by the sun
// shadow
+
total_light += newlight_compute_quadratic
(
wnormal, halfview,
- g_point_light_positions[ aLights.x ].xyz,
- g_point_light_colours[ aLights.x ].rgb
- );
+ light_positions[0].xyz,
+ light_colours[0].rgb
+ ) * board_shadow;
total_light += newlight_compute_quadratic
(
wnormal, halfview,
- g_point_light_positions[ aLights.y ].xyz,
- g_point_light_colours[ aLights.y ].rgb
- );
+ light_positions[1].xyz,
+ light_colours[1].rgb
+ ) * board_shadow;
total_light += newlight_compute_quadratic
(
wnormal, halfview,
- g_point_light_positions[ aLights.z ].xyz,
- g_point_light_colours[ aLights.z ].rgb
- );
+ light_positions[2].xyz,
+ light_colours[2].rgb
+ ) * board_shadow;
return apply_fog( diffuse * total_light, fdist );
}
int g_light_preview;
int g_shadow_samples;
- vec4 g_point_light_positions[32];
- vec4 g_point_light_colours[32];
+ // g_time ?
+
+ //vec4 g_point_light_positions[32];
+ //vec4 g_point_light_colours[32];
};
uniform sampler2D g_world_depth;
return clamp( fdelta, 0.1, 0.2 )-0.1;
}
-float sdLine( vec3 p, vec3 a, vec3 b )
-{
- vec3 pa = p - a;
- vec3 ba = b - a;
-
- float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
- return length( pa - ba*h );
-}
-
vec3 apply_fog( vec3 vfrag, float fdist )
{
float dist = pow(fdist*0.0008,1.2);
famt+=shadow_sample((vdir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);
famt+=shadow_sample((vdir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);
- // player shadow
- float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );
- float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );
- player_shadow *= player_shadow*player_shadow*player_shadow;
-
- return 1.0 - max( player_shadow*0.8, famt );
+ return 1.0 - famt;
}
vec3 newlight_compute_world_diffuse( vec3 wnormal )
uniform sampler2D uTexMain;
uniform vec3 uCamera;
-uniform vec3 uBoard0;
-uniform vec3 uBoard1;
in vec4 aColour;
in vec2 aUv;
.static_src =
"uniform sampler2D uTexMain;\n"
"uniform vec3 uCamera;\n"
-"uniform vec3 uBoard0;\n"
-"uniform vec3 uBoard1;\n"
"\n"
"in vec4 aColour;\n"
"in vec2 aUv;\n"
" int g_light_preview;\n"
" int g_shadow_samples;\n"
"\n"
-" vec4 g_point_light_positions[32];\n"
-" vec4 g_point_light_colours[32];\n"
+" // g_time ?\n"
+"\n"
+" //vec4 g_point_light_positions[32];\n"
+" //vec4 g_point_light_colours[32];\n"
"};\n"
"\n"
"uniform sampler2D g_world_depth;\n"
" return clamp( fdelta, 0.1, 0.2 )-0.1;\n"
"}\n"
"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
"vec3 apply_fog( vec3 vfrag, float fdist )\n"
"{\n"
" float dist = pow(fdist*0.0008,1.2);\n"
" famt+=shadow_sample((vdir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
" famt+=shadow_sample((vdir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
"\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - max( player_shadow*0.8, famt );\n"
+" return 1.0 - famt;\n"
"}\n"
"\n"
"vec3 newlight_compute_world_diffuse( vec3 wnormal )\n"
" return light_colour*attenuation;\n"
"}\n"
"\n"
-"#line 13 0 \n"
+"#line 11 0 \n"
"#line 1 2 \n"
"const float k_motion_lerp_amount = 0.01;\n"
"\n"
" oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
"}\n"
"\n"
-"#line 14 0 \n"
+"#line 12 0 \n"
"\n"
"void main()\n"
"{\n"
static GLuint _uniform_model_character_view_uTransforms;
static GLuint _uniform_model_character_view_uTexMain;
static GLuint _uniform_model_character_view_uCamera;
-static GLuint _uniform_model_character_view_uBoard0;
-static GLuint _uniform_model_character_view_uBoard1;
static GLuint _uniform_model_character_view_g_world_depth;
static void shader_model_character_view_uPv(m4x4f m){
glUniformMatrix4fv(_uniform_model_character_view_uPv,1,GL_FALSE,(float*)m);
static void shader_model_character_view_uCamera(v3f v){
glUniform3fv(_uniform_model_character_view_uCamera,1,v);
}
-static void shader_model_character_view_uBoard0(v3f v){
- glUniform3fv(_uniform_model_character_view_uBoard0,1,v);
-}
-static void shader_model_character_view_uBoard1(v3f v){
- glUniform3fv(_uniform_model_character_view_uBoard1,1,v);
-}
static void shader_model_character_view_g_world_depth(int i){
glUniform1i(_uniform_model_character_view_g_world_depth,i);
}
_uniform_model_character_view_uTransforms = glGetUniformLocation( _shader_model_character_view.id, "uTransforms" );
_uniform_model_character_view_uTexMain = glGetUniformLocation( _shader_model_character_view.id, "uTexMain" );
_uniform_model_character_view_uCamera = glGetUniformLocation( _shader_model_character_view.id, "uCamera" );
- _uniform_model_character_view_uBoard0 = glGetUniformLocation( _shader_model_character_view.id, "uBoard0" );
- _uniform_model_character_view_uBoard1 = glGetUniformLocation( _shader_model_character_view.id, "uBoard1" );
_uniform_model_character_view_g_world_depth = glGetUniformLocation( _shader_model_character_view.id, "g_world_depth" );
}
#endif /* SHADER_model_character_view_H */
-layout (location = 0) out vec4 oColour;
-
-uniform vec4 uColour;
uniform sampler2D uTexGarbage;
uniform float uTime;
in vec2 aUv;
in vec3 aNorm;
in vec3 aCo;
+in vec3 aWorldCo;
+#include "common_world.glsl"
#include "motion_vectors_fs.glsl"
void main()
{
compute_motion_vectors();
- float fintensity = 1.0-(abs(aNorm.y)*0.7);
+ vec3 rd = normalize(aNorm);
+
+ float fintensity = 1.0-(abs(rd.y)*0.7);
float fblend = pow(fintensity,4.0);
- vec3 horizon = vec3( 0.8, 0.9, 0.9 );
- vec3 skycolour = vec3( 0.5, 0.6, 0.9 );
+ vec3 horizon = vec3( 0.87, 0.93, 0.98 );
+ vec3 skycolour = vec3( 0.16, 0.58, 0.95 ) - rd.y*rd.y*0.5;
vec3 diffuse = mix( skycolour, horizon, fblend );
float fmove = uTime * 0.004;
- vec2 cloudplane = (aNorm.xz / (aNorm.y*sign(aNorm.y))) * 0.05;
+ vec2 cloudplane = (rd.xz / (rd.y*sign(rd.y))) * 0.05;
vec4 clouds1 = texture( uTexGarbage, cloudplane + vec2(0.1,0.4)*fmove*2.0 );
- vec4 clouds2 = texture( uTexGarbage, cloudplane + vec2(0.3,0.1)*fmove );
+ vec4 clouds2 = texture( uTexGarbage, cloudplane*2.0 + vec2(0.3,0.1)*fmove );
float cloud_d = max(clouds1.b*clouds2.r -0.2 - clouds2.g*0.4,0.0);
- float cloud_e = pow(cloud_d,1.5)*pow(abs(aNorm.y),0.3)*2.0;
+ float cloud_e = pow(cloud_d,1.5)*pow(abs(rd.y),0.3)*2.0;
vec3 colour_ocean = vec3( 0.61, 0.84, 0.9 );
- float fhorizon = step( aNorm.y * 0.5 + 0.5, 0.5 );
+ float fhorizon = step( rd.y * 0.5 + 0.5, 0.5 );
vec3 skycomp = mix(diffuse, vec3(1.0,1.0,1.0), cloud_e);
- oColour = vec4(pow(skycomp, vec3(1.5)),1.0);
+
+
+ float sundot = clamp(dot(rd, -g_light_directions[0].xyz), 0.0, 1.0);
+ vec3 sun = 0.25 * vec3(1.0,0.7,0.4) * pow( sundot,5.0 );
+ sun += 0.25 * vec3(1.0,0.8,0.6) * pow( sundot,64.0 );
+ sun += 0.2 * vec3(1.0,0.8,0.6) * pow( sundot,512.0 );
+ skycomp += sun * g_light_colours[0].rgb;
+
+ oColour = vec4(skycomp,1.0);
}
.fs =
{
.static_src =
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"uniform vec4 uColour;\n"
"uniform sampler2D uTexGarbage;\n"
"uniform float uTime;\n"
"\n"
"in vec2 aUv;\n"
"in vec3 aNorm;\n"
"in vec3 aCo;\n"
+"in vec3 aWorldCo;\n"
"\n"
"#line 1 1 \n"
+"layout (location = 0) out vec4 oColour;\n"
+"\n"
+"layout (std140) uniform ub_world_lighting\n"
+"{\n"
+" vec4 g_light_colours[3];\n"
+" vec4 g_light_directions[3];\n"
+" vec4 g_ambient_colour;\n"
+"\n"
+" vec4 g_water_plane;\n"
+" vec4 g_depth_bounds;\n"
+" float g_water_fog;\n"
+" int g_light_count;\n"
+" int g_light_preview;\n"
+" int g_shadow_samples;\n"
+"\n"
+" // g_time ?\n"
+"\n"
+" //vec4 g_point_light_positions[32];\n"
+" //vec4 g_point_light_colours[32];\n"
+"};\n"
+"\n"
+"uniform sampler2D g_world_depth;\n"
+"\n"
+"float world_depth_sample( vec3 pos )\n"
+"{\n"
+" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
+" return texture( g_world_depth, depth_coord ).r;\n"
+"}\n"
+"\n"
+"float world_water_depth( vec3 pos )\n"
+"{\n"
+" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
+" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
+" return texture( g_world_depth, depth_coord ).g - ref_depth;\n"
+"}\n"
+"\n"
+"float shadow_sample( vec3 vdir )\n"
+"{\n"
+" vec3 sample_pos = aWorldCo + vdir;\n"
+" float height_sample = world_depth_sample( sample_pos );\n"
+"\n"
+" float fdelta = height_sample - sample_pos.y;\n"
+" return clamp( fdelta, 0.1, 0.2 )-0.1;\n"
+"}\n"
+"\n"
+"vec3 apply_fog( vec3 vfrag, float fdist )\n"
+"{\n"
+" float dist = pow(fdist*0.0008,1.2);\n"
+" return mix( vfrag, vec3(0.55,0.76,1.0), min( 1.0, dist ) );\n"
+"}\n"
+"\n"
+"\n"
+"// New lighting model\n"
+"\n"
+"vec3 newlight_compute_ambient()\n"
+"{\n"
+" return g_ambient_colour.rgb;\n"
+"}\n"
+"\n"
+"float newlight_compute_sun_shadow()\n"
+"{\n"
+" if( g_shadow_samples == 0 )\n"
+" {\n"
+" return 1.0;\n"
+" }\n"
+"\n"
+" float fspread = g_light_colours[0].w;\n"
+" vec3 vdir = g_light_directions[0].xyz;\n"
+" float flength = g_light_directions[0].w;\n"
+"\n"
+" float famt = 0.0;\n"
+" famt+=shadow_sample((vdir+vec3(-0.563, 0.550, 0.307)*fspread)*flength*0.1);\n"
+" famt+=shadow_sample((vdir+vec3( 0.808, 0.686, 0.346)*fspread)*flength*0.2);\n"
+" famt+=shadow_sample((vdir+vec3( 0.787, 0.074,-0.065)*fspread)*flength*0.3);\n"
+" famt+=shadow_sample((vdir+vec3(-0.593, 0.071,-0.425)*fspread)*flength*0.4);\n"
+" famt+=shadow_sample((vdir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
+" famt+=shadow_sample((vdir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
+" famt+=shadow_sample((vdir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
+" famt+=shadow_sample((vdir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
+"\n"
+" return 1.0 - famt;\n"
+"}\n"
+"\n"
+"vec3 newlight_compute_world_diffuse( vec3 wnormal )\n"
+"{\n"
+" vec3 vtotal = g_ambient_colour.rgb;\n"
+"\n"
+" for( int i=0; i<g_light_count; i++ )\n"
+" {\n"
+" vec3 vcolour = g_light_colours[i].rgb;\n"
+" vec3 vdir = g_light_directions[i].xyz;\n"
+"\n"
+" float flight = max(dot( vdir, wnormal )*0.75+0.25,0.0);\n"
+" vtotal += vcolour*flight;\n"
+" }\n"
+"\n"
+" return vtotal;\n"
+"}\n"
+"\n"
+"vec3 newlight_compute_sun_spec( vec3 wnormal, vec3 halfview, float fintensity )\n"
+"{\n"
+" vec3 vcolour = g_light_colours[0].rgb;\n"
+" vec3 vdir = g_light_directions[0].xyz;\n"
+"\n"
+" vec3 specdir = reflect( -vdir, wnormal );\n"
+" float spec = pow(max(dot( halfview, specdir ), 0.0), 10.0);\n"
+" return vcolour*spec*fintensity;\n"
+"}\n"
+"\n"
+"vec3 newlight_compute_quadratic( vec3 wnormal, vec3 halfview, \n"
+" vec3 light_pos, vec3 light_colour )\n"
+"{\n"
+" vec3 light_delta = (light_pos-aWorldCo) * 10.0;\n"
+"\n"
+" float quadratic = dot(light_delta,light_delta);\n"
+" float attenuation = 1.0f/( 1.0f + quadratic );\n"
+" attenuation *= max( 0.0, dot( normalize(light_delta), wnormal ) );\n"
+"\n"
+" return light_colour*attenuation;\n"
+"}\n"
+"\n"
+"#line 11 0 \n"
+"#line 1 2 \n"
"const float k_motion_lerp_amount = 0.01;\n"
"\n"
"#line 2 0 \n"
" oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
"}\n"
"\n"
-"#line 13 0 \n"
+"#line 12 0 \n"
"\n"
"void main()\n"
"{\n"
" compute_motion_vectors();\n"
"\n"
-" float fintensity = 1.0-(abs(aNorm.y)*0.7);\n"
+" vec3 rd = normalize(aNorm);\n"
+"\n"
+" float fintensity = 1.0-(abs(rd.y)*0.7);\n"
" float fblend = pow(fintensity,4.0);\n"
-" vec3 horizon = vec3( 0.8, 0.9, 0.9 );\n"
-" vec3 skycolour = vec3( 0.5, 0.6, 0.9 );\n"
+" vec3 horizon = vec3( 0.87, 0.93, 0.98 );\n"
+" vec3 skycolour = vec3( 0.16, 0.58, 0.95 ) - rd.y*rd.y*0.5;\n"
" vec3 diffuse = mix( skycolour, horizon, fblend );\n"
"\n"
" float fmove = uTime * 0.004;\n"
-" vec2 cloudplane = (aNorm.xz / (aNorm.y*sign(aNorm.y))) * 0.05;\n"
+" vec2 cloudplane = (rd.xz / (rd.y*sign(rd.y))) * 0.05;\n"
" vec4 clouds1 = texture( uTexGarbage, cloudplane + vec2(0.1,0.4)*fmove*2.0 );\n"
-" vec4 clouds2 = texture( uTexGarbage, cloudplane + vec2(0.3,0.1)*fmove );\n"
+" vec4 clouds2 = texture( uTexGarbage, cloudplane*2.0 + vec2(0.3,0.1)*fmove );\n"
"\n"
" float cloud_d = max(clouds1.b*clouds2.r -0.2 - clouds2.g*0.4,0.0);\n"
-" float cloud_e = pow(cloud_d,1.5)*pow(abs(aNorm.y),0.3)*2.0;\n"
+" float cloud_e = pow(cloud_d,1.5)*pow(abs(rd.y),0.3)*2.0;\n"
"\n"
" vec3 colour_ocean = vec3( 0.61, 0.84, 0.9 );\n"
-" float fhorizon = step( aNorm.y * 0.5 + 0.5, 0.5 );\n"
+" float fhorizon = step( rd.y * 0.5 + 0.5, 0.5 );\n"
"\n"
" vec3 skycomp = mix(diffuse, vec3(1.0,1.0,1.0), cloud_e);\n"
-" oColour = vec4(pow(skycomp, vec3(1.5)),1.0);\n"
+"\n"
+"\n"
+" float sundot = clamp(dot(rd, -g_light_directions[0].xyz), 0.0, 1.0);\n"
+" vec3 sun = 0.25 * vec3(1.0,0.7,0.4) * pow( sundot,5.0 );\n"
+" sun += 0.25 * vec3(1.0,0.8,0.6) * pow( sundot,64.0 );\n"
+" sun += 0.2 * vec3(1.0,0.8,0.6) * pow( sundot,512.0 );\n"
+" skycomp += sun * g_light_colours[0].rgb;\n"
+"\n"
+" oColour = vec4(skycomp,1.0);\n"
"}\n"
""},
};
static GLuint _uniform_model_sky_uMdl;
static GLuint _uniform_model_sky_uPv;
static GLuint _uniform_model_sky_uPvmPrev;
-static GLuint _uniform_model_sky_uColour;
static GLuint _uniform_model_sky_uTexGarbage;
static GLuint _uniform_model_sky_uTime;
+static GLuint _uniform_model_sky_g_world_depth;
static void shader_model_sky_uMdl(m4x3f m){
glUniformMatrix4x3fv(_uniform_model_sky_uMdl,1,GL_FALSE,(float*)m);
}
static void shader_model_sky_uPvmPrev(m4x4f m){
glUniformMatrix4fv(_uniform_model_sky_uPvmPrev,1,GL_FALSE,(float*)m);
}
-static void shader_model_sky_uColour(v4f v){
- glUniform4fv(_uniform_model_sky_uColour,1,v);
-}
static void shader_model_sky_uTexGarbage(int i){
glUniform1i(_uniform_model_sky_uTexGarbage,i);
}
static void shader_model_sky_uTime(float f){
glUniform1f(_uniform_model_sky_uTime,f);
}
+static void shader_model_sky_g_world_depth(int i){
+ glUniform1i(_uniform_model_sky_g_world_depth,i);
+}
static void shader_model_sky_register(void){
vg_shader_register( &_shader_model_sky );
}
_uniform_model_sky_uMdl = glGetUniformLocation( _shader_model_sky.id, "uMdl" );
_uniform_model_sky_uPv = glGetUniformLocation( _shader_model_sky.id, "uPv" );
_uniform_model_sky_uPvmPrev = glGetUniformLocation( _shader_model_sky.id, "uPvmPrev" );
- _uniform_model_sky_uColour = glGetUniformLocation( _shader_model_sky.id, "uColour" );
_uniform_model_sky_uTexGarbage = glGetUniformLocation( _shader_model_sky.id, "uTexGarbage" );
_uniform_model_sky_uTime = glGetUniformLocation( _shader_model_sky.id, "uTime" );
+ _uniform_model_sky_g_world_depth = glGetUniformLocation( _shader_model_sky.id, "g_world_depth" );
}
#endif /* SHADER_model_sky_H */
uniform mat4x3 uMdl;
uniform mat4 uPv;
uniform mat4 uPvmPrev;
+uniform samplerBuffer uLightsArray;
out vec2 aUv;
out vec4 aNorm;
out vec3 aCo;
out vec3 aWorldCo;
-flat out ivec4 aLights;
+flat out vec4 light_colours[3];
+flat out vec4 light_positions[3];
void main()
{
aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );
aCo = a_co;
aWorldCo = world_pos0;
- aLights = a_lights;
+
+ // read lights
+ light_colours[0] = texelFetch( uLightsArray, a_lights.x*2+0 );
+ light_colours[1] = texelFetch( uLightsArray, a_lights.y*2+0 );
+ light_colours[2] = texelFetch( uLightsArray, a_lights.z*2+0 );
+ light_positions[0] = texelFetch( uLightsArray, a_lights.x*2+1 );
+ light_positions[1] = texelFetch( uLightsArray, a_lights.y*2+1 );
+ light_positions[2] = texelFetch( uLightsArray, a_lights.z*2+1 );
}
uniform vec3 uBoard0;
uniform vec3 uBoard1;
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
#include "common_scene.glsl"
// Water blending
"uniform mat4x3 uMdl;\n"
"uniform mat4 uPv;\n"
"uniform mat4 uPvmPrev;\n"
+"uniform samplerBuffer uLightsArray;\n"
"\n"
"out vec2 aUv;\n"
"out vec4 aNorm;\n"
"out vec3 aCo;\n"
"out vec3 aWorldCo;\n"
-"flat out ivec4 aLights;\n"
+"flat out vec4 light_colours[3];\n"
+"flat out vec4 light_positions[3];\n"
"\n"
"void main()\n"
"{\n"
" aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
" aCo = a_co;\n"
" aWorldCo = world_pos0;\n"
-" aLights = a_lights;\n"
+"\n"
+" // read lights\n"
+" light_colours[0] = texelFetch( uLightsArray, a_lights.x*2+0 );\n"
+" light_colours[1] = texelFetch( uLightsArray, a_lights.y*2+0 );\n"
+" light_colours[2] = texelFetch( uLightsArray, a_lights.z*2+0 );\n"
+" light_positions[0] = texelFetch( uLightsArray, a_lights.x*2+1 );\n"
+" light_positions[1] = texelFetch( uLightsArray, a_lights.y*2+1 );\n"
+" light_positions[2] = texelFetch( uLightsArray, a_lights.z*2+1 );\n"
"}\n"
""},
.fs =
"uniform vec3 uBoard0;\n"
"uniform vec3 uBoard1;\n"
"\n"
+"#line 1 1 \n"
+"// :D\n"
+"\n"
"in vec2 aUv;\n"
"in vec4 aNorm;\n"
"in vec3 aCo;\n"
"in vec3 aWorldCo;\n"
-"flat in ivec4 aLights;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
+"flat in vec4 light_colours[3];\n"
+"flat in vec4 light_positions[3];\n"
"\n"
"#line 1 1 \n"
"layout (location = 0) out vec4 oColour;\n"
" int g_light_preview;\n"
" int g_shadow_samples;\n"
"\n"
-" vec4 g_point_light_positions[32];\n"
-" vec4 g_point_light_colours[32];\n"
+" // g_time ?\n"
+"\n"
+" //vec4 g_point_light_positions[32];\n"
+" //vec4 g_point_light_colours[32];\n"
"};\n"
"\n"
"uniform sampler2D g_world_depth;\n"
" return clamp( fdelta, 0.1, 0.2 )-0.1;\n"
"}\n"
"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
"vec3 apply_fog( vec3 vfrag, float fdist )\n"
"{\n"
" float dist = pow(fdist*0.0008,1.2);\n"
" famt+=shadow_sample((vdir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
" famt+=shadow_sample((vdir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
"\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - max( player_shadow*0.8, famt );\n"
+" return 1.0 - famt;\n"
"}\n"
"\n"
"vec3 newlight_compute_world_diffuse( vec3 wnormal )\n"
" return light_colour*attenuation;\n"
"}\n"
"\n"
-"#line 4 0 \n"
+"#line 11 0 \n"
+"\n"
+"float sdLine( vec3 p, vec3 a, vec3 b )\n"
+"{\n"
+" vec3 pa = p - a;\n"
+" vec3 ba = b - a;\n"
+"\n"
+" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
+" return length( pa - ba*h );\n"
+"}\n"
+"\n"
+"float compute_board_shadow()\n"
+"{\n"
+" // player shadow\n"
+" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
+" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
+" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
+"\n"
+" return 1.0 - player_shadow*0.8;\n"
+"}\n"
"\n"
"vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n"
"{\n"
" world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n"
"\n"
" float world_shadow = newlight_compute_sun_shadow();\n"
+" float board_shadow = compute_board_shadow();\n"
"\n"
-" total_light += world_light * world_shadow;\n"
+" total_light += world_light * min( board_shadow, world_shadow );\n"
"\n"
" // Compute the other lights that exist in the map, not effected by the sun\n"
" // shadow\n"
+"\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.x ].xyz,\n"
-" g_point_light_colours[ aLights.x ].rgb \n"
-" );\n"
+" light_positions[0].xyz,\n"
+" light_colours[0].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.y ].xyz,\n"
-" g_point_light_colours[ aLights.y ].rgb \n"
-" );\n"
+" light_positions[1].xyz,\n"
+" light_colours[1].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.z ].xyz,\n"
-" g_point_light_colours[ aLights.z ].rgb \n"
-" );\n"
+" light_positions[2].xyz,\n"
+" light_colours[2].rgb \n"
+" ) * board_shadow;\n"
"\n"
" return apply_fog( diffuse * total_light, fdist );\n"
"}\n"
"\n"
-"#line 14 0 \n"
+"#line 8 0 \n"
"\n"
"// Water blending\n"
"// ==============\n"
static GLuint _uniform_scene_depth_uMdl;
static GLuint _uniform_scene_depth_uPv;
static GLuint _uniform_scene_depth_uPvmPrev;
+static GLuint _uniform_scene_depth_uLightsArray;
static GLuint _uniform_scene_depth_uCamera;
static GLuint _uniform_scene_depth_uBoard0;
static GLuint _uniform_scene_depth_uBoard1;
_uniform_scene_depth_uMdl = glGetUniformLocation( _shader_scene_depth.id, "uMdl" );
_uniform_scene_depth_uPv = glGetUniformLocation( _shader_scene_depth.id, "uPv" );
_uniform_scene_depth_uPvmPrev = glGetUniformLocation( _shader_scene_depth.id, "uPvmPrev" );
+ _uniform_scene_depth_uLightsArray = glGetUniformLocation( _shader_scene_depth.id, "uLightsArray" );
_uniform_scene_depth_uCamera = glGetUniformLocation( _shader_scene_depth.id, "uCamera" );
_uniform_scene_depth_uBoard0 = glGetUniformLocation( _shader_scene_depth.id, "uBoard0" );
_uniform_scene_depth_uBoard1 = glGetUniformLocation( _shader_scene_depth.id, "uBoard1" );
uniform vec3 uBoard0;
uniform vec3 uBoard1;
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
#include "common_scene.glsl"
void main()
"uniform mat4x3 uMdl;\n"
"uniform mat4 uPv;\n"
"uniform mat4 uPvmPrev;\n"
+"uniform samplerBuffer uLightsArray;\n"
"\n"
"out vec2 aUv;\n"
"out vec4 aNorm;\n"
"out vec3 aCo;\n"
"out vec3 aWorldCo;\n"
-"flat out ivec4 aLights;\n"
+"flat out vec4 light_colours[3];\n"
+"flat out vec4 light_positions[3];\n"
"\n"
"void main()\n"
"{\n"
" aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
" aCo = a_co;\n"
" aWorldCo = world_pos0;\n"
-" aLights = a_lights;\n"
+"\n"
+" // read lights\n"
+" light_colours[0] = texelFetch( uLightsArray, a_lights.x*2+0 );\n"
+" light_colours[1] = texelFetch( uLightsArray, a_lights.y*2+0 );\n"
+" light_colours[2] = texelFetch( uLightsArray, a_lights.z*2+0 );\n"
+" light_positions[0] = texelFetch( uLightsArray, a_lights.x*2+1 );\n"
+" light_positions[1] = texelFetch( uLightsArray, a_lights.y*2+1 );\n"
+" light_positions[2] = texelFetch( uLightsArray, a_lights.z*2+1 );\n"
"}\n"
""},
.fs =
"uniform vec3 uBoard0;\n"
"uniform vec3 uBoard1;\n"
"\n"
+"#line 1 1 \n"
+"// :D\n"
+"\n"
"in vec2 aUv;\n"
"in vec4 aNorm;\n"
"in vec3 aCo;\n"
"in vec3 aWorldCo;\n"
-"flat in ivec4 aLights;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
+"flat in vec4 light_colours[3];\n"
+"flat in vec4 light_positions[3];\n"
"\n"
"#line 1 1 \n"
"layout (location = 0) out vec4 oColour;\n"
" int g_light_preview;\n"
" int g_shadow_samples;\n"
"\n"
-" vec4 g_point_light_positions[32];\n"
-" vec4 g_point_light_colours[32];\n"
+" // g_time ?\n"
+"\n"
+" //vec4 g_point_light_positions[32];\n"
+" //vec4 g_point_light_colours[32];\n"
"};\n"
"\n"
"uniform sampler2D g_world_depth;\n"
" return clamp( fdelta, 0.1, 0.2 )-0.1;\n"
"}\n"
"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
"vec3 apply_fog( vec3 vfrag, float fdist )\n"
"{\n"
" float dist = pow(fdist*0.0008,1.2);\n"
" famt+=shadow_sample((vdir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
" famt+=shadow_sample((vdir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
"\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - max( player_shadow*0.8, famt );\n"
+" return 1.0 - famt;\n"
"}\n"
"\n"
"vec3 newlight_compute_world_diffuse( vec3 wnormal )\n"
" return light_colour*attenuation;\n"
"}\n"
"\n"
-"#line 4 0 \n"
+"#line 11 0 \n"
+"\n"
+"float sdLine( vec3 p, vec3 a, vec3 b )\n"
+"{\n"
+" vec3 pa = p - a;\n"
+" vec3 ba = b - a;\n"
+"\n"
+" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
+" return length( pa - ba*h );\n"
+"}\n"
+"\n"
+"float compute_board_shadow()\n"
+"{\n"
+" // player shadow\n"
+" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
+" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
+" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
+"\n"
+" return 1.0 - player_shadow*0.8;\n"
+"}\n"
"\n"
"vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n"
"{\n"
" world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n"
"\n"
" float world_shadow = newlight_compute_sun_shadow();\n"
+" float board_shadow = compute_board_shadow();\n"
"\n"
-" total_light += world_light * world_shadow;\n"
+" total_light += world_light * min( board_shadow, world_shadow );\n"
"\n"
" // Compute the other lights that exist in the map, not effected by the sun\n"
" // shadow\n"
+"\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.x ].xyz,\n"
-" g_point_light_colours[ aLights.x ].rgb \n"
-" );\n"
+" light_positions[0].xyz,\n"
+" light_colours[0].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.y ].xyz,\n"
-" g_point_light_colours[ aLights.y ].rgb \n"
-" );\n"
+" light_positions[1].xyz,\n"
+" light_colours[1].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.z ].xyz,\n"
-" g_point_light_colours[ aLights.z ].rgb \n"
-" );\n"
+" light_positions[2].xyz,\n"
+" light_colours[2].rgb \n"
+" ) * board_shadow;\n"
"\n"
" return apply_fog( diffuse * total_light, fdist );\n"
"}\n"
"\n"
-"#line 14 0 \n"
+"#line 8 0 \n"
"\n"
"void main()\n"
"{\n"
static GLuint _uniform_scene_position_uMdl;
static GLuint _uniform_scene_position_uPv;
static GLuint _uniform_scene_position_uPvmPrev;
+static GLuint _uniform_scene_position_uLightsArray;
static GLuint _uniform_scene_position_uCamera;
static GLuint _uniform_scene_position_uBoard0;
static GLuint _uniform_scene_position_uBoard1;
_uniform_scene_position_uMdl = glGetUniformLocation( _shader_scene_position.id, "uMdl" );
_uniform_scene_position_uPv = glGetUniformLocation( _shader_scene_position.id, "uPv" );
_uniform_scene_position_uPvmPrev = glGetUniformLocation( _shader_scene_position.id, "uPvmPrev" );
+ _uniform_scene_position_uLightsArray = glGetUniformLocation( _shader_scene_position.id, "uLightsArray" );
_uniform_scene_position_uCamera = glGetUniformLocation( _shader_scene_position.id, "uCamera" );
_uniform_scene_position_uBoard0 = glGetUniformLocation( _shader_scene_position.id, "uBoard0" );
_uniform_scene_position_uBoard1 = glGetUniformLocation( _shader_scene_position.id, "uBoard1" );
uniform vec3 uBoard0;
uniform vec3 uBoard1;
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
#include "common_scene.glsl"
#include "motion_vectors_fs.glsl"
"uniform mat4x3 uMdl;\n"
"uniform mat4 uPv;\n"
"uniform mat4 uPvmPrev;\n"
+"uniform samplerBuffer uLightsArray;\n"
"\n"
"out vec2 aUv;\n"
"out vec4 aNorm;\n"
"out vec3 aCo;\n"
"out vec3 aWorldCo;\n"
-"flat out ivec4 aLights;\n"
+"flat out vec4 light_colours[3];\n"
+"flat out vec4 light_positions[3];\n"
"\n"
"void main()\n"
"{\n"
" aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
" aCo = a_co;\n"
" aWorldCo = world_pos0;\n"
-" aLights = a_lights;\n"
+"\n"
+" // read lights\n"
+" light_colours[0] = texelFetch( uLightsArray, a_lights.x*2+0 );\n"
+" light_colours[1] = texelFetch( uLightsArray, a_lights.y*2+0 );\n"
+" light_colours[2] = texelFetch( uLightsArray, a_lights.z*2+0 );\n"
+" light_positions[0] = texelFetch( uLightsArray, a_lights.x*2+1 );\n"
+" light_positions[1] = texelFetch( uLightsArray, a_lights.y*2+1 );\n"
+" light_positions[2] = texelFetch( uLightsArray, a_lights.z*2+1 );\n"
"}\n"
""},
.fs =
"uniform vec3 uBoard0;\n"
"uniform vec3 uBoard1;\n"
"\n"
+"#line 1 1 \n"
+"// :D\n"
+"\n"
"in vec2 aUv;\n"
"in vec4 aNorm;\n"
"in vec3 aCo;\n"
"in vec3 aWorldCo;\n"
-"flat in ivec4 aLights;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
+"flat in vec4 light_colours[3];\n"
+"flat in vec4 light_positions[3];\n"
"\n"
"#line 1 1 \n"
"layout (location = 0) out vec4 oColour;\n"
" int g_light_preview;\n"
" int g_shadow_samples;\n"
"\n"
-" vec4 g_point_light_positions[32];\n"
-" vec4 g_point_light_colours[32];\n"
+" // g_time ?\n"
+"\n"
+" //vec4 g_point_light_positions[32];\n"
+" //vec4 g_point_light_colours[32];\n"
"};\n"
"\n"
"uniform sampler2D g_world_depth;\n"
" return clamp( fdelta, 0.1, 0.2 )-0.1;\n"
"}\n"
"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
"vec3 apply_fog( vec3 vfrag, float fdist )\n"
"{\n"
" float dist = pow(fdist*0.0008,1.2);\n"
" famt+=shadow_sample((vdir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
" famt+=shadow_sample((vdir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
"\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - max( player_shadow*0.8, famt );\n"
+" return 1.0 - famt;\n"
"}\n"
"\n"
"vec3 newlight_compute_world_diffuse( vec3 wnormal )\n"
" return light_colour*attenuation;\n"
"}\n"
"\n"
-"#line 4 0 \n"
+"#line 11 0 \n"
+"\n"
+"float sdLine( vec3 p, vec3 a, vec3 b )\n"
+"{\n"
+" vec3 pa = p - a;\n"
+" vec3 ba = b - a;\n"
+"\n"
+" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
+" return length( pa - ba*h );\n"
+"}\n"
+"\n"
+"float compute_board_shadow()\n"
+"{\n"
+" // player shadow\n"
+" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
+" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
+" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
+"\n"
+" return 1.0 - player_shadow*0.8;\n"
+"}\n"
"\n"
"vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n"
"{\n"
" world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n"
"\n"
" float world_shadow = newlight_compute_sun_shadow();\n"
+" float board_shadow = compute_board_shadow();\n"
"\n"
-" total_light += world_light * world_shadow;\n"
+" total_light += world_light * min( board_shadow, world_shadow );\n"
"\n"
" // Compute the other lights that exist in the map, not effected by the sun\n"
" // shadow\n"
+"\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.x ].xyz,\n"
-" g_point_light_colours[ aLights.x ].rgb \n"
-" );\n"
+" light_positions[0].xyz,\n"
+" light_colours[0].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.y ].xyz,\n"
-" g_point_light_colours[ aLights.y ].rgb \n"
-" );\n"
+" light_positions[1].xyz,\n"
+" light_colours[1].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.z ].xyz,\n"
-" g_point_light_colours[ aLights.z ].rgb \n"
-" );\n"
+" light_positions[2].xyz,\n"
+" light_colours[2].rgb \n"
+" ) * board_shadow;\n"
"\n"
" return apply_fog( diffuse * total_light, fdist );\n"
"}\n"
"\n"
-"#line 15 0 \n"
+"#line 9 0 \n"
"#line 1 2 \n"
"const float k_motion_lerp_amount = 0.01;\n"
"\n"
" oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
"}\n"
"\n"
-"#line 16 0 \n"
+"#line 10 0 \n"
"\n"
"void main()\n"
"{\n"
static GLuint _uniform_scene_route_uMdl;
static GLuint _uniform_scene_route_uPv;
static GLuint _uniform_scene_route_uPvmPrev;
+static GLuint _uniform_scene_route_uLightsArray;
static GLuint _uniform_scene_route_uTexGarbage;
static GLuint _uniform_scene_route_uTexGradients;
static GLuint _uniform_scene_route_uCamera;
_uniform_scene_route_uMdl = glGetUniformLocation( _shader_scene_route.id, "uMdl" );
_uniform_scene_route_uPv = glGetUniformLocation( _shader_scene_route.id, "uPv" );
_uniform_scene_route_uPvmPrev = glGetUniformLocation( _shader_scene_route.id, "uPvmPrev" );
+ _uniform_scene_route_uLightsArray = glGetUniformLocation( _shader_scene_route.id, "uLightsArray" );
_uniform_scene_route_uTexGarbage = glGetUniformLocation( _shader_scene_route.id, "uTexGarbage" );
_uniform_scene_route_uTexGradients = glGetUniformLocation( _shader_scene_route.id, "uTexGradients" );
_uniform_scene_route_uCamera = glGetUniformLocation( _shader_scene_route.id, "uCamera" );
uniform vec3 uBoard0;
uniform vec3 uBoard1;
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
#include "common_scene.glsl"
#include "motion_vectors_fs.glsl"
"uniform mat4x3 uMdl;\n"
"uniform mat4 uPv;\n"
"uniform mat4 uPvmPrev;\n"
+"uniform samplerBuffer uLightsArray;\n"
"\n"
"out vec2 aUv;\n"
"out vec4 aNorm;\n"
"out vec3 aCo;\n"
"out vec3 aWorldCo;\n"
-"flat out ivec4 aLights;\n"
+"flat out vec4 light_colours[3];\n"
+"flat out vec4 light_positions[3];\n"
"\n"
"void main()\n"
"{\n"
" aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
" aCo = a_co;\n"
" aWorldCo = world_pos0;\n"
-" aLights = a_lights;\n"
+"\n"
+" // read lights\n"
+" light_colours[0] = texelFetch( uLightsArray, a_lights.x*2+0 );\n"
+" light_colours[1] = texelFetch( uLightsArray, a_lights.y*2+0 );\n"
+" light_colours[2] = texelFetch( uLightsArray, a_lights.z*2+0 );\n"
+" light_positions[0] = texelFetch( uLightsArray, a_lights.x*2+1 );\n"
+" light_positions[1] = texelFetch( uLightsArray, a_lights.y*2+1 );\n"
+" light_positions[2] = texelFetch( uLightsArray, a_lights.z*2+1 );\n"
"}\n"
""},
.fs =
"uniform vec3 uBoard0;\n"
"uniform vec3 uBoard1;\n"
"\n"
+"#line 1 1 \n"
+"// :D\n"
+"\n"
"in vec2 aUv;\n"
"in vec4 aNorm;\n"
"in vec3 aCo;\n"
"in vec3 aWorldCo;\n"
-"flat in ivec4 aLights;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
+"flat in vec4 light_colours[3];\n"
+"flat in vec4 light_positions[3];\n"
"\n"
"#line 1 1 \n"
"layout (location = 0) out vec4 oColour;\n"
" int g_light_preview;\n"
" int g_shadow_samples;\n"
"\n"
-" vec4 g_point_light_positions[32];\n"
-" vec4 g_point_light_colours[32];\n"
+" // g_time ?\n"
+"\n"
+" //vec4 g_point_light_positions[32];\n"
+" //vec4 g_point_light_colours[32];\n"
"};\n"
"\n"
"uniform sampler2D g_world_depth;\n"
" return clamp( fdelta, 0.1, 0.2 )-0.1;\n"
"}\n"
"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
"vec3 apply_fog( vec3 vfrag, float fdist )\n"
"{\n"
" float dist = pow(fdist*0.0008,1.2);\n"
" famt+=shadow_sample((vdir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
" famt+=shadow_sample((vdir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
"\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - max( player_shadow*0.8, famt );\n"
+" return 1.0 - famt;\n"
"}\n"
"\n"
"vec3 newlight_compute_world_diffuse( vec3 wnormal )\n"
" return light_colour*attenuation;\n"
"}\n"
"\n"
-"#line 4 0 \n"
+"#line 11 0 \n"
+"\n"
+"float sdLine( vec3 p, vec3 a, vec3 b )\n"
+"{\n"
+" vec3 pa = p - a;\n"
+" vec3 ba = b - a;\n"
+"\n"
+" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
+" return length( pa - ba*h );\n"
+"}\n"
+"\n"
+"float compute_board_shadow()\n"
+"{\n"
+" // player shadow\n"
+" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
+" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
+" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
+"\n"
+" return 1.0 - player_shadow*0.8;\n"
+"}\n"
"\n"
"vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n"
"{\n"
" world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n"
"\n"
" float world_shadow = newlight_compute_sun_shadow();\n"
+" float board_shadow = compute_board_shadow();\n"
"\n"
-" total_light += world_light * world_shadow;\n"
+" total_light += world_light * min( board_shadow, world_shadow );\n"
"\n"
" // Compute the other lights that exist in the map, not effected by the sun\n"
" // shadow\n"
+"\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.x ].xyz,\n"
-" g_point_light_colours[ aLights.x ].rgb \n"
-" );\n"
+" light_positions[0].xyz,\n"
+" light_colours[0].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.y ].xyz,\n"
-" g_point_light_colours[ aLights.y ].rgb \n"
-" );\n"
+" light_positions[1].xyz,\n"
+" light_colours[1].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.z ].xyz,\n"
-" g_point_light_colours[ aLights.z ].rgb \n"
-" );\n"
+" light_positions[2].xyz,\n"
+" light_colours[2].rgb \n"
+" ) * board_shadow;\n"
"\n"
" return apply_fog( diffuse * total_light, fdist );\n"
"}\n"
"\n"
-"#line 15 0 \n"
+"#line 9 0 \n"
"#line 1 2 \n"
"const float k_motion_lerp_amount = 0.01;\n"
"\n"
" oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
"}\n"
"\n"
-"#line 16 0 \n"
+"#line 10 0 \n"
"\n"
"void main()\n"
"{\n"
static GLuint _uniform_scene_standard_uMdl;
static GLuint _uniform_scene_standard_uPv;
static GLuint _uniform_scene_standard_uPvmPrev;
+static GLuint _uniform_scene_standard_uLightsArray;
static GLuint _uniform_scene_standard_uTexGarbage;
static GLuint _uniform_scene_standard_uTexMain;
static GLuint _uniform_scene_standard_uCamera;
_uniform_scene_standard_uMdl = glGetUniformLocation( _shader_scene_standard.id, "uMdl" );
_uniform_scene_standard_uPv = glGetUniformLocation( _shader_scene_standard.id, "uPv" );
_uniform_scene_standard_uPvmPrev = glGetUniformLocation( _shader_scene_standard.id, "uPvmPrev" );
+ _uniform_scene_standard_uLightsArray = glGetUniformLocation( _shader_scene_standard.id, "uLightsArray" );
_uniform_scene_standard_uTexGarbage = glGetUniformLocation( _shader_scene_standard.id, "uTexGarbage" );
_uniform_scene_standard_uTexMain = glGetUniformLocation( _shader_scene_standard.id, "uTexMain" );
_uniform_scene_standard_uCamera = glGetUniformLocation( _shader_scene_standard.id, "uCamera" );
uniform vec3 uCamera;
uniform vec4 uPlane;
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
#include "common_scene.glsl"
#include "motion_vectors_fs.glsl"
"uniform mat4x3 uMdl;\n"
"uniform mat4 uPv;\n"
"uniform mat4 uPvmPrev;\n"
+"uniform samplerBuffer uLightsArray;\n"
"\n"
"out vec2 aUv;\n"
"out vec4 aNorm;\n"
"out vec3 aCo;\n"
"out vec3 aWorldCo;\n"
-"flat out ivec4 aLights;\n"
+"flat out vec4 light_colours[3];\n"
+"flat out vec4 light_positions[3];\n"
"\n"
"void main()\n"
"{\n"
" aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
" aCo = a_co;\n"
" aWorldCo = world_pos0;\n"
-" aLights = a_lights;\n"
+"\n"
+" // read lights\n"
+" light_colours[0] = texelFetch( uLightsArray, a_lights.x*2+0 );\n"
+" light_colours[1] = texelFetch( uLightsArray, a_lights.y*2+0 );\n"
+" light_colours[2] = texelFetch( uLightsArray, a_lights.z*2+0 );\n"
+" light_positions[0] = texelFetch( uLightsArray, a_lights.x*2+1 );\n"
+" light_positions[1] = texelFetch( uLightsArray, a_lights.y*2+1 );\n"
+" light_positions[2] = texelFetch( uLightsArray, a_lights.z*2+1 );\n"
"}\n"
""},
.fs =
"uniform vec3 uCamera;\n"
"uniform vec4 uPlane;\n"
"\n"
+"#line 1 1 \n"
+"// :D\n"
+"\n"
"in vec2 aUv;\n"
"in vec4 aNorm;\n"
"in vec3 aCo;\n"
"in vec3 aWorldCo;\n"
-"flat in ivec4 aLights;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
+"flat in vec4 light_colours[3];\n"
+"flat in vec4 light_positions[3];\n"
"\n"
"#line 1 1 \n"
"layout (location = 0) out vec4 oColour;\n"
" int g_light_preview;\n"
" int g_shadow_samples;\n"
"\n"
-" vec4 g_point_light_positions[32];\n"
-" vec4 g_point_light_colours[32];\n"
+" // g_time ?\n"
+"\n"
+" //vec4 g_point_light_positions[32];\n"
+" //vec4 g_point_light_colours[32];\n"
"};\n"
"\n"
"uniform sampler2D g_world_depth;\n"
" return clamp( fdelta, 0.1, 0.2 )-0.1;\n"
"}\n"
"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
"vec3 apply_fog( vec3 vfrag, float fdist )\n"
"{\n"
" float dist = pow(fdist*0.0008,1.2);\n"
" famt+=shadow_sample((vdir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
" famt+=shadow_sample((vdir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
"\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - max( player_shadow*0.8, famt );\n"
+" return 1.0 - famt;\n"
"}\n"
"\n"
"vec3 newlight_compute_world_diffuse( vec3 wnormal )\n"
" return light_colour*attenuation;\n"
"}\n"
"\n"
-"#line 4 0 \n"
+"#line 11 0 \n"
+"\n"
+"float sdLine( vec3 p, vec3 a, vec3 b )\n"
+"{\n"
+" vec3 pa = p - a;\n"
+" vec3 ba = b - a;\n"
+"\n"
+" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
+" return length( pa - ba*h );\n"
+"}\n"
+"\n"
+"float compute_board_shadow()\n"
+"{\n"
+" // player shadow\n"
+" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
+" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
+" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
+"\n"
+" return 1.0 - player_shadow*0.8;\n"
+"}\n"
"\n"
"vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n"
"{\n"
" world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n"
"\n"
" float world_shadow = newlight_compute_sun_shadow();\n"
+" float board_shadow = compute_board_shadow();\n"
"\n"
-" total_light += world_light * world_shadow;\n"
+" total_light += world_light * min( board_shadow, world_shadow );\n"
"\n"
" // Compute the other lights that exist in the map, not effected by the sun\n"
" // shadow\n"
+"\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.x ].xyz,\n"
-" g_point_light_colours[ aLights.x ].rgb \n"
-" );\n"
+" light_positions[0].xyz,\n"
+" light_colours[0].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.y ].xyz,\n"
-" g_point_light_colours[ aLights.y ].rgb \n"
-" );\n"
+" light_positions[1].xyz,\n"
+" light_colours[1].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.z ].xyz,\n"
-" g_point_light_colours[ aLights.z ].rgb \n"
-" );\n"
+" light_positions[2].xyz,\n"
+" light_colours[2].rgb \n"
+" ) * board_shadow;\n"
"\n"
" return apply_fog( diffuse * total_light, fdist );\n"
"}\n"
"\n"
-"#line 15 0 \n"
+"#line 9 0 \n"
"#line 1 2 \n"
"const float k_motion_lerp_amount = 0.01;\n"
"\n"
" oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
"}\n"
"\n"
-"#line 16 0 \n"
+"#line 10 0 \n"
"\n"
"void main()\n"
"{\n"
static GLuint _uniform_scene_standard_alphatest_uMdl;
static GLuint _uniform_scene_standard_alphatest_uPv;
static GLuint _uniform_scene_standard_alphatest_uPvmPrev;
+static GLuint _uniform_scene_standard_alphatest_uLightsArray;
static GLuint _uniform_scene_standard_alphatest_uTexGarbage;
static GLuint _uniform_scene_standard_alphatest_uTexMain;
static GLuint _uniform_scene_standard_alphatest_uBoard0;
_uniform_scene_standard_alphatest_uMdl = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uMdl" );
_uniform_scene_standard_alphatest_uPv = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uPv" );
_uniform_scene_standard_alphatest_uPvmPrev = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uPvmPrev" );
+ _uniform_scene_standard_alphatest_uLightsArray = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uLightsArray" );
_uniform_scene_standard_alphatest_uTexGarbage = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uTexGarbage" );
_uniform_scene_standard_alphatest_uTexMain = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uTexMain" );
_uniform_scene_standard_alphatest_uBoard0 = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uBoard0" );
uniform vec3 uBoard0;
uniform vec3 uBoard1;
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
#include "common_scene.glsl"
#include "motion_vectors_fs.glsl"
"uniform mat4x3 uMdl;\n"
"uniform mat4 uPv;\n"
"uniform mat4 uPvmPrev;\n"
+"uniform samplerBuffer uLightsArray;\n"
"\n"
"out vec2 aUv;\n"
"out vec4 aNorm;\n"
"out vec3 aCo;\n"
"out vec3 aWorldCo;\n"
-"flat out ivec4 aLights;\n"
+"flat out vec4 light_colours[3];\n"
+"flat out vec4 light_positions[3];\n"
"\n"
"void main()\n"
"{\n"
" aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
" aCo = a_co;\n"
" aWorldCo = world_pos0;\n"
-" aLights = a_lights;\n"
+"\n"
+" // read lights\n"
+" light_colours[0] = texelFetch( uLightsArray, a_lights.x*2+0 );\n"
+" light_colours[1] = texelFetch( uLightsArray, a_lights.y*2+0 );\n"
+" light_colours[2] = texelFetch( uLightsArray, a_lights.z*2+0 );\n"
+" light_positions[0] = texelFetch( uLightsArray, a_lights.x*2+1 );\n"
+" light_positions[1] = texelFetch( uLightsArray, a_lights.y*2+1 );\n"
+" light_positions[2] = texelFetch( uLightsArray, a_lights.z*2+1 );\n"
"}\n"
""},
.fs =
"uniform vec3 uBoard0;\n"
"uniform vec3 uBoard1;\n"
"\n"
+"#line 1 1 \n"
+"// :D\n"
+"\n"
"in vec2 aUv;\n"
"in vec4 aNorm;\n"
"in vec3 aCo;\n"
"in vec3 aWorldCo;\n"
-"flat in ivec4 aLights;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
+"flat in vec4 light_colours[3];\n"
+"flat in vec4 light_positions[3];\n"
"\n"
"#line 1 1 \n"
"layout (location = 0) out vec4 oColour;\n"
" int g_light_preview;\n"
" int g_shadow_samples;\n"
"\n"
-" vec4 g_point_light_positions[32];\n"
-" vec4 g_point_light_colours[32];\n"
+" // g_time ?\n"
+"\n"
+" //vec4 g_point_light_positions[32];\n"
+" //vec4 g_point_light_colours[32];\n"
"};\n"
"\n"
"uniform sampler2D g_world_depth;\n"
" return clamp( fdelta, 0.1, 0.2 )-0.1;\n"
"}\n"
"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
"vec3 apply_fog( vec3 vfrag, float fdist )\n"
"{\n"
" float dist = pow(fdist*0.0008,1.2);\n"
" famt+=shadow_sample((vdir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
" famt+=shadow_sample((vdir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
"\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - max( player_shadow*0.8, famt );\n"
+" return 1.0 - famt;\n"
"}\n"
"\n"
"vec3 newlight_compute_world_diffuse( vec3 wnormal )\n"
" return light_colour*attenuation;\n"
"}\n"
"\n"
-"#line 4 0 \n"
+"#line 11 0 \n"
+"\n"
+"float sdLine( vec3 p, vec3 a, vec3 b )\n"
+"{\n"
+" vec3 pa = p - a;\n"
+" vec3 ba = b - a;\n"
+"\n"
+" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
+" return length( pa - ba*h );\n"
+"}\n"
+"\n"
+"float compute_board_shadow()\n"
+"{\n"
+" // player shadow\n"
+" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
+" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
+" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
+"\n"
+" return 1.0 - player_shadow*0.8;\n"
+"}\n"
"\n"
"vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n"
"{\n"
" world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n"
"\n"
" float world_shadow = newlight_compute_sun_shadow();\n"
+" float board_shadow = compute_board_shadow();\n"
"\n"
-" total_light += world_light * world_shadow;\n"
+" total_light += world_light * min( board_shadow, world_shadow );\n"
"\n"
" // Compute the other lights that exist in the map, not effected by the sun\n"
" // shadow\n"
+"\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.x ].xyz,\n"
-" g_point_light_colours[ aLights.x ].rgb \n"
-" );\n"
+" light_positions[0].xyz,\n"
+" light_colours[0].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.y ].xyz,\n"
-" g_point_light_colours[ aLights.y ].rgb \n"
-" );\n"
+" light_positions[1].xyz,\n"
+" light_colours[1].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.z ].xyz,\n"
-" g_point_light_colours[ aLights.z ].rgb \n"
-" );\n"
+" light_positions[2].xyz,\n"
+" light_colours[2].rgb \n"
+" ) * board_shadow;\n"
"\n"
" return apply_fog( diffuse * total_light, fdist );\n"
"}\n"
"\n"
-"#line 16 0 \n"
+"#line 10 0 \n"
"#line 1 2 \n"
"const float k_motion_lerp_amount = 0.01;\n"
"\n"
" oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
"}\n"
"\n"
-"#line 17 0 \n"
+"#line 11 0 \n"
"\n"
"void main()\n"
"{\n"
static GLuint _uniform_scene_terrain_uMdl;
static GLuint _uniform_scene_terrain_uPv;
static GLuint _uniform_scene_terrain_uPvmPrev;
+static GLuint _uniform_scene_terrain_uLightsArray;
static GLuint _uniform_scene_terrain_uTexGarbage;
static GLuint _uniform_scene_terrain_uTexGradients;
static GLuint _uniform_scene_terrain_uCamera;
_uniform_scene_terrain_uMdl = glGetUniformLocation( _shader_scene_terrain.id, "uMdl" );
_uniform_scene_terrain_uPv = glGetUniformLocation( _shader_scene_terrain.id, "uPv" );
_uniform_scene_terrain_uPvmPrev = glGetUniformLocation( _shader_scene_terrain.id, "uPvmPrev" );
+ _uniform_scene_terrain_uLightsArray = glGetUniformLocation( _shader_scene_terrain.id, "uLightsArray" );
_uniform_scene_terrain_uTexGarbage = glGetUniformLocation( _shader_scene_terrain.id, "uTexGarbage" );
_uniform_scene_terrain_uTexGradients = glGetUniformLocation( _shader_scene_terrain.id, "uTexGradients" );
_uniform_scene_terrain_uCamera = glGetUniformLocation( _shader_scene_terrain.id, "uCamera" );
uniform vec3 uBoard0;
uniform vec3 uBoard1;
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
#include "common_scene.glsl"
#include "motion_vectors_fs.glsl"
"uniform mat4x3 uMdl;\n"
"uniform mat4 uPv;\n"
"uniform mat4 uPvmPrev;\n"
+"uniform samplerBuffer uLightsArray;\n"
"\n"
"out vec2 aUv;\n"
"out vec4 aNorm;\n"
"out vec3 aCo;\n"
"out vec3 aWorldCo;\n"
-"flat out ivec4 aLights;\n"
+"flat out vec4 light_colours[3];\n"
+"flat out vec4 light_positions[3];\n"
"\n"
"void main()\n"
"{\n"
" aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
" aCo = a_co;\n"
" aWorldCo = world_pos0;\n"
-" aLights = a_lights;\n"
+"\n"
+" // read lights\n"
+" light_colours[0] = texelFetch( uLightsArray, a_lights.x*2+0 );\n"
+" light_colours[1] = texelFetch( uLightsArray, a_lights.y*2+0 );\n"
+" light_colours[2] = texelFetch( uLightsArray, a_lights.z*2+0 );\n"
+" light_positions[0] = texelFetch( uLightsArray, a_lights.x*2+1 );\n"
+" light_positions[1] = texelFetch( uLightsArray, a_lights.y*2+1 );\n"
+" light_positions[2] = texelFetch( uLightsArray, a_lights.z*2+1 );\n"
"}\n"
""},
.fs =
"uniform vec3 uBoard0;\n"
"uniform vec3 uBoard1;\n"
"\n"
+"#line 1 1 \n"
+"// :D\n"
+"\n"
"in vec2 aUv;\n"
"in vec4 aNorm;\n"
"in vec3 aCo;\n"
"in vec3 aWorldCo;\n"
-"flat in ivec4 aLights;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
+"flat in vec4 light_colours[3];\n"
+"flat in vec4 light_positions[3];\n"
"\n"
"#line 1 1 \n"
"layout (location = 0) out vec4 oColour;\n"
" int g_light_preview;\n"
" int g_shadow_samples;\n"
"\n"
-" vec4 g_point_light_positions[32];\n"
-" vec4 g_point_light_colours[32];\n"
+" // g_time ?\n"
+"\n"
+" //vec4 g_point_light_positions[32];\n"
+" //vec4 g_point_light_colours[32];\n"
"};\n"
"\n"
"uniform sampler2D g_world_depth;\n"
" return clamp( fdelta, 0.1, 0.2 )-0.1;\n"
"}\n"
"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
"vec3 apply_fog( vec3 vfrag, float fdist )\n"
"{\n"
" float dist = pow(fdist*0.0008,1.2);\n"
" famt+=shadow_sample((vdir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
" famt+=shadow_sample((vdir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
"\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - max( player_shadow*0.8, famt );\n"
+" return 1.0 - famt;\n"
"}\n"
"\n"
"vec3 newlight_compute_world_diffuse( vec3 wnormal )\n"
" return light_colour*attenuation;\n"
"}\n"
"\n"
-"#line 4 0 \n"
+"#line 11 0 \n"
+"\n"
+"float sdLine( vec3 p, vec3 a, vec3 b )\n"
+"{\n"
+" vec3 pa = p - a;\n"
+" vec3 ba = b - a;\n"
+"\n"
+" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
+" return length( pa - ba*h );\n"
+"}\n"
+"\n"
+"float compute_board_shadow()\n"
+"{\n"
+" // player shadow\n"
+" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
+" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
+" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
+"\n"
+" return 1.0 - player_shadow*0.8;\n"
+"}\n"
"\n"
"vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n"
"{\n"
" world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n"
"\n"
" float world_shadow = newlight_compute_sun_shadow();\n"
+" float board_shadow = compute_board_shadow();\n"
"\n"
-" total_light += world_light * world_shadow;\n"
+" total_light += world_light * min( board_shadow, world_shadow );\n"
"\n"
" // Compute the other lights that exist in the map, not effected by the sun\n"
" // shadow\n"
+"\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.x ].xyz,\n"
-" g_point_light_colours[ aLights.x ].rgb \n"
-" );\n"
+" light_positions[0].xyz,\n"
+" light_colours[0].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.y ].xyz,\n"
-" g_point_light_colours[ aLights.y ].rgb \n"
-" );\n"
+" light_positions[1].xyz,\n"
+" light_colours[1].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.z ].xyz,\n"
-" g_point_light_colours[ aLights.z ].rgb \n"
-" );\n"
+" light_positions[2].xyz,\n"
+" light_colours[2].rgb \n"
+" ) * board_shadow;\n"
"\n"
" return apply_fog( diffuse * total_light, fdist );\n"
"}\n"
"\n"
-"#line 14 0 \n"
+"#line 8 0 \n"
"#line 1 2 \n"
"const float k_motion_lerp_amount = 0.01;\n"
"\n"
" oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
"}\n"
"\n"
-"#line 15 0 \n"
+"#line 9 0 \n"
"\n"
"void main()\n"
"{\n"
static GLuint _uniform_scene_vertex_blend_uMdl;
static GLuint _uniform_scene_vertex_blend_uPv;
static GLuint _uniform_scene_vertex_blend_uPvmPrev;
+static GLuint _uniform_scene_vertex_blend_uLightsArray;
static GLuint _uniform_scene_vertex_blend_uTexGarbage;
static GLuint _uniform_scene_vertex_blend_uTexGradients;
static GLuint _uniform_scene_vertex_blend_uCamera;
_uniform_scene_vertex_blend_uMdl = glGetUniformLocation( _shader_scene_vertex_blend.id, "uMdl" );
_uniform_scene_vertex_blend_uPv = glGetUniformLocation( _shader_scene_vertex_blend.id, "uPv" );
_uniform_scene_vertex_blend_uPvmPrev = glGetUniformLocation( _shader_scene_vertex_blend.id, "uPvmPrev" );
+ _uniform_scene_vertex_blend_uLightsArray = glGetUniformLocation( _shader_scene_vertex_blend.id, "uLightsArray" );
_uniform_scene_vertex_blend_uTexGarbage = glGetUniformLocation( _shader_scene_vertex_blend.id, "uTexGarbage" );
_uniform_scene_vertex_blend_uTexGradients = glGetUniformLocation( _shader_scene_vertex_blend.id, "uTexGradients" );
_uniform_scene_vertex_blend_uCamera = glGetUniformLocation( _shader_scene_vertex_blend.id, "uCamera" );
uniform vec3 uShoreColour;
uniform vec3 uOceanColour;
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
#include "common_scene.glsl"
#include "motion_vectors_fs.glsl"
"uniform mat4x3 uMdl;\n"
"uniform mat4 uPv;\n"
"uniform mat4 uPvmPrev;\n"
+"uniform samplerBuffer uLightsArray;\n"
"\n"
"out vec2 aUv;\n"
"out vec4 aNorm;\n"
"out vec3 aCo;\n"
"out vec3 aWorldCo;\n"
-"flat out ivec4 aLights;\n"
+"flat out vec4 light_colours[3];\n"
+"flat out vec4 light_positions[3];\n"
"\n"
"void main()\n"
"{\n"
" aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
" aCo = a_co;\n"
" aWorldCo = world_pos0;\n"
-" aLights = a_lights;\n"
+"\n"
+" // read lights\n"
+" light_colours[0] = texelFetch( uLightsArray, a_lights.x*2+0 );\n"
+" light_colours[1] = texelFetch( uLightsArray, a_lights.y*2+0 );\n"
+" light_colours[2] = texelFetch( uLightsArray, a_lights.z*2+0 );\n"
+" light_positions[0] = texelFetch( uLightsArray, a_lights.x*2+1 );\n"
+" light_positions[1] = texelFetch( uLightsArray, a_lights.y*2+1 );\n"
+" light_positions[2] = texelFetch( uLightsArray, a_lights.z*2+1 );\n"
"}\n"
""},
.fs =
"uniform vec3 uShoreColour;\n"
"uniform vec3 uOceanColour;\n"
"\n"
+"#line 1 1 \n"
+"// :D\n"
+"\n"
"in vec2 aUv;\n"
"in vec4 aNorm;\n"
"in vec3 aCo;\n"
"in vec3 aWorldCo;\n"
-"flat in ivec4 aLights;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
+"flat in vec4 light_colours[3];\n"
+"flat in vec4 light_positions[3];\n"
"\n"
"#line 1 1 \n"
"layout (location = 0) out vec4 oColour;\n"
" int g_light_preview;\n"
" int g_shadow_samples;\n"
"\n"
-" vec4 g_point_light_positions[32];\n"
-" vec4 g_point_light_colours[32];\n"
+" // g_time ?\n"
+"\n"
+" //vec4 g_point_light_positions[32];\n"
+" //vec4 g_point_light_colours[32];\n"
"};\n"
"\n"
"uniform sampler2D g_world_depth;\n"
" return clamp( fdelta, 0.1, 0.2 )-0.1;\n"
"}\n"
"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
"vec3 apply_fog( vec3 vfrag, float fdist )\n"
"{\n"
" float dist = pow(fdist*0.0008,1.2);\n"
" famt+=shadow_sample((vdir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
" famt+=shadow_sample((vdir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
"\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - max( player_shadow*0.8, famt );\n"
+" return 1.0 - famt;\n"
"}\n"
"\n"
"vec3 newlight_compute_world_diffuse( vec3 wnormal )\n"
" return light_colour*attenuation;\n"
"}\n"
"\n"
-"#line 4 0 \n"
+"#line 11 0 \n"
+"\n"
+"float sdLine( vec3 p, vec3 a, vec3 b )\n"
+"{\n"
+" vec3 pa = p - a;\n"
+" vec3 ba = b - a;\n"
+"\n"
+" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
+" return length( pa - ba*h );\n"
+"}\n"
+"\n"
+"float compute_board_shadow()\n"
+"{\n"
+" // player shadow\n"
+" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
+" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
+" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
+"\n"
+" return 1.0 - player_shadow*0.8;\n"
+"}\n"
"\n"
"vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n"
"{\n"
" world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n"
"\n"
" float world_shadow = newlight_compute_sun_shadow();\n"
+" float board_shadow = compute_board_shadow();\n"
"\n"
-" total_light += world_light * world_shadow;\n"
+" total_light += world_light * min( board_shadow, world_shadow );\n"
"\n"
" // Compute the other lights that exist in the map, not effected by the sun\n"
" // shadow\n"
+"\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.x ].xyz,\n"
-" g_point_light_colours[ aLights.x ].rgb \n"
-" );\n"
+" light_positions[0].xyz,\n"
+" light_colours[0].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.y ].xyz,\n"
-" g_point_light_colours[ aLights.y ].rgb \n"
-" );\n"
+" light_positions[1].xyz,\n"
+" light_colours[1].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.z ].xyz,\n"
-" g_point_light_colours[ aLights.z ].rgb \n"
-" );\n"
+" light_positions[2].xyz,\n"
+" light_colours[2].rgb \n"
+" ) * board_shadow;\n"
"\n"
" return apply_fog( diffuse * total_light, fdist );\n"
"}\n"
"\n"
-"#line 22 0 \n"
+"#line 16 0 \n"
"#line 1 2 \n"
"const float k_motion_lerp_amount = 0.01;\n"
"\n"
" oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
"}\n"
"\n"
-"#line 23 0 \n"
+"#line 17 0 \n"
"\n"
"vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue, \n"
" vec4 beneath, vec4 above )\n"
static GLuint _uniform_scene_water_uMdl;
static GLuint _uniform_scene_water_uPv;
static GLuint _uniform_scene_water_uPvmPrev;
+static GLuint _uniform_scene_water_uLightsArray;
static GLuint _uniform_scene_water_uTexMain;
static GLuint _uniform_scene_water_uTexDudv;
static GLuint _uniform_scene_water_uTexBack;
_uniform_scene_water_uMdl = glGetUniformLocation( _shader_scene_water.id, "uMdl" );
_uniform_scene_water_uPv = glGetUniformLocation( _shader_scene_water.id, "uPv" );
_uniform_scene_water_uPvmPrev = glGetUniformLocation( _shader_scene_water.id, "uPvmPrev" );
+ _uniform_scene_water_uLightsArray = glGetUniformLocation( _shader_scene_water.id, "uLightsArray" );
_uniform_scene_water_uTexMain = glGetUniformLocation( _shader_scene_water.id, "uTexMain" );
_uniform_scene_water_uTexDudv = glGetUniformLocation( _shader_scene_water.id, "uTexDudv" );
_uniform_scene_water_uTexBack = glGetUniformLocation( _shader_scene_water.id, "uTexBack" );
uniform vec3 uShoreColour;
uniform vec3 uOceanColour;
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
#include "common_scene.glsl"
#include "motion_vectors_fs.glsl"
"uniform mat4x3 uMdl;\n"
"uniform mat4 uPv;\n"
"uniform mat4 uPvmPrev;\n"
+"uniform samplerBuffer uLightsArray;\n"
"\n"
"out vec2 aUv;\n"
"out vec4 aNorm;\n"
"out vec3 aCo;\n"
"out vec3 aWorldCo;\n"
-"flat out ivec4 aLights;\n"
+"flat out vec4 light_colours[3];\n"
+"flat out vec4 light_positions[3];\n"
"\n"
"void main()\n"
"{\n"
" aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
" aCo = a_co;\n"
" aWorldCo = world_pos0;\n"
-" aLights = a_lights;\n"
+"\n"
+" // read lights\n"
+" light_colours[0] = texelFetch( uLightsArray, a_lights.x*2+0 );\n"
+" light_colours[1] = texelFetch( uLightsArray, a_lights.y*2+0 );\n"
+" light_colours[2] = texelFetch( uLightsArray, a_lights.z*2+0 );\n"
+" light_positions[0] = texelFetch( uLightsArray, a_lights.x*2+1 );\n"
+" light_positions[1] = texelFetch( uLightsArray, a_lights.y*2+1 );\n"
+" light_positions[2] = texelFetch( uLightsArray, a_lights.z*2+1 );\n"
"}\n"
""},
.fs =
"uniform vec3 uShoreColour;\n"
"uniform vec3 uOceanColour;\n"
"\n"
+"#line 1 1 \n"
+"// :D\n"
+"\n"
"in vec2 aUv;\n"
"in vec4 aNorm;\n"
"in vec3 aCo;\n"
"in vec3 aWorldCo;\n"
-"flat in ivec4 aLights;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
+"flat in vec4 light_colours[3];\n"
+"flat in vec4 light_positions[3];\n"
"\n"
"#line 1 1 \n"
"layout (location = 0) out vec4 oColour;\n"
" int g_light_preview;\n"
" int g_shadow_samples;\n"
"\n"
-" vec4 g_point_light_positions[32];\n"
-" vec4 g_point_light_colours[32];\n"
+" // g_time ?\n"
+"\n"
+" //vec4 g_point_light_positions[32];\n"
+" //vec4 g_point_light_colours[32];\n"
"};\n"
"\n"
"uniform sampler2D g_world_depth;\n"
" return clamp( fdelta, 0.1, 0.2 )-0.1;\n"
"}\n"
"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
"vec3 apply_fog( vec3 vfrag, float fdist )\n"
"{\n"
" float dist = pow(fdist*0.0008,1.2);\n"
" famt+=shadow_sample((vdir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
" famt+=shadow_sample((vdir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
"\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - max( player_shadow*0.8, famt );\n"
+" return 1.0 - famt;\n"
"}\n"
"\n"
"vec3 newlight_compute_world_diffuse( vec3 wnormal )\n"
" return light_colour*attenuation;\n"
"}\n"
"\n"
-"#line 4 0 \n"
+"#line 11 0 \n"
+"\n"
+"float sdLine( vec3 p, vec3 a, vec3 b )\n"
+"{\n"
+" vec3 pa = p - a;\n"
+" vec3 ba = b - a;\n"
+"\n"
+" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
+" return length( pa - ba*h );\n"
+"}\n"
+"\n"
+"float compute_board_shadow()\n"
+"{\n"
+" // player shadow\n"
+" float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
+" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
+" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
+"\n"
+" return 1.0 - player_shadow*0.8;\n"
+"}\n"
"\n"
"vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n"
"{\n"
" world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n"
"\n"
" float world_shadow = newlight_compute_sun_shadow();\n"
+" float board_shadow = compute_board_shadow();\n"
"\n"
-" total_light += world_light * world_shadow;\n"
+" total_light += world_light * min( board_shadow, world_shadow );\n"
"\n"
" // Compute the other lights that exist in the map, not effected by the sun\n"
" // shadow\n"
+"\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.x ].xyz,\n"
-" g_point_light_colours[ aLights.x ].rgb \n"
-" );\n"
+" light_positions[0].xyz,\n"
+" light_colours[0].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.y ].xyz,\n"
-" g_point_light_colours[ aLights.y ].rgb \n"
-" );\n"
+" light_positions[1].xyz,\n"
+" light_colours[1].rgb \n"
+" ) * board_shadow;\n"
" total_light += newlight_compute_quadratic\n"
" ( \n"
" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.z ].xyz,\n"
-" g_point_light_colours[ aLights.z ].rgb \n"
-" );\n"
+" light_positions[2].xyz,\n"
+" light_colours[2].rgb \n"
+" ) * board_shadow;\n"
"\n"
" return apply_fog( diffuse * total_light, fdist );\n"
"}\n"
"\n"
-"#line 19 0 \n"
+"#line 13 0 \n"
"#line 1 2 \n"
"const float k_motion_lerp_amount = 0.01;\n"
"\n"
" oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
"}\n"
"\n"
-"#line 20 0 \n"
+"#line 14 0 \n"
"\n"
"vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue )\n"
"{\n"
static GLuint _uniform_scene_water_fast_uMdl;
static GLuint _uniform_scene_water_fast_uPv;
static GLuint _uniform_scene_water_fast_uPvmPrev;
+static GLuint _uniform_scene_water_fast_uLightsArray;
static GLuint _uniform_scene_water_fast_uTexDudv;
static GLuint _uniform_scene_water_fast_uTime;
static GLuint _uniform_scene_water_fast_uCamera;
_uniform_scene_water_fast_uMdl = glGetUniformLocation( _shader_scene_water_fast.id, "uMdl" );
_uniform_scene_water_fast_uPv = glGetUniformLocation( _shader_scene_water_fast.id, "uPv" );
_uniform_scene_water_fast_uPvmPrev = glGetUniformLocation( _shader_scene_water_fast.id, "uPvmPrev" );
+ _uniform_scene_water_fast_uLightsArray = glGetUniformLocation( _shader_scene_water_fast.id, "uLightsArray" );
_uniform_scene_water_fast_uTexDudv = glGetUniformLocation( _shader_scene_water_fast.id, "uTexDudv" );
_uniform_scene_water_fast_uTime = glGetUniformLocation( _shader_scene_water_fast.id, "uTime" );
_uniform_scene_water_fast_uCamera = glGetUniformLocation( _shader_scene_water_fast.id, "uCamera" );
int g_light_preview;
int g_shadow_samples;
+#if 0
v4f g_point_light_positions[32];
v4f g_point_light_colours[32];
+#endif
}
ub_lighting;
GLuint ubo_lighting;
int ubo_bind_point;
+ GLuint tbo_light_entities,
+ tex_light_entities;
+
struct framebuffer heightmap;
/*
}
}
- world.sky_time += world.sky_rate * vg.time_delta;
- world.sky_rate = vg_lerp( world.sky_rate, world.sky_target_rate,
- vg.time_delta * 5.0 );
#endif
+ world_global.sky_time += world_global.sky_rate * vg.time_delta;
+ world_global.sky_rate = vg_lerp( world_global.sky_rate,
+ world_global.sky_target_rate,
+ vg.time_delta * 5.0 );
world_routes_update( world );
#if 0
0xff00ff00 );
}
- for( int i=0; i<world->light_count; i++ )
+ if( 0 )
{
- struct world_light *light = &world->lights[i];
+ for( int i=0; i<world->light_count; i++ )
+ {
+ struct world_light *light = &world->lights[i];
- u32 colour = 0xff000000;
- u8 r = light->colour[0] * 255.0f,
- g = light->colour[1] * 255.0f,
- b = light->colour[2] * 255.0f;
+ u32 colour = 0xff000000;
+ u8 r = light->colour[0] * 255.0f,
+ g = light->colour[1] * 255.0f,
+ b = light->colour[2] * 255.0f;
- colour |= r;
- colour |= g << 8;
- colour |= b << 16;
+ colour |= r;
+ colour |= g << 8;
+ colour |= b << 16;
- vg_line_pt3( light->co, 0.25f, colour );
+ vg_line_pt3( light->co, 0.25f, colour );
+ }
}
world_global.in_trigger = in_trigger;
vg_acquire_thread_sync();
{
+ /* create scene lighting buffer */
+ glGenBuffers( 1, &world->tbo_light_entities );
+ glBindBuffer( GL_TEXTURE_BUFFER, world->tbo_light_entities );
+ glBufferData( GL_TEXTURE_BUFFER, world->light_count*sizeof(float)*8,
+ NULL, GL_DYNAMIC_DRAW );
+
+ v4f *light_dst = glMapBuffer( GL_TEXTURE_BUFFER, GL_WRITE_ONLY );
+
+ for( int i=0; i<world->light_count; i++ )
+ {
+ struct world_light *light = &world->lights[i];
+
+ v3_muls( light->colour, light->colour[3] * 2.0f, light_dst[i*2+0] );
+ v3_copy( light->co, light_dst[i*2+1] );
+ }
+
+ glUnmapBuffer( GL_TEXTURE_BUFFER );
+
+ glGenTextures( 1, &world->tex_light_entities );
+ glBindTexture( GL_TEXTURE_BUFFER, world->tex_light_entities );
+ glTexBuffer( GL_TEXTURE_BUFFER, GL_RGBA32F, world->tbo_light_entities );
+
+
/* Upload lighting uniform buffer */
if( world->water.enabled )
v4_copy( world->water.plane, world->ub_lighting.g_water_plane );
info_vec[3] = 1.0f/ (bounds[1][2]-bounds[0][2]);
v4_copy( info_vec, world->ub_lighting.g_depth_bounds );
- /* add scene lights */
- for( int i=0; i<world->light_count; i++ )
- {
- struct world_light *light = &world->lights[i];
-
- v3_muls( light->colour, light->colour[3] * 2.0f,
- world->ub_lighting.g_point_light_colours[i] );
- v3_copy( light->co,
- world->ub_lighting.g_point_light_positions[i] );
- }
-
/* upload full buffer */
glBindBuffer( GL_UNIFORM_BUFFER, world->ubo_lighting );
glBufferSubData( GL_UNIFORM_BUFFER, 0,
vg_release_thread_sync();
}
-VG_STATIC void world_link_lighting_ub( world_instance *world,
- GLuint shader, int texture_id )
+VG_STATIC void world_link_lighting_ub( world_instance *world, GLuint shader )
{
GLuint idx = glGetUniformBlockIndex( shader, "ub_world_lighting" );
glUniformBlockBinding( shader, idx, world->ubo_bind_point );
+}
+
+VG_STATIC void world_bind_position_texture( world_instance *world,
+ GLuint shader, GLuint location,
+ int slot )
+{
+ render_fb_bind_texture( &world->heightmap, 0, slot );
+ glUniform1i( location, slot );
+}
- render_fb_bind_texture( &world->heightmap, 0, texture_id );
- glUniform1i( glGetUniformLocation( shader, "g_world_depth" ), texture_id );
+VG_STATIC void world_bind_light_array( world_instance *world,
+ GLuint shader, GLuint location,
+ int slot )
+{
+ glActiveTexture( GL_TEXTURE0 + slot );
+ glBindTexture( GL_TEXTURE_BUFFER, world->tex_light_entities );
+ glUniform1i( location, slot );
}
VG_STATIC void render_world_depth( world_instance *world, camera *cam );
shader_scene_vertex_blend_use();
shader_scene_vertex_blend_uTexGarbage(0);
shader_scene_vertex_blend_uTexGradients(1);
- world_link_lighting_ub( world, _shader_scene_vertex_blend.id, 2 );
+ world_link_lighting_ub( world, _shader_scene_vertex_blend.id );
+ world_bind_position_texture( world, _shader_scene_vertex_blend.id,
+ _uniform_scene_vertex_blend_g_world_depth, 2 );
+ world_bind_light_array( world, _shader_scene_vertex_blend.id,
+ _uniform_scene_vertex_blend_uLightsArray, 3 );
+
vg_tex2d_bind( &tex_terrain_noise, 0 );
shader_scene_vertex_blend_uPv( cam->mtx.pv );
shader_scene_standard_uTexMain(1);
shader_scene_standard_uPv( cam->mtx.pv );
shader_scene_standard_uPvmPrev( cam->mtx_prev.pv );
- world_link_lighting_ub( world, _shader_scene_standard.id, 2 );
+
+ world_link_lighting_ub( world, _shader_scene_standard.id );
+ world_bind_position_texture( world, _shader_scene_standard.id,
+ _uniform_scene_standard_g_world_depth, 2 );
+ world_bind_light_array( world, _shader_scene_standard.id,
+ _uniform_scene_standard_uLightsArray, 3 );
+
bind_terrain_noise();
shader_scene_standard_uMdl( identity_matrix );
shader_scene_standard_alphatest_uTexMain(1);
shader_scene_standard_alphatest_uPv( cam->mtx.pv );
shader_scene_standard_alphatest_uPvmPrev( cam->mtx_prev.pv );
- world_link_lighting_ub( world, _shader_scene_standard_alphatest.id, 2 );
+
+ world_link_lighting_ub( world, _shader_scene_standard_alphatest.id );
+ world_bind_position_texture( world, _shader_scene_standard_alphatest.id,
+ _uniform_scene_standard_alphatest_g_world_depth, 2 );
+ world_bind_light_array( world, _shader_scene_standard_alphatest.id,
+ _uniform_scene_standard_alphatest_uLightsArray, 3 );
+
+
bind_terrain_noise();
shader_scene_standard_alphatest_uMdl( identity_matrix );
shader_scene_terrain_use();
shader_scene_terrain_uTexGarbage(0);
shader_scene_terrain_uTexGradients(1);
- world_link_lighting_ub( world, _shader_scene_terrain.id, 2 );
+
+ world_link_lighting_ub( world, _shader_scene_terrain.id );
+ world_bind_position_texture( world, _shader_scene_terrain.id,
+ _uniform_scene_terrain_g_world_depth, 2 );
+ world_bind_light_array( world, _shader_scene_terrain.id,
+ _uniform_scene_terrain_uLightsArray, 3 );
vg_tex2d_bind( &tex_terrain_noise, 0 );
shader_scene_depth_uPv( cam->mtx.pv );
shader_scene_depth_uPvmPrev( cam->mtx_prev.pv );
shader_scene_depth_uMdl( identity_matrix );
- world_link_lighting_ub( world, _shader_scene_depth.id, 2 );
+ world_link_lighting_ub( world, _shader_scene_depth.id );
mesh_bind( &world->mesh_geo );
mesh_draw( &world->mesh_geo );
shader_scene_position_uPv( cam->mtx.pv );
shader_scene_position_uPvmPrev( cam->mtx_prev.pv );
shader_scene_position_uMdl( identity_matrix );
- world_link_lighting_ub( world, _shader_scene_position.id, 2 );
+ world_link_lighting_ub( world, _shader_scene_position.id );
mesh_bind( &world->mesh_geo );
mesh_draw( &world->mesh_geo );
}
VG_STATIC void bind_terrain_noise(void);
+VG_STATIC void world_bind_light_array( world_instance *world,
+ GLuint shader, GLuint location,
+ int slot );
+
VG_STATIC void render_world_routes( world_instance *world, camera *cam )
{
m4x3f identity_matrix;
shader_scene_route_use();
shader_scene_route_uTexGarbage(0);
- world_link_lighting_ub( world, _shader_scene_route.id, 2 );
+ world_link_lighting_ub( world, _shader_scene_route.id );
+ world_bind_position_texture( world, _shader_scene_route.id,
+ _uniform_scene_route_g_world_depth, 2 );
+ world_bind_light_array( world, _shader_scene_route.id,
+ _uniform_scene_route_uLightsArray, 3 );
bind_terrain_noise();
shader_scene_route_uPv( cam->mtx.pv );
v4_copy( (v4f){ 0.0f, 1.0f, 0.0f, height }, world->water.plane );
}
-VG_STATIC void world_link_lighting_ub( world_instance *world,
- GLuint shader, int texture_id );
+VG_STATIC void world_link_lighting_ub( world_instance *world, GLuint shader );
+VG_STATIC void world_bind_position_texture( world_instance *world,
+ GLuint shader, GLuint location,
+ int slot );
/*
* Does not write motion vectors
1.0f / (float)vg.window_x,
1.0f / (float)vg.window_y });
- world_link_lighting_ub( world, _shader_scene_water.id, 2 );
+ world_link_lighting_ub( world, _shader_scene_water.id );
+ world_bind_position_texture( world, _shader_scene_water.id,
+ _uniform_scene_water_g_world_depth, 2 );
render_fb_bind_texture( gpipeline.fb_water_beneath, 0, 3 );
shader_scene_water_uTexBack( 3 );
shader_scene_water_fast_uTime( world_global.time );
shader_scene_water_fast_uCamera( cam->transform[3] );
shader_scene_water_fast_uSurfaceY( world->water.height );
- world_link_lighting_ub( world, _shader_scene_water_fast.id, 2 );
+ world_link_lighting_ub( world, _shader_scene_water_fast.id );
+ world_bind_position_texture( world, _shader_scene_water_fast.id,
+ _uniform_scene_water_fast_g_world_depth, 2 );
m4x3f full;
m4x3_identity( full );