From: hgn Date: Thu, 2 Mar 2023 22:28:04 +0000 (+0000) Subject: checkin X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;h=791f807111a1f740f745c67db642aa7a8bee56e8;hp=e61356f70eddb79f05d7b9e329e91963ec74f817;p=carveJwlIkooP6JGAAIwe30JlM.git checkin --- diff --git a/blender_export.py b/blender_export.py index b60b2e0..6117ff8 100644 --- a/blender_export.py +++ b/blender_export.py @@ -837,6 +837,9 @@ class classtype_world_light( Structure ): _.type = 1 _.angle = math.cos(data.spot_size*0.5) #} + + if data.cv_data.bp0: + _.type += 2 #} @staticmethod @@ -1340,7 +1343,7 @@ def encoder_build_scene_graph( collection ): for obj in collection.all_objects: #{ - if obj.parent: continue + #if obj.parent: continue def _extend( p, n, d ): #{ @@ -1915,7 +1918,7 @@ def encoder_process_definition( node_def ): #{ obj = node_def['obj'] obj_type = obj.type - obj_co = obj.location + obj_co = obj.matrix_world @ Vector((0,0,0)) if obj_type == 'ARMATURE': obj_classtype = 'classtype_skeleton' @@ -2642,6 +2645,31 @@ class CV_MESH_SETTINGS(bpy.types.PropertyGroup): v3: bpy.props.FloatVectorProperty(name="v3",size=3) #} +class CV_LIGHT_SETTINGS(bpy.types.PropertyGroup): +#{ + bp0: bpy.props.BoolProperty( name="bp0" ); +#} + +class CV_LIGHT_PANEL(bpy.types.Panel): +#{ + bl_label="[Skate Rift]" + bl_idname="SCENE_PT_cv_light" + bl_space_type='PROPERTIES' + bl_region_type='WINDOW' + bl_context='data' + + def draw(_,context): + #{ + active_object = context.active_object + if active_object == None: return + + if active_object.type != 'LIGHT': return + + data = active_object.data.cv_data + _.layout.prop( data, "bp0", text="Only on during night" ) + #} +#} + class CV_OBJ_SETTINGS(bpy.types.PropertyGroup): #{ uid: bpy.props.IntProperty( name="" ) @@ -2709,7 +2737,7 @@ class CV_BONE_SETTINGS(bpy.types.PropertyGroup): class CV_BONE_PANEL(bpy.types.Panel): #{ - bl_label="Bone Config" + bl_label="[Skate Rift]" bl_idname="SCENE_PT_cv_bone" bl_space_type='PROPERTIES' bl_region_type='WINDOW' @@ -3002,7 +3030,8 @@ class CV_INTERFACE(bpy.types.Panel): classes = [CV_OBJ_SETTINGS,CV_OBJ_PANEL,CV_COMPILE,CV_INTERFACE,\ CV_MESH_SETTINGS, CV_SCENE_SETTINGS, CV_BONE_SETTINGS,\ CV_BONE_PANEL, CV_COLLECTION_SETTINGS, CV_COMPILE_THIS,\ - CV_MATERIAL_SETTINGS, CV_MATERIAL_PANEL ] + CV_MATERIAL_SETTINGS, CV_MATERIAL_PANEL, CV_LIGHT_SETTINGS,\ + CV_LIGHT_PANEL] def register(): #{ @@ -3019,6 +3048,7 @@ def register(): bpy.props.PointerProperty(type=CV_COLLECTION_SETTINGS) bpy.types.Material.cv_data = \ bpy.props.PointerProperty(type=CV_MATERIAL_SETTINGS) + bpy.types.Light.cv_data = bpy.props.PointerProperty(type=CV_LIGHT_SETTINGS) cv_view_draw_handler = bpy.types.SpaceView3D.draw_handler_add(\ cv_draw,(),'WINDOW','POST_VIEW') diff --git a/common.h b/common.h index c1f325e..7420009 100644 --- a/common.h +++ b/common.h @@ -114,7 +114,8 @@ VG_STATIC int k_ragdoll_div = 1, k_ragdoll_debug_collider = 1, k_ragdoll_debug_constraints = 0; -VG_STATIC int k_debug_light_index = 1; +VG_STATIC int k_debug_light_indices = 0, + k_debug_light_complexity = 0; VG_STATIC int freecam = 0; VG_STATIC int walk_grid_iterations = 1; @@ -156,6 +157,8 @@ VG_STATIC void common_var_temp(void) VG_VAR_I32( k_ragdoll_div ); VG_VAR_I32( k_ragdoll_debug_collider ); VG_VAR_I32( k_ragdoll_debug_constraints ); + VG_VAR_I32( k_debug_light_indices ); + VG_VAR_I32( k_debug_light_complexity ); VG_VAR_F32( k_friction_lat ); diff --git a/maps_src/mp_mtzero.mdl b/maps_src/mp_mtzero.mdl index 0c4d0ab..d20a0e8 100644 Binary files a/maps_src/mp_mtzero.mdl and b/maps_src/mp_mtzero.mdl differ diff --git a/model.h b/model.h index b2d258d..7c4e0d9 100644 --- a/model.h +++ b/model.h @@ -276,7 +276,9 @@ struct classtype_world_light enum light_type { k_light_type_point, - k_light_type_spot + k_light_type_spot, + k_light_type_point_nighttime_only, + k_light_type_spot_nighttime_only } type; diff --git a/shaders/common_scene.glsl b/shaders/common_scene.glsl index 2cf00b9..91dc6a1 100644 --- a/shaders/common_scene.glsl +++ b/shaders/common_scene.glsl @@ -72,35 +72,57 @@ vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal ) vec4 light_dir_1 = texelFetch( uLightsArray, light_indices.y*3+2 ); vec4 light_dir_2 = texelFetch( uLightsArray, light_indices.z*3+2 ); - //return vec3(fract(distance(light_co_0.xyz,aWorldCo)), - // fract(distance(light_co_1.xyz,aWorldCo)), - // fract(distance(light_co_2.xyz,aWorldCo))); - - // return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125), - // fract(light_indices.z * 0.125 )); - - total_light += newlight_compute_spot - ( - wnormal, halfview, - light_colour_0.rgb, - light_co_0.xyz, - light_dir_0 - ) * board_shadow; - - total_light += newlight_compute_spot - ( - wnormal, halfview, - light_colour_1.rgb, - light_co_1.xyz, - light_dir_1 - ) * board_shadow; - total_light += newlight_compute_spot - ( - wnormal, halfview, - light_colour_2.rgb, - light_co_2.xyz, - light_dir_2 - ) * board_shadow; + if( g_debug_indices == 1 ) + { + float rings = min( fract(distance(light_co_0.xyz,aWorldCo)), + min( fract(distance(light_co_1.xyz,aWorldCo)), + fract(distance(light_co_2.xyz,aWorldCo)) ) + ); + + return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125), + fract(light_indices.z * 0.125 )) + (rings-0.5) * 0.25; + } + + if( g_debug_complexity == 1 ) + { + return vec3(1.0,0.0,0.0) * ( light_indices.w/3.0 ); + } + + if( light_indices.w >= 1 ) + { + total_light += newlight_compute_spot + ( + wnormal, halfview, + light_colour_0.rgb, + light_co_0.xyz, + light_dir_0 + ) * board_shadow + * step( world.day_phase, light_colour_0.w ); + + if( light_indices.w >= 2 ) + { + total_light += newlight_compute_spot + ( + wnormal, halfview, + light_colour_1.rgb, + light_co_1.xyz, + light_dir_1 + ) * board_shadow + * step( world.day_phase, light_colour_1.w ); + + if( light_indices.w >= 3 ) + { + total_light += newlight_compute_spot + ( + wnormal, halfview, + light_colour_2.rgb, + light_co_2.xyz, + light_dir_2 + ) * board_shadow + * step( world.day_phase, light_colour_2.w ); + } + } + } vec3 fog_colour = scene_sky( -halfview, world ); diff --git a/shaders/common_world.glsl b/shaders/common_world.glsl index 4393409..ccf416e 100644 --- a/shaders/common_world.glsl +++ b/shaders/common_world.glsl @@ -14,6 +14,9 @@ layout (std140) uniform ub_world_lighting int g_light_preview; int g_shadow_samples; + int g_debug_indices; + int g_debug_complexity; + // g_time ? //vec4 g_point_light_positions[32]; diff --git a/shaders/model_character_view.h b/shaders/model_character_view.h index 68a4667..2017f7d 100644 --- a/shaders/model_character_view.h +++ b/shaders/model_character_view.h @@ -100,6 +100,9 @@ static struct vg_shader _shader_model_character_view = { " int g_light_preview;\n" " int g_shadow_samples;\n" "\n" +" int g_debug_indices;\n" +" int g_debug_complexity;\n" +"\n" " // g_time ?\n" "\n" " //vec4 g_point_light_positions[32];\n" diff --git a/shaders/model_sky.h b/shaders/model_sky.h index d1edd1d..2fb62ff 100644 --- a/shaders/model_sky.h +++ b/shaders/model_sky.h @@ -91,6 +91,9 @@ static struct vg_shader _shader_model_sky = { " int g_light_preview;\n" " int g_shadow_samples;\n" "\n" +" int g_debug_indices;\n" +" int g_debug_complexity;\n" +"\n" " // g_time ?\n" "\n" " //vec4 g_point_light_positions[32];\n" diff --git a/shaders/scene_depth.h b/shaders/scene_depth.h index 63ff702..f40c461 100644 --- a/shaders/scene_depth.h +++ b/shaders/scene_depth.h @@ -101,6 +101,9 @@ static struct vg_shader _shader_scene_depth = { " int g_light_preview;\n" " int g_shadow_samples;\n" "\n" +" int g_debug_indices;\n" +" int g_debug_complexity;\n" +"\n" " // g_time ?\n" "\n" " //vec4 g_point_light_positions[32];\n" @@ -441,35 +444,57 @@ static struct vg_shader _shader_scene_depth = { " vec4 light_dir_1 = texelFetch( uLightsArray, light_indices.y*3+2 );\n" " vec4 light_dir_2 = texelFetch( uLightsArray, light_indices.z*3+2 );\n" "\n" -" //return vec3(fract(distance(light_co_0.xyz,aWorldCo)),\n" -" // fract(distance(light_co_1.xyz,aWorldCo)),\n" -" // fract(distance(light_co_2.xyz,aWorldCo)));\n" -"\n" -" // return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" -" // fract(light_indices.z * 0.125 ));\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_0.rgb,\n" -" light_co_0.xyz,\n" -" light_dir_0\n" -" ) * board_shadow;\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_1.rgb,\n" -" light_co_1.xyz,\n" -" light_dir_1\n" -" ) * board_shadow;\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_2.rgb,\n" -" light_co_2.xyz,\n" -" light_dir_2\n" -" ) * board_shadow;\n" +" if( g_debug_indices == 1 )\n" +" {\n" +" float rings = min( fract(distance(light_co_0.xyz,aWorldCo)),\n" +" min( fract(distance(light_co_1.xyz,aWorldCo)),\n" +" fract(distance(light_co_2.xyz,aWorldCo)) ) \n" +" );\n" +" \n" +" return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" +" fract(light_indices.z * 0.125 )) + (rings-0.5) * 0.25;\n" +" }\n" +"\n" +" if( g_debug_complexity == 1 )\n" +" {\n" +" return vec3(1.0,0.0,0.0) * ( light_indices.w/3.0 );\n" +" }\n" +"\n" +" if( light_indices.w >= 1 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_0.rgb,\n" +" light_co_0.xyz,\n" +" light_dir_0\n" +" ) * board_shadow \n" +" * step( world.day_phase, light_colour_0.w );\n" +"\n" +" if( light_indices.w >= 2 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_1.rgb,\n" +" light_co_1.xyz,\n" +" light_dir_1\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_1.w );\n" +"\n" +" if( light_indices.w >= 3 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_2.rgb,\n" +" light_co_2.xyz,\n" +" light_dir_2\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_2.w );\n" +" }\n" +" }\n" +" }\n" "\n" " vec3 fog_colour = scene_sky( -halfview, world );\n" " \n" diff --git a/shaders/scene_position.h b/shaders/scene_position.h index 5fed747..8966955 100644 --- a/shaders/scene_position.h +++ b/shaders/scene_position.h @@ -101,6 +101,9 @@ static struct vg_shader _shader_scene_position = { " int g_light_preview;\n" " int g_shadow_samples;\n" "\n" +" int g_debug_indices;\n" +" int g_debug_complexity;\n" +"\n" " // g_time ?\n" "\n" " //vec4 g_point_light_positions[32];\n" @@ -441,35 +444,57 @@ static struct vg_shader _shader_scene_position = { " vec4 light_dir_1 = texelFetch( uLightsArray, light_indices.y*3+2 );\n" " vec4 light_dir_2 = texelFetch( uLightsArray, light_indices.z*3+2 );\n" "\n" -" //return vec3(fract(distance(light_co_0.xyz,aWorldCo)),\n" -" // fract(distance(light_co_1.xyz,aWorldCo)),\n" -" // fract(distance(light_co_2.xyz,aWorldCo)));\n" -"\n" -" // return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" -" // fract(light_indices.z * 0.125 ));\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_0.rgb,\n" -" light_co_0.xyz,\n" -" light_dir_0\n" -" ) * board_shadow;\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_1.rgb,\n" -" light_co_1.xyz,\n" -" light_dir_1\n" -" ) * board_shadow;\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_2.rgb,\n" -" light_co_2.xyz,\n" -" light_dir_2\n" -" ) * board_shadow;\n" +" if( g_debug_indices == 1 )\n" +" {\n" +" float rings = min( fract(distance(light_co_0.xyz,aWorldCo)),\n" +" min( fract(distance(light_co_1.xyz,aWorldCo)),\n" +" fract(distance(light_co_2.xyz,aWorldCo)) ) \n" +" );\n" +" \n" +" return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" +" fract(light_indices.z * 0.125 )) + (rings-0.5) * 0.25;\n" +" }\n" +"\n" +" if( g_debug_complexity == 1 )\n" +" {\n" +" return vec3(1.0,0.0,0.0) * ( light_indices.w/3.0 );\n" +" }\n" +"\n" +" if( light_indices.w >= 1 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_0.rgb,\n" +" light_co_0.xyz,\n" +" light_dir_0\n" +" ) * board_shadow \n" +" * step( world.day_phase, light_colour_0.w );\n" +"\n" +" if( light_indices.w >= 2 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_1.rgb,\n" +" light_co_1.xyz,\n" +" light_dir_1\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_1.w );\n" +"\n" +" if( light_indices.w >= 3 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_2.rgb,\n" +" light_co_2.xyz,\n" +" light_dir_2\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_2.w );\n" +" }\n" +" }\n" +" }\n" "\n" " vec3 fog_colour = scene_sky( -halfview, world );\n" " \n" diff --git a/shaders/scene_route.h b/shaders/scene_route.h index 9d95111..61c14e6 100644 --- a/shaders/scene_route.h +++ b/shaders/scene_route.h @@ -102,6 +102,9 @@ static struct vg_shader _shader_scene_route = { " int g_light_preview;\n" " int g_shadow_samples;\n" "\n" +" int g_debug_indices;\n" +" int g_debug_complexity;\n" +"\n" " // g_time ?\n" "\n" " //vec4 g_point_light_positions[32];\n" @@ -442,35 +445,57 @@ static struct vg_shader _shader_scene_route = { " vec4 light_dir_1 = texelFetch( uLightsArray, light_indices.y*3+2 );\n" " vec4 light_dir_2 = texelFetch( uLightsArray, light_indices.z*3+2 );\n" "\n" -" //return vec3(fract(distance(light_co_0.xyz,aWorldCo)),\n" -" // fract(distance(light_co_1.xyz,aWorldCo)),\n" -" // fract(distance(light_co_2.xyz,aWorldCo)));\n" -"\n" -" // return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" -" // fract(light_indices.z * 0.125 ));\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_0.rgb,\n" -" light_co_0.xyz,\n" -" light_dir_0\n" -" ) * board_shadow;\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_1.rgb,\n" -" light_co_1.xyz,\n" -" light_dir_1\n" -" ) * board_shadow;\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_2.rgb,\n" -" light_co_2.xyz,\n" -" light_dir_2\n" -" ) * board_shadow;\n" +" if( g_debug_indices == 1 )\n" +" {\n" +" float rings = min( fract(distance(light_co_0.xyz,aWorldCo)),\n" +" min( fract(distance(light_co_1.xyz,aWorldCo)),\n" +" fract(distance(light_co_2.xyz,aWorldCo)) ) \n" +" );\n" +" \n" +" return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" +" fract(light_indices.z * 0.125 )) + (rings-0.5) * 0.25;\n" +" }\n" +"\n" +" if( g_debug_complexity == 1 )\n" +" {\n" +" return vec3(1.0,0.0,0.0) * ( light_indices.w/3.0 );\n" +" }\n" +"\n" +" if( light_indices.w >= 1 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_0.rgb,\n" +" light_co_0.xyz,\n" +" light_dir_0\n" +" ) * board_shadow \n" +" * step( world.day_phase, light_colour_0.w );\n" +"\n" +" if( light_indices.w >= 2 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_1.rgb,\n" +" light_co_1.xyz,\n" +" light_dir_1\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_1.w );\n" +"\n" +" if( light_indices.w >= 3 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_2.rgb,\n" +" light_co_2.xyz,\n" +" light_dir_2\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_2.w );\n" +" }\n" +" }\n" +" }\n" "\n" " vec3 fog_colour = scene_sky( -halfview, world );\n" " \n" diff --git a/shaders/scene_standard.h b/shaders/scene_standard.h index 239a8ad..a385437 100644 --- a/shaders/scene_standard.h +++ b/shaders/scene_standard.h @@ -102,6 +102,9 @@ static struct vg_shader _shader_scene_standard = { " int g_light_preview;\n" " int g_shadow_samples;\n" "\n" +" int g_debug_indices;\n" +" int g_debug_complexity;\n" +"\n" " // g_time ?\n" "\n" " //vec4 g_point_light_positions[32];\n" @@ -442,35 +445,57 @@ static struct vg_shader _shader_scene_standard = { " vec4 light_dir_1 = texelFetch( uLightsArray, light_indices.y*3+2 );\n" " vec4 light_dir_2 = texelFetch( uLightsArray, light_indices.z*3+2 );\n" "\n" -" //return vec3(fract(distance(light_co_0.xyz,aWorldCo)),\n" -" // fract(distance(light_co_1.xyz,aWorldCo)),\n" -" // fract(distance(light_co_2.xyz,aWorldCo)));\n" -"\n" -" // return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" -" // fract(light_indices.z * 0.125 ));\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_0.rgb,\n" -" light_co_0.xyz,\n" -" light_dir_0\n" -" ) * board_shadow;\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_1.rgb,\n" -" light_co_1.xyz,\n" -" light_dir_1\n" -" ) * board_shadow;\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_2.rgb,\n" -" light_co_2.xyz,\n" -" light_dir_2\n" -" ) * board_shadow;\n" +" if( g_debug_indices == 1 )\n" +" {\n" +" float rings = min( fract(distance(light_co_0.xyz,aWorldCo)),\n" +" min( fract(distance(light_co_1.xyz,aWorldCo)),\n" +" fract(distance(light_co_2.xyz,aWorldCo)) ) \n" +" );\n" +" \n" +" return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" +" fract(light_indices.z * 0.125 )) + (rings-0.5) * 0.25;\n" +" }\n" +"\n" +" if( g_debug_complexity == 1 )\n" +" {\n" +" return vec3(1.0,0.0,0.0) * ( light_indices.w/3.0 );\n" +" }\n" +"\n" +" if( light_indices.w >= 1 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_0.rgb,\n" +" light_co_0.xyz,\n" +" light_dir_0\n" +" ) * board_shadow \n" +" * step( world.day_phase, light_colour_0.w );\n" +"\n" +" if( light_indices.w >= 2 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_1.rgb,\n" +" light_co_1.xyz,\n" +" light_dir_1\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_1.w );\n" +"\n" +" if( light_indices.w >= 3 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_2.rgb,\n" +" light_co_2.xyz,\n" +" light_dir_2\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_2.w );\n" +" }\n" +" }\n" +" }\n" "\n" " vec3 fog_colour = scene_sky( -halfview, world );\n" " \n" diff --git a/shaders/scene_standard_alphatest.h b/shaders/scene_standard_alphatest.h index c2c479a..46c1976 100644 --- a/shaders/scene_standard_alphatest.h +++ b/shaders/scene_standard_alphatest.h @@ -102,6 +102,9 @@ static struct vg_shader _shader_scene_standard_alphatest = { " int g_light_preview;\n" " int g_shadow_samples;\n" "\n" +" int g_debug_indices;\n" +" int g_debug_complexity;\n" +"\n" " // g_time ?\n" "\n" " //vec4 g_point_light_positions[32];\n" @@ -442,35 +445,57 @@ static struct vg_shader _shader_scene_standard_alphatest = { " vec4 light_dir_1 = texelFetch( uLightsArray, light_indices.y*3+2 );\n" " vec4 light_dir_2 = texelFetch( uLightsArray, light_indices.z*3+2 );\n" "\n" -" //return vec3(fract(distance(light_co_0.xyz,aWorldCo)),\n" -" // fract(distance(light_co_1.xyz,aWorldCo)),\n" -" // fract(distance(light_co_2.xyz,aWorldCo)));\n" -"\n" -" // return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" -" // fract(light_indices.z * 0.125 ));\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_0.rgb,\n" -" light_co_0.xyz,\n" -" light_dir_0\n" -" ) * board_shadow;\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_1.rgb,\n" -" light_co_1.xyz,\n" -" light_dir_1\n" -" ) * board_shadow;\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_2.rgb,\n" -" light_co_2.xyz,\n" -" light_dir_2\n" -" ) * board_shadow;\n" +" if( g_debug_indices == 1 )\n" +" {\n" +" float rings = min( fract(distance(light_co_0.xyz,aWorldCo)),\n" +" min( fract(distance(light_co_1.xyz,aWorldCo)),\n" +" fract(distance(light_co_2.xyz,aWorldCo)) ) \n" +" );\n" +" \n" +" return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" +" fract(light_indices.z * 0.125 )) + (rings-0.5) * 0.25;\n" +" }\n" +"\n" +" if( g_debug_complexity == 1 )\n" +" {\n" +" return vec3(1.0,0.0,0.0) * ( light_indices.w/3.0 );\n" +" }\n" +"\n" +" if( light_indices.w >= 1 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_0.rgb,\n" +" light_co_0.xyz,\n" +" light_dir_0\n" +" ) * board_shadow \n" +" * step( world.day_phase, light_colour_0.w );\n" +"\n" +" if( light_indices.w >= 2 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_1.rgb,\n" +" light_co_1.xyz,\n" +" light_dir_1\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_1.w );\n" +"\n" +" if( light_indices.w >= 3 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_2.rgb,\n" +" light_co_2.xyz,\n" +" light_dir_2\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_2.w );\n" +" }\n" +" }\n" +" }\n" "\n" " vec3 fog_colour = scene_sky( -halfview, world );\n" " \n" diff --git a/shaders/scene_terrain.h b/shaders/scene_terrain.h index cf19762..da84797 100644 --- a/shaders/scene_terrain.h +++ b/shaders/scene_terrain.h @@ -103,6 +103,9 @@ static struct vg_shader _shader_scene_terrain = { " int g_light_preview;\n" " int g_shadow_samples;\n" "\n" +" int g_debug_indices;\n" +" int g_debug_complexity;\n" +"\n" " // g_time ?\n" "\n" " //vec4 g_point_light_positions[32];\n" @@ -443,35 +446,57 @@ static struct vg_shader _shader_scene_terrain = { " vec4 light_dir_1 = texelFetch( uLightsArray, light_indices.y*3+2 );\n" " vec4 light_dir_2 = texelFetch( uLightsArray, light_indices.z*3+2 );\n" "\n" -" //return vec3(fract(distance(light_co_0.xyz,aWorldCo)),\n" -" // fract(distance(light_co_1.xyz,aWorldCo)),\n" -" // fract(distance(light_co_2.xyz,aWorldCo)));\n" -"\n" -" // return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" -" // fract(light_indices.z * 0.125 ));\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_0.rgb,\n" -" light_co_0.xyz,\n" -" light_dir_0\n" -" ) * board_shadow;\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_1.rgb,\n" -" light_co_1.xyz,\n" -" light_dir_1\n" -" ) * board_shadow;\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_2.rgb,\n" -" light_co_2.xyz,\n" -" light_dir_2\n" -" ) * board_shadow;\n" +" if( g_debug_indices == 1 )\n" +" {\n" +" float rings = min( fract(distance(light_co_0.xyz,aWorldCo)),\n" +" min( fract(distance(light_co_1.xyz,aWorldCo)),\n" +" fract(distance(light_co_2.xyz,aWorldCo)) ) \n" +" );\n" +" \n" +" return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" +" fract(light_indices.z * 0.125 )) + (rings-0.5) * 0.25;\n" +" }\n" +"\n" +" if( g_debug_complexity == 1 )\n" +" {\n" +" return vec3(1.0,0.0,0.0) * ( light_indices.w/3.0 );\n" +" }\n" +"\n" +" if( light_indices.w >= 1 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_0.rgb,\n" +" light_co_0.xyz,\n" +" light_dir_0\n" +" ) * board_shadow \n" +" * step( world.day_phase, light_colour_0.w );\n" +"\n" +" if( light_indices.w >= 2 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_1.rgb,\n" +" light_co_1.xyz,\n" +" light_dir_1\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_1.w );\n" +"\n" +" if( light_indices.w >= 3 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_2.rgb,\n" +" light_co_2.xyz,\n" +" light_dir_2\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_2.w );\n" +" }\n" +" }\n" +" }\n" "\n" " vec3 fog_colour = scene_sky( -halfview, world );\n" " \n" diff --git a/shaders/scene_vertex_blend.h b/shaders/scene_vertex_blend.h index 028392d..097046f 100644 --- a/shaders/scene_vertex_blend.h +++ b/shaders/scene_vertex_blend.h @@ -101,6 +101,9 @@ static struct vg_shader _shader_scene_vertex_blend = { " int g_light_preview;\n" " int g_shadow_samples;\n" "\n" +" int g_debug_indices;\n" +" int g_debug_complexity;\n" +"\n" " // g_time ?\n" "\n" " //vec4 g_point_light_positions[32];\n" @@ -441,35 +444,57 @@ static struct vg_shader _shader_scene_vertex_blend = { " vec4 light_dir_1 = texelFetch( uLightsArray, light_indices.y*3+2 );\n" " vec4 light_dir_2 = texelFetch( uLightsArray, light_indices.z*3+2 );\n" "\n" -" //return vec3(fract(distance(light_co_0.xyz,aWorldCo)),\n" -" // fract(distance(light_co_1.xyz,aWorldCo)),\n" -" // fract(distance(light_co_2.xyz,aWorldCo)));\n" -"\n" -" // return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" -" // fract(light_indices.z * 0.125 ));\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_0.rgb,\n" -" light_co_0.xyz,\n" -" light_dir_0\n" -" ) * board_shadow;\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_1.rgb,\n" -" light_co_1.xyz,\n" -" light_dir_1\n" -" ) * board_shadow;\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_2.rgb,\n" -" light_co_2.xyz,\n" -" light_dir_2\n" -" ) * board_shadow;\n" +" if( g_debug_indices == 1 )\n" +" {\n" +" float rings = min( fract(distance(light_co_0.xyz,aWorldCo)),\n" +" min( fract(distance(light_co_1.xyz,aWorldCo)),\n" +" fract(distance(light_co_2.xyz,aWorldCo)) ) \n" +" );\n" +" \n" +" return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" +" fract(light_indices.z * 0.125 )) + (rings-0.5) * 0.25;\n" +" }\n" +"\n" +" if( g_debug_complexity == 1 )\n" +" {\n" +" return vec3(1.0,0.0,0.0) * ( light_indices.w/3.0 );\n" +" }\n" +"\n" +" if( light_indices.w >= 1 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_0.rgb,\n" +" light_co_0.xyz,\n" +" light_dir_0\n" +" ) * board_shadow \n" +" * step( world.day_phase, light_colour_0.w );\n" +"\n" +" if( light_indices.w >= 2 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_1.rgb,\n" +" light_co_1.xyz,\n" +" light_dir_1\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_1.w );\n" +"\n" +" if( light_indices.w >= 3 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_2.rgb,\n" +" light_co_2.xyz,\n" +" light_dir_2\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_2.w );\n" +" }\n" +" }\n" +" }\n" "\n" " vec3 fog_colour = scene_sky( -halfview, world );\n" " \n" diff --git a/shaders/scene_water.h b/shaders/scene_water.h index a6fa804..e9e052b 100644 --- a/shaders/scene_water.h +++ b/shaders/scene_water.h @@ -109,6 +109,9 @@ static struct vg_shader _shader_scene_water = { " int g_light_preview;\n" " int g_shadow_samples;\n" "\n" +" int g_debug_indices;\n" +" int g_debug_complexity;\n" +"\n" " // g_time ?\n" "\n" " //vec4 g_point_light_positions[32];\n" @@ -449,35 +452,57 @@ static struct vg_shader _shader_scene_water = { " vec4 light_dir_1 = texelFetch( uLightsArray, light_indices.y*3+2 );\n" " vec4 light_dir_2 = texelFetch( uLightsArray, light_indices.z*3+2 );\n" "\n" -" //return vec3(fract(distance(light_co_0.xyz,aWorldCo)),\n" -" // fract(distance(light_co_1.xyz,aWorldCo)),\n" -" // fract(distance(light_co_2.xyz,aWorldCo)));\n" -"\n" -" // return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" -" // fract(light_indices.z * 0.125 ));\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_0.rgb,\n" -" light_co_0.xyz,\n" -" light_dir_0\n" -" ) * board_shadow;\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_1.rgb,\n" -" light_co_1.xyz,\n" -" light_dir_1\n" -" ) * board_shadow;\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_2.rgb,\n" -" light_co_2.xyz,\n" -" light_dir_2\n" -" ) * board_shadow;\n" +" if( g_debug_indices == 1 )\n" +" {\n" +" float rings = min( fract(distance(light_co_0.xyz,aWorldCo)),\n" +" min( fract(distance(light_co_1.xyz,aWorldCo)),\n" +" fract(distance(light_co_2.xyz,aWorldCo)) ) \n" +" );\n" +" \n" +" return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" +" fract(light_indices.z * 0.125 )) + (rings-0.5) * 0.25;\n" +" }\n" +"\n" +" if( g_debug_complexity == 1 )\n" +" {\n" +" return vec3(1.0,0.0,0.0) * ( light_indices.w/3.0 );\n" +" }\n" +"\n" +" if( light_indices.w >= 1 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_0.rgb,\n" +" light_co_0.xyz,\n" +" light_dir_0\n" +" ) * board_shadow \n" +" * step( world.day_phase, light_colour_0.w );\n" +"\n" +" if( light_indices.w >= 2 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_1.rgb,\n" +" light_co_1.xyz,\n" +" light_dir_1\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_1.w );\n" +"\n" +" if( light_indices.w >= 3 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_2.rgb,\n" +" light_co_2.xyz,\n" +" light_dir_2\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_2.w );\n" +" }\n" +" }\n" +" }\n" "\n" " vec3 fog_colour = scene_sky( -halfview, world );\n" " \n" diff --git a/shaders/scene_water_fast.h b/shaders/scene_water_fast.h index 7708cac..bab38cd 100644 --- a/shaders/scene_water_fast.h +++ b/shaders/scene_water_fast.h @@ -106,6 +106,9 @@ static struct vg_shader _shader_scene_water_fast = { " int g_light_preview;\n" " int g_shadow_samples;\n" "\n" +" int g_debug_indices;\n" +" int g_debug_complexity;\n" +"\n" " // g_time ?\n" "\n" " //vec4 g_point_light_positions[32];\n" @@ -446,35 +449,57 @@ static struct vg_shader _shader_scene_water_fast = { " vec4 light_dir_1 = texelFetch( uLightsArray, light_indices.y*3+2 );\n" " vec4 light_dir_2 = texelFetch( uLightsArray, light_indices.z*3+2 );\n" "\n" -" //return vec3(fract(distance(light_co_0.xyz,aWorldCo)),\n" -" // fract(distance(light_co_1.xyz,aWorldCo)),\n" -" // fract(distance(light_co_2.xyz,aWorldCo)));\n" -"\n" -" // return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" -" // fract(light_indices.z * 0.125 ));\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_0.rgb,\n" -" light_co_0.xyz,\n" -" light_dir_0\n" -" ) * board_shadow;\n" -"\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_1.rgb,\n" -" light_co_1.xyz,\n" -" light_dir_1\n" -" ) * board_shadow;\n" -" total_light += newlight_compute_spot\n" -" ( \n" -" wnormal, halfview,\n" -" light_colour_2.rgb,\n" -" light_co_2.xyz,\n" -" light_dir_2\n" -" ) * board_shadow;\n" +" if( g_debug_indices == 1 )\n" +" {\n" +" float rings = min( fract(distance(light_co_0.xyz,aWorldCo)),\n" +" min( fract(distance(light_co_1.xyz,aWorldCo)),\n" +" fract(distance(light_co_2.xyz,aWorldCo)) ) \n" +" );\n" +" \n" +" return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n" +" fract(light_indices.z * 0.125 )) + (rings-0.5) * 0.25;\n" +" }\n" +"\n" +" if( g_debug_complexity == 1 )\n" +" {\n" +" return vec3(1.0,0.0,0.0) * ( light_indices.w/3.0 );\n" +" }\n" +"\n" +" if( light_indices.w >= 1 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_0.rgb,\n" +" light_co_0.xyz,\n" +" light_dir_0\n" +" ) * board_shadow \n" +" * step( world.day_phase, light_colour_0.w );\n" +"\n" +" if( light_indices.w >= 2 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_1.rgb,\n" +" light_co_1.xyz,\n" +" light_dir_1\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_1.w );\n" +"\n" +" if( light_indices.w >= 3 )\n" +" {\n" +" total_light += newlight_compute_spot\n" +" ( \n" +" wnormal, halfview,\n" +" light_colour_2.rgb,\n" +" light_co_2.xyz,\n" +" light_dir_2\n" +" ) * board_shadow\n" +" * step( world.day_phase, light_colour_2.w );\n" +" }\n" +" }\n" +" }\n" "\n" " vec3 fog_colour = scene_sky( -halfview, world );\n" " \n" diff --git a/world.h b/world.h index 3f806cb..ef93596 100644 --- a/world.h +++ b/world.h @@ -93,6 +93,9 @@ struct world_instance int g_light_preview; int g_shadow_samples; + int g_debug_indices; + int g_debug_complexity; + #if 0 v4f g_point_light_positions[32]; v4f g_point_light_colours[32]; @@ -625,6 +628,8 @@ VG_STATIC void world_update( world_instance *world, v3f pos ) g_time += vg.time_delta * (1.0/(k_day_length*60.0)); world->ub_lighting.g_time = g_time; + world->ub_lighting.g_debug_indices = k_debug_light_indices; + world->ub_lighting.g_debug_complexity = k_debug_light_complexity; glBindBuffer( GL_UNIFORM_BUFFER, world->ubo_lighting ); glBufferSubData( GL_UNIFORM_BUFFER, 0, @@ -734,7 +739,7 @@ VG_STATIC void world_update( world_instance *world, v3f pos ) 0xff00ff00 ); } - if( k_debug_light_index ) + if( k_debug_light_indices ) { for( int i=0; ilight_count; i++ ) { diff --git a/world_gen.h b/world_gen.h index b6c2f15..026701a 100644 --- a/world_gen.h +++ b/world_gen.h @@ -450,7 +450,7 @@ VG_STATIC float colour_luminance( v3f v ) } VG_STATIC float calc_light_influence( world_instance *world, v3f position, - v3f normal, int light ) + int light ) { struct world_light *world_light = &world->lights[ light ]; struct classtype_world_light *inf = world_light->inf; @@ -462,16 +462,15 @@ VG_STATIC float calc_light_influence( world_instance *world, v3f position, float quadratic = v3_dot( light_delta, light_delta ), attenuation = 1.0f/( 1.0f + quadratic ); - v3_normalize( light_delta ); - //attenuation *= vg_maxf( 0.0, v3_dot( light_delta, normal ) ); - float quadratic_light = attenuation * colour_luminance( inf->colour ); - if( inf->type == k_light_type_point ) + if( (inf->type == k_light_type_point) || + (inf->type == k_light_type_point_nighttime_only) ) { return quadratic_light; } - else if( inf->type == k_light_type_spot ) + else if( (inf->type == k_light_type_spot) || + (inf->type == k_light_type_spot_nighttime_only) ) { v3f dir; q_mulv( world_light->node->q, (v3f){0.0f,1.0f,0.0f}, dir ); @@ -494,31 +493,23 @@ VG_STATIC void world_scene_compute_light_clusters( world_instance *world, vert->lights[0] = 0; vert->lights[1] = 1; vert->lights[2] = 2; - vert->lights[3] = 3; - - float influences[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - - v3f co, norm; - v3_copy( vert->co, co ); + vert->lights[3] = 0; - norm[0] = vert->norm[0]; - norm[1] = vert->norm[1]; - norm[2] = vert->norm[2]; - - v3_muls( norm, 1.0f/127.0f, norm ); + float influences[3] = { 0.0f, 0.0f, 0.0f }; + const int N = vg_list_size( influences ); for( int j=0; jlight_count; j ++ ) { - float influence = calc_light_influence( world, co, norm, j ); + float influence = calc_light_influence( world, vert->co, j ); - int best_pos = 4; + int best_pos = N; for( int k=best_pos-1; k>=0; k -- ) if( influence > influences[k] ) best_pos = k; - if( best_pos < 4 ) + if( best_pos < N ) { - for( int k=3; k>best_pos; k -- ) + for( int k=N-1; k>best_pos; k -- ) { influences[k] = influences[k-1]; vert->lights[k] = vert->lights[k-1]; @@ -528,6 +519,12 @@ VG_STATIC void world_scene_compute_light_clusters( world_instance *world, vert->lights[best_pos] = j; } } + + for( int j=0; j 0.00000125f ) + vert->lights[3] ++ ; + } } } @@ -669,7 +666,17 @@ VG_STATIC void world_post_process( world_instance *world ) /* colour + night */ v3_muls( inf->colour, inf->colour[3] * 2.0f, light_dst[i*3+0] ); - light_dst[i*3+0][3] = 1.0f; + light_dst[i*3+0][3] = 0.0f; + + if( (inf->type == k_light_type_spot_nighttime_only) || + (inf->type == k_light_type_point_nighttime_only ) ) + { + u32 hash = (i * 29986577) & 0xff; + float switch_on = hash; + switch_on *= (1.0f/255.0f); + + light_dst[i*3+0][3] = 0.44f + switch_on * 0.015f; + } /* position + nothing */ v3_copy( light->node->co, light_dst[i*3+1] );