-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
[gd_scene load_steps=6 format=3 uid="uid://b3bej4wl0tvj0"] | ||
|
||
[ext_resource type="Script" path="res://COGITO/Assets/Shader/ShaderPrecompiler.gd" id="1_5rykf"] | ||
|
||
[sub_resource type="QuadMesh" id="QuadMesh_8skhu"] | ||
size = Vector2(0, 0) | ||
|
||
[sub_resource type="ViewportTexture" id="ViewportTexture_dghy8"] | ||
viewport_path = NodePath("SubViewport") | ||
|
||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_k37ri"] | ||
resource_local_to_scene = true | ||
albedo_texture = SubResource("ViewportTexture_dghy8") | ||
|
||
[sub_resource type="QuadMesh" id="QuadMesh_upqev"] | ||
|
||
[node name="ShaderCache" type="MeshInstance3D"] | ||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1) | ||
mesh = SubResource("QuadMesh_8skhu") | ||
surface_material_override/0 = SubResource("StandardMaterial3D_k37ri") | ||
script = ExtResource("1_5rykf") | ||
|
||
[node name="SubViewport" type="SubViewport" parent="."] | ||
|
||
[node name="QuadRender" type="MeshInstance3D" parent="SubViewport"] | ||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -20, 0) | ||
layers = 262144 | ||
mesh = SubResource("QuadMesh_upqev") | ||
skeleton = NodePath("../..") | ||
|
||
[node name="VisibleOnScreenNotifier3D" type="VisibleOnScreenNotifier3D" parent="SubViewport"] | ||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -20, 0) | ||
layers = 262144 | ||
aabb = AABB(-0.5, 0, -1, 1, 1, 2) | ||
|
||
[node name="Camera3D" type="Camera3D" parent="SubViewport"] | ||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -20, 0) | ||
cull_mask = 262144 | ||
current = true | ||
|
||
[connection signal="screen_entered" from="SubViewport/VisibleOnScreenNotifier3D" to="." method="_on_visible_on_screen_notifier_3d_screen_entered"] | ||
[connection signal="screen_exited" from="SubViewport/VisibleOnScreenNotifier3D" to="." method="_on_visible_on_screen_notifier_3d_screen_exited"] | ||
[connection signal="tree_exiting" from="SubViewport/VisibleOnScreenNotifier3D" to="." method="_on_visible_on_screen_notifier_3d_tree_exiting"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
extends Node3D | ||
class_name ShaderPrecompiler | ||
|
||
static var scene = preload("./ShaderLoader.tscn") | ||
static var shader_compiler_scene = null | ||
static var quad = null | ||
|
||
var materials : Array[ShaderMaterial] | ||
|
||
const placement = Vector3.ONE*9999 | ||
const SHADER_LAYER = 19 | ||
|
||
var is_rendering : bool = false # debugging | ||
static var queued = false | ||
|
||
# UNKNOWN: MultimeshInstances? Particles? | ||
static func precompile(tree : SceneTree, shader : ShaderMaterial): | ||
if shader_compiler_scene == null: | ||
shader_compiler_scene = scene.instantiate() | ||
tree.root.get_camera_3d().add_child(shader_compiler_scene) | ||
quad = shader_compiler_scene.get_node("./SubViewport/QuadRender") | ||
|
||
shader_compiler_scene.materials.push_back(shader) | ||
if not queued: | ||
queued = true | ||
|
||
func _process(delta): | ||
if not queued: | ||
return | ||
if len(shader_compiler_scene.materials) == 0: | ||
queued = false | ||
shader_compiler_scene.queue_free() | ||
else: | ||
var mat = shader_compiler_scene.materials.pop_back() | ||
print(mat) | ||
shader_compiler_scene.material_override = mat | ||
|
||
func _on_visible_on_screen_notifier_3d_screen_entered(): | ||
is_rendering = true | ||
|
||
func _on_visible_on_screen_notifier_3d_screen_exited(): | ||
is_rendering = false | ||
|
||
|
||
func _on_visible_on_screen_notifier_3d_tree_exiting(): | ||
if shader_compiler_scene == self: | ||
shader_compiler_scene = null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters