Skip to content

Commit 4f66c12

Browse files
committed
Add rasterize mesh texture demo
1 parent 9456158 commit 4f66c12

File tree

14 files changed

+573
-0
lines changed

14 files changed

+573
-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+
}]
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 setup 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: 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://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/hdr_compression=1
22+
compress/normal_map=0
23+
compress/channel_pack=0
24+
mipmaps/generate=false
25+
mipmaps/limit=-1
26+
roughness/mode=0
27+
roughness/src_normal=""
28+
process/fix_alpha_border=true
29+
process/premult_alpha=false
30+
process/normal_map_invert_y=false
31+
process/hdr_as_srgb=false
32+
process/hdr_clamp_exposure=false
33+
process/size_limit=0
34+
detect_3d/compress_to=0
35+
svg/scale=1.0
36+
editor/scale_with_editor_scale=false
37+
editor/convert_colors_with_editor_theme=false
3.72 KB
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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/hdr_compression=1
22+
compress/normal_map=0
23+
compress/channel_pack=0
24+
mipmaps/generate=false
25+
mipmaps/limit=-1
26+
roughness/mode=0
27+
roughness/src_normal=""
28+
process/fix_alpha_border=true
29+
process/premult_alpha=false
30+
process/normal_map_invert_y=false
31+
process/hdr_as_srgb=false
32+
process/hdr_clamp_exposure=false
33+
process/size_limit=0
34+
detect_3d/compress_to=0
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
[gd_scene load_steps=16 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_272bh"]
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+
8+
[sub_resource type="PrismMesh" id="PrismMesh_kek77"]
9+
10+
[sub_resource type="Texture2D" id="Texture2D_4c57u"]
11+
resource_local_to_scene = false
12+
resource_name = ""
13+
script = ExtResource("3_5vw27")
14+
size = Vector2i(256, 256)
15+
clear_color = Color(0.412266, 0.447241, 0.735728, 1)
16+
mesh = SubResource("PrismMesh_kek77")
17+
base_texture = ExtResource("1_7mycd")
18+
projection = Projection(-0.605, -1.285, 0, 0, 1.09, -1.67, 0.11, 0, 0.755, 0.035, 1.2, 0, 0.025, -0.26, 0, 1.355)
19+
glsl_file = ExtResource("2_272bh")
20+
metadata/_custom_type_script = "uid://delyovxoqvijt"
21+
22+
[sub_resource type="TorusMesh" id="TorusMesh_lquwl"]
23+
24+
[sub_resource type="Texture2D" id="Texture2D_7mycd"]
25+
resource_local_to_scene = false
26+
resource_name = ""
27+
script = ExtResource("3_5vw27")
28+
size = Vector2i(256, 256)
29+
clear_color = Color(0.271125, 0.510188, 0.620698, 1)
30+
mesh = SubResource("TorusMesh_lquwl")
31+
base_texture = ExtResource("1_7mycd")
32+
projection = Projection(-0.71, -0.91, 0.5, 0.01, 0.25, 1.53, 0.315, 0, 1.43, -0.135, 0.48, 0.14, 0.085, 0.02, 0.75, 1.845)
33+
glsl_file = ExtResource("2_272bh")
34+
metadata/_custom_type_script = "uid://delyovxoqvijt"
35+
36+
[sub_resource type="QuadMesh" id="QuadMesh_1bvp3"]
37+
38+
[sub_resource type="Texture2D" id="Texture2D_lquwl"]
39+
resource_local_to_scene = false
40+
resource_name = ""
41+
script = ExtResource("3_5vw27")
42+
size = Vector2i(256, 256)
43+
clear_color = Color(0.572798, 0.384286, 0.683792, 0.337255)
44+
mesh = SubResource("QuadMesh_1bvp3")
45+
base_texture = ExtResource("1_7mycd")
46+
projection = Projection(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
47+
glsl_file = ExtResource("2_272bh")
48+
metadata/_custom_type_script = "uid://delyovxoqvijt"
49+
50+
[sub_resource type="Gradient" id="Gradient_1bvp3"]
51+
interpolation_color_space = 2
52+
colors = PackedColorArray(0.692862, 0.522376, 0.466238, 1, 0.634748, 0.521037, 0.665456, 1)
53+
54+
[sub_resource type="GradientTexture2D" id="GradientTexture2D_lquwl"]
55+
gradient = SubResource("Gradient_1bvp3")
56+
57+
[sub_resource type="TextMesh" id="TextMesh_7mycd"]
58+
text = "Rasterize Mesh Texture"
59+
60+
[sub_resource type="Texture2D" id="Texture2D_272bh"]
61+
resource_local_to_scene = false
62+
resource_name = ""
63+
script = ExtResource("3_5vw27")
64+
size = Vector2i(552, 131)
65+
clear_color = Color(1, 1, 1, 0)
66+
mesh = SubResource("TextMesh_7mycd")
67+
base_texture = SubResource("GradientTexture2D_lquwl")
68+
projection = Projection(1.095, 0, 0, 0, 0, -5.53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
69+
glsl_file = ExtResource("2_272bh")
70+
metadata/_custom_type_script = "uid://cdfq6x7v36k1e"
71+
72+
[sub_resource type="Texture2D" id="Texture2D_1bvp3"]
73+
resource_local_to_scene = false
74+
resource_name = ""
75+
script = ExtResource("3_5vw27")
76+
size = Vector2i(256, 256)
77+
clear_color = Color(1, 1, 1, 0)
78+
mesh = ExtResource("4_1bvp3")
79+
base_texture = ExtResource("1_7mycd")
80+
projection = Projection(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
81+
glsl_file = ExtResource("2_272bh")
82+
metadata/_custom_type_script = "uid://cdfq6x7v36k1e"
83+
84+
[node name="Node2D" type="Node2D"]
85+
86+
[node name="Prism" type="Sprite2D" parent="."]
87+
position = Vector2(573, 321)
88+
texture = SubResource("Texture2D_4c57u")
89+
90+
[node name="Torus" type="Sprite2D" parent="."]
91+
position = Vector2(898, 319)
92+
texture = SubResource("Texture2D_7mycd")
93+
94+
[node name="Quad" type="Sprite2D" parent="."]
95+
position = Vector2(252, 321)
96+
texture = SubResource("Texture2D_lquwl")
97+
98+
[node name="Text" type="Sprite2D" parent="."]
99+
position = Vector2(293, 89)
100+
texture = SubResource("Texture2D_272bh")
101+
102+
[node name="2DMesh" type="Sprite2D" parent="."]
103+
position = Vector2(-157, 325)
104+
texture = SubResource("Texture2D_1bvp3")

0 commit comments

Comments
 (0)