diff options
author | mikatomik <mikec_2007@hotmail.com> | 2022-07-19 07:24:13 -0400 |
---|---|---|
committer | mikatomik <mikec_2007@hotmail.com> | 2022-08-27 08:09:41 -0400 |
commit | ff5e9214e671af7a7c7c238207e5d6086eba2936 (patch) | |
tree | edd30e28055535583ebb07825b1c8b34e203f161 /utility_scripts | |
parent | 44e739bb05542d1249ccf8388bd15b3f0b052e0c (diff) | |
download | project-s-ff5e9214e671af7a7c7c238207e5d6086eba2936.tar.gz project-s-ff5e9214e671af7a7c7c238207e5d6086eba2936.zip |
Add generic testing map
Initial version of shipyard map implemented for testing.
Base_char mesh and goo-gun meshes property "use in baked light"
set to true during experiment with GI probes for global illumination.
Label added to view model to display in-game FPS.
Main camera "far" property turned up to 500 so the whole
map can be drawn.
General purpose liquid shader added for use as water
in shipyard_map.
World default environment updated for visual quality.
Shader_Compiler.gd implemented to combat stuttering when
compiling shaders on the fly. This may be obsolete with
the release of Godot 3.5 that introduced async compilation.
Signed-off-by: mikatomik <mikec_2007@hotmail.com>
Diffstat (limited to '')
-rw-r--r-- | utility_scripts/shader_compiler.gd | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/utility_scripts/shader_compiler.gd b/utility_scripts/shader_compiler.gd new file mode 100644 index 0000000..7ef6104 --- /dev/null +++ b/utility_scripts/shader_compiler.gd @@ -0,0 +1,78 @@ +extends Spatial + +#This script loops through all the nodes in the scene, finds their materials, +#then adds them to a generated quad mesh to force all shaders to be compiled. +#Once they are all compiled, the node emits a signal saying it's done and frees itself. + +#This is to prevent frame stutter when compiling shaders mid-game. +#If you need to compile a material that is not present +#when the scene loads (i.e. instanced nodes) add a copy of their .tscn as a child of +#this node in the scene window. + +#This spatial node must be placed somewhere within the camera's frustum. It does not have +#to be directly visible, it can be under a floor or behind a wall, as long as it stays +#within the camera frustum bounds for the amount of frames specified below. + +signal all_shaders_compiled + +const num_frames = 10 #How many frames the script runs for. +var found_materials = [] +var found_particles = [] +var counter = 0 + + +func _ready(): + compile_shaders(get_tree().root) + +func _process(_delta): + counter += 1 + if counter >= num_frames: + emit_signal("all_shaders_compiled") + queue_free() + +func compile_shaders(scene): + for child in scene.get_children(): + if child is MeshInstance: + for i in range(child.get_surface_material_count()): + var mat = child.get_surface_material(i) + if mat == null: + mat = child.mesh.surface_get_material(i) + if mat == null: + print("Error: No material assigned to " + str(child.name) + ". Could not compile.") + + if is_instance_valid(mat): + if not mat in found_materials: + generate_quad(mat) + found_materials.append(mat) + + if child is Particles: + var particle = child as Particles + var particle_mat = particle.get_process_material() + + if particle_mat == null: + print("Error: No process material assigned to " + str(child.name) + ". Could not compile.") + + if is_instance_valid(particle_mat): + if not particle_mat in found_particles: + var particles_to_compile = particle.duplicate() + duplicate_particles(particles_to_compile) + found_particles.append(particle_mat) + + compile_shaders(child) + + +func generate_quad(material): + var quad = QuadMesh.new() + var mesh = MeshInstance.new() + mesh.mesh = quad + mesh.set_surface_material(0, material) + add_child(mesh) + + mesh.global_transform.origin.x += randf() * 0.5 + mesh.global_transform.origin.y += randf() * 0.5 + mesh.global_transform.origin.z += randf() * 0.5 + +func duplicate_particles(particle_node): + particle_node.translation = self.translation + particle_node.rotation = Vector3.ZERO + add_child(particle_node) |