X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fviewchar.h;h=0cd026d9481827fa6f52584323a2994bbd975781;hb=4bb5686fffc24abdc4a722051ca066378cb8d419;hp=23cb8b77f86553206114a850527cd5bd83a17aaf;hpb=3d5597be2fd4b5d9ea3bf8863e15cc9bc8123755;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/viewchar.h b/shaders/viewchar.h index 23cb8b7..0cd026d 100644 --- a/shaders/viewchar.h +++ b/shaders/viewchar.h @@ -39,7 +39,7 @@ static struct vg_shader _shader_viewchar = { "\n" " vec3 world_pos = co0*a_weights[0] + co1*a_weights[1] + co2*a_weights[2];\n" " vec3 world_normal = n0*a_weights[0] + n1*a_weights[1] + n2*a_weights[2];\n" -"\n" +" \n" " gl_Position = uPv * vec4( world_pos, 1.0 );\n" " aColour = a_colour;\n" " aUv = a_uv;\n" @@ -55,6 +55,7 @@ static struct vg_shader _shader_viewchar = { "out vec4 FragColor;\n" "\n" "uniform sampler2D uTexMain;\n" +"uniform vec3 uCamera;\n" "\n" "in vec4 aColour;\n" "in vec2 aUv;\n" @@ -74,6 +75,7 @@ static struct vg_shader _shader_viewchar = { " float g_water_fog;\n" " int g_light_count;\n" " int g_light_preview;\n" +" int g_shadow_samples;\n" "};\n" "\n" "uniform sampler2D g_world_depth;\n" @@ -138,6 +140,11 @@ static struct vg_shader _shader_viewchar = { "\n" "vec3 do_light_shadowing( vec3 vfrag )\n" "{\n" +" if( g_shadow_samples == 0 )\n" +" {\n" +" return vfrag;\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" @@ -160,23 +167,26 @@ static struct vg_shader _shader_viewchar = { " return mix( vfrag, vec3(0.55,0.76,1.0), min( 1.0, dist ) );\n" "}\n" "\n" -"#line 12 0 \n" +"#line 13 0 \n" "\n" "void main()\n" "{\n" " vec3 vfrag = texture( uTexMain, aUv ).rgb;\n" "\n" " // Lighting\n" -" //vec3 halfview = uCamera - aWorldCo;\n" -" //float fdist = length( halfview );\n" -" //halfview /= fdist;\n" +" vec3 halfview = uCamera - aWorldCo;\n" +" float fdist = length( halfview );\n" +" halfview /= fdist;\n" +"\n" +" vec3 qnorm = normalize(floor(aNorm*2.0)*0.5) + vec3(0.001,0.0,0.0);\n" "\n" -" //vfrag = do_light_diffuse( vfrag, aNorm );\n" -" //vfrag = do_light_spec( vfrag, aNorm, halfview, 0.1 );\n" -" //vfrag = do_light_shadowing( vfrag );\n" -" //vfrag = apply_fog( vfrag, fdist );\n" +" vfrag = mix( vfrag, do_light_diffuse( vfrag, qnorm ), 0.5 );\n" +" //vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );\n" +" vfrag = do_light_shadowing( vfrag );\n" +" vfrag = apply_fog( vfrag, fdist );\n" "\n" -" FragColor = vec4(vfrag,1.0);\n" +" float opacity = clamp( fdist, 0.1, 1.0 );\n" +" FragColor = vec4(vfrag,opacity);\n" "}\n" ""}, }; @@ -184,6 +194,7 @@ static struct vg_shader _shader_viewchar = { static GLuint _uniform_viewchar_uPv; static GLuint _uniform_viewchar_uTransforms; static GLuint _uniform_viewchar_uTexMain; +static GLuint _uniform_viewchar_uCamera; static GLuint _uniform_viewchar_g_world_depth; static void shader_viewchar_uPv(m4x4f m){ glUniformMatrix4fv( _uniform_viewchar_uPv, 1, GL_FALSE, (float *)m ); @@ -191,6 +202,9 @@ static void shader_viewchar_uPv(m4x4f m){ static void shader_viewchar_uTexMain(int i){ glUniform1i( _uniform_viewchar_uTexMain, i ); } +static void shader_viewchar_uCamera(v3f v){ + glUniform3fv( _uniform_viewchar_uCamera, 1, v ); +} static void shader_viewchar_g_world_depth(int i){ glUniform1i( _uniform_viewchar_g_world_depth, i ); } @@ -202,6 +216,7 @@ static void shader_viewchar_link(void){ _uniform_viewchar_uPv = glGetUniformLocation( _shader_viewchar.id, "uPv" ); _uniform_viewchar_uTransforms = glGetUniformLocation( _shader_viewchar.id, "uTransforms" ); _uniform_viewchar_uTexMain = glGetUniformLocation( _shader_viewchar.id, "uTexMain" ); + _uniform_viewchar_uCamera = glGetUniformLocation( _shader_viewchar.id, "uCamera" ); _uniform_viewchar_g_world_depth = glGetUniformLocation( _shader_viewchar.id, "g_world_depth" ); } #endif /* SHADER_viewchar_H */