From f199bbdc3741a3e75605f2fedbafe351d079b544 Mon Sep 17 00:00:00 2001 From: Lean Mendoza Date: Wed, 18 Sep 2024 06:57:08 -0300 Subject: [PATCH] lights initial (#217) * lights initial * Pb -> PB --------- Co-authored-by: robtfm <50659922+robtfm@users.noreply.github.com> --- .../sdk/components/global_light.proto | 22 ++++++++++ .../sdk/components/gltf_node.proto | 6 +-- proto/decentraland/sdk/components/light.proto | 42 +++++++++++++++++++ .../sdk/components/spotlight.proto | 21 ++++++++++ 4 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 proto/decentraland/sdk/components/global_light.proto create mode 100644 proto/decentraland/sdk/components/light.proto create mode 100644 proto/decentraland/sdk/components/spotlight.proto diff --git a/proto/decentraland/sdk/components/global_light.proto b/proto/decentraland/sdk/components/global_light.proto new file mode 100644 index 00000000..ea76ccb6 --- /dev/null +++ b/proto/decentraland/sdk/components/global_light.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; +package decentraland.sdk.components; + +import "decentraland/common/colors.proto"; +import "decentraland/common/vectors.proto"; + +import "decentraland/sdk/components/common/id.proto"; +option (common.ecs_component_id) = 1206; + +// defines the global scene light settings. must be added to the scene root. +// to control sunlight color, intensity, shadows etc, you can also add a PBLight to the scene root. +message PBGlobalLight { + // the direction the directional light shines in. + // default depends on time of day and explorer implementation + optional decentraland.common.Vector3 direction = 1; + // ambient light color + // default: White + optional decentraland.common.Color3 ambient_color = 2; + // ambient light intensity. the explorer default ambient brightness is multiplied by this non-physical quantity. + // default 1 + optional float ambient_brightness = 3; +} diff --git a/proto/decentraland/sdk/components/gltf_node.proto b/proto/decentraland/sdk/components/gltf_node.proto index 9f2e3503..86d1e26a 100644 --- a/proto/decentraland/sdk/components/gltf_node.proto +++ b/proto/decentraland/sdk/components/gltf_node.proto @@ -5,12 +5,12 @@ import "decentraland/sdk/components/common/id.proto"; option (common.ecs_component_id) = 1200; // a GltfNode links a scene entity with a node from within a gltf, allowing the scene to inspect it or modify it. -// This component must be added to a direct child of an entity with a PbGltfContainer component, or +// This component must be added to a direct child of an entity with a PBGltfContainer component, or // to a direct child of another entity with a GltfNode component, and the referenced gltf node must be a descendent of the gltf node // in the parent. // The name must match the path of one of the nodes within the Gltf. These are available on the GltfContainerLoadingState component. // -// The renderer will attach a PbGltfNodeState to the entity describing the state. Once the state is `GNS_READY`, +// The renderer will attach a PBGltfNodeState to the entity describing the state. Once the state is `GNS_READY`, // - the `Transform` will be updated to match the position of the node within the gltf (relative to the gltf root, or the parent node), // - a `MeshRenderer` with a GltfMesh mesh type will be added (if the gltf node has a mesh). // - a `MeshCollider` with a GltfMesh mesh type will be added (if the gltf node has a collider). @@ -27,7 +27,7 @@ option (common.ecs_component_id) = 1200; // - `MeshCollider` can be added/modified/removed to create/modify/remove a collider on the node. // - `Material` can be added or modified to change the material properties. If the gltf node has a material, the original material will be // used as a base, and any gltf features (e.g. occlusion maps) from the gtlf spec that the renderer supports but that are not exposed in the -// PbMaterial will be maintained. +// PBMaterial will be maintained. // // The scene can add additional entities as children to the gltf node, but structural modifications of the gltf are not possible: // - changing the scene hierarchy will not change the gltf node hierarchy. Moving the entity out of the gltf will sever the link and diff --git a/proto/decentraland/sdk/components/light.proto b/proto/decentraland/sdk/components/light.proto new file mode 100644 index 00000000..167560e5 --- /dev/null +++ b/proto/decentraland/sdk/components/light.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; +package decentraland.sdk.components; + +import "decentraland/common/colors.proto"; + +import "decentraland/sdk/components/common/id.proto"; +option (common.ecs_component_id) = 1204; + +// defines a light source. +// the world has a default directional light (like sunlight) which can be overridden by adding the light component to the scene root. +// a PBGlobalLight component can also be added to the root to control the directional light direction. +// point lights (lightbulbs) or spotlights can be created by attaching the light component to non-root entities. +message PBLight { + // whether the light is on + // default true + optional bool enabled = 1; + // light brightness in lux (lumens/m^2). + // + // for global directional light, this applies as a constant value at all surfaces and distances (though the effect on the surface still depends on incidence angle). + // the default global light illuminance varies from 400 (sunrise/sunset) to 10,000 (midday). + // for typical values, see https://en.wikipedia.org/wiki/Lux#Illuminance + // + // for point and spot lights, this is the lumens/m^2 at 1m distance from the light. to transform from raw lumens, + // divide lumens by ~12 (4*pi). + // e.g. a 100w household bulb with 1200 lumens would have an illuminance of ~100. + // a lighthouse bulb with 200,000 lumens would have an illuminance of ~15,000 (ignoring beam reflections) + // + // default + // for point/spotlights: 10,000 + // for global directional light: depends on explorer implementation. may vary on light direction, time of day, etc + optional float illuminance = 2; + // whether the light should cast shadows. + // note: even when set to true the engine may not display shadows, or may only show shadows for a limited number + // of lights depending on the implementation, platform, and user settings. + // default + // for point/spotlights: false / off + // for global directional light: true / on + optional bool shadows = 3; + // light color + // default White + optional decentraland.common.Color3 color = 4; +} diff --git a/proto/decentraland/sdk/components/spotlight.proto b/proto/decentraland/sdk/components/spotlight.proto new file mode 100644 index 00000000..40f46add --- /dev/null +++ b/proto/decentraland/sdk/components/spotlight.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; +package decentraland.sdk.components; + +import "decentraland/sdk/components/common/id.proto"; +option (common.ecs_component_id) = 1205; + +// defines a spotlight. +// spotlights are point lights that emit light only in a cone around the transform's forward direction. +// add this component together with the PBLight component to transform a point light into a spotlight. +// note that spotlights do not model any internal reflections / focus, they only restrict the area of effect. +// so for e.g. a torch beam, the bulb illuminance should be multiplied by the solid angle. +// a typical torch with a beam width of 15 degrees would use outer angle of 0.15 (7.5 degrees in radians), +// and an illuminance approximately equal to the bulb's lumens, e.g. 1200. +message PBSpotlight { + // the cone radius in radians. distance away from forward in which the light is visible. + // for a torch a value around 0.15 is appropriate. + float angle = 1; + // optional angle at which the light is brightest. should be <= outer angle. + // if specified, the light will fall off smoothly between `inner_angle` and `angle`. + optional float inner_angle = 2; +}