grid based
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / model_character_view.h
index d1c8efd4e590bade1a3c2cb1f112747b246d6e18..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,11 +72,10 @@ 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"
-"uniform vec3 uBoard0;\n"
-"uniform vec3 uBoard1;\n"
 "\n"
 "in vec4 aColour;\n"
 "in vec2 aUv;\n"
@@ -88,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"
@@ -95,12 +98,18 @@ 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"
-"   vec4 g_point_light_positions[32];\n"
-"   vec4 g_point_light_colours[32];\n"
+"   int g_debug_indices;\n"
+"   int g_debug_complexity;\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"
@@ -111,6 +120,13 @@ static struct vg_shader _shader_model_character_view = {
 "   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"
@@ -120,15 +136,6 @@ static struct vg_shader _shader_model_character_view = {
 "   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"
@@ -143,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"
@@ -151,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"
@@ -164,12 +171,7 @@ static struct vg_shader _shader_model_character_view = {
 "   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"
@@ -198,19 +200,46 @@ 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     13        0 \n"
+"#line     11        0 \n"
 "#line       1        2 \n"
 "const float k_motion_lerp_amount = 0.01;\n"
 "\n"
@@ -230,7 +259,7 @@ static struct vg_shader _shader_model_character_view = {
 "   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"
@@ -249,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"
@@ -264,8 +293,6 @@ static GLuint _uniform_model_character_view_uPv;
 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);
@@ -276,12 +303,6 @@ static void shader_model_character_view_uTexMain(int i){
 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);
 }
@@ -294,8 +315,6 @@ static void shader_model_character_view_link(void){
    _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 */