class classtype_route(Structure):
_pack_ = 1
_fields_ = [("pstr_name",c_uint32),
- ("id_start",c_uint32)]
+ ("id_start",c_uint32),
+ ("colour",c_float*3)]
# Exporter
# ==============================================================================
entdata_length += sizeof( classtype_route )
r = classtype_route()
r.pstr_name = emplace_string("not-implemented")
+ r.colour[0] = obj.cv_data.colour[0]
+ r.colour[1] = obj.cv_data.colour[1]
+ r.colour[2] = obj.cv_data.colour[2]
+
if obj.cv_data.target != None:
- r.target = obj.cv_data.target.cv_data.uid
+ r.id_start = obj.cv_data.target.cv_data.uid
entdata_buffer += [r]
def drawbpath(o0,o1,c0,c1):
drawsbpath(o0,o1,c0,c1,1.0,1.0)
- def drawbline(o0,o1,c0,c1):
+ def drawbline(p0,p1,c0,c1):
nonlocal verts, colours
- verts += [o0.location]
- verts += [o1.location]
+ verts += [p0,p1]
colours += [c0,c1]
-
- for obj in bpy.context.collection.objects:
- if obj.cv_data.classtype == 'k_classtype_gate' and False:
- if obj.cv_data.target != None:
- p0 = obj.location
- p1 = obj.cv_data.target.location
- for i in range(20):
- t = i/20.0
- t1 = (i+0.5)/20.0
-
- pa = p0*t+p1*(1.0-t)
- pb = p0*t1+p1*(1.0-t1)
-
- verts += [(pa[0],pa[1],pa[2])]
- verts += [(pb[0],pb[1],pb[2])]
- colours += [(0,1,0,1.0),(1,0,0,1.0)]
+ for obj in bpy.context.collection.objects:
+ if obj.cv_data.classtype == 'k_classtype_gate':
if obj.type == 'MESH':
dims = obj.data.cv_data.v0
else:
verts += [(v1[0],v1[1],v1[2])]
colours += [(1,1,0,1),(1,1,0,1)]
+ sw = (0.4,0.4,0.4,0.2)
+ if obj.cv_data.target != None:
+ drawbline( obj.location, obj.cv_data.target.location, sw,sw )
+
+ elif obj.cv_data.classtype == 'k_classtype_route_node':
+ sw = Vector((0.4,0.4,0.4,0.2))
+ sw2 = Vector((1.5,0.2,0.2,0.0))
+ if obj.cv_data.target != None:
+ drawbpath( obj, obj.cv_data.target, sw, sw )
+ if obj.cv_data.target1 != None:
+ drawbpath( obj, obj.cv_data.target1, sw, sw )
+
+ drawbhandle( obj, 1.0, (0.8,0.8,0.8,1.0) )
+ drawbhandle( obj, -1.0, (0.4,0.4,0.4,1.0) )
+
+ p1 = obj.location+ \
+ obj.matrix_world.to_quaternion() @ Vector((0,0,-6+1.5))
+ drawbline( obj.location, p1, sw,sw2 )
+
+
elif obj.cv_data.classtype == 'k_classtype_block':
a = obj.data.cv_data.v0
b = obj.data.cv_data.v1
verts += [(v0[0],v0[1],v0[2])]
verts += [(v1[0],v1[1],v1[2])]
colours += [(0,1,1,1),(0,1,1,1)]
-
+
elif obj.cv_data.classtype == 'k_classtype_route':
vs = [None]*2
vs[0] = obj.location
loop_complete = False
while si > 0:
+ if stack_i[si-1] == 2:
+ si -= 1
+ continue
+
+ if si == 0: # Loop failed to complete
+ break
+
node = stack[si-1]
targets = [None,None]
if node.cv_data.classtype == 'k_classtype_route_node':
targets[1] = node.cv_data.target1
-
+
nextnode = targets[stack_i[si-1]]
stack_i[si-1] += 1
si += 1
continue
- if stack_i[si-1] == 2:
- si -= 1
-
- if si == 0: # Loop failed to complete
- break
-
if loop_complete:
course_colours = [Vector((0,0.8,0.2,1.0)), \
Vector((0,0.3,0.9,1.0)), \
target1: bpy.props.PointerProperty( type=bpy.types.Object, name="target1", \
poll=cv_poll_target )
+ colour: bpy.props.FloatVectorProperty(name="colour",subtype='COLOR',\
+ min=0.0,max=1.0)
+
classtype: bpy.props.EnumProperty(
name="Format",
items = [
elif active_object.cv_data.classtype == 'k_classtype_route':
_.layout.prop( active_object.cv_data, "target" )
+ _.layout.prop( active_object.cv_data, "colour" )
elif active_object.cv_data.classtype == 'k_classtype_block':
mesh = active_object.data
v3f pos, normal;
};
+/* TODO: he needs a home somewhere */
+static void eval_bezier_time( v3f p0, v3f p1, v3f h0, v3f h1, float t, v3f p )
+{
+ float tt = t*t,
+ ttt = tt*t;
+
+ v3_muls( p1, ttt, p );
+ v3_muladds( p, h1, 3.0f*tt -3.0f*ttt, p );
+ v3_muladds( p, h0, 3.0f*ttt -6.0f*tt +3.0f*t, p );
+ v3_muladds( p, p0, 3.0f*tt -ttt -3.0f*t +1.0f, p );
+}
+
#endif /* COMMON_H */
fb_resize( &grender.fb );
}
-static void render_gate( teleport_gate *gate, m4x3f camera )
+static int render_gate( teleport_gate *gate, m4x3f camera )
{
v3f viewpos, viewdir, gatedir;
v3_copy( camera[3], viewpos );
v3f v0;
v3_sub( viewpos, gate->co[0], v0 );
if( v3_dot(v0, gatedir) >= 0.0f )
- return;
+ return 0;
if( v3_dist( viewpos, gate->co[0] ) > 100.0f )
- return;
+ return 0;
v3f a,b,c,d;
glStencilFunc( GL_ALWAYS, 1, 0xFF );
glDisable( GL_STENCIL_TEST );
}
+
+ return 1;
}
static int gate_intersect( teleport_gate *gate, v3f pos, v3f last )
/*
* Draw world
*/
-
+
render_world( vg_pv, player.camera );
render_water_texture( player.camera );
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
render_water_surface( vg_pv, player.camera );
- vg_tex2d_bind( &tex_water, 1 );
-
- for( int i=0; i<world.gate_count; i++ )
- {
- render_gate( &world.gates[i], player.camera );
- }
-
+ vg_tex2d_bind( &tex_water, 1 ); /*TODO: ?*/
+ render_world_gates( vg_pv, player.camera );
/* Copy the RGB of what we have into the background buffer */
glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
{
u32 pstr_name;
u32 id_start;
+ v3f colour;
};
#pragma pack(pop)
static struct gplayer
{
/* Physics */
- rigidbody rb, collide_front, collide_back;
+ rigidbody rb, collide_front, collide_back, rb_gate_frame;
v3f a, v_last, m, bob, vl;
{
v3_add( manifold[i].n, surface_avg, surface_avg );
+#if 0
if( manifold[i].element_id <= world.sm_geo_std_oob.vertex_count )
{
player.is_dead = 1;
character_ragdoll_copypose( &player.mdl, player.rb.v );
return;
}
+#endif
}
v3_normalize( surface_avg );
/*
* Gate intersection, by tracing a line over the gate planes
*/
- for( int i=0; i<world.gate_count; i++ )
+ for( int i=0; i<world.routes.gate_count; i++ )
{
- teleport_gate *gate = &world.gates[i];
+ struct route_gate *rg = &world.routes.gates[i];
+ teleport_gate *gate = &rg->gate;
if( gate_intersect( gate, player.rb.co, prevco ) )
{
v4f transport_rotation;
m3x3_q( gate->transport, transport_rotation );
q_mul( transport_rotation, player.rb.q, player.rb.q );
-
+
+ world_routes_activate_gate( i );
+ player.rb_gate_frame = player.rb;
break;
}
}
rb_update_transform( &player.rb );
m3x3_mulv( player.rb.to_world, (v3f){ 0.0f, 0.0f, -1.2f }, player.rb.v );
+
+ player.rb_gate_frame = player.rb;
return 1;
}
player.land_target_colours[i], 0.25f);
if( vg_get_axis("grabl")>0.0f)
- reset_player(0,NULL);
+ {
+ player.rb = player.rb_gate_frame;
+ player.is_dead = 0;
+ player.in_air = 1;
+ m3x3_identity( player.vr );
+
+ player.mdl.shoes[0] = 1;
+ player.mdl.shoes[1] = 1;
+ }
if( vg_get_button_down( "switchmode" ) )
{
/*
* Append a model into the scene with a given transform
*/
-
static void scene_add_submesh( scene *pscene, mdl_header *mdl,
mdl_submesh *sm, m4x3f transform )
{
pscene->indice_count += sm->indice_count;
}
+/*
+ * One by one adders for simplified access (mostly procedural stuff)
+ */
+static void scene_push_tri( scene *pscene, u32 tri[3] )
+{
+ pscene->indices = buffer_reserve( pscene->indices, pscene->indice_count,
+ &pscene->indice_cap, 3, sizeof(u32) );
+
+ u32 *dst = &pscene->indices[pscene->indice_count];
+ dst[0] = tri[0];
+ dst[1] = tri[1];
+ dst[2] = tri[2];
+
+ pscene->indice_count += 3;
+}
+
+static void scene_push_vert( scene *pscene, mdl_vert *v )
+{
+ pscene->verts = buffer_reserve( pscene->verts, pscene->vertex_count,
+ &pscene->vertex_cap, 1, sizeof(mdl_vert) );
+
+ pscene->verts[pscene->vertex_count ++] = *v;
+}
+
static void scene_copy_slice( scene *pscene, mdl_submesh *sm )
{
sm->indice_start = pscene->submesh.indice_start;
mesh_drawn( 0, pscene->indice_count );
}
-static void scene_free( scene *pscene )
+static void scene_free_offline_buffers( scene *pscene )
{
free( pscene->verts );
free( pscene->indices );
+}
+static void scene_free( scene *pscene )
+{
+ scene_free_offline_buffers( pscene );
/* TODO: bvh */
}
--- /dev/null
+out vec4 FragColor;
+
+uniform sampler2D uTexGarbage;
+uniform sampler2D uTexGradients;
+uniform vec3 uCamera;
+uniform vec4 uColour;
+
+in vec4 aColour;
+in vec2 aUv;
+in vec3 aNorm;
+in vec3 aCo;
+in vec3 aWorldCo;
+
+#include "common_world.glsl"
+
+void main()
+{
+ vec3 vfrag = vec3(0.5,0.5,0.5);
+
+ // ws modulation
+ vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );
+
+ // Creating normal patches
+ vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;
+ vec3 qnorm = normalize(floor(aNorm*4.0+modnorm)*0.25) + vec3(0.001,0.0,0.0);
+
+ vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));
+ vec3 tangent1 = cross(qnorm,tangent0);
+ vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.035;
+
+ // Patch local noise
+ vec4 rgarbage = texture( uTexGarbage, uvdiffuse );
+
+ vfrag = pow(uColour.rgb,vec3(1.0/2.2));
+ vfrag -= rgarbage.a*0.1;
+
+ if( wgarbage.g < 0.3 )
+ discard;
+
+ if( g_light_preview == 1 )
+ {
+ vfrag = vec3(0.5);
+ }
+
+ // Lighting
+ vec3 halfview = uCamera - aWorldCo;
+ float fdist = length( halfview );
+ halfview /= fdist;
+
+ vfrag = do_light_diffuse( vfrag, qnorm );
+ vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );
+ vfrag = do_light_shadowing( vfrag );
+ vfrag = apply_fog( vfrag, fdist );
+
+ FragColor = vec4(vfrag, 1.0 );
+}
--- /dev/null
+#ifndef SHADER_route_H
+#define SHADER_route_H
+static void shader_route_link(void);
+static void shader_route_register(void);
+static struct vg_shader _shader_route = {
+ .name = "route",
+ .link = shader_route_link,
+ .vs =
+{
+.orig_file = "../shaders/standard.vs",
+.static_src =
+"layout (location=0) in vec3 a_co;\n"
+"layout (location=1) in vec3 a_norm;\n"
+"layout (location=2) in vec4 a_colour;\n"
+"layout (location=3) in vec2 a_uv;\n"
+"\n"
+"#line 2 0 \n"
+"\n"
+"uniform mat4 uPv;\n"
+"uniform mat4x3 uMdl;\n"
+"\n"
+"out vec4 aColour;\n"
+"out vec2 aUv;\n"
+"out vec3 aNorm;\n"
+"out vec3 aCo;\n"
+"out vec3 aWorldCo;\n"
+"\n"
+"void main()\n"
+"{\n"
+" vec3 world_pos = uMdl * vec4(a_co,1.0);\n"
+" gl_Position = uPv * vec4( world_pos, 1.0 );\n"
+" aColour = a_colour;\n"
+" aUv = a_uv;\n"
+" aNorm = mat3(uMdl) * a_norm;\n"
+" aCo = a_co;\n"
+" aWorldCo = world_pos;\n"
+"}\n"
+""},
+ .fs =
+{
+.orig_file = "../shaders/route.fs",
+.static_src =
+"out vec4 FragColor;\n"
+"\n"
+"uniform sampler2D uTexGarbage;\n"
+"uniform sampler2D uTexGradients;\n"
+"uniform vec3 uCamera;\n"
+"uniform vec4 uColour;\n"
+"\n"
+"in vec4 aColour;\n"
+"in vec2 aUv;\n"
+"in vec3 aNorm;\n"
+"in vec3 aCo;\n"
+"in vec3 aWorldCo;\n"
+"\n"
+"#line 1 1 \n"
+"layout (std140) uniform ub_world_lighting\n"
+"{\n"
+" vec4 g_light_colours[3];\n"
+" vec4 g_light_directions[3];\n"
+" vec4 g_ambient_colour;\n"
+"\n"
+" vec4 g_water_plane;\n"
+" vec4 g_depth_bounds;\n"
+" float g_water_fog;\n"
+" int g_light_count;\n"
+" int g_light_preview;\n"
+"};\n"
+"\n"
+"uniform sampler2D g_world_depth;\n"
+"\n"
+"// Standard diffuse + spec models\n"
+"// ==============================\n"
+"\n"
+"vec3 do_light_diffuse( vec3 vfrag, vec3 wnormal )\n"
+"{\n"
+" vec3 vtotal = g_ambient_colour.rgb;\n"
+"\n"
+" for( int i=0; i<g_light_count; i++ )\n"
+" {\n"
+" vec3 vcolour = g_light_colours[i].rgb;\n"
+" vec3 vdir = g_light_directions[i].xyz;\n"
+"\n"
+" float flight = max(dot( vdir, wnormal )*0.75+0.25,0.0);\n"
+" vtotal += vcolour*flight;\n"
+" }\n"
+"\n"
+" return vfrag * vtotal;\n"
+"}\n"
+"\n"
+"vec3 do_light_spec( vec3 vfrag, vec3 wnormal, vec3 halfview, float fintensity )\n"
+"{\n"
+" vec3 vcolour = g_light_colours[0].rgb;\n"
+" vec3 vdir = g_light_directions[0].xyz;\n"
+"\n"
+" vec3 specdir = reflect( -vdir, wnormal );\n"
+" float spec = pow(max(dot( halfview, specdir ), 0.0), 10.0);\n"
+" return vfrag + vcolour*spec*fintensity;\n"
+"}\n"
+"\n"
+"float world_depth_sample( vec3 pos )\n"
+"{\n"
+" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
+" return texture( g_world_depth, depth_coord ).r;\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"
+"\n"
+" float fdelta = height_sample - sample_pos.y;\n"
+" return clamp( fdelta, 0.1, 0.2 )-0.1;\n"
+"}\n"
+"\n"
+"vec3 do_light_shadowing_old( vec3 vfrag )\n"
+"{\n"
+" float faccum = 0.0;\n"
+" faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 ));\n"
+" faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 ));\n"
+" faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 ));\n"
+" faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 ));\n"
+" faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 )*1.5);\n"
+" faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 )*1.5);\n"
+" faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 )*1.5);\n"
+" faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 )*1.5);\n"
+" return mix( vfrag, g_ambient_colour.rgb, faccum );\n"
+"}\n"
+"\n"
+"vec3 do_light_shadowing( vec3 vfrag )\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"
+"\n"
+" float famt = 0.0;\n"
+" famt+=shadow_sample((vdir+vec3(-0.563, 0.550, 0.307)*fspread)*flength*0.1);\n"
+" famt+=shadow_sample((vdir+vec3( 0.808, 0.686, 0.346)*fspread)*flength*0.2);\n"
+" famt+=shadow_sample((vdir+vec3( 0.787, 0.074,-0.065)*fspread)*flength*0.3);\n"
+" famt+=shadow_sample((vdir+vec3(-0.593, 0.071,-0.425)*fspread)*flength*0.4);\n"
+" famt+=shadow_sample((vdir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
+" famt+=shadow_sample((vdir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
+" 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"
+" return mix( vfrag, g_ambient_colour.rgb, famt );\n"
+"}\n"
+"\n"
+"vec3 apply_fog( vec3 vfrag, float fdist )\n"
+"{\n"
+" float dist = pow(fdist*0.0008,1.2);\n"
+" return mix( vfrag, vec3(0.55,0.76,1.0), min( 1.0, dist ) );\n"
+"}\n"
+"\n"
+"#line 15 0 \n"
+"\n"
+"void main()\n"
+"{\n"
+" vec3 vfrag = vec3(0.5,0.5,0.5);\n"
+"\n"
+" // ws modulation\n"
+" vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );\n"
+"\n"
+" // Creating normal patches\n"
+" vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;\n"
+" vec3 qnorm = normalize(floor(aNorm*4.0+modnorm)*0.25) + vec3(0.001,0.0,0.0);\n"
+"\n"
+" vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));\n"
+" vec3 tangent1 = cross(qnorm,tangent0);\n"
+" vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.035;\n"
+" \n"
+" // Patch local noise\n"
+" vec4 rgarbage = texture( uTexGarbage, uvdiffuse );\n"
+"\n"
+" vfrag = pow(uColour.rgb,vec3(1.0/2.2));\n"
+" vfrag -= rgarbage.a*0.1;\n"
+"\n"
+" if( wgarbage.g < 0.3 )\n"
+" discard;\n"
+"\n"
+" if( g_light_preview == 1 )\n"
+" {\n"
+" vfrag = vec3(0.5);\n"
+" }\n"
+"\n"
+" // Lighting\n"
+" vec3 halfview = uCamera - aWorldCo;\n"
+" float fdist = length( halfview );\n"
+" halfview /= fdist;\n"
+"\n"
+" vfrag = do_light_diffuse( vfrag, qnorm );\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"
+"}\n"
+""},
+};
+
+static GLuint _uniform_route_uPv;
+static GLuint _uniform_route_uMdl;
+static GLuint _uniform_route_uTexGarbage;
+static GLuint _uniform_route_uTexGradients;
+static GLuint _uniform_route_uCamera;
+static GLuint _uniform_route_uColour;
+static GLuint _uniform_route_g_world_depth;
+static void shader_route_uPv(m4x4f m){
+ glUniformMatrix4fv( _uniform_route_uPv, 1, GL_FALSE, (float *)m );
+}
+static void shader_route_uMdl(m4x3f m){
+ glUniformMatrix4x3fv( _uniform_route_uMdl, 1, GL_FALSE, (float *)m );
+}
+static void shader_route_uTexGarbage(int i){
+ glUniform1i( _uniform_route_uTexGarbage, i );
+}
+static void shader_route_uTexGradients(int i){
+ glUniform1i( _uniform_route_uTexGradients, i );
+}
+static void shader_route_uCamera(v3f v){
+ glUniform3fv( _uniform_route_uCamera, 1, v );
+}
+static void shader_route_uColour(v4f v){
+ glUniform4fv( _uniform_route_uColour, 1, v );
+}
+static void shader_route_g_world_depth(int i){
+ glUniform1i( _uniform_route_g_world_depth, i );
+}
+static void shader_route_register(void){
+ vg_shader_register( &_shader_route );
+}
+static void shader_route_use(void){ glUseProgram(_shader_route.id); }
+static void shader_route_link(void){
+ _uniform_route_uPv = glGetUniformLocation( _shader_route.id, "uPv" );
+ _uniform_route_uMdl = glGetUniformLocation( _shader_route.id, "uMdl" );
+ _uniform_route_uTexGarbage = glGetUniformLocation( _shader_route.id, "uTexGarbage" );
+ _uniform_route_uTexGradients = glGetUniformLocation( _shader_route.id, "uTexGradients" );
+ _uniform_route_uCamera = glGetUniformLocation( _shader_route.id, "uCamera" );
+ _uniform_route_uColour = glGetUniformLocation( _shader_route.id, "uColour" );
+ _uniform_route_g_world_depth = glGetUniformLocation( _shader_route.id, "g_world_depth" );
+}
+#endif /* SHADER_route_H */
float t, speed;
};
-static void eval_bezier_time( v3f p0, v3f p1, v3f h0, v3f h1, float t, v3f p )
-{
- float tt = t*t,
- ttt = tt*t;
-
- v3_muls( p1, ttt, p );
- v3_muladds( p, h1, 3.0f*tt -3.0f*ttt, p );
- v3_muladds( p, h0, 3.0f*ttt -6.0f*tt +3.0f*t, p );
- v3_muladds( p, p0, 3.0f*tt -ttt -3.0f*t +1.0f, p );
-}
-
static float eval_bezier_length( v3f p0, v3f p1, v3f h0, v3f h1, int res )
{
float length = 0.0f, m = 1.0f/(float)res;
shader sky standard.vs sky.fs
shader planeinf standard.vs planeinf.fs
shader gpos standard.vs gpos.fs
+shader route standard.vs route.fs
struct subworld_physics system_physics;
*/
- teleport_gate gates[64];
- u32 gate_count;
-
/* Paths */
traffic_node traffic[128];
u32 traffic_count;
shader_gpos_register();
shader_fscolour_register();
shader_alphatest_register();
+
+ world_routes_register();
}
static void world_free(void)
mdl_header *mworld = mdl_load( "models/mp_dev.mdl" );
world.spawn_count = 0;
- world.gate_count = 0;
world.traffic_count = 0;
world.instance_cache = NULL;
if( pnode->classtype == k_classtype_none )
{}
-#if 0
- else if( pnode->classtype == k_classtype_gate )
- {
- struct classtype_gate *entgate = mdl_get_entdata( mworld, pnode );
-
- if( entgate->target )
- {
- mdl_node *pother = mdl_node_from_id( mworld, entgate->target );
-
- teleport_gate *gate = &world.gates[ world.gate_count ++ ];
-
- v3_copy( pnode->co, gate->co[0] );
- v3_copy( pother->co, gate->co[1] );
- v4_copy( pnode->q, gate->q[0] );
- v4_copy( pother->q, gate->q[1] );
- v2_copy( pnode->s, gate->dims );
-
- gate_transform_update( gate );
- }
- }
-#endif
else if( pnode->classtype == k_classtype_spawn )
{
struct respawn_point *rp = &world.spawns[ world.spawn_count ++ ];
scene_copy_slice( &world.foliage, &world.sm_foliage_alphatest );
scene_upload( &world.foliage );
- world_routes_init( mworld );
+ world_routes_loadfrom( mworld );
for( int i=0; i<world.instance_cache_count; i++ )
free( world.instance_cache[i].mdl );
glDepthMask( GL_TRUE );
}
+static void render_world_gates( m4x4f projection, m4x3f camera )
+{
+ int count = 0;
+ for( int i=0; i<world.routes.gate_count; i++ )
+ {
+ struct route_gate *rg = &world.routes.gates[i];
+ count += render_gate( &rg->gate, camera );
+
+ if( count == 2 )
+ return;
+ }
+}
+
static void render_world( m4x4f projection, m4x3f camera )
{
render_sky( camera );
+ render_world_routes( projection, camera[3] );
render_world_vb( projection, camera[3] );
render_world_alphatest( projection, camera[3] );
render_terrain( projection, camera[3] );
#include "model.h"
#include "gate.h"
+#include "shaders/vblend.h"
+#include "shaders/route.h"
+
struct subworld_routes
{
struct route_node
{
- v3f co, right, h;
+ v3f co, right, up, h;
u32 next[2];
- u32 is_gate, gate_id;
+ u32 is_gate, gate_id, current_refs, ref_count;
+ u32 route_ids[4]; /* Gates can be linked into up to four routes */
}
*nodes;
v4f colour;
u32 start;
+ mdl_submesh sm;
+
+ int active;
+ float factive;
}
*routes;
{
teleport_gate gate;
- u32 route_ids[4]; /* Gates can be linked into up to four routes */
u32 route_count,
node_id;
}
u32 gate_count,
gate_cap;
+
+ u32 active_gate;
+
+ scene scene_lines;
};
static struct subworld_routes *subworld_routes(void);
/*
* TODO list:
* when a gate is passed through it needs to trigger into an active state
- */
+ */
+
+static void debug_sbpath( struct route_node *rna, struct route_node *rnb,
+ u32 colour, float xoffset )
+{
+ v3f p0, h0, p1, h1, l, p;
+
+ v3_copy( rna->co, p0 );
+ v3_muladds( rna->co, rna->h, 1.0f, h0 );
+ v3_copy( rnb->co, p1 );
+ v3_muladds( rnb->co, rnb->h, -1.0f, h1 );
+
+ v3_muladds( p0, rna->right, xoffset, p0 );
+ v3_muladds( h0, rna->right, xoffset, h0 );
+ v3_muladds( p1, rnb->right, xoffset, p1 );
+ v3_muladds( h1, rnb->right, xoffset, h1 );
+
+ v3_copy( p0, l );
+
+ for( int i=0; i<5; i++ )
+ {
+ float t = (float)(i+1)/5.0f;
+ eval_bezier_time( p0, p1, h0, h1, t, p );
+ vg_line( p, l, colour );
+ v3_copy( p, l );
+ }
+}
+
+static void world_routes_activate_gate( u32 id )
+{
+ struct subworld_routes *r = subworld_routes();
+ struct route_gate *ig = &r->gates[id];
+ struct route_node *pnode = &r->nodes[ig->node_id],
+ *pdest = &r->nodes[pnode->next[0]];
+
+ r->active_gate = id;
+
+ for( int i=0; i<r->route_count; i++ )
+ {
+ struct route *route = &r->routes[i];
+
+ route->active = 0;
+ for( int j=0; j<pdest->ref_count; j++ )
+ {
+ if( pdest->route_ids[j] == i )
+ {
+ route->active = 1;
+ break;
+ }
+ }
+ }
+}
+
+static u32 world_routes_get_path( struct route *route, u32 stack[64] )
+{
+ struct subworld_routes *r = subworld_routes();
+ u32 stack_i[64];
+
+ stack[0] = route->start;
+ stack_i[0] = 0;
+
+ u32 si = 1;
+ int loop_complete = 0;
+
+ while( si )
+ {
+ if( stack_i[si-1] == 2 )
+ {
+ si --;
+ continue;
+ }
+
+ struct route_node *rn = &r->nodes[stack[si-1]];
+ u32 nextid = rn->next[stack_i[si-1]];
+ stack_i[si-1] ++;
+
+ if( nextid != 0xffffffff )
+ {
+ if( nextid == stack[0] )
+ {
+ loop_complete = 1;
+ break;
+ }
+
+ int valid = 1;
+ for( int sj=0; sj<si; sj++ )
+ {
+ if( stack[sj] == nextid )
+ {
+ valid = 0;
+ break;
+ }
+ }
+
+ if( valid )
+ {
+ stack_i[si] = 0;
+ stack[si] = nextid;
+ si ++;
+ continue;
+ }
+ }
+ }
+
+ if( loop_complete )
+ return si;
+
+ return 0;
+}
static void world_routes_debug(void)
{
struct route_node *rn = &r->nodes[i];
vg_line_pt3( rn->co, 1.0f, rn->is_gate? 0xffffff00: 0xff00b2ff );
}
+
+ for( int i=0; i<r->route_count; i++ )
+ {
+ struct route *route = &r->routes[i];
+
+ u32 stack[64];
+ u32 si = world_routes_get_path( route, stack );
+
+ u32 colours[] = { 0xfff58142, 0xff42cbf5, 0xff42f56c, 0xfff542b3,
+ 0xff5442f5 };
+
+ u32 cc = colours[i%vg_list_size(colours)];
+
+ for( int sj=0; sj<si; sj++ )
+ {
+ int sk = (sj+1)%si;
+ debug_sbpath( &r->nodes[stack[sj]], &r->nodes[stack[sk]], cc,
+ (float)i );
+ }
+ }
+
+ for( int i=0; i<r->node_count; i++ )
+ {
+ struct route_node *ri = &r->nodes[i],
+ *rj = NULL;
+
+ for( int j=0; j<2; j++ )
+ {
+ if( ri->next[j] != 0xffffffff )
+ {
+ rj = &r->nodes[ri->next[j]];
+ vg_line( ri->co, rj->co, 0x20ffffff );
+ }
+ }
+ }
}
static void world_routes_free(void)
{
if( *uid )
*uid = mdl_node_from_id( mdl, *uid )->sub_uid;
+ else
+ *uid = 0xffffffff;
}
-static void world_routes_init( mdl_header *mdl )
+static void world_routes_gen_meshes(void)
+{
+ struct subworld_routes *r = subworld_routes();
+ scene_init( &r->scene_lines );
+
+ for( int i=0; i<r->route_count; i++ )
+ {
+ struct route *route = &r->routes[i];
+
+ u32 stack[64];
+ u32 si = world_routes_get_path( route, stack );
+
+ u32 last_valid = 0;
+
+ for( int sj=0; sj<si; sj++ )
+ {
+ int sk=(sj+1)%si;
+
+ struct route_node *rnj = &r->nodes[ stack[sj] ],
+ *rnk = &r->nodes[ stack[sk] ],
+ *rnl;
+
+ if( rnj->is_gate && rnk->is_gate )
+ {
+ last_valid = 0;
+ continue;
+ }
+
+ float base_x0 = (float)rnj->ref_count*-0.5f + (float)rnj->current_refs,
+ base_x1 = (float)rnk->ref_count*-0.5f + (float)rnk->current_refs;
+
+ if( rnk->is_gate )
+ {
+ rnl = &r->nodes[ rnk->next[0] ];
+ base_x1 = (float)rnl->ref_count*-0.5f + (float)rnl->current_refs;
+ }
+
+ if( sk == 0 )
+ {
+ base_x1 -= 1.0f;
+ }
+
+ v3f p0, h0, p1, h1, p, pd;
+
+ v3_copy( rnj->co, p0 );
+ v3_muladds( rnj->co, rnj->h, 1.0f, h0 );
+ v3_copy( rnk->co, p1 );
+ v3_muladds( rnk->co, rnk->h, -1.0f, h1 );
+
+ float t=0.0f;
+ int it = 0;
+
+ for( int it=0; it<256; it ++ )
+ {
+ float const k_sample_dist = 0.02f;
+ eval_bezier_time( p0,p1,h0,h1, t,p );
+ eval_bezier_time( p0,p1,h0,h1, t+k_sample_dist,pd );
+
+ float mod = k_sample_dist / v3_dist( p, pd );
+
+ v3f v0,up, right;
+ v3_muls( rnj->up, 1.0f-t, up );
+ v3_muladds( up, rnk->up, t, up );
+
+ v3_sub( pd,p,v0 );
+ v3_cross( up, v0, right );
+ v3_normalize( right );
+
+ float cur_x = (1.0f-t)*base_x0 + t*base_x1;
+
+ v3f sc, sa, sb, down;
+ v3_muladds( p, right, cur_x, sc );
+ v3_muladds( sc, up, 1.5f, sc );
+ v3_muladds( sc, right, 0.45f, sa );
+ v3_muladds( sc, right, -0.45f, sb );
+ v3_muls( up, -1.0f, down );
+
+ ray_hit ha, hb;
+ ha.dist = 8.0f;
+ hb.dist = 8.0f;
+ if(ray_world( sa, down, &ha ) &&
+ ray_world( sb, down, &hb ))
+ {
+ mdl_vert va, vb;
+
+ v3_muladds( ha.pos, up, 0.06f, va.co );
+ v3_muladds( hb.pos, up, 0.06f, vb.co );
+ v3_copy( up, va.norm );
+ v3_copy( up, vb.norm );
+ v3_zero( va.colour );
+ v3_zero( vb.colour );
+ v2_zero( va.uv );
+ v2_zero( vb.uv );
+
+ scene_push_vert( &r->scene_lines, &va );
+ scene_push_vert( &r->scene_lines, &vb );
+
+ if( last_valid )
+ {
+ /* Connect them with triangles */
+ scene_push_tri( &r->scene_lines, (u32[3]){
+ last_valid+0-2, last_valid+1-2, last_valid+2-2} );
+ scene_push_tri( &r->scene_lines, (u32[3]){
+ last_valid+1-2, last_valid+3-2, last_valid+2-2} );
+ }
+
+ last_valid = r->scene_lines.vertex_count;
+ }
+ else
+ last_valid = 0;
+
+ t += 1.0f*mod;
+
+ if( t >= 1.0f )
+ {
+ /* TODO special case for end of loop, need to add triangles
+ * between first and last rungs */
+ break;
+ }
+ }
+
+ rnj->current_refs ++;
+ }
+
+ scene_copy_slice( &r->scene_lines, &route->sm );
+ }
+
+ scene_upload( &r->scene_lines );
+ scene_free_offline_buffers( &r->scene_lines );
+}
+
+static void bind_terrain_textures(void);
+static void render_world_routes( m4x4f projection, v3f camera )
+{
+ struct subworld_routes *r = subworld_routes();
+
+ m4x3f identity_matrix;
+ m4x3_identity( identity_matrix );
+
+ shader_route_use();
+ shader_route_uTexGarbage(0);
+ shader_link_standard_ub( _shader_route.id, 2 );
+ bind_terrain_textures();
+
+ shader_route_uPv( projection );
+ shader_route_uMdl( identity_matrix );
+ shader_route_uCamera( camera );
+
+ scene_bind( &r->scene_lines );
+
+ for( int i=0; i<r->route_count; i++ )
+ {
+ struct route *route = &r->routes[i];
+ route->factive = vg_lerpf( route->factive, route->active, 0.01f );
+
+ v4f colour;
+ v3_lerp( (v3f){0.7f,0.7f,0.7f}, route->colour, route->factive, colour );
+ colour[3] = 1.0f;
+
+ shader_route_uColour( colour );
+ mdl_draw_submesh( &route->sm );
+ }
+}
+
+static void world_routes_register(void)
+{
+ shader_route_register();
+}
+
+static void world_routes_loadfrom( mdl_header *mdl )
{
struct subworld_routes *r = subworld_routes();
r->nodes = NULL;
v3_copy( transform[0], rn->right );
v3_normalize( rn->right );
- v3_copy( transform[2], rn->h );
+ v3_copy( transform[1], rn->up );
+ v3_normalize( rn->up );
+ v3_muls( transform[2], -1.0f, rn->h );
v3_copy( transform[3], rn->co );
+ rn->ref_count = 0;
+ rn->current_refs = 0;
if( pnode->classtype == k_classtype_gate )
{
rn->gate_id = r->gate_count;
rn->is_gate = 1;
- struct route_gate *rg = &r->gates[r->gate_count];
- rg->node_id = r->node_count;
-
/* TODO */
-
- r->gate_count ++;
+ if( inf->target )
+ {
+ mdl_node *pother = mdl_node_from_id( mdl, inf->target );
+
+ if( pother->classtype == k_classtype_gate )
+ {
+ struct route_gate *rg = &r->gates[r->gate_count];
+ rg->node_id = r->node_count;
+
+ v3_copy( pnode->co, rg->gate.co[0] );
+ v3_copy( pother->co, rg->gate.co[1] );
+ v4_copy( pnode->q, rg->gate.q[0] );
+ v4_copy( pother->q, rg->gate.q[1] );
+ v2_copy( inf->dims, rg->gate.dims );
+
+ gate_transform_update( &rg->gate );
+
+ r->gate_count ++;
+ }
+ }
}
else
{
struct route *route = &r->routes[r->route_count];
- v4_zero( route->colour );
+ v3_copy( inf->colour, route->colour );
+ route->colour[3] = 1.0f;
+
route->name = NULL;
route->start = inf->id_start;
+ route->active = 0;
+ route->factive = 0.0f;
r->route_count ++;
}
for( int j=0; j<2; j++ )
world_id_fixup( &rn->next[j], mdl );
-
- if( rn->is_gate )
- world_id_fixup( &rn->gate_id, mdl );
}
- for( int i=0; i<r->gate_count; i++ )
+ for( int i=0; i<r->route_count; i++ )
{
- struct route_gate *rg = &r->gates[i];
- world_id_fixup( &rg->node_id, mdl );
+ struct route *route = &r->routes[i];
+ world_id_fixup( &route->start, mdl );
}
+ /*
+ * Gather references
+ */
for( int i=0; i<r->route_count; i++ )
{
struct route *route = &r->routes[i];
- world_id_fixup( &route->start, mdl );
+
+ u32 stack[64];
+ u32 si = world_routes_get_path( route, stack );
+
+ for( int sj=0; sj<si; sj++ )
+ {
+ struct route_node *rn = &r->nodes[ stack[sj] ];
+ rn->route_ids[ rn->ref_count ++ ] = i;
+
+ if( rn->ref_count > 4 )
+ vg_warn( "Too many references on route node %i\n", i );
+ }
}
+
+ world_routes_gen_meshes();
}
#endif /* ROUTES_H */