X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fscene_position.h;h=895b03bd97e6a4f914244691e2118898667a8f72;hb=409edea2cf6271956137918e4e0b4f1c2addf620;hp=a748f487e5a82d94fc46b5b76e0af0046895759a;hpb=f3a2490079baf440238b78e54f4476649eddbda2;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/scene_position.h b/shaders/scene_position.h index a748f48..895b03b 100644 --- a/shaders/scene_position.h +++ b/shaders/scene_position.h @@ -36,12 +36,14 @@ static struct vg_shader _shader_scene_position = { "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" @@ -57,7 +59,14 @@ static struct vg_shader _shader_scene_position = { " 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 = @@ -69,14 +78,15 @@ static struct vg_shader _shader_scene_position = { "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" @@ -94,8 +104,10 @@ static struct vg_shader _shader_scene_position = { " 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" @@ -122,15 +134,6 @@ static struct vg_shader _shader_scene_position = { " 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" @@ -166,12 +169,7 @@ static struct vg_shader _shader_scene_position = { " 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" @@ -212,7 +210,26 @@ static struct vg_shader _shader_scene_position = { " 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" @@ -230,34 +247,36 @@ static struct vg_shader _shader_scene_position = { " 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" @@ -275,6 +294,7 @@ static struct vg_shader _shader_scene_position = { 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; @@ -308,6 +328,7 @@ static void shader_scene_position_link(void){ _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" );