Browse Source

Refactor projects with the unlit material (#89)

Artsiom Trubchyk 3 tháng trước cách đây
mục cha
commit
6fe16106d5

+ 9 - 1
material/unlit/example/unlit.fp

@@ -9,10 +9,18 @@ uniform lowp sampler2D texture0;
 // The final color of the fragment.
 out lowp vec4 final_color;
 
+uniform fs_uniforms
+{
+    mediump vec4 tint;
+};
+
 void main()
 {
+    // Pre-multiply alpha since all runtime textures already are
+    vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
+
     // Sample the texture at the fragment's texture coordinates.
-    vec4 color = texture(texture0, var_texcoord0.xy);
+    vec4 color = texture(texture0, var_texcoord0.xy) * tint_pm;
 
     // Output the sampled color.
     final_color = color;

+ 10 - 4
material/unlit/example/unlit.material

@@ -3,10 +3,6 @@ tags: "model"
 vertex_program: "/example/unlit.vp"
 fragment_program: "/example/unlit.fp"
 vertex_space: VERTEX_SPACE_LOCAL
-vertex_constants {
-  name: "mtx_world"
-  type: CONSTANT_TYPE_WORLD
-}
 vertex_constants {
   name: "mtx_view"
   type: CONSTANT_TYPE_VIEW
@@ -15,6 +11,16 @@ vertex_constants {
   name: "mtx_proj"
   type: CONSTANT_TYPE_PROJECTION
 }
+fragment_constants {
+  name: "tint"
+  type: CONSTANT_TYPE_USER
+  value {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+    w: 1.0
+  }
+}
 samplers {
   name: "texture0"
   wrap_u: WRAP_MODE_CLAMP_TO_EDGE

+ 4 - 2
material/unlit/example/unlit.vp

@@ -4,10 +4,12 @@
 in vec4 position;
 in vec2 texcoord0;
 
-// The projection, view and world matrices.
+// The model's world matrix.
+in mat4 mtx_world;
+
+// The projection and view matrices.
 uniform general_vp
 {
-    mat4 mtx_world;
     mat4 mtx_view;
     mat4 mtx_proj;
 };

+ 9 - 1
model/gltf/assets/materials/unlit.fp

@@ -9,10 +9,18 @@ uniform lowp sampler2D texture0;
 // The final color of the fragment.
 out lowp vec4 final_color;
 
+uniform fs_uniforms
+{
+    mediump vec4 tint;
+};
+
 void main()
 {
+    // Pre-multiply alpha since all runtime textures already are
+    vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
+
     // Sample the texture at the fragment's texture coordinates.
-    vec4 color = texture(texture0, var_texcoord0.xy);
+    vec4 color = texture(texture0, var_texcoord0.xy) * tint_pm;
 
     // Output the sampled color.
     final_color = color;

+ 10 - 4
model/gltf/assets/materials/unlit.material

@@ -3,10 +3,6 @@ tags: "model"
 vertex_program: "/assets/materials/unlit.vp"
 fragment_program: "/assets/materials/unlit.fp"
 vertex_space: VERTEX_SPACE_LOCAL
-vertex_constants {
-  name: "mtx_world"
-  type: CONSTANT_TYPE_WORLD
-}
 vertex_constants {
   name: "mtx_view"
   type: CONSTANT_TYPE_VIEW
@@ -15,6 +11,16 @@ vertex_constants {
   name: "mtx_proj"
   type: CONSTANT_TYPE_PROJECTION
 }
+fragment_constants {
+  name: "tint"
+  type: CONSTANT_TYPE_USER
+  value {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+    w: 1.0
+  }
+}
 samplers {
   name: "texture0"
   wrap_u: WRAP_MODE_CLAMP_TO_EDGE

+ 4 - 2
model/gltf/assets/materials/unlit.vp

@@ -4,10 +4,12 @@
 in vec4 position;
 in vec2 texcoord0;
 
-// The projection, view and world matrices.
+// The model's world matrix.
+in mat4 mtx_world;
+
+// The projection and view matrices.
 uniform general_vp
 {
-    mat4 mtx_world;
     mat4 mtx_view;
     mat4 mtx_proj;
 };

+ 28 - 0
model/gltf/assets/models/License.txt

@@ -0,0 +1,28 @@
+	
+
+	Prototype Kit (1.0)
+
+	Created/distributed by Kenney (www.kenney.nl)
+	Creation date: 28-08-2024 09:59
+	
+			------------------------------
+
+	License: (Creative Commons Zero, CC0)
+	http://creativecommons.org/publicdomain/zero/1.0/
+
+	You can use this content for personal, educational, and commercial purposes.
+
+	Support by crediting 'Kenney' or 'www.kenney.nl' (this is not a requirement)
+
+			------------------------------
+
+	• Website : www.kenney.nl
+	• Donate  : www.kenney.nl/donate
+
+	• Patreon : patreon.com/kenney
+	
+	Follow on social media for updates:
+
+	• Twitter:   twitter.com/KenneyNL
+	• Instagram: instagram.com/kenney_nl
+	• Mastodon:  mastodon.gamedev.place/@kenney

+ 0 - 0
model/gltf/assets/models/colormap.png → model/gltf/assets/models/Textures/colormap.png


+ 9 - 9
model/gltf/example/gltf.collection

@@ -12,7 +12,7 @@ embedded_instances {
   "  material: \\\"/assets/materials/unlit.material\\\"\\n"
   "  textures {\\n"
   "    sampler: \\\"texture0\\\"\\n"
-  "    texture: \\\"/assets/models/colormap.png\\\"\\n"
+  "    texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
   "  }\\n"
   "}\\n"
   "\"\n"
@@ -56,7 +56,7 @@ embedded_instances {
   "  material: \\\"/assets/materials/unlit.material\\\"\\n"
   "  textures {\\n"
   "    sampler: \\\"texture0\\\"\\n"
-  "    texture: \\\"/assets/models/colormap.png\\\"\\n"
+  "    texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
   "  }\\n"
   "}\\n"
   "\"\n"
@@ -75,7 +75,7 @@ embedded_instances {
   "  material: \\\"/assets/materials/unlit.material\\\"\\n"
   "  textures {\\n"
   "    sampler: \\\"texture0\\\"\\n"
-  "    texture: \\\"/assets/models/colormap.png\\\"\\n"
+  "    texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
   "  }\\n"
   "}\\n"
   "\"\n"
@@ -93,7 +93,7 @@ embedded_instances {
   "  material: \\\"/assets/materials/unlit.material\\\"\\n"
   "  textures {\\n"
   "    sampler: \\\"texture0\\\"\\n"
-  "    texture: \\\"/assets/models/colormap.png\\\"\\n"
+  "    texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
   "  }\\n"
   "}\\n"
   "\"\n"
@@ -112,7 +112,7 @@ embedded_instances {
   "  material: \\\"/assets/materials/unlit.material\\\"\\n"
   "  textures {\\n"
   "    sampler: \\\"texture0\\\"\\n"
-  "    texture: \\\"/assets/models/colormap.png\\\"\\n"
+  "    texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
   "  }\\n"
   "}\\n"
   "\"\n"
@@ -131,7 +131,7 @@ embedded_instances {
   "  material: \\\"/assets/materials/unlit.material\\\"\\n"
   "  textures {\\n"
   "    sampler: \\\"texture0\\\"\\n"
-  "    texture: \\\"/assets/models/colormap.png\\\"\\n"
+  "    texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
   "  }\\n"
   "}\\n"
   "\"\n"
@@ -150,7 +150,7 @@ embedded_instances {
   "  material: \\\"/assets/materials/unlit.material\\\"\\n"
   "  textures {\\n"
   "    sampler: \\\"texture0\\\"\\n"
-  "    texture: \\\"/assets/models/colormap.png\\\"\\n"
+  "    texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
   "  }\\n"
   "}\\n"
   "\"\n"
@@ -169,7 +169,7 @@ embedded_instances {
   "  material: \\\"/assets/materials/unlit.material\\\"\\n"
   "  textures {\\n"
   "    sampler: \\\"texture0\\\"\\n"
-  "    texture: \\\"/assets/models/colormap.png\\\"\\n"
+  "    texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
   "  }\\n"
   "}\\n"
   "\"\n"
@@ -188,7 +188,7 @@ embedded_instances {
   "  material: \\\"/assets/materials/unlit.material\\\"\\n"
   "  textures {\\n"
   "    sampler: \\\"texture0\\\"\\n"
-  "    texture: \\\"/assets/models/colormap.png\\\"\\n"
+  "    texture: \\\"/assets/models/Textures/colormap.png\\\"\\n"
   "  }\\n"
   "}\\n"
   "\"\n"

+ 12 - 0
render/orbit_camera/.editor_settings

@@ -64,6 +64,18 @@
         "/example/orbit_camera.collection"
         :scene
       ]
+      [
+        "/assets/materials/unlit.fp"
+        :code
+      ]
+      [
+        "/assets/materials/unlit.vp"
+        :code
+      ]
+      [
+        "/assets/materials/unlit.material"
+        :cljfx-form-view
+      ]
     ]
   }
 }

+ 9 - 1
render/orbit_camera/example/unlit.fp → render/orbit_camera/assets/materials/unlit.fp

@@ -9,10 +9,18 @@ uniform lowp sampler2D texture0;
 // The final color of the fragment.
 out lowp vec4 final_color;
 
+uniform fs_uniforms
+{
+    mediump vec4 tint;
+};
+
 void main()
 {
+    // Pre-multiply alpha since all runtime textures already are
+    vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
+
     // Sample the texture at the fragment's texture coordinates.
-    vec4 color = texture(texture0, var_texcoord0.xy);
+    vec4 color = texture(texture0, var_texcoord0.xy) * tint_pm;
 
     // Output the sampled color.
     final_color = color;

+ 12 - 6
render/orbit_camera/example/unlit.material → render/orbit_camera/assets/materials/unlit.material

@@ -1,12 +1,8 @@
 name: "unlit"
 tags: "model"
-vertex_program: "/example/unlit.vp"
-fragment_program: "/example/unlit.fp"
+vertex_program: "/assets/materials/unlit.vp"
+fragment_program: "/assets/materials/unlit.fp"
 vertex_space: VERTEX_SPACE_LOCAL
-vertex_constants {
-  name: "mtx_world"
-  type: CONSTANT_TYPE_WORLD
-}
 vertex_constants {
   name: "mtx_view"
   type: CONSTANT_TYPE_VIEW
@@ -15,6 +11,16 @@ vertex_constants {
   name: "mtx_proj"
   type: CONSTANT_TYPE_PROJECTION
 }
+fragment_constants {
+  name: "tint"
+  type: CONSTANT_TYPE_USER
+  value {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+    w: 1.0
+  }
+}
 samplers {
   name: "texture0"
   wrap_u: WRAP_MODE_CLAMP_TO_EDGE

+ 4 - 2
render/orbit_camera/example/unlit.vp → render/orbit_camera/assets/materials/unlit.vp

@@ -4,10 +4,12 @@
 in vec4 position;
 in vec2 texcoord0;
 
-// The projection, view and world matrices.
+// The model's world matrix.
+in mat4 mtx_world;
+
+// The projection and view matrices.
 uniform general_vp
 {
-    mat4 mtx_world;
     mat4 mtx_view;
     mat4 mtx_proj;
 };

+ 1 - 1
render/orbit_camera/example/orbit_camera.collection

@@ -9,7 +9,7 @@ embedded_instances {
   "name: \\\"{{NAME}}\\\"\\n"
   "materials {\\n"
   "  name: \\\"colormap\\\"\\n"
-  "  material: \\\"/example/unlit.material\\\"\\n"
+  "  material: \\\"/assets/materials/unlit.material\\\"\\n"
   "  textures {\\n"
   "    sampler: \\\"texture0\\\"\\n"
   "    texture: \\\"/assets/models/kenney_prototype-kit/Textures/colormap.png\\\"\\n"