X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fviewchar.h;h=551804a44be99347a4b4df781e7401088338f07a;hb=3ee65e6e24bfc39db7c7dd8c1f4cec3d5c42d0f8;hp=23cb8b77f86553206114a850527cd5bd83a17aaf;hpb=6a4dafa6fe9a3dd4bb88698bbe964154364390ec;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/viewchar.h b/shaders/viewchar.h index 23cb8b7..551804a 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" @@ -160,23 +161,25 @@ 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" +" 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" "\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" +" float opacity = clamp( fdist, 0.1, 1.0 );\n" "\n" -" FragColor = vec4(vfrag,1.0);\n" +" FragColor = vec4(vfrag,opacity);\n" "}\n" ""}, }; @@ -184,6 +187,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 +195,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 +209,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 */