Skip to content

Commit 3f037b4

Browse files
committed
Add rasterize mesh texture demo
1 parent 48aaefb commit 3f037b4

16 files changed

+639
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[gd_resource type="ArrayMesh" format=3 uid="uid://j7duroqwmiuw"]
2+
3+
[resource]
4+
_surfaces = [{
5+
"2d": true,
6+
"aabb": AABB(-64, -64, 0, 128, 128, 0),
7+
"attribute_data": PackedByteArray(51, 51, 118, 63, 0, 0, 0, 0, 0, 0, 32, 61, 0, 0, 0, 0, 205, 204, 204, 58, 0, 0, 32, 61, 0, 0, 0, 0, 102, 102, 121, 63, 154, 153, 249, 60, 0, 0, 128, 63, 51, 51, 119, 63, 0, 0, 128, 63, 205, 204, 127, 63, 0, 0, 118, 63, 0, 0, 128, 63, 205, 204, 204, 60),
8+
"format": 34393296913,
9+
"index_count": 18,
10+
"index_data": PackedByteArray(0, 0, 7, 0, 6, 0, 6, 0, 5, 0, 4, 0, 4, 0, 3, 0, 2, 0, 2, 0, 1, 0, 0, 0, 0, 0, 6, 0, 4, 0, 4, 0, 2, 0, 0, 0),
11+
"primitive": 3,
12+
"uv_scale": Vector4(0, 0, 0, 0),
13+
"vertex_count": 8,
14+
"vertex_data": PackedByteArray(102, 102, 108, 66, 0, 0, 128, 194, 0, 0, 108, 194, 0, 0, 128, 194, 51, 51, 127, 194, 0, 0, 108, 194, 0, 0, 128, 194, 204, 204, 114, 66, 102, 102, 112, 194, 0, 0, 128, 66, 102, 102, 110, 66, 0, 0, 128, 66, 154, 153, 127, 66, 0, 0, 108, 66, 0, 0, 128, 66, 51, 51, 115, 194)
15+
}]

rendering/mesh_texture_rd/3d.tscn

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[gd_scene load_steps=7 format=3 uid="uid://mx52oimcwqtn"]
2+
3+
[ext_resource type="Texture2D" uid="uid://bg8txxwsr4qn8" path="res://text_texture.tres" id="1_y2yqg"]
4+
5+
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_y2yqg"]
6+
sky_horizon_color = Color(0.66224277, 0.6717428, 0.6867428, 1)
7+
ground_horizon_color = Color(0.66224277, 0.6717428, 0.6867428, 1)
8+
9+
[sub_resource type="Sky" id="Sky_fji6l"]
10+
sky_material = SubResource("ProceduralSkyMaterial_y2yqg")
11+
12+
[sub_resource type="Environment" id="Environment_73ytm"]
13+
background_mode = 2
14+
sky = SubResource("Sky_fji6l")
15+
tonemap_mode = 2
16+
glow_enabled = true
17+
18+
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_y2yqg"]
19+
transparency = 1
20+
shading_mode = 0
21+
albedo_texture = ExtResource("1_y2yqg")
22+
23+
[sub_resource type="BoxMesh" id="BoxMesh_p1i0w"]
24+
25+
[node name="3d" type="Node3D"]
26+
27+
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
28+
environment = SubResource("Environment_73ytm")
29+
30+
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
31+
transform = Transform3D(-0.8660254, -0.43301278, 0.25, 0, 0.49999997, 0.86602545, -0.50000006, 0.75, -0.43301266, 0, 0, 0)
32+
shadow_enabled = true
33+
34+
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
35+
material_override = SubResource("StandardMaterial3D_y2yqg")
36+
mesh = SubResource("BoxMesh_p1i0w")
37+
38+
[node name="Camera3D" type="Camera3D" parent="."]
39+
transform = Transform3D(0.7071068, 0.5, -0.5, 0, 0.7071068, 0.70710677, 0.7071068, -0.5, 0.5, -1, 1, 1)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Rasterize Mesh Texture
2+
3+
This is a demo showing how to set up a basic render pipeline to draw mesh to texture using RenderingDevice.
4+
5+
Language: GDScript
6+
7+
Renderer: Mobile
8+
9+
## Screenshots
10+
11+
![Screenshot](screenshots/rasterize_mesh_texture.webp)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#[vertex]
2+
#version 450
3+
4+
layout(location = 0) in vec3 position;
5+
layout(location = 1) in vec2 uv;
6+
7+
layout(location = 0) out vec2 uv_interp;
8+
9+
layout(push_constant) uniform Data {
10+
mat4 xform;
11+
};
12+
13+
void main() {
14+
uv_interp = uv;
15+
gl_Position = xform * vec4(position, 1.0);
16+
}
17+
18+
#[fragment]
19+
#version 450
20+
21+
layout(location = 0) in vec2 uv_interp;
22+
23+
layout(location = 0) out vec4 frag_color;
24+
25+
layout(set = 0, binding = 0) uniform sampler2D tex;
26+
27+
void main() {
28+
frag_color = texture(tex, uv_interp);
29+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[remap]
2+
3+
importer="glsl"
4+
type="RDShaderFile"
5+
uid="uid://bsbaafha2qt2x"
6+
path="res://.godot/imported/base_texture.glsl-7668889287fcd72a7484b036a760efd0.res"
7+
8+
[deps]
9+
10+
source_file="res://base_texture.glsl"
11+
dest_files=["res://.godot/imported/base_texture.glsl-7668889287fcd72a7484b036a760efd0.res"]
12+
13+
[params]
14+
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://crm65s53yy1n6"
6+
path="res://.godot/imported/godot_icon.svg-7b3f4db08ef4bccb8acaa5db9e9fe760.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://godot_icon.svg"
14+
dest_files=["res://.godot/imported/godot_icon.svg-7b3f4db08ef4bccb8acaa5db9e9fe760.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/uastc_level=0
22+
compress/rdo_quality_loss=0.0
23+
compress/hdr_compression=1
24+
compress/normal_map=0
25+
compress/channel_pack=0
26+
mipmaps/generate=false
27+
mipmaps/limit=-1
28+
roughness/mode=0
29+
roughness/src_normal=""
30+
process/fix_alpha_border=true
31+
process/premult_alpha=false
32+
process/normal_map_invert_y=false
33+
process/hdr_as_srgb=false
34+
process/hdr_clamp_exposure=false
35+
process/size_limit=0
36+
process/resolution_scale=1.0
37+
detect_3d/compress_to=0
38+
svg/scale=1.0
39+
editor/scale_with_editor_scale=false
40+
editor/convert_colors_with_editor_theme=false
3.72 KB
Loading
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://b1ukde136ayme"
6+
path="res://.godot/imported/icon.webp-e94f9a68b0f625a567a797079e4d325f.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://icon.webp"
14+
dest_files=["res://.godot/imported/icon.webp-e94f9a68b0f625a567a797079e4d325f.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/uastc_level=0
22+
compress/rdo_quality_loss=0.0
23+
compress/hdr_compression=1
24+
compress/normal_map=0
25+
compress/channel_pack=0
26+
mipmaps/generate=false
27+
mipmaps/limit=-1
28+
roughness/mode=0
29+
roughness/src_normal=""
30+
process/fix_alpha_border=true
31+
process/premult_alpha=false
32+
process/normal_map_invert_y=false
33+
process/hdr_as_srgb=false
34+
process/hdr_clamp_exposure=false
35+
process/size_limit=0
36+
process/resolution_scale=1.0
37+
detect_3d/compress_to=0
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
[gd_scene load_steps=14 format=3 uid="uid://cnk1inmvelj4x"]
2+
3+
[ext_resource type="Texture2D" uid="uid://crm65s53yy1n6" path="res://godot_icon.svg" id="1_7mycd"]
4+
[ext_resource type="RDShaderFile" uid="uid://bsbaafha2qt2x" path="res://base_texture.glsl" id="2_7mycd"]
5+
[ext_resource type="Script" uid="uid://cdfq6x7v36k1e" path="res://mesh_texture_rd.gd" id="3_5vw27"]
6+
[ext_resource type="ArrayMesh" uid="uid://j7duroqwmiuw" path="res://2d_array_mesh.tres" id="4_1bvp3"]
7+
[ext_resource type="Texture2D" uid="uid://bg8txxwsr4qn8" path="res://text_texture.tres" id="4_lquwl"]
8+
[ext_resource type="PackedScene" uid="uid://mx52oimcwqtn" path="res://3d.tscn" id="6_7mycd"]
9+
10+
[sub_resource type="PrismMesh" id="PrismMesh_kek77"]
11+
12+
[sub_resource type="Texture2D" id="Texture2D_5vw27"]
13+
resource_local_to_scene = false
14+
resource_name = ""
15+
script = ExtResource("3_5vw27")
16+
clear_color = Color(0.412266, 0.447241, 0.735728, 1)
17+
mesh = SubResource("PrismMesh_kek77")
18+
base_texture = ExtResource("1_7mycd")
19+
projection = Projection(-0.6, -1.3, 0, 0, 1.1, -1.67, 0, 0, -0.76, 0, -1.2, 0, 0, -0.26, 0, 1.36)
20+
21+
[sub_resource type="TorusMesh" id="TorusMesh_lquwl"]
22+
23+
[sub_resource type="Texture2D" id="Texture2D_7mycd"]
24+
resource_local_to_scene = false
25+
resource_name = ""
26+
script = ExtResource("3_5vw27")
27+
clear_color = Color(0.271125, 0.510188, 0.620698, 1)
28+
mesh = SubResource("TorusMesh_lquwl")
29+
base_texture = ExtResource("1_7mycd")
30+
projection = Projection(-0.7, -0.92, 0.5, 0, 0.25, -1.5, 0.32, 0, 1.43, -0.14, 0.48, 0.14, 0.1, 0.02, 0.75, 1.85)
31+
metadata/_custom_type_script = "uid://delyovxoqvijt"
32+
33+
[sub_resource type="QuadMesh" id="QuadMesh_1bvp3"]
34+
35+
[sub_resource type="Texture2D" id="Texture2D_lquwl"]
36+
resource_local_to_scene = false
37+
resource_name = ""
38+
script = ExtResource("3_5vw27")
39+
clear_color = Color(0.572798, 0.384286, 0.683792, 0.337255)
40+
mesh = SubResource("QuadMesh_1bvp3")
41+
base_texture = ExtResource("1_7mycd")
42+
projection = Projection(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
43+
metadata/_custom_type_script = "uid://delyovxoqvijt"
44+
45+
[sub_resource type="Texture2D" id="Texture2D_272bh"]
46+
resource_local_to_scene = false
47+
resource_name = ""
48+
script = ExtResource("3_5vw27")
49+
mesh = ExtResource("4_1bvp3")
50+
base_texture = ExtResource("1_7mycd")
51+
projection = Projection(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 100)
52+
metadata/_custom_type_script = "uid://cdfq6x7v36k1e"
53+
54+
[node name="Node2D" type="Node2D"]
55+
56+
[node name="Prism" type="Sprite2D" parent="."]
57+
position = Vector2(573, 321)
58+
texture = SubResource("Texture2D_5vw27")
59+
60+
[node name="Torus" type="Sprite2D" parent="."]
61+
position = Vector2(898, 319)
62+
texture = SubResource("Texture2D_7mycd")
63+
64+
[node name="Quad" type="Sprite2D" parent="."]
65+
position = Vector2(252, 321)
66+
texture = SubResource("Texture2D_lquwl")
67+
68+
[node name="Text" type="Sprite2D" parent="."]
69+
position = Vector2(293, 89)
70+
texture = ExtResource("4_lquwl")
71+
72+
[node name="3d" parent="." instance=ExtResource("6_7mycd")]
73+
74+
[node name="2DMesh" type="Sprite2D" parent="."]
75+
position = Vector2(244, 797)
76+
texture = SubResource("Texture2D_272bh")

0 commit comments

Comments
 (0)