grid based
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / model_character_view.h
index 18d5c19062ec5d9afc1b92e55b68d3d1e19ec2e3..b5073c19796ab789dd4cd5c929e1b91658b31683 100644 (file)
@@ -7,6 +7,7 @@ static struct vg_shader _shader_model_character_view = {
    .link = shader_model_character_view_link,
    .vs = 
 {
+.orig_file = "shaders/model_skinned.vs",
 .static_src = 
 "layout (location=0) in vec3 a_co;\n"
 "layout (location=1) in vec3 a_norm;\n"
@@ -71,6 +72,7 @@ static struct vg_shader _shader_model_character_view = {
 ""},
    .fs = 
 {
+.orig_file = "shaders/model_character_view.fs",
 .static_src = 
 "uniform sampler2D uTexMain;\n"
 "uniform vec3 uCamera;\n"
@@ -86,6 +88,9 @@ static struct vg_shader _shader_model_character_view = {
 "\n"
 "layout (std140) uniform ub_world_lighting\n"
 "{\n"
+"   vec4 g_cube_min;\n"
+"   vec4 g_cube_inv_range;\n"
+"\n"
 "   vec4 g_light_colours[3];\n"
 "   vec4 g_light_directions[3];\n"
 "   vec4 g_ambient_colour;\n"
@@ -93,10 +98,14 @@ static struct vg_shader _shader_model_character_view = {
 "   vec4 g_water_plane;\n"
 "   vec4 g_depth_bounds;\n"
 "   float g_water_fog;\n"
+"   float g_time;\n"
 "   int g_light_count;\n"
 "   int g_light_preview;\n"
 "   int g_shadow_samples;\n"
 "\n"
+"   int g_debug_indices;\n"
+"   int g_debug_complexity;\n"
+"\n"
 "   // g_time ?\n"
 "\n"
 "   //vec4 g_point_light_positions[32];\n"
@@ -141,7 +150,7 @@ static struct vg_shader _shader_model_character_view = {
 "   return g_ambient_colour.rgb;\n"
 "}\n"
 "\n"
-"float newlight_compute_sun_shadow()\n"
+"float newlight_compute_sun_shadow( vec3 dir )\n"
 "{\n"
 "   if( g_shadow_samples == 0 )\n"
 "   {\n"
@@ -149,7 +158,7 @@ static struct vg_shader _shader_model_character_view = {
 "   }\n"
 "\n"
 "   float fspread = g_light_colours[0].w;\n"
-"   vec3  vdir = g_light_directions[0].xyz;\n"
+"   vec3  vdir = dir;\n"
 "   float flength = g_light_directions[0].w;\n"
 "\n"
 "   float famt = 0.0;\n"
@@ -191,16 +200,43 @@ static struct vg_shader _shader_model_character_view = {
 "   return vcolour*spec*fintensity;\n"
 "}\n"
 "\n"
-"vec3 newlight_compute_quadratic( vec3 wnormal, vec3 halfview, \n"
-"                                 vec3 light_pos, vec3 light_colour )\n"
+"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
+"{\n"
+"   vec3 specdir = reflect( -dir, wnormal );\n"
+"   return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
+"}\n"
+"\n"
+"vec3 newlight_compute_quadratic( vec3 wnormal, float max_dist,\n"
+"                                 vec3 light_colour, vec3 light_pos )\n"
+"{\n"
+"   vec3 light_delta = light_pos-aWorldCo;\n"
+"\n"
+"   float dist2 = dot(light_delta,light_delta);\n"
+"\n"
+"   float quadratic = dist2*100.0;\n"
+"   float attenuation  = 1.0f/( 1.0f + quadratic );\n"
+"         attenuation *= max( dot( normalize(light_delta), wnormal ), 0.0 );\n"
+"\n"
+"   float falloff = max( 0.0, 1.0-(dist2*max_dist) );\n"
+"   return light_colour * attenuation * falloff;\n"
+"}\n"
+"\n"
+"vec3 newlight_compute_spot( vec3 wnormal, vec3 halfview, \n"
+"                            vec3 light_colour, vec3 light_pos,\n"
+"                            vec4 light_dir )\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"
+"   light_delta = normalize( light_delta );\n"
+"   attenuation *= max( 0.0, dot( light_delta, wnormal ) );\n"
+"\n"
+"   float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) ),\n"
+"            falloff = max( 0.0,( spot_theta - light_dir.w ) / (1.0-light_dir.w) );\n"
+"\n"
+"   return light_colour*attenuation*falloff;\n"
 "}\n"
 "\n"
 "#line     11        0 \n"
@@ -242,7 +278,7 @@ static struct vg_shader _shader_model_character_view = {
 "   vec3 total_light = newlight_compute_ambient();\n"
 "   vec3 world_light = newlight_compute_world_diffuse( qnorm );\n"
 "\n"
-"   float world_shadow = newlight_compute_sun_shadow();\n"
+"   float world_shadow = newlight_compute_sun_shadow( vec3(1.0) );\n"
 "   total_light += world_light * world_shadow;\n"
 "\n"
 "   vfrag = apply_fog( vfrag * total_light, fdist );\n"