diff --git a/NOTES.md b/NOTES.md index 421c7f7..b853db5 100644 --- a/NOTES.md +++ b/NOTES.md @@ -29,3 +29,11 @@ venkovního úhlu. Protože reálně jsem od něj mega daleko, takže portálov - Tohle platí hlavně u ~~free-standing~~ portálů na které jde koukat z obou stran. *Bylo by divné kdyby byl zezadu portálu ve vzduchu light source jenom proto, že na druhé straně portálu (bůh ví kde) takový source někde je* - Free-standing portál neni uplně dobrý příklad, protože by to světlo mělo házet _výseč_ ven. To ničím fajné, to jsme zpátky u raytracingu. Leda by to člověk oblbnul nějakým shadow meshem nebo něco.. hm. Velmi specifické. Ale u těch dveří jako v semaforovém levelu by to fungovalo asi v pohodě, protože kolem futer je stěna. - Spotlight..? + +### Procedural mesh + +- Normály jsou pass. Mám jenom 8 vertexů, takže to bude dycky vypadat blbě. Ale portály jsou stejně vždycky unshaded. + - Zmínit v DP! Docela dobrý sell, obhajoba rozhodnutí. +- Když se na portál podívám přímo zepředu (ortogonálně), tak ten indent není vubec vidět. Nejsem si jistý jestli to je k něčemu.. ten portálový mesh který jsem vzal z _simple portal sytem_ ani žádné UV coodinates nemá. + +![portal-uv-coordinates](assets/portal-uv-coordinates.png) diff --git a/assets/.gdignore b/assets/.gdignore new file mode 100644 index 0000000..e69de29 diff --git a/assets/portal-uv-coordinates.png b/assets/portal-uv-coordinates.png new file mode 100644 index 0000000..132b6ea Binary files /dev/null and b/assets/portal-uv-coordinates.png differ diff --git a/levels/test_procedural_portal.tscn b/levels/test_procedural_portal.tscn index ae003c4..4c3614a 100644 --- a/levels/test_procedural_portal.tscn +++ b/levels/test_procedural_portal.tscn @@ -1,24 +1,22 @@ -[gd_scene load_steps=9 format=4 uid="uid://c0ieh1abu1xne"] +[gd_scene load_steps=8 format=4 uid="uid://c0ieh1abu1xne"] -[ext_resource type="Texture2D" uid="uid://c8nq55glypfp8" path="res://addons/kenney_prototype_tools/textures/light/texture_07.png" id="1_dn1le"] +[ext_resource type="Material" uid="uid://bv36triwinl2f" path="res://textures/uv-checker-material.tres" id="1_dn1le"] [ext_resource type="Script" uid="uid://d2bvvjsibau8c" path="res://addons/simple-portal-system/scripts/portal.gd" id="1_ksg6r"] [ext_resource type="PackedScene" uid="uid://d1dtxvwk86ple" path="res://procedural_mesh_maker.tscn" id="2_4vena"] -[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_dn1le"] -albedo_texture = ExtResource("1_dn1le") - -[sub_resource type="ArrayMesh" id="ArrayMesh_4vena"] +[sub_resource type="ArrayMesh" id="ArrayMesh_1w8eh"] _surfaces = [{ -"aabb": AABB(-1, -1.3, -0.1, 2, 2.6, 0.1), -"attribute_data": PackedByteArray("AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AACAPwAAgD/NzMw9zczMPWZmZj/NzMw9zczMPWZmZj9mZmY/ZmZmPw=="), +"aabb": AABB(-1, -1.3, -0.133, 2, 2.6, 0.133), +"attribute_data": PackedByteArray("AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AACAPwAAgD8nMYg9soZRPdv5bj+yhlE9JzGIPZXncj/b+W4/ledyPw=="), "format": 34359742487, "index_count": 30, "index_data": PackedByteArray("AAABAAQABAABAAUAAQADAAUABQADAAcAAwACAAcABwACAAYAAgAAAAYABgAAAAQABAAFAAYABgAFAAcA"), -"material": SubResource("StandardMaterial3D_dn1le"), +"material": ExtResource("1_dn1le"), +"name": "Portal Material", "primitive": 3, "uv_scale": Vector4(0, 0, 0, 0), "vertex_count": 8, -"vertex_data": PackedByteArray("AACAv2Zmpj8AAAAAAACAP2Zmpj8AAAAAAACAv2Zmpr8AAAAAAACAP2Zmpr8AAAAAZmZmv5mZmT/NzMy9ZmZmP5mZmT/NzMy9ZmZmv5mZmb/NzMy9ZmZmP5mZmb/NzMy9/3//f/9/AID/f/9//38AgP9//3//fwCA/3//f/9/AID/f/9//38AgP9//3//fwCA/3//f/9/AID/f/9//38AgA==") +"vertex_data": PackedByteArray("AACAv2Zmpj8AAAAAAACAP2Zmpj8AAAAAAACAv2Zmpr8AAAAAAACAP2Zmpr8AAAAAtvNdv0FglT8nMQi+tvNdP0FglT8nMQi+tvNdv0Fglb8nMQi+tvNdP0Fglb8nMQi+/3//f/9/AID/f/9//38AgP9//3//fwCA/3//f/9/AID/f/9//38AgP9//3//fwCA/3//f/9/AID/f/9//38AgA==") }] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_82kw5"] @@ -58,18 +56,18 @@ shadow_mesh = SubResource("ArrayMesh_dn1le") [node name="ProceduralPortal" type="Node3D"] [node name="MeshInstance3D" type="MeshInstance3D" parent="."] -mesh = SubResource("ArrayMesh_4vena") +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 7.4625e-05, -0.0007523, 0.000824571) +mesh = SubResource("ArrayMesh_1w8eh") script = ExtResource("1_ksg6r") [node name="ProceduralMeshMaker" parent="." node_paths=PackedStringArray("portal") instance=ExtResource("2_4vena")] height = 2.6 width = 2.0 +indent = 0.133 portal = NodePath("../MeshInstance3D") [node name="OmniLight3D" type="OmniLight3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.52963, 0, 1.51112) -light_color = Color(5.0056e-06, 0.824088, 0.326623, 1) -light_energy = 2.0 metadata/_edit_lock_ = true [node name="OfficialPortal" type="MeshInstance3D" parent="."] diff --git a/procedural_mesh_maker.gd b/procedural_mesh_maker.gd index f78eaf3..e4bb220 100644 --- a/procedural_mesh_maker.gd +++ b/procedural_mesh_maker.gd @@ -8,6 +8,8 @@ extends Node @export var portal: Portal +const UV_CHECKER_MATERIAL = preload("res://textures/uv-checker-material.tres") + func _add_inspector_buttons() -> Array: var buttons = [] @@ -36,8 +38,9 @@ func generate_portal_mesh() -> void: return if portal.mesh != null: - push_warning("The portal %s already has a mesh!" % portal.name) - return + push_warning("The portal %s already has a mesh! Replacing." % portal.name) + portal.mesh = null + var mesh = ArrayMesh.new() print("[PMM] Creating mesh") @@ -53,7 +56,7 @@ func generate_portal_mesh() -> void: # Just to save some chars var w = width / 2 var h = height / 2 - var i = indent + # Outside rect var TOP_LEFT = Vector3(-w, h, 0) @@ -71,9 +74,11 @@ func generate_portal_mesh() -> void: INDENT_TL, INDENT_TR, INDENT_BL, INDENT_BR ]) + var ix = indent / width + var iy = indent / height uvs.append_array([ Vector2(0, 0), Vector2(1, 0), Vector2(0, 1), Vector2(1, 1), # Outside UVs - Vector2(i, i), Vector2(1-i, i), Vector2(i, 1-i), Vector2(1-i, 1-i) # Indented UVs + Vector2(ix, iy), Vector2(1-ix, iy), Vector2(ix, 1-iy), Vector2(1-ix, 1-iy) # Indented UVs ]) # We are going for a flat-surface look here. Portals should be unshaded anyways. @@ -104,7 +109,7 @@ func generate_portal_mesh() -> void: 6, 0, 4, # left section done 4, 5, 6, - 6, 5, 7 # middle done + 6, 5, 7, # middle sectiondone ]) surface_array[Mesh.ARRAY_VERTEX] = verts @@ -112,7 +117,9 @@ func generate_portal_mesh() -> void: surface_array[Mesh.ARRAY_NORMAL] = normals surface_array[Mesh.ARRAY_INDEX] = indices - # No blendshapes, lods, or compression used. + # TODO: Shadow mesh maybe? Should a portal even cast a shadow? mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, surface_array) + mesh.surface_set_material(0, UV_CHECKER_MATERIAL) + mesh.surface_set_name(0, "Portal Material") portal.mesh = mesh print("[PMM] Mesh assigned") diff --git a/textures/uv-checker-material.tres b/textures/uv-checker-material.tres new file mode 100644 index 0000000..ac10108 --- /dev/null +++ b/textures/uv-checker-material.tres @@ -0,0 +1,7 @@ +[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://bv36triwinl2f"] + +[ext_resource type="Texture2D" uid="uid://ya8afistbdec" path="res://textures/uv-checker.png" id="1_xdbe0"] + +[resource] +shading_mode = 0 +albedo_texture = ExtResource("1_xdbe0") diff --git a/textures/uv-checker.png b/textures/uv-checker.png new file mode 100644 index 0000000..42ac905 Binary files /dev/null and b/textures/uv-checker.png differ diff --git a/textures/uv-checker.png.import b/textures/uv-checker.png.import new file mode 100644 index 0000000..a0631c6 --- /dev/null +++ b/textures/uv-checker.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ya8afistbdec" +path.s3tc="res://.godot/imported/uv-checker.png-26b18af46d2dfdb0ee67624bb4da1f2d.s3tc.ctex" +metadata={ +"imported_formats": ["s3tc_bptc"], +"vram_texture": true +} + +[deps] + +source_file="res://textures/uv-checker.png" +dest_files=["res://.godot/imported/uv-checker.png-26b18af46d2dfdb0ee67624bb4da1f2d.s3tc.ctex"] + +[params] + +compress/mode=2 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=true +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=0