-
Notifications
You must be signed in to change notification settings - Fork 34
Added basic lights components example in 3D #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,18 @@ | ||
| path_settings { | ||
| path: "**" | ||
| profile: "Default" | ||
| } | ||
| profiles { | ||
| name: "Default" | ||
| platforms { | ||
| os: OS_ID_GENERIC | ||
| formats { | ||
| format: TEXTURE_FORMAT_RGBA | ||
| compression_level: BEST | ||
| compression_type: COMPRESSION_TYPE_DEFAULT | ||
| } | ||
| mipmaps: false | ||
| max_texture_size: 0 | ||
| premultiply_alpha: true | ||
| } | ||
| } |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or 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,11 @@ | ||
| mesh: "/assets/meshes/cars_kenney/police.glb" | ||
| name: "police" | ||
| create_go_bones: false | ||
| materials { | ||
| name: "colormap" | ||
| material: "/builtins/materials/model_instanced_lit.material" | ||
| textures { | ||
| sampler: "tex0" | ||
| texture: "/assets/textures/colormap_cars.png" | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
render/basic_lights_3d/assets/models/city/building-type-a.model
This file contains hidden or 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,11 @@ | ||
| mesh: "/assets/meshes/city_kenney/building-type-a.glb" | ||
| name: "building-type-a" | ||
| create_go_bones: false | ||
| materials { | ||
| name: "colormap" | ||
| material: "/builtins/materials/model_instanced_lit.material" | ||
| textures { | ||
| sampler: "tex0" | ||
| texture: "/assets/textures/colormap_city.png" | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
render/basic_lights_3d/assets/models/city/building-type-b.model
This file contains hidden or 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,11 @@ | ||
| mesh: "/assets/meshes/city_kenney/building-type-b.glb" | ||
| name: "building-type-b" | ||
| create_go_bones: false | ||
| materials { | ||
| name: "colormap" | ||
| material: "/builtins/materials/model_instanced_lit.material" | ||
| textures { | ||
| sampler: "tex0" | ||
| texture: "/assets/textures/colormap_city.png" | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
render/basic_lights_3d/assets/models/city/building-type-c.model
This file contains hidden or 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,11 @@ | ||
| mesh: "/assets/meshes/city_kenney/building-type-c.glb" | ||
| name: "building-type-c" | ||
| create_go_bones: false | ||
| materials { | ||
| name: "colormap" | ||
| material: "/builtins/materials/model_instanced_lit.material" | ||
| textures { | ||
| sampler: "tex0" | ||
| texture: "/assets/textures/colormap_city.png" | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
render/basic_lights_3d/assets/models/city/building-type-d.model
This file contains hidden or 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,11 @@ | ||
| mesh: "/assets/meshes/city_kenney/building-type-d.glb" | ||
| name: "building-type-d" | ||
| create_go_bones: false | ||
| materials { | ||
| name: "colormap" | ||
| material: "/builtins/materials/model_instanced_lit.material" | ||
| textures { | ||
| sampler: "tex0" | ||
| texture: "/assets/textures/colormap_city.png" | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
render/basic_lights_3d/assets/models/city/building-type-e.model
This file contains hidden or 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,11 @@ | ||
| mesh: "/assets/meshes/city_kenney/building-type-e.glb" | ||
| name: "building-type-e" | ||
| create_go_bones: false | ||
| materials { | ||
| name: "colormap" | ||
| material: "/builtins/materials/model_instanced_lit.material" | ||
| textures { | ||
| sampler: "tex0" | ||
| texture: "/assets/textures/colormap_city.png" | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
render/basic_lights_3d/assets/models/city/building-type-f.model
This file contains hidden or 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,11 @@ | ||
| mesh: "/assets/meshes/city_kenney/building-type-f.glb" | ||
| name: "building-type-f" | ||
| create_go_bones: false | ||
| materials { | ||
| name: "colormap" | ||
| material: "/builtins/materials/model_instanced_lit.material" | ||
| textures { | ||
| sampler: "tex0" | ||
| texture: "/assets/textures/colormap_city.png" | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
render/basic_lights_3d/assets/models/city/building-type-g.model
This file contains hidden or 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,11 @@ | ||
| mesh: "/assets/meshes/city_kenney/building-type-g.glb" | ||
| name: "building-type-g" | ||
| create_go_bones: false | ||
| materials { | ||
| name: "colormap" | ||
| material: "/builtins/materials/model_instanced_lit.material" | ||
| textures { | ||
| sampler: "tex0" | ||
| texture: "/assets/textures/colormap_city.png" | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
render/basic_lights_3d/assets/models/city/driveway-long.model
This file contains hidden or 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,11 @@ | ||
| mesh: "/assets/meshes/city_kenney/driveway-long.glb" | ||
| name: "driveway-long" | ||
| create_go_bones: false | ||
| materials { | ||
| name: "colormap" | ||
| material: "/builtins/materials/model_instanced_lit.material" | ||
| textures { | ||
| sampler: "tex0" | ||
| texture: "/assets/textures/colormap_city.png" | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
render/basic_lights_3d/assets/models/city/tree-large.model
This file contains hidden or 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,11 @@ | ||
| mesh: "/assets/meshes/city_kenney/tree-large.glb" | ||
| name: "tree-large" | ||
| create_go_bones: false | ||
| materials { | ||
| name: "colormap" | ||
| material: "/builtins/materials/model_instanced_lit.material" | ||
| textures { | ||
| sampler: "tex0" | ||
| texture: "/assets/textures/colormap_city.png" | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
render/basic_lights_3d/assets/models/city/tree-small.model
This file contains hidden or 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,11 @@ | ||
| mesh: "/assets/meshes/city_kenney/tree-small.glb" | ||
| name: "tree-small" | ||
| create_go_bones: false | ||
| materials { | ||
| name: "colormap" | ||
| material: "/builtins/materials/model_instanced_lit.material" | ||
| textures { | ||
| sampler: "tex0" | ||
| texture: "/assets/textures/colormap_city.png" | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
render/basic_lights_3d/assets/models/road/light-curved.model
This file contains hidden or 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,11 @@ | ||
| mesh: "/assets/meshes/road_kenney/light-curved.glb" | ||
| name: "light-curved-double" | ||
| materials { | ||
| name: "colormap" | ||
| material: "/builtins/materials/model_instanced_lit.material" | ||
| textures { | ||
| sampler: "tex0" | ||
| texture: "/assets/textures/colormap_roads.png" | ||
| } | ||
| } | ||
| create_go_bones: false |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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,87 @@ | ||
| --- | ||
| name: Basic Lights 3D | ||
| tags: render, 3d | ||
| title: Basic Lights 3D | ||
| brief: This example shows how ambient, directional, point, and spot lights affect 3D models that use built-in lit materials. | ||
| author: aglitchman | ||
| scripts: car.script, orbit_camera.script | ||
| thumbnail: thumbnail.webp | ||
| --- | ||
|
|
||
| This example sets up a small 3D city scene with several light component types. | ||
| The police car moves through the street so its headlights, rear lights, | ||
| and siren lights can be seen on nearby models. | ||
|
|
||
| You can orbit the camera around the scene with the mouse or touch input. | ||
|
|
||
| Read more about [Light components in the manual](https://defold.com/manuals/light/). | ||
|
|
||
| ## What You'll Learn | ||
|
|
||
| - How to add ambient, directional, point, and spot light components to a 3D scene. | ||
| - How to use built-in lit model materials that respond to light components. | ||
| - How changing or animating properties of the parent game object of light components affect them. | ||
|
|
||
| ## Setup | ||
|
|
||
| The bootstrap collection `example/basic_lights_3d.collection` contains a simple city scene made from model components. | ||
| There is also: | ||
|
|
||
| - a camera game object with camera component and `orbit_camera.script` | ||
| - a `lights` game object that groups the scene lights, lamp, and moving car with light components | ||
|
|
||
|  | ||
|
|
||
| All visible models in this scene use `/builtins/materials/model_instanced_lit.material`. | ||
| Lit built-in materials are an example for model components to receive and react to the light from Defold Light components introduced in Defold 1.13.1. | ||
|
|
||
| You can use a material variant that matches the model: | ||
|
|
||
| - `/builtins/materials/model_lit.material` for a regular static model. | ||
| - `/builtins/materials/model_instanced_lit.material` for static models that utilise GPU instancing. | ||
| - `/builtins/materials/model_skinned_lit.material` for a skinned (animated) model. | ||
| - `/builtins/materials/model_skinned_instanced_lit.material` for skinned (animated( models that can be instanced. | ||
|
|
||
| In the model file, the `colormap` material slot has assigned `model_instanced_lit.material`, | ||
| and the texture sampler `tex0` points to the color map used by that model group. | ||
|
|
||
|  | ||
|
|
||
| ## How It Works | ||
|
|
||
| The `sun` game object contains two light components. | ||
|
|
||
| The `ambient_light` adds a constant color to the shading of the models, | ||
| so that unlit sides of the models are not completely black. | ||
|
|
||
| The `directional_light` represents distant light, like sunlight, | ||
| and uses the parent game object's rotation to define the light direction. | ||
|
|
||
| The police siren lights on the car uses two point light components. | ||
| The point light is used as a light source that has a position in the world, | ||
| and a spherical area around it defined by the `range`. | ||
| It uses the parent's game objects position and scale. | ||
| It also has a `color` and `intensity`. | ||
|
|
||
| The `red_light` and the `blue_light` are child game objects of the car, so they move with it. | ||
| The `car.script` animates the scale of the two light game objects at different times, | ||
| which makes the red and blue light contribution pulse, like the police siren lights. | ||
|
|
||
|  | ||
|
|
||
| The headlights, rear lights, and street lamp use spot light components. | ||
| A spot light is for a light that has a volume in a shape of a cone, e.g. flashlights, lamps or car's lights. | ||
| It has the same `color`, `intensity`, and `range` controls as a point light, | ||
| plus `inner_cone_angle` and `outer_cone_angle` to shape the beam. | ||
| It uses the parent's game objects position, scale and rotation. | ||
| In this scene the headlights are yellow spot lights with a long range, | ||
| the rear lights are shorter red spot lights, | ||
| and the street lamp points downward from the lamp model. | ||
|
|
||
|  | ||
|
|
||
| The car movement is intentionally simple - `car.script` just animates the car position back and forth, | ||
| flips its rotation every five seconds, and animates the scale of the siren lights. | ||
| The lighting behavior itself comes from the light components and the built-in lit model materials. | ||
|
|
||
| All the models in the example are from [Kenney asset packs](https://kenney.nl/assets/) (Road, City and Cars), licensed under CC0. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.