chaos pt 1
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / scene_terrain.h
index 00e9399683f21884280e053f30e80cd6f3426603..6d40ebda27d763c2106182d787f2ca363f13e1b8 100644 (file)
@@ -67,8 +67,6 @@ static struct vg_shader _shader_scene_terrain = {
 "uniform vec3 uCamera;\n"
 "uniform vec3 uSandColour;\n"
 "uniform vec2 uBlendOffset;\n"
-"uniform vec3 uBoard0;\n"
-"uniform vec3 uBoard1;\n"
 "\n"
 "#line       1        1 \n"
 "// :D\n"
@@ -97,6 +95,8 @@ static struct vg_shader _shader_scene_terrain = {
 "   vec4 g_sunset_ambient;\n"
 "   vec4 g_sun_colour;\n"
 "   vec4 g_sun_dir;\n"
+"   vec4 g_board_0;\n"
+"   vec4 g_board_1;\n"
 "\n"
 "   float g_water_fog;\n"
 "   float g_time;\n"
@@ -197,7 +197,7 @@ static struct vg_shader _shader_scene_terrain = {
 "   return ambient + (light_sun + sky_reflection) * shadow;\n"
 "}\n"
 "\n"
-"#line     42        0 \n"
+"#line     44        0 \n"
 "\n"
 "float world_depth_sample( vec3 pos )\n"
 "{\n"
@@ -211,19 +211,15 @@ static struct vg_shader _shader_scene_terrain = {
 "   return world_depth_sample( pos ) - 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"
+"float shadow_sample( vec3 co ){\n"
+"   float height_sample = world_depth_sample( co );\n"
 "\n"
-"   float fdelta = height_sample - sample_pos.y;\n"
+"   float fdelta = height_sample - co.y;\n"
 "   return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
 "}\n"
 "\n"
-"float newlight_compute_sun_shadow( vec3 dir )\n"
-"{\n"
-"   if( g_shadow_samples == 0 )\n"
-"   {\n"
+"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
+"   if( g_shadow_samples == 0 ){\n"
 "      return 1.0;\n"
 "   }\n"
 "\n"
@@ -231,15 +227,15 @@ static struct vg_shader _shader_scene_terrain = {
 "   float flength = g_shadow_length;\n"
 "\n"
 "   float famt = 0.0;\n"
-"   famt += shadow_sample((dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-"   famt += shadow_sample((dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-"   famt += shadow_sample((dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-"   famt += shadow_sample((dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
+"   famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
+"   famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
+"   famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
+"   famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
 "\n"
-"   //famt+=shadow_sample((dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-"   //famt+=shadow_sample((dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-"   //famt+=shadow_sample((dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-"   //famt+=shadow_sample((dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
+"   //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
+"   //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
+"   //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
+"   //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
 "\n"
 "   return 1.0 - famt;\n"
 "}\n"
@@ -276,7 +272,7 @@ static struct vg_shader _shader_scene_terrain = {
 "   light_delta = normalize( light_delta );\n"
 "\n"
 "   float quadratic = dist2*100.0;\n"
-"   float attenuation  = 1.0f/( 1.0f + quadratic );\n"
+"   float attenuation  = 1.0/( 1.0 + quadratic );\n"
 "         attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
 "\n"
 "   float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
@@ -327,8 +323,8 @@ static struct vg_shader _shader_scene_terrain = {
 "   float fdist = length(halfview);\n"
 "   halfview /= fdist;\n"
 "\n"
-"   float world_shadow = newlight_compute_sun_shadow( g_sun_dir.xyz \n"
-"                                    * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
+"   float world_shadow = newlight_compute_sun_shadow( \n"
+"               co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
 "\n"
 "   vec3 total_light = clearskies_lighting( \n"
 "                           normal, min( light_mask, world_shadow ), halfview );\n"
@@ -392,7 +388,8 @@ static struct vg_shader _shader_scene_terrain = {
 "float compute_board_shadow()\n"
 "{\n"
 "   // player shadow\n"
-"   float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
+"   float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
+"                                                      g_board_1.xyz )-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"
@@ -404,7 +401,7 @@ static struct vg_shader _shader_scene_terrain = {
 "   return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
 "}\n"
 "\n"
-"#line     10        0 \n"
+"#line      8        0 \n"
 "#line       1        2 \n"
 "const float k_motion_lerp_amount = 0.01;\n"
 "\n"
@@ -424,7 +421,7 @@ static struct vg_shader _shader_scene_terrain = {
 "   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
 "}\n"
 "\n"
-"#line     11        0 \n"
+"#line      9        0 \n"
 "\n"
 "void main()\n"
 "{\n"
@@ -477,8 +474,6 @@ static GLuint _uniform_scene_terrain_uTexGradients;
 static GLuint _uniform_scene_terrain_uCamera;
 static GLuint _uniform_scene_terrain_uSandColour;
 static GLuint _uniform_scene_terrain_uBlendOffset;
-static GLuint _uniform_scene_terrain_uBoard0;
-static GLuint _uniform_scene_terrain_uBoard1;
 static GLuint _uniform_scene_terrain_g_world_depth;
 static GLuint _uniform_scene_terrain_uLightsArray;
 static GLuint _uniform_scene_terrain_uLightsIndex;
@@ -506,12 +501,6 @@ static void shader_scene_terrain_uSandColour(v3f v){
 static void shader_scene_terrain_uBlendOffset(v2f v){
    glUniform2fv(_uniform_scene_terrain_uBlendOffset,1,v);
 }
-static void shader_scene_terrain_uBoard0(v3f v){
-   glUniform3fv(_uniform_scene_terrain_uBoard0,1,v);
-}
-static void shader_scene_terrain_uBoard1(v3f v){
-   glUniform3fv(_uniform_scene_terrain_uBoard1,1,v);
-}
 static void shader_scene_terrain_g_world_depth(int i){
    glUniform1i(_uniform_scene_terrain_g_world_depth,i);
 }
@@ -528,8 +517,6 @@ static void shader_scene_terrain_link(void){
    _uniform_scene_terrain_uCamera = glGetUniformLocation( _shader_scene_terrain.id, "uCamera" );
    _uniform_scene_terrain_uSandColour = glGetUniformLocation( _shader_scene_terrain.id, "uSandColour" );
    _uniform_scene_terrain_uBlendOffset = glGetUniformLocation( _shader_scene_terrain.id, "uBlendOffset" );
-   _uniform_scene_terrain_uBoard0 = glGetUniformLocation( _shader_scene_terrain.id, "uBoard0" );
-   _uniform_scene_terrain_uBoard1 = glGetUniformLocation( _shader_scene_terrain.id, "uBoard1" );
    _uniform_scene_terrain_g_world_depth = glGetUniformLocation( _shader_scene_terrain.id, "g_world_depth" );
    _uniform_scene_terrain_uLightsArray = glGetUniformLocation( _shader_scene_terrain.id, "uLightsArray" );
    _uniform_scene_terrain_uLightsIndex = glGetUniformLocation( _shader_scene_terrain.id, "uLightsIndex" );