Skip to content

Commit e967b85

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

16 files changed

+671
-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: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
[gd_scene load_steps=8 format=3 uid="uid://mx52oimcwqtn"]
2+
3+
[ext_resource type="Texture2D" uid="uid://reux267ue6un" path="res://tex.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="Shader" id="Shader_y2yqg"]
19+
code = "// NOTE: Shader automatically converted from Godot Engine 4.5.beta's StandardMaterial3D.
20+
21+
shader_type spatial;
22+
render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_burley, specular_schlick_ggx, unshaded;
23+
24+
uniform vec4 albedo : source_color;
25+
uniform sampler2D texture_albedo : source_color, filter_linear_mipmap, repeat_enable;
26+
uniform ivec2 albedo_texture_size;
27+
uniform float point_size : hint_range(0.1, 128.0, 0.1);
28+
29+
uniform float roughness : hint_range(0.0, 1.0);
30+
uniform sampler2D texture_metallic : hint_default_white, filter_linear_mipmap, repeat_enable;
31+
uniform vec4 metallic_texture_channel;
32+
uniform sampler2D texture_roughness : hint_roughness_r, filter_linear_mipmap, repeat_enable;
33+
34+
uniform float specular : hint_range(0.0, 1.0, 0.01);
35+
uniform float metallic : hint_range(0.0, 1.0, 0.01);
36+
37+
uniform vec3 uv1_scale;
38+
uniform vec3 uv1_offset;
39+
uniform vec3 uv2_scale;
40+
uniform vec3 uv2_offset;
41+
42+
void vertex() {
43+
UV = UV * uv1_scale.xy + uv1_offset.xy;
44+
}
45+
46+
void fragment() {
47+
vec2 base_uv = UV;
48+
49+
vec4 albedo_tex = texture(texture_albedo, base_uv);
50+
ALBEDO = albedo.rgb * albedo_tex.rgb;
51+
52+
float metallic_tex = dot(texture(texture_metallic, base_uv), metallic_texture_channel);
53+
METALLIC = metallic_tex * metallic;
54+
SPECULAR = specular;
55+
56+
vec4 roughness_texture_channel = vec4(1.0, 0.0, 0.0, 0.0);
57+
float roughness_tex = dot(texture(texture_roughness, base_uv), roughness_texture_channel);
58+
ROUGHNESS = roughness_tex * roughness;
59+
}
60+
"
61+
62+
[sub_resource type="ShaderMaterial" id="ShaderMaterial_fji6l"]
63+
render_priority = 0
64+
shader = SubResource("Shader_y2yqg")
65+
shader_parameter/albedo = Color(1, 1, 1, 1)
66+
shader_parameter/texture_albedo = ExtResource("1_y2yqg")
67+
shader_parameter/albedo_texture_size = Vector2i(256, 256)
68+
shader_parameter/point_size = 1.0
69+
shader_parameter/roughness = 1.0
70+
shader_parameter/metallic_texture_channel = Vector4(1, 0, 0, 0)
71+
shader_parameter/specular = 0.5
72+
shader_parameter/metallic = 0.0
73+
shader_parameter/uv1_scale = Vector3(1, 1, 1)
74+
shader_parameter/uv1_offset = Vector3(0, 0, 0)
75+
shader_parameter/uv2_scale = Vector3(1, 1, 1)
76+
shader_parameter/uv2_offset = Vector3(0, 0, 0)
77+
78+
[sub_resource type="BoxMesh" id="BoxMesh_p1i0w"]
79+
80+
[node name="3d" type="Node3D"]
81+
82+
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
83+
environment = SubResource("Environment_73ytm")
84+
85+
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
86+
transform = Transform3D(-0.8660254, -0.43301278, 0.25, 0, 0.49999997, 0.86602545, -0.50000006, 0.75, -0.43301266, 0, 0, 0)
87+
shadow_enabled = true
88+
89+
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
90+
material_override = SubResource("ShaderMaterial_fji6l")
91+
mesh = SubResource("BoxMesh_p1i0w")
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: 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: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
[gd_scene load_steps=17 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="Script" uid="uid://cdfq6x7v36k1e" path="res://mesh_texture_rd.gd" id="3_5vw27"]
5+
[ext_resource type="RDShaderFile" uid="uid://bsbaafha2qt2x" path="res://base_texture.glsl" id="3_lquwl"]
6+
[ext_resource type="ArrayMesh" uid="uid://j7duroqwmiuw" path="res://2d_array_mesh.tres" id="4_1bvp3"]
7+
[ext_resource type="Texture2D" uid="uid://reux267ue6un" path="res://tex.tres" id="4_lquwl"]
8+
9+
[sub_resource type="TorusMesh" id="TorusMesh_lquwl"]
10+
11+
[sub_resource type="Texture2D" id="Texture2D_7mycd"]
12+
resource_local_to_scene = false
13+
resource_name = ""
14+
script = ExtResource("3_5vw27")
15+
clear_color = Color(0.271125, 0.510188, 0.620698, 1)
16+
mesh = SubResource("TorusMesh_lquwl")
17+
base_texture = ExtResource("1_7mycd")
18+
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)
19+
metadata/_custom_type_script = "uid://delyovxoqvijt"
20+
21+
[sub_resource type="QuadMesh" id="QuadMesh_1bvp3"]
22+
23+
[sub_resource type="Texture2D" id="Texture2D_lquwl"]
24+
resource_local_to_scene = false
25+
resource_name = ""
26+
script = ExtResource("3_5vw27")
27+
clear_color = Color(0.572798, 0.384286, 0.683792, 0.337255)
28+
mesh = SubResource("QuadMesh_1bvp3")
29+
base_texture = ExtResource("1_7mycd")
30+
projection = Projection(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
31+
metadata/_custom_type_script = "uid://delyovxoqvijt"
32+
33+
[sub_resource type="Gradient" id="Gradient_1bvp3"]
34+
interpolation_color_space = 2
35+
colors = PackedColorArray(0.692862, 0.522376, 0.466238, 1, 0.634748, 0.521037, 0.665456, 1)
36+
37+
[sub_resource type="GradientTexture2D" id="GradientTexture2D_lquwl"]
38+
gradient = SubResource("Gradient_1bvp3")
39+
40+
[sub_resource type="TextMesh" id="TextMesh_7mycd"]
41+
text = "Rasterize Mesh Texture"
42+
43+
[sub_resource type="Texture2D" id="Texture2D_272bh"]
44+
resource_local_to_scene = false
45+
resource_name = ""
46+
script = ExtResource("3_5vw27")
47+
size = Vector2i(552, 131)
48+
mesh = SubResource("TextMesh_7mycd")
49+
base_texture = SubResource("GradientTexture2D_lquwl")
50+
projection = Projection(1.095, 0, 0, 0, 0, -5.53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
51+
metadata/_custom_type_script = "uid://cdfq6x7v36k1e"
52+
53+
[sub_resource type="FastNoiseLite" id="FastNoiseLite_1bvp3"]
54+
55+
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_lquwl"]
56+
noise = SubResource("FastNoiseLite_1bvp3")
57+
58+
[sub_resource type="Texture2D" id="Texture2D_1bvp3"]
59+
resource_local_to_scene = false
60+
resource_name = ""
61+
script = ExtResource("3_5vw27")
62+
mesh = ExtResource("4_1bvp3")
63+
base_texture = SubResource("NoiseTexture2D_lquwl")
64+
projection = Projection(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
65+
metadata/_custom_type_script = "uid://cdfq6x7v36k1e"
66+
67+
[node name="Node2D" type="Node2D"]
68+
69+
[node name="Prism" type="Sprite2D" parent="."]
70+
position = Vector2(573, 321)
71+
texture = ExtResource("4_lquwl")
72+
73+
[node name="Torus" type="Sprite2D" parent="."]
74+
position = Vector2(898, 319)
75+
texture = SubResource("Texture2D_7mycd")
76+
77+
[node name="Quad" type="Sprite2D" parent="."]
78+
position = Vector2(252, 321)
79+
texture = SubResource("Texture2D_lquwl")
80+
81+
[node name="Text" type="Sprite2D" parent="."]
82+
position = Vector2(293, 89)
83+
texture = SubResource("Texture2D_272bh")
84+
85+
[node name="2DMesh" type="Sprite2D" parent="."]
86+
position = Vector2(244, 543)
87+
texture = SubResource("Texture2D_1bvp3")

0 commit comments

Comments
 (0)