Skip to content

Commit 6fe1610

Browse files
authored
Refactor projects with the unlit material (#89)
1 parent 6bd82a0 commit 6fe1610

File tree

14 files changed

+121
-33
lines changed

14 files changed

+121
-33
lines changed

material/unlit/example/unlit.fp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ uniform lowp sampler2D texture0;
99
// The final color of the fragment.
1010
out lowp vec4 final_color;
1111

12+
uniform fs_uniforms
13+
{
14+
mediump vec4 tint;
15+
};
16+
1217
void main()
1318
{
19+
// Pre-multiply alpha since all runtime textures already are
20+
vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
21+
1422
// Sample the texture at the fragment's texture coordinates.
15-
vec4 color = texture(texture0, var_texcoord0.xy);
23+
vec4 color = texture(texture0, var_texcoord0.xy) * tint_pm;
1624

1725
// Output the sampled color.
1826
final_color = color;

material/unlit/example/unlit.material

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ tags: "model"
33
vertex_program: "/example/unlit.vp"
44
fragment_program: "/example/unlit.fp"
55
vertex_space: VERTEX_SPACE_LOCAL
6-
vertex_constants {
7-
name: "mtx_world"
8-
type: CONSTANT_TYPE_WORLD
9-
}
106
vertex_constants {
117
name: "mtx_view"
128
type: CONSTANT_TYPE_VIEW
@@ -15,6 +11,16 @@ vertex_constants {
1511
name: "mtx_proj"
1612
type: CONSTANT_TYPE_PROJECTION
1713
}
14+
fragment_constants {
15+
name: "tint"
16+
type: CONSTANT_TYPE_USER
17+
value {
18+
x: 1.0
19+
y: 1.0
20+
z: 1.0
21+
w: 1.0
22+
}
23+
}
1824
samplers {
1925
name: "texture0"
2026
wrap_u: WRAP_MODE_CLAMP_TO_EDGE

material/unlit/example/unlit.vp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
in vec4 position;
55
in vec2 texcoord0;
66

7-
// The projection, view and world matrices.
7+
// The model's world matrix.
8+
in mat4 mtx_world;
9+
10+
// The projection and view matrices.
811
uniform general_vp
912
{
10-
mat4 mtx_world;
1113
mat4 mtx_view;
1214
mat4 mtx_proj;
1315
};

model/gltf/assets/materials/unlit.fp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ uniform lowp sampler2D texture0;
99
// The final color of the fragment.
1010
out lowp vec4 final_color;
1111

12+
uniform fs_uniforms
13+
{
14+
mediump vec4 tint;
15+
};
16+
1217
void main()
1318
{
19+
// Pre-multiply alpha since all runtime textures already are
20+
vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
21+
1422
// Sample the texture at the fragment's texture coordinates.
15-
vec4 color = texture(texture0, var_texcoord0.xy);
23+
vec4 color = texture(texture0, var_texcoord0.xy) * tint_pm;
1624

1725
// Output the sampled color.
1826
final_color = color;

model/gltf/assets/materials/unlit.material

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ tags: "model"
33
vertex_program: "/assets/materials/unlit.vp"
44
fragment_program: "/assets/materials/unlit.fp"
55
vertex_space: VERTEX_SPACE_LOCAL
6-
vertex_constants {
7-
name: "mtx_world"
8-
type: CONSTANT_TYPE_WORLD
9-
}
106
vertex_constants {
117
name: "mtx_view"
128
type: CONSTANT_TYPE_VIEW
@@ -15,6 +11,16 @@ vertex_constants {
1511
name: "mtx_proj"
1612
type: CONSTANT_TYPE_PROJECTION
1713
}
14+
fragment_constants {
15+
name: "tint"
16+
type: CONSTANT_TYPE_USER
17+
value {
18+
x: 1.0
19+
y: 1.0
20+
z: 1.0
21+
w: 1.0
22+
}
23+
}
1824
samplers {
1925
name: "texture0"
2026
wrap_u: WRAP_MODE_CLAMP_TO_EDGE

model/gltf/assets/materials/unlit.vp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
in vec4 position;
55
in vec2 texcoord0;
66

7-
// The projection, view and world matrices.
7+
// The model's world matrix.
8+
in mat4 mtx_world;
9+
10+
// The projection and view matrices.
811
uniform general_vp
912
{
10-
mat4 mtx_world;
1113
mat4 mtx_view;
1214
mat4 mtx_proj;
1315
};

model/gltf/assets/models/License.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
3+
Prototype Kit (1.0)
4+
5+
Created/distributed by Kenney (www.kenney.nl)
6+
Creation date: 28-08-2024 09:59
7+
8+
------------------------------
9+
10+
License: (Creative Commons Zero, CC0)
11+
http://creativecommons.org/publicdomain/zero/1.0/
12+
13+
You can use this content for personal, educational, and commercial purposes.
14+
15+
Support by crediting 'Kenney' or 'www.kenney.nl' (this is not a requirement)
16+
17+
------------------------------
18+
19+
• Website : www.kenney.nl
20+
• Donate : www.kenney.nl/donate
21+
22+
• Patreon : patreon.com/kenney
23+
24+
Follow on social media for updates:
25+
26+
• Twitter: twitter.com/KenneyNL
27+
• Instagram: instagram.com/kenney_nl
28+
• Mastodon: mastodon.gamedev.place/@kenney

model/gltf/example/gltf.collection

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ embedded_instances {
1212
" material: \\\"/assets/materials/unlit.material\\\"\\n"
1313
" textures {\\n"
1414
" sampler: \\\"texture0\\\"\\n"
15-
" texture: \\\"/assets/models/colormap.png\\\"\\n"
15+
" texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
1616
" }\\n"
1717
"}\\n"
1818
"\"\n"
@@ -56,7 +56,7 @@ embedded_instances {
5656
" material: \\\"/assets/materials/unlit.material\\\"\\n"
5757
" textures {\\n"
5858
" sampler: \\\"texture0\\\"\\n"
59-
" texture: \\\"/assets/models/colormap.png\\\"\\n"
59+
" texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
6060
" }\\n"
6161
"}\\n"
6262
"\"\n"
@@ -75,7 +75,7 @@ embedded_instances {
7575
" material: \\\"/assets/materials/unlit.material\\\"\\n"
7676
" textures {\\n"
7777
" sampler: \\\"texture0\\\"\\n"
78-
" texture: \\\"/assets/models/colormap.png\\\"\\n"
78+
" texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
7979
" }\\n"
8080
"}\\n"
8181
"\"\n"
@@ -93,7 +93,7 @@ embedded_instances {
9393
" material: \\\"/assets/materials/unlit.material\\\"\\n"
9494
" textures {\\n"
9595
" sampler: \\\"texture0\\\"\\n"
96-
" texture: \\\"/assets/models/colormap.png\\\"\\n"
96+
" texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
9797
" }\\n"
9898
"}\\n"
9999
"\"\n"
@@ -112,7 +112,7 @@ embedded_instances {
112112
" material: \\\"/assets/materials/unlit.material\\\"\\n"
113113
" textures {\\n"
114114
" sampler: \\\"texture0\\\"\\n"
115-
" texture: \\\"/assets/models/colormap.png\\\"\\n"
115+
" texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
116116
" }\\n"
117117
"}\\n"
118118
"\"\n"
@@ -131,7 +131,7 @@ embedded_instances {
131131
" material: \\\"/assets/materials/unlit.material\\\"\\n"
132132
" textures {\\n"
133133
" sampler: \\\"texture0\\\"\\n"
134-
" texture: \\\"/assets/models/colormap.png\\\"\\n"
134+
" texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
135135
" }\\n"
136136
"}\\n"
137137
"\"\n"
@@ -150,7 +150,7 @@ embedded_instances {
150150
" material: \\\"/assets/materials/unlit.material\\\"\\n"
151151
" textures {\\n"
152152
" sampler: \\\"texture0\\\"\\n"
153-
" texture: \\\"/assets/models/colormap.png\\\"\\n"
153+
" texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
154154
" }\\n"
155155
"}\\n"
156156
"\"\n"
@@ -169,7 +169,7 @@ embedded_instances {
169169
" material: \\\"/assets/materials/unlit.material\\\"\\n"
170170
" textures {\\n"
171171
" sampler: \\\"texture0\\\"\\n"
172-
" texture: \\\"/assets/models/colormap.png\\\"\\n"
172+
" texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
173173
" }\\n"
174174
"}\\n"
175175
"\"\n"
@@ -188,7 +188,7 @@ embedded_instances {
188188
" material: \\\"/assets/materials/unlit.material\\\"\\n"
189189
" textures {\\n"
190190
" sampler: \\\"texture0\\\"\\n"
191-
" texture: \\\"/assets/models/colormap.png\\\"\\n"
191+
" texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
192192
" }\\n"
193193
"}\\n"
194194
"\"\n"

render/orbit_camera/.editor_settings

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@
6464
"/example/orbit_camera.collection"
6565
:scene
6666
]
67+
[
68+
"/assets/materials/unlit.fp"
69+
:code
70+
]
71+
[
72+
"/assets/materials/unlit.vp"
73+
:code
74+
]
75+
[
76+
"/assets/materials/unlit.material"
77+
:cljfx-form-view
78+
]
6779
]
6880
}
6981
}

render/orbit_camera/example/unlit.fp renamed to render/orbit_camera/assets/materials/unlit.fp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ uniform lowp sampler2D texture0;
99
// The final color of the fragment.
1010
out lowp vec4 final_color;
1111

12+
uniform fs_uniforms
13+
{
14+
mediump vec4 tint;
15+
};
16+
1217
void main()
1318
{
19+
// Pre-multiply alpha since all runtime textures already are
20+
vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
21+
1422
// Sample the texture at the fragment's texture coordinates.
15-
vec4 color = texture(texture0, var_texcoord0.xy);
23+
vec4 color = texture(texture0, var_texcoord0.xy) * tint_pm;
1624

1725
// Output the sampled color.
1826
final_color = color;

render/orbit_camera/example/unlit.material renamed to render/orbit_camera/assets/materials/unlit.material

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
name: "unlit"
22
tags: "model"
3-
vertex_program: "/example/unlit.vp"
4-
fragment_program: "/example/unlit.fp"
3+
vertex_program: "/assets/materials/unlit.vp"
4+
fragment_program: "/assets/materials/unlit.fp"
55
vertex_space: VERTEX_SPACE_LOCAL
6-
vertex_constants {
7-
name: "mtx_world"
8-
type: CONSTANT_TYPE_WORLD
9-
}
106
vertex_constants {
117
name: "mtx_view"
128
type: CONSTANT_TYPE_VIEW
@@ -15,6 +11,16 @@ vertex_constants {
1511
name: "mtx_proj"
1612
type: CONSTANT_TYPE_PROJECTION
1713
}
14+
fragment_constants {
15+
name: "tint"
16+
type: CONSTANT_TYPE_USER
17+
value {
18+
x: 1.0
19+
y: 1.0
20+
z: 1.0
21+
w: 1.0
22+
}
23+
}
1824
samplers {
1925
name: "texture0"
2026
wrap_u: WRAP_MODE_CLAMP_TO_EDGE

render/orbit_camera/example/unlit.vp renamed to render/orbit_camera/assets/materials/unlit.vp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
in vec4 position;
55
in vec2 texcoord0;
66

7-
// The projection, view and world matrices.
7+
// The model's world matrix.
8+
in mat4 mtx_world;
9+
10+
// The projection and view matrices.
811
uniform general_vp
912
{
10-
mat4 mtx_world;
1113
mat4 mtx_view;
1214
mat4 mtx_proj;
1315
};

render/orbit_camera/example/orbit_camera.collection

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ embedded_instances {
99
"name: \\\"{{NAME}}\\\"\\n"
1010
"materials {\\n"
1111
" name: \\\"colormap\\\"\\n"
12-
" material: \\\"/example/unlit.material\\\"\\n"
12+
" material: \\\"/assets/materials/unlit.material\\\"\\n"
1313
" textures {\\n"
1414
" sampler: \\\"texture0\\\"\\n"
1515
" texture: \\\"/assets/models/kenney_prototype-kit/Textures/colormap.png\\\"\\n"

0 commit comments

Comments
 (0)