Skip to content

Commit b13af36

Browse files
committed
Add rasterize mesh texture demo
1 parent 819d201 commit b13af36

15 files changed

+581
-0
lines changed
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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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(set=0, binding=0) 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+
19+
#[fragment]
20+
#version 450
21+
22+
layout(location=0) in vec2 uv_interp;
23+
24+
layout(location=0) out vec4 frag_color;
25+
26+
layout(set=0, binding=1) uniform sampler2D tex;
27+
28+
void main() {
29+
frag_color = texture(tex, uv_interp);
30+
}
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=1
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=1
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
[gd_scene load_steps=15 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="Script" uid="uid://dhrhfhw6h8kqv" path="res://sprite_2d.gd" id="4_lquwl"]
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+
[node name="Node2D" type="Node2D"]
73+
74+
[node name="Prism" type="Sprite2D" parent="."]
75+
position = Vector2(573, 321)
76+
texture = SubResource("Texture2D_4c57u")
77+
script = ExtResource("4_lquwl")
78+
mesh_tex = SubResource("Texture2D_4c57u")
79+
80+
[node name="Torus" type="Sprite2D" parent="."]
81+
position = Vector2(898, 319)
82+
texture = SubResource("Texture2D_7mycd")
83+
script = ExtResource("4_lquwl")
84+
mesh_tex = SubResource("Texture2D_7mycd")
85+
86+
[node name="Quad" type="Sprite2D" parent="."]
87+
position = Vector2(252, 321)
88+
texture = SubResource("Texture2D_lquwl")
89+
script = ExtResource("4_lquwl")
90+
mesh_tex = SubResource("Texture2D_lquwl")
91+
92+
[node name="Text" type="Sprite2D" parent="."]
93+
position = Vector2(293, 89)
94+
texture = SubResource("Texture2D_272bh")
95+
script = ExtResource("4_lquwl")
96+
mesh_tex = SubResource("Texture2D_272bh")

0 commit comments

Comments
 (0)