diff --git a/render/basic_lights_3d/all.texture_profiles b/render/basic_lights_3d/all.texture_profiles new file mode 100644 index 00000000..5b0d7762 --- /dev/null +++ b/render/basic_lights_3d/all.texture_profiles @@ -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 + } +} diff --git a/render/basic_lights_3d/assets/meshes/cars_kenney/police.glb b/render/basic_lights_3d/assets/meshes/cars_kenney/police.glb new file mode 100644 index 00000000..41296808 Binary files /dev/null and b/render/basic_lights_3d/assets/meshes/cars_kenney/police.glb differ diff --git a/render/basic_lights_3d/assets/meshes/city_kenney/building-type-a.glb b/render/basic_lights_3d/assets/meshes/city_kenney/building-type-a.glb new file mode 100644 index 00000000..870bf63a Binary files /dev/null and b/render/basic_lights_3d/assets/meshes/city_kenney/building-type-a.glb differ diff --git a/render/basic_lights_3d/assets/meshes/city_kenney/building-type-b.glb b/render/basic_lights_3d/assets/meshes/city_kenney/building-type-b.glb new file mode 100644 index 00000000..d25162a9 Binary files /dev/null and b/render/basic_lights_3d/assets/meshes/city_kenney/building-type-b.glb differ diff --git a/render/basic_lights_3d/assets/meshes/city_kenney/building-type-c.glb b/render/basic_lights_3d/assets/meshes/city_kenney/building-type-c.glb new file mode 100644 index 00000000..91bbbacb Binary files /dev/null and b/render/basic_lights_3d/assets/meshes/city_kenney/building-type-c.glb differ diff --git a/render/basic_lights_3d/assets/meshes/city_kenney/building-type-d.glb b/render/basic_lights_3d/assets/meshes/city_kenney/building-type-d.glb new file mode 100644 index 00000000..7d62e09e Binary files /dev/null and b/render/basic_lights_3d/assets/meshes/city_kenney/building-type-d.glb differ diff --git a/render/basic_lights_3d/assets/meshes/city_kenney/building-type-e.glb b/render/basic_lights_3d/assets/meshes/city_kenney/building-type-e.glb new file mode 100644 index 00000000..cf6476d7 Binary files /dev/null and b/render/basic_lights_3d/assets/meshes/city_kenney/building-type-e.glb differ diff --git a/render/basic_lights_3d/assets/meshes/city_kenney/building-type-f.glb b/render/basic_lights_3d/assets/meshes/city_kenney/building-type-f.glb new file mode 100644 index 00000000..db684971 Binary files /dev/null and b/render/basic_lights_3d/assets/meshes/city_kenney/building-type-f.glb differ diff --git a/render/basic_lights_3d/assets/meshes/city_kenney/building-type-g.glb b/render/basic_lights_3d/assets/meshes/city_kenney/building-type-g.glb new file mode 100644 index 00000000..6248db1a Binary files /dev/null and b/render/basic_lights_3d/assets/meshes/city_kenney/building-type-g.glb differ diff --git a/render/basic_lights_3d/assets/meshes/city_kenney/driveway-long.glb b/render/basic_lights_3d/assets/meshes/city_kenney/driveway-long.glb new file mode 100644 index 00000000..7ebcdce4 Binary files /dev/null and b/render/basic_lights_3d/assets/meshes/city_kenney/driveway-long.glb differ diff --git a/render/basic_lights_3d/assets/meshes/city_kenney/tree-large.glb b/render/basic_lights_3d/assets/meshes/city_kenney/tree-large.glb new file mode 100644 index 00000000..c82ee870 Binary files /dev/null and b/render/basic_lights_3d/assets/meshes/city_kenney/tree-large.glb differ diff --git a/render/basic_lights_3d/assets/meshes/city_kenney/tree-small.glb b/render/basic_lights_3d/assets/meshes/city_kenney/tree-small.glb new file mode 100644 index 00000000..e0804156 Binary files /dev/null and b/render/basic_lights_3d/assets/meshes/city_kenney/tree-small.glb differ diff --git a/render/basic_lights_3d/assets/meshes/road_kenney/light-curved.glb b/render/basic_lights_3d/assets/meshes/road_kenney/light-curved.glb new file mode 100644 index 00000000..0768255d Binary files /dev/null and b/render/basic_lights_3d/assets/meshes/road_kenney/light-curved.glb differ diff --git a/render/basic_lights_3d/assets/models/cars/police.model b/render/basic_lights_3d/assets/models/cars/police.model new file mode 100644 index 00000000..7700147e --- /dev/null +++ b/render/basic_lights_3d/assets/models/cars/police.model @@ -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" + } +} diff --git a/render/basic_lights_3d/assets/models/city/building-type-a.model b/render/basic_lights_3d/assets/models/city/building-type-a.model new file mode 100644 index 00000000..09160364 --- /dev/null +++ b/render/basic_lights_3d/assets/models/city/building-type-a.model @@ -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" + } +} diff --git a/render/basic_lights_3d/assets/models/city/building-type-b.model b/render/basic_lights_3d/assets/models/city/building-type-b.model new file mode 100644 index 00000000..74a38fa0 --- /dev/null +++ b/render/basic_lights_3d/assets/models/city/building-type-b.model @@ -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" + } +} diff --git a/render/basic_lights_3d/assets/models/city/building-type-c.model b/render/basic_lights_3d/assets/models/city/building-type-c.model new file mode 100644 index 00000000..5529b526 --- /dev/null +++ b/render/basic_lights_3d/assets/models/city/building-type-c.model @@ -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" + } +} diff --git a/render/basic_lights_3d/assets/models/city/building-type-d.model b/render/basic_lights_3d/assets/models/city/building-type-d.model new file mode 100644 index 00000000..a44fa34e --- /dev/null +++ b/render/basic_lights_3d/assets/models/city/building-type-d.model @@ -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" + } +} diff --git a/render/basic_lights_3d/assets/models/city/building-type-e.model b/render/basic_lights_3d/assets/models/city/building-type-e.model new file mode 100644 index 00000000..6f79cd37 --- /dev/null +++ b/render/basic_lights_3d/assets/models/city/building-type-e.model @@ -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" + } +} diff --git a/render/basic_lights_3d/assets/models/city/building-type-f.model b/render/basic_lights_3d/assets/models/city/building-type-f.model new file mode 100644 index 00000000..2940c7b1 --- /dev/null +++ b/render/basic_lights_3d/assets/models/city/building-type-f.model @@ -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" + } +} diff --git a/render/basic_lights_3d/assets/models/city/building-type-g.model b/render/basic_lights_3d/assets/models/city/building-type-g.model new file mode 100644 index 00000000..2ed4a06a --- /dev/null +++ b/render/basic_lights_3d/assets/models/city/building-type-g.model @@ -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" + } +} diff --git a/render/basic_lights_3d/assets/models/city/driveway-long.model b/render/basic_lights_3d/assets/models/city/driveway-long.model new file mode 100644 index 00000000..d35f23c3 --- /dev/null +++ b/render/basic_lights_3d/assets/models/city/driveway-long.model @@ -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" + } +} diff --git a/render/basic_lights_3d/assets/models/city/tree-large.model b/render/basic_lights_3d/assets/models/city/tree-large.model new file mode 100644 index 00000000..28e118ad --- /dev/null +++ b/render/basic_lights_3d/assets/models/city/tree-large.model @@ -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" + } +} diff --git a/render/basic_lights_3d/assets/models/city/tree-small.model b/render/basic_lights_3d/assets/models/city/tree-small.model new file mode 100644 index 00000000..30b04e22 --- /dev/null +++ b/render/basic_lights_3d/assets/models/city/tree-small.model @@ -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" + } +} diff --git a/render/basic_lights_3d/assets/models/road/light-curved.model b/render/basic_lights_3d/assets/models/road/light-curved.model new file mode 100644 index 00000000..7018e523 --- /dev/null +++ b/render/basic_lights_3d/assets/models/road/light-curved.model @@ -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 diff --git a/render/basic_lights_3d/assets/textures/colormap_cars.png b/render/basic_lights_3d/assets/textures/colormap_cars.png new file mode 100644 index 00000000..5c4b1857 Binary files /dev/null and b/render/basic_lights_3d/assets/textures/colormap_cars.png differ diff --git a/render/basic_lights_3d/assets/textures/colormap_city.png b/render/basic_lights_3d/assets/textures/colormap_city.png new file mode 100644 index 00000000..9bf7c64e Binary files /dev/null and b/render/basic_lights_3d/assets/textures/colormap_city.png differ diff --git a/render/basic_lights_3d/assets/textures/colormap_roads.png b/render/basic_lights_3d/assets/textures/colormap_roads.png new file mode 100644 index 00000000..edee5867 Binary files /dev/null and b/render/basic_lights_3d/assets/textures/colormap_roads.png differ diff --git a/render/basic_lights_3d/assets/textures/green.png b/render/basic_lights_3d/assets/textures/green.png new file mode 100644 index 00000000..81197caa Binary files /dev/null and b/render/basic_lights_3d/assets/textures/green.png differ diff --git a/render/basic_lights_3d/example.md b/render/basic_lights_3d/example.md new file mode 100644 index 00000000..837e6082 --- /dev/null +++ b/render/basic_lights_3d/example.md @@ -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 + +![setup](setup.png) + +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. + +![material](material.png) + +## 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. + +![pointlight](pointlight.png) + +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. + +![spotlight](spotlight.png) + +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. diff --git a/render/basic_lights_3d/example/basic_lights_3d.collection b/render/basic_lights_3d/example/basic_lights_3d.collection new file mode 100644 index 00000000..89032428 --- /dev/null +++ b/render/basic_lights_3d/example/basic_lights_3d.collection @@ -0,0 +1,822 @@ +name: "orbit_camera" +scale_along_z: 1 +embedded_instances { + id: "scene" + children: "ground" + children: "roads" + data: "components {\n" + " id: \"building-type-a\"\n" + " component: \"/assets/models/city/building-type-a.model\"\n" + " position {\n" + " z: -1.0\n" + " }\n" + " rotation {\n" + " y: 1.0\n" + " w: 6.123234E-17\n" + " }\n" + "}\n" + "components {\n" + " id: \"building-type-a1\"\n" + " component: \"/assets/models/city/building-type-b.model\"\n" + " position {\n" + " x: 2.0\n" + " z: -1.0\n" + " }\n" + " rotation {\n" + " y: 1.0\n" + " w: 6.123234E-17\n" + " }\n" + "}\n" + "components {\n" + " id: \"building-type-a2\"\n" + " component: \"/assets/models/city/building-type-c.model\"\n" + " position {\n" + " x: 2.0\n" + " z: 1.0\n" + " }\n" + "}\n" + "components {\n" + " id: \"building-type-a3\"\n" + " component: \"/assets/models/city/building-type-d.model\"\n" + " position {\n" + " z: 1.0\n" + " }\n" + "}\n" + "components {\n" + " id: \"building-type-a4\"\n" + " component: \"/assets/models/city/building-type-e.model\"\n" + " position {\n" + " x: -2.0\n" + " z: -1.0\n" + " }\n" + " rotation {\n" + " y: 1.0\n" + " w: 6.123234E-17\n" + " }\n" + "}\n" + "components {\n" + " id: \"building-type-a5\"\n" + " component: \"/assets/models/city/building-type-g.model\"\n" + " position {\n" + " x: -2.0\n" + " z: 1.0\n" + " }\n" + "}\n" + "components {\n" + " id: \"building-type-a6\"\n" + " component: \"/assets/models/city/building-type-a.model\"\n" + " position {\n" + " z: -1.0\n" + " }\n" + " rotation {\n" + " y: 1.0\n" + " w: 6.123234E-17\n" + " }\n" + "}\n" + "components {\n" + " id: \"tree\"\n" + " component: \"/assets/models/city/tree-large.model\"\n" + " position {\n" + " x: -3.0\n" + " z: -1.0\n" + " }\n" + " rotation {\n" + " y: 1.0\n" + " w: 6.123234E-17\n" + " }\n" + "}\n" + "components {\n" + " id: \"tree1\"\n" + " component: \"/assets/models/city/tree-large.model\"\n" + " position {\n" + " x: 3.5\n" + " }\n" + " rotation {\n" + " y: 1.0\n" + " w: 6.123234E-17\n" + " }\n" + "}\n" + "components {\n" + " id: \"tree2\"\n" + " component: \"/assets/models/city/tree-small.model\"\n" + " position {\n" + " x: -3.0\n" + " z: 0.8\n" + " }\n" + " rotation {\n" + " y: 1.0\n" + " w: 6.123234E-17\n" + " }\n" + "}\n" + "components {\n" + " id: \"tree3\"\n" + " component: \"/assets/models/city/tree-small.model\"\n" + " position {\n" + " x: -1.0\n" + " z: -0.5\n" + " }\n" + " rotation {\n" + " y: 1.0\n" + " w: 6.123234E-17\n" + " }\n" + "}\n" + "components {\n" + " id: \"tree4\"\n" + " component: \"/assets/models/city/tree-small.model\"\n" + " position {\n" + " x: 1.0\n" + " z: 0.5\n" + " }\n" + " rotation {\n" + " y: 1.0\n" + " w: 6.123234E-17\n" + " }\n" + "}\n" + "" +} +embedded_instances { + id: "camera" + data: "components {\n" + " id: \"main\"\n" + " component: \"/example/orbit_camera.script\"\n" + " properties {\n" + " id: \"zoom\"\n" + " value: \"5.0\"\n" + " type: PROPERTY_TYPE_NUMBER\n" + " }\n" + " properties {\n" + " id: \"zoom_speed\"\n" + " value: \"0.05\"\n" + " type: PROPERTY_TYPE_NUMBER\n" + " }\n" + " properties {\n" + " id: \"rotation_speed\"\n" + " value: \"0.4\"\n" + " type: PROPERTY_TYPE_NUMBER\n" + " }\n" + "}\n" + "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: 500.0\\n" + "auto_aspect_ratio: 1\\n" + "\"\n" + "}\n" + "" + position { + x: -4.0 + y: 1.4 + z: 0.4 + } + rotation { + x: -0.16580236 + y: -0.62755096 + z: -0.1391247 + w: 0.7478861 + } +} +embedded_instances { + id: "lights" + children: "car" + children: "lamp" + children: "sun" + data: "" +} +embedded_instances { + id: "sun" + data: "embedded_components {\n" + " id: \"directional_light\"\n" + " type: \"directional_light\"\n" + " data: \"data {\\n" + " struct {\\n" + " fields {\\n" + " key: \\\"color\\\"\\n" + " value {\\n" + " list {\\n" + " values {\\n" + " number: 1.0\\n" + " }\\n" + " values {\\n" + " number: 1.0\\n" + " }\\n" + " values {\\n" + " number: 1.0\\n" + " }\\n" + " }\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"intensity\\\"\\n" + " value {\\n" + " number: 0.9\\n" + " }\\n" + " }\\n" + " }\\n" + "}\\n" + "\"\n" + "}\n" + "embedded_components {\n" + " id: \"ambient_light\"\n" + " type: \"ambient_light\"\n" + " data: \"data {\\n" + " struct {\\n" + " fields {\\n" + " key: \\\"color\\\"\\n" + " value {\\n" + " list {\\n" + " values {\\n" + " number: 1.0\\n" + " }\\n" + " values {\\n" + " number: 1.0\\n" + " }\\n" + " values {\\n" + " number: 1.0\\n" + " }\\n" + " }\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"intensity\\\"\\n" + " value {\\n" + " number: 0.3\\n" + " }\\n" + " }\\n" + " }\\n" + "}\\n" + "\"\n" + "}\n" + "" + position { + y: 2.0 + } + rotation { + x: -0.4082179 + y: -0.23456971 + z: -0.10938165 + w: 0.8754261 + } +} +embedded_instances { + id: "roads" + data: "components {\n" + " id: \"road\"\n" + " component: \"/assets/models/city/driveway-long.model\"\n" + " rotation {\n" + " y: 0.70710677\n" + " w: 0.70710677\n" + " }\n" + "}\n" + "components {\n" + " id: \"road1\"\n" + " component: \"/assets/models/city/driveway-long.model\"\n" + " position {\n" + " x: -0.4\n" + " }\n" + " rotation {\n" + " y: 0.70710677\n" + " w: 0.70710677\n" + " }\n" + "}\n" + "components {\n" + " id: \"road2\"\n" + " component: \"/assets/models/city/driveway-long.model\"\n" + " position {\n" + " x: 0.4\n" + " }\n" + " rotation {\n" + " y: 0.70710677\n" + " w: 0.70710677\n" + " }\n" + "}\n" + "components {\n" + " id: \"road3\"\n" + " component: \"/assets/models/city/driveway-long.model\"\n" + " position {\n" + " x: 0.8\n" + " }\n" + " rotation {\n" + " y: 0.70710677\n" + " w: 0.70710677\n" + " }\n" + "}\n" + "components {\n" + " id: \"road4\"\n" + " component: \"/assets/models/city/driveway-long.model\"\n" + " position {\n" + " x: -0.8\n" + " }\n" + " rotation {\n" + " y: 0.70710677\n" + " w: 0.70710677\n" + " }\n" + "}\n" + "components {\n" + " id: \"road5\"\n" + " component: \"/assets/models/city/driveway-long.model\"\n" + " position {\n" + " x: 1.2\n" + " }\n" + " rotation {\n" + " y: 0.70710677\n" + " w: 0.70710677\n" + " }\n" + "}\n" + "components {\n" + " id: \"road6\"\n" + " component: \"/assets/models/city/driveway-long.model\"\n" + " position {\n" + " x: -1.2\n" + " }\n" + " rotation {\n" + " y: 0.70710677\n" + " w: 0.70710677\n" + " }\n" + "}\n" + "" + scale3 { + x: 2.0 + y: 2.0 + z: 2.0 + } +} +embedded_instances { + id: "car" + children: "blue_light" + children: "headlight_left" + children: "headlight_right" + children: "rearlight_left" + children: "rearlight_right" + children: "red_light" + data: "components {\n" + " id: \"police\"\n" + " component: \"/assets/models/cars/police.model\"\n" + "}\n" + "components {\n" + " id: \"car\"\n" + " component: \"/example/car.script\"\n" + "}\n" + "" + position { + x: -2.5 + y: 0.01 + } + rotation { + y: 0.70710677 + w: 0.70710677 + } + scale3 { + x: 0.2 + y: 0.2 + z: 0.2 + } +} +embedded_instances { + id: "red_light" + data: "embedded_components {\n" + " id: \"point_light\"\n" + " type: \"point_light\"\n" + " data: \"data {\\n" + " struct {\\n" + " fields {\\n" + " key: \\\"color\\\"\\n" + " value {\\n" + " list {\\n" + " values {\\n" + " number: 1.0\\n" + " }\\n" + " values {\\n" + " number: 0.0\\n" + " }\\n" + " values {\\n" + " number: 0.0\\n" + " }\\n" + " }\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"intensity\\\"\\n" + " value {\\n" + " number: 4.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"range\\\"\\n" + " value {\\n" + " number: 8.0\\n" + " }\\n" + " }\\n" + " }\\n" + "}\\n" + "\"\n" + "}\n" + "" + position { + x: 0.4 + y: 1.4 + z: 0.1 + } + scale3 { + x: 0.5 + y: 0.5 + } +} +embedded_instances { + id: "blue_light" + data: "embedded_components {\n" + " id: \"point_light\"\n" + " type: \"point_light\"\n" + " data: \"data {\\n" + " struct {\\n" + " fields {\\n" + " key: \\\"color\\\"\\n" + " value {\\n" + " list {\\n" + " values {\\n" + " number: 0.0\\n" + " }\\n" + " values {\\n" + " number: 0.0\\n" + " }\\n" + " values {\\n" + " number: 1.0\\n" + " }\\n" + " }\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"intensity\\\"\\n" + " value {\\n" + " number: 4.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"range\\\"\\n" + " value {\\n" + " number: 8.0\\n" + " }\\n" + " }\\n" + " }\\n" + "}\\n" + "\"\n" + "}\n" + "" + position { + x: -0.4 + y: 1.4 + z: 0.1 + } + scale3 { + x: 0.5 + y: 0.5 + } +} +embedded_instances { + id: "headlight_right" + data: "embedded_components {\n" + " id: \"spot_light\"\n" + " type: \"spot_light\"\n" + " data: \"data {\\n" + " struct {\\n" + " fields {\\n" + " key: \\\"color\\\"\\n" + " value {\\n" + " list {\\n" + " values {\\n" + " number: 1.0\\n" + " }\\n" + " values {\\n" + " number: 1.0\\n" + " }\\n" + " values {\\n" + " number: 0.0\\n" + " }\\n" + " }\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"inner_cone_angle\\\"\\n" + " value {\\n" + " number: 30.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"intensity\\\"\\n" + " value {\\n" + " number: 3.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"outer_cone_angle\\\"\\n" + " value {\\n" + " number: 60.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"range\\\"\\n" + " value {\\n" + " number: 20.0\\n" + " }\\n" + " }\\n" + " }\\n" + "}\\n" + "\"\n" + "}\n" + "" + position { + x: -0.4 + y: 0.5 + z: 1.6 + } + rotation { + y: 1.0 + w: 6.123234E-17 + } +} +embedded_instances { + id: "headlight_left" + data: "embedded_components {\n" + " id: \"spot_light\"\n" + " type: \"spot_light\"\n" + " data: \"data {\\n" + " struct {\\n" + " fields {\\n" + " key: \\\"color\\\"\\n" + " value {\\n" + " list {\\n" + " values {\\n" + " number: 1.0\\n" + " }\\n" + " values {\\n" + " number: 1.0\\n" + " }\\n" + " values {\\n" + " number: 0.0\\n" + " }\\n" + " }\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"inner_cone_angle\\\"\\n" + " value {\\n" + " number: 30.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"intensity\\\"\\n" + " value {\\n" + " number: 3.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"outer_cone_angle\\\"\\n" + " value {\\n" + " number: 60.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"range\\\"\\n" + " value {\\n" + " number: 20.0\\n" + " }\\n" + " }\\n" + " }\\n" + "}\\n" + "\"\n" + "}\n" + "" + position { + x: 0.4 + y: 0.5 + z: 1.6 + } + rotation { + y: 1.0 + w: 6.123234E-17 + } +} +embedded_instances { + id: "rearlight_left" + data: "embedded_components {\n" + " id: \"spot_light\"\n" + " type: \"spot_light\"\n" + " data: \"data {\\n" + " struct {\\n" + " fields {\\n" + " key: \\\"color\\\"\\n" + " value {\\n" + " list {\\n" + " values {\\n" + " number: 1.0\\n" + " }\\n" + " values {\\n" + " number: 0.0\\n" + " }\\n" + " values {\\n" + " number: 0.0\\n" + " }\\n" + " }\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"inner_cone_angle\\\"\\n" + " value {\\n" + " number: 40.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"intensity\\\"\\n" + " value {\\n" + " number: 3.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"outer_cone_angle\\\"\\n" + " value {\\n" + " number: 60.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"range\\\"\\n" + " value {\\n" + " number: 8.0\\n" + " }\\n" + " }\\n" + " }\\n" + "}\\n" + "\"\n" + "}\n" + "" + position { + x: 0.4 + y: 0.5 + z: -1.6 + } +} +embedded_instances { + id: "rearlight_right" + data: "embedded_components {\n" + " id: \"spot_light\"\n" + " type: \"spot_light\"\n" + " data: \"data {\\n" + " struct {\\n" + " fields {\\n" + " key: \\\"color\\\"\\n" + " value {\\n" + " list {\\n" + " values {\\n" + " number: 1.0\\n" + " }\\n" + " values {\\n" + " number: 0.0\\n" + " }\\n" + " values {\\n" + " number: 0.0\\n" + " }\\n" + " }\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"inner_cone_angle\\\"\\n" + " value {\\n" + " number: 40.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"intensity\\\"\\n" + " value {\\n" + " number: 3.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"outer_cone_angle\\\"\\n" + " value {\\n" + " number: 60.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"range\\\"\\n" + " value {\\n" + " number: 8.0\\n" + " }\\n" + " }\\n" + " }\\n" + "}\\n" + "\"\n" + "}\n" + "" + position { + x: -0.4 + y: 0.5 + z: -1.6 + } +} +embedded_instances { + id: "ground" + data: "embedded_components {\n" + " id: \"model\"\n" + " type: \"model\"\n" + " data: \"mesh: \\\"/builtins/assets/gltf/quad_2x2.gltf\\\"\\n" + "name: \\\"{{NAME}}\\\"\\n" + "materials {\\n" + " name: \\\"default\\\"\\n" + " material: \\\"/builtins/materials/model_instanced_lit.material\\\"\\n" + " textures {\\n" + " sampler: \\\"tex0\\\"\\n" + " texture: \\\"/assets/textures/green.png\\\"\\n" + " }\\n" + "}\\n" + "\"\n" + " rotation {\n" + " x: -0.70710677\n" + " w: 0.70710677\n" + " }\n" + "}\n" + "" + scale3 { + x: 8.0 + y: 8.0 + z: 8.0 + } +} +embedded_instances { + id: "lamp" + children: "lamp_light" + data: "components {\n" + " id: \"lamp\"\n" + " component: \"/assets/models/road/light-curved.model\"\n" + " rotation {\n" + " y: 1.0\n" + " w: 6.123234E-17\n" + " }\n" + "}\n" + "" + position { + x: 1.0 + z: -0.5 + } +} +embedded_instances { + id: "lamp_light" + data: "embedded_components {\n" + " id: \"spot_light\"\n" + " type: \"spot_light\"\n" + " data: \"data {\\n" + " struct {\\n" + " fields {\\n" + " key: \\\"color\\\"\\n" + " value {\\n" + " list {\\n" + " values {\\n" + " number: 1.0\\n" + " }\\n" + " values {\\n" + " number: 1.0\\n" + " }\\n" + " values {\\n" + " number: 0.0\\n" + " }\\n" + " }\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"inner_cone_angle\\\"\\n" + " value {\\n" + " number: 0.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"intensity\\\"\\n" + " value {\\n" + " number: 3.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"outer_cone_angle\\\"\\n" + " value {\\n" + " number: 70.0\\n" + " }\\n" + " }\\n" + " fields {\\n" + " key: \\\"range\\\"\\n" + " value {\\n" + " number: 2.0\\n" + " }\\n" + " }\\n" + " }\\n" + "}\\n" + "\"\n" + "}\n" + "" + position { + y: 0.62 + z: 0.17 + } + rotation { + x: -0.8433914 + w: 0.53729963 + } +} diff --git a/render/basic_lights_3d/example/car.script b/render/basic_lights_3d/example/car.script new file mode 100644 index 00000000..360e66ba --- /dev/null +++ b/render/basic_lights_3d/example/car.script @@ -0,0 +1,22 @@ +function init(self) + -- Start an animation to go over X axis looking like the car is driving back and forth + go.animate(".", "position.x", go.PLAYBACK_LOOP_PINGPONG, 2.5, go.EASING_INOUTSINE, 10) + + -- Store car's initial rotation + self.rotation = go.get_rotation(".") + + -- Every 5 seconds start a rotation animation + timer.delay(5, true, function() + -- Rotate the car around its Y axis + self.rotation.y = - self.rotation.y + go.animate(".", "rotation", go.PLAYBACK_ONCE_FORWARD, self.rotation, go.EASING_INOUTSINE, 0.5) + end) + + -- Animate the scale of the game object containing a blue light component of the police siren lights + go.animate("/blue_light", "scale", go.PLAYBACK_LOOP_PINGPONG, vmath.vector3(1.5), go.EASING_INOUTSINE, 1) + + -- Animate the scale of the game object containing a red light component of the police siren lights + timer.delay(0.5, false, function() + go.animate("/red_light", "scale", go.PLAYBACK_LOOP_PINGPONG, vmath.vector3(1.5), go.EASING_INOUTSINE, 1) + end) +end \ No newline at end of file diff --git a/render/basic_lights_3d/example/orbit_camera.script b/render/basic_lights_3d/example/orbit_camera.script new file mode 100644 index 00000000..a9775708 --- /dev/null +++ b/render/basic_lights_3d/example/orbit_camera.script @@ -0,0 +1,49 @@ +-- The initial zoom level +go.property("zoom", 3) +-- The speed of the zoom +go.property("zoom_speed", 0.1) +-- The speed of the rotation +go.property("rotation_speed", 0.5) +-- The offset of the camera from the origin +go.property("offset", vmath.vector3(0, 0, 0)) + +function init(self) + -- Acquire input focus to receive input events + msg.post(".", "acquire_input_focus") + + -- Initialize start values + self.yaw = go.get(".", "euler.y") + self.pitch = go.get(".", "euler.x") + self.zoom_offset = 0 + self.current_yaw = self.yaw + self.current_pitch = self.pitch + self.current_zoom = self.zoom_offset +end + +function update(self, dt) + -- Animate camera rotation and zoom + self.current_yaw = vmath.lerp(0.15, self.current_yaw, self.yaw) + self.current_pitch = vmath.lerp(0.15, self.current_pitch, self.pitch) + self.current_zoom = vmath.lerp(0.15, self.current_zoom, self.zoom_offset) + + -- Calculate rotation and position + local camera_yaw = vmath.quat_rotation_y(math.rad(self.current_yaw)) + local camera_pitch = vmath.quat_rotation_x(math.rad(self.current_pitch)) + local camera_rotation = camera_yaw * camera_pitch + local camera_position = self.offset + vmath.rotate(camera_rotation, vmath.vector3(0, 0, self.zoom + self.current_zoom)) + + -- Set camera position and rotation + go.set_position(camera_position) + go.set_rotation(camera_rotation) +end + +function on_input(self, action_id, action) + if action_id == hash("touch") and not action.pressed then + self.yaw = self.yaw - action.dx * self.rotation_speed + self.pitch = self.pitch + action.dy * self.rotation_speed + elseif action_id == hash("mouse_wheel_up") then + self.zoom_offset = self.zoom_offset - self.zoom * self.zoom_speed + elseif action_id == hash("mouse_wheel_down") then + self.zoom_offset = self.zoom_offset + self.zoom * self.zoom_speed + end +end diff --git a/render/basic_lights_3d/game.project b/render/basic_lights_3d/game.project new file mode 100644 index 00000000..e9dc711b --- /dev/null +++ b/render/basic_lights_3d/game.project @@ -0,0 +1,66 @@ +[project] +title = Basic Lights 3D +version = 0.1 +dependencies = + +[bootstrap] +main_collection = /example/basic_lights_3d.collectionc + +[input] +game_binding = /builtins/input/all.input_bindingc +repeat_interval = 0.05 + +[display] +width = 720 +height = 720 +high_dpi = 1 + +[physics] +scale = 0.02 +gravity_y = -500.0 + +[script] +shared_state = 1 + +[collection_proxy] +max_count = 256 + +[label] +subpixels = 1 + +[sprite] +subpixels = 1 +max_count = 32765 + +[windows] +iap_provider = + +[android] +package = com.defold.examples + +[ios] +bundle_identifier = com.defold.examples + +[osx] +bundle_identifier = com.defold.examples + +[html5] +show_fullscreen_button = 0 +show_made_with_defold = 0 +scale_mode = no_scale +heap_size = 64 + +[graphics] +texture_profiles = /all.texture_profiles + +[collection] +max_instances = 32765 + +[particle_fx] +max_emitter_count = 1024 + +[render] +clear_color_blue = 0.9 +clear_color_green = 0.9 +clear_color_red = 0.9 + diff --git a/render/basic_lights_3d/material.png b/render/basic_lights_3d/material.png new file mode 100644 index 00000000..8358bb7e Binary files /dev/null and b/render/basic_lights_3d/material.png differ diff --git a/render/basic_lights_3d/pointlight.png b/render/basic_lights_3d/pointlight.png new file mode 100644 index 00000000..7db15d40 Binary files /dev/null and b/render/basic_lights_3d/pointlight.png differ diff --git a/render/basic_lights_3d/setup.png b/render/basic_lights_3d/setup.png new file mode 100644 index 00000000..b73c285f Binary files /dev/null and b/render/basic_lights_3d/setup.png differ diff --git a/render/basic_lights_3d/spotlight.png b/render/basic_lights_3d/spotlight.png new file mode 100644 index 00000000..a2ba662b Binary files /dev/null and b/render/basic_lights_3d/spotlight.png differ diff --git a/render/basic_lights_3d/thumbnail.webp b/render/basic_lights_3d/thumbnail.webp new file mode 100644 index 00000000..1a2fe078 Binary files /dev/null and b/render/basic_lights_3d/thumbnail.webp differ