-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from aglitchman/patch/unlit-example
Add "Unlit" material example
- Loading branch information
Showing
12 changed files
with
187 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
|
||
Train Kit (1.1) | ||
|
||
Created/distributed by Kenney (www.kenney.nl) | ||
Creation date: 22-09-2024 23:33 | ||
Additional credit(s): Guus Vermeulen, Tony Schaer | ||
|
||
------------------------------ | ||
|
||
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: "unlit" | ||
scale_along_z: 1 | ||
embedded_instances { | ||
id: "train" | ||
data: "embedded_components {\n" | ||
" id: \"model\"\n" | ||
" type: \"model\"\n" | ||
" data: \"mesh: \\\"/assets/models/kenney_train-kit/train-locomotive-b.glb\\\"\\n" | ||
"name: \\\"{{NAME}}\\\"\\n" | ||
"materials {\\n" | ||
" name: \\\"colormap\\\"\\n" | ||
" material: \\\"/examples/material/unlit/unlit.material\\\"\\n" | ||
" textures {\\n" | ||
" sampler: \\\"texture0\\\"\\n" | ||
" texture: \\\"/assets/models/kenney_train-kit/Textures/colormap.png\\\"\\n" | ||
" }\\n" | ||
"}\\n" | ||
"\"\n" | ||
"}\n" | ||
"" | ||
} | ||
embedded_instances { | ||
id: "camera" | ||
data: "embedded_components {\n" | ||
" id: \"camera\"\n" | ||
" type: \"camera\"\n" | ||
" data: \"aspect_ratio: 1.0\\n" | ||
"fov: 0.7854\\n" | ||
"near_z: 0.1\\n" | ||
"far_z: 1000.0\\n" | ||
"auto_aspect_ratio: 1\\n" | ||
"\"\n" | ||
"}\n" | ||
"" | ||
position { | ||
x: 3.543836 | ||
y: 3.619002 | ||
z: 3.104797 | ||
} | ||
rotation { | ||
x: -0.26769933 | ||
y: 0.3956773 | ||
z: 0.12174567 | ||
w: 0.8700313 | ||
} | ||
} | ||
embedded_instances { | ||
id: "main" | ||
data: "components {\n" | ||
" id: \"unlit\"\n" | ||
" component: \"/examples/material/unlit/unlit.script\"\n" | ||
"}\n" | ||
"" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#version 140 | ||
|
||
// Inputs should match the vertex shader's outputs. | ||
in vec2 var_texcoord0; | ||
|
||
// The texture to sample. | ||
uniform lowp sampler2D texture0; | ||
|
||
// The final color of the fragment. | ||
out lowp vec4 final_color; | ||
|
||
void main() | ||
{ | ||
// Sample the texture at the fragment's texture coordinates. | ||
vec4 color = texture(texture0, var_texcoord0.xy); | ||
|
||
// Output the sampled color. | ||
final_color = color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: "unlit" | ||
tags: "model" | ||
vertex_program: "/examples/material/unlit/unlit.vp" | ||
fragment_program: "/examples/material/unlit/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 | ||
} | ||
vertex_constants { | ||
name: "mtx_proj" | ||
type: CONSTANT_TYPE_PROJECTION | ||
} | ||
samplers { | ||
name: "texture0" | ||
wrap_u: WRAP_MODE_CLAMP_TO_EDGE | ||
wrap_v: WRAP_MODE_CLAMP_TO_EDGE | ||
filter_min: FILTER_MODE_MIN_LINEAR | ||
filter_mag: FILTER_MODE_MAG_LINEAR | ||
max_anisotropy: 0.0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
title: Unlit | ||
brief: This example demonstrates how to create and apply an custom non-lit material to a 3D model. | ||
scripts: unlit.script, unlit.vp, unlit.fp | ||
--- | ||
|
||
In industry-established terms, a material that is not affected by lighting is called "unlit" or "non-lit". It is used to create retro-style graphics or for effects that should not depend on lighting (headlights, lamps). | ||
|
||
This example contains a game object with a model that has an `unlit` material applied to it. The material is assigned custom vertex and fragment shaders. To set up a perspective camera, a camera is added to the collection, which is enabled in the script via the `acquire_camera_focus` message when the collection loads. | ||
|
||
The unlit shader is very simple and just transfers the texture color to the model. This is an excellent starting point for creating new materials and for creating effects that do not depend on lighting. The shaders are written in GLSL 1.40, which is available from Defold 1.9.2. | ||
|
||
The model used in this example is from Kenney's [Train Pack](https://kenney.itch.io/train-pack), licensed under CC0. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function init(self) | ||
msg.post("/camera", "acquire_camera_focus") | ||
msg.post("@render:", "use_camera_projection") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#version 140 | ||
|
||
// The model's vertex position and texture coordinates. | ||
in vec4 position; | ||
in vec2 texcoord0; | ||
|
||
// The projection, view and world matrices. | ||
uniform general_vp | ||
{ | ||
mat4 mtx_world; | ||
mat4 mtx_view; | ||
mat4 mtx_proj; | ||
}; | ||
|
||
// The output of a vertex shader are passed to the fragment shader. | ||
// The texture coordinates of the vertex. | ||
out vec2 var_texcoord0; | ||
|
||
void main() | ||
{ | ||
// Pass the texture coordinates to the fragment shader. | ||
var_texcoord0 = texcoord0; | ||
|
||
// Transform the vertex position to clip space. | ||
gl_Position = mtx_proj * mtx_view * mtx_world * vec4(position.xyz, 1.0); | ||
} |