-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
KHR_lights_punctual extension proposal #1223
Merged
Merged
Changes from 29 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
31ca6c2
First draft of khr_lights
MiiBond 524fd6b
Updates to clarify units
MiiBond 8cb0c17
Removing hemisphere light
MiiBond bd8938e
Update spotlight property description
MiiBond 07a8fec
Adjustments to light descriptions for directional and spotlights
MiiBond 2113228
Clarifying usage of ambient lights and colour space of lights
MiiBond e7ae552
Adding base node properties to lights
MiiBond 0610717
Removing name properites from lights in KHR_lights example.
MiiBond 72096c4
Adding light's name property back in for consistency
MiiBond e495b9e
Fix typos in schemas
MiiBond 625b28e
Remove redundant bounds specification for inner and outer cone angles
MiiBond dbc99db
Fix inconsistency in spotlight angle bounds
MiiBond 8326130
Updates to light schemas
MiiBond 26f376f
Merge branch 'master' of github.com:KhronosGroup/glTF into khr_lights_v1
MiiBond 0a79dc7
Move KHR_lights to match new folder structure
MiiBond 6aff0cc
Few tweaks to address comments
MiiBond 6e871f6
Adding range
MiiBond c605724
Add range property to schema
MiiBond 766ba65
Remove reference to aesthetic reasons for using light range.
MiiBond b5dff39
Merge branch 'master' of github.com:KhronosGroup/glTF into khr_lights_v1
MiiBond 8ae54ee
Rename extension and remove ambient lights
MiiBond 3dcdfb0
Format exponents.
bd047d4
Update readme title.
34ae110
Update inner and outer angle description for spotlights
MiiBond 382d3d6
Merge branch 'master' of github.com:KhronosGroup/glTF into khr_lights_v1
MiiBond be36985
Merge branch 'khr_lights_v1' of github.com:MiiBond/glTF into khr_ligh…
MiiBond 2945499
Remove reference to UE4 and Frostbite
MiiBond 08bc3c7
Remove more references to ambient lights
MiiBond 28d2bac
Make it clearer that the spotlight code is for the attenuation betwee…
MiiBond 78a93ae
Updating the list of contributors
MiiBond d9a6811
Updating the description for range
MiiBond 50050e6
Merge branch 'master' of github.com:KhronosGroup/glTF into khr_lights_v1
MiiBond 66dfb38
Change default light direction from pointing down +Z to pointing down -Z
MiiBond 1048d16
Address several comments
MiiBond 10ed0c6
Scale affects light orientation, not properties.
d9313cf
Remove space in filename.
fa6d985
Remove space in filename.
2d240ec
+z -> -z
93ae7df
Make 'light' required on node.
e4989c1
Make 'lights' required on top-level extension.
03f63e0
Use default values when 'spot' property is omitted.
f49c51e
Make spot property required when type is 'spot'.
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 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,153 @@ | ||
# KHR\_lights\_punctual | ||
|
||
## Contributors | ||
|
||
* Norbert Nopper, UX3D, <mailto:[email protected]> | ||
* Thomas Kress, UX3D, <mailto:[email protected]> | ||
* Mike Bond, Adobe, <mailto:[email protected]> | ||
|
||
## Status | ||
|
||
Draft (not ratified yet) | ||
|
||
## Dependencies | ||
|
||
Written against the glTF 2.0 spec. | ||
|
||
## Overview | ||
|
||
This extension defines a set of lights for use with glTF 2.0. Lights define light sources within a scene. | ||
|
||
Many 3D tools and engines support built-in implementations of light types. Using this extension, tools can export and engines can import these lights. | ||
|
||
This extension defines three "punctual" light types: `directional`, `point` and `spot`. Punctual lights are defined as parameterized, infinitely small points that emit light in well-defined directions and intensities. | ||
|
||
These lights are referenced by nodes and inherit the transform of that node. | ||
|
||
A conforming implementation of this extension must be able to load light data defined in the asset and has to render the asset using those lights. | ||
|
||
## Defining Lights | ||
|
||
Lights are defined within a dictionary property in the glTF manifest file, by adding an `extensions` property to the top-level glTF 2.0 object and defining a `KHR_lights_punctual` property with a `lights` array inside it. | ||
|
||
Each light defines a mandatory `type` property that designates the type of light (`directional`, `point` or `spot`). The following example defines a white-colored directional light. | ||
|
||
```javascript | ||
"extensions": { | ||
"KHR_lights_punctual" : { | ||
"lights": [ | ||
{ | ||
"color": [ | ||
1.0, | ||
1.0, | ||
1.0 | ||
], | ||
"type": "directional" | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
## Adding Light Instances to Nodes | ||
|
||
Lights must be attached to a node by defining the `extensions.KHR_lights_punctual` property and, within that, an index into the `lights` array using the `light` property. | ||
|
||
```javascript | ||
"nodes" : [ | ||
{ | ||
"extensions" : { | ||
"KHR_lights_punctual" : { | ||
"light" : 0 | ||
} | ||
} | ||
} | ||
] | ||
``` | ||
|
||
The light will inherit the transform of the node. For light types that have a position (`point` and `spot` lights), the light's position is defined as the node's world location. | ||
For light types that have a direction (`directional` and `spot` lights), the light's direction is defined as the 3-vector `(0.0, 0.0, 1.0)` and the rotation of the node orients the light accordingly. | ||
|
||
## Light Types | ||
|
||
All light types share the common set of properties listed below. | ||
|
||
### Light Shared Properties | ||
|
||
| Property | Description | Required | | ||
|:-----------------------|:------------------------------------------| :--------------------------| | ||
| `name` | Name of the light. | No, Default: `""` | | ||
| `color` | RGB value for light's color in linear space. | No, Default: `[1.0, 1.0, 1.0]` | | ||
| `intensity` | Brightness of light in. The units that this is defined in depend on the type of light. `point` and `spot` lights use luminous intensity in candela (lm/sr) while `directional` lights use illuminance in lux (lm/m<sup>2</sup>) | No, Default: `1.0` | | ||
| `type` | Declares the type of the light. | :white_check_mark: Yes | | ||
| `range` | Hint defining a distance cutoff at which the light's intensity may be considered to have reached zero. Supported only for `point` and `spot` lights. | No, Default: `0.0` | | ||
|
||
## Range Property | ||
|
||
The range property (allowed only on point and spot lights) defines a distance cutoff at which the light's intensity must be considered zero, meaning the light no longer affects the surrounding area. This can be useful to cull geometry that a light may not visibly affect, potentially having a significant positive impact on rendering performance. It is required that, when given a non-zero value, rendering engines ignore the light beyond this range. | ||
|
||
Within the range of the light, attenuation should follow the inverse square law as closely as possible, although some non-quadratic falloff near the edge of the range may be used to avoid a hard cutoff. A `range` of 0 implies that no cutoff should be used, attenuating only according to inverse square law. | ||
|
||
A recommended implementation for this attenuation with a cutoff range is as follows: | ||
|
||
**attenuation = max( min( 1.0 - ( current_distance / range )<sup>4</sup>, 1 ), 0 ) / current_distance<sup>2</sup>** | ||
|
||
### Directional | ||
|
||
Directional lights are light sources that act as though they are infinitely far away and emit light in the direction of the local +z axis. This light type inherits the orientation of the node that it belongs to but ignores position and scale. Because it is at an infinite distance, the light is not attenuated. Its intensity is defined in lumens per metre squared, or lux (lm/m<sup>2</sup>). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this say |
||
|
||
### Point | ||
|
||
Point lights emit light in all directions from its position in space (and ignore rotation and scale). The brightness of the light attenuates in a physically correct manner as distance increases from the light's position (i.e. brightness goes like the inverse square of the distance). Point light intensity is defined in candela, which is lumens per square radian (lm/sr). | ||
|
||
### Spot | ||
|
||
Spot lights emit light in a cone in the direction of the local +z axis. The angle and falloff of the cone is defined using two numbers, the `innerConeAngle` and `outerConeAngle`. As with point lights, the brightness also attenuates in a physically correct manner as distance increases from the light's position (i.e. brightness goes like the inverse square of the distance). Spot light intensity refers to the brightness inside the `innerConeAngle` (and at the location of the light) and is defined in candela, which is lumens per square radian (lm/sr). Engines that don't support two angles for spotlights should use `outerConeAngle` as the spotlight angle (leaving `innerConeAngle` to implicitly be `0`). | ||
|
||
| Property | Description | Required | | ||
|:-----------------------|:------------------------------------------| :--------------------------| | ||
| `innerConeAngle` | Angle, in radians, from centre of spotlight where falloff begins. Must be greater than or equal to `0` and less than `outerConeAngle`. | No, Default: `0` | | ||
| `outerConeAngle` | Angle, in radians, from centre of spotlight where falloff ends. Must be greater than `innerConeAngle` and less than or equal to `PI / 2.0`. | No, Default: `PI / 4.0` | | ||
|
||
```javascript | ||
"extensions": { | ||
"KHR_lights_punctual" : { | ||
"lights": [ | ||
{ | ||
"spot": { | ||
"innerConeAngle": 0.785398163397448, | ||
"outerConeAngle": 1.57079632679, | ||
}, | ||
"color": [ | ||
1.0, | ||
1.0, | ||
1.0 | ||
], | ||
"type": "spot" | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
## Inner and Outer Cone Angles | ||
|
||
There should be a smooth attenuation of brightness between the `innerConeAngle` and `outerConeAngle` angles. In reality, this "angular" attenuation is very complex as it depends on the physical size of the spotlight and the shape of the sheath around the bulb. | ||
|
||
Conforming implementations will model this angular attenuation with a curve that follows a steeper decline in brightness before leveling off when moving from the inner to the outer angle. | ||
|
||
It is common to model this falloff by interpolating between the cosine of each angle. This is an efficient approximation that provides decent results. | ||
|
||
Reference code: | ||
|
||
```c++ | ||
// These two values can be calculated on the CPU and passed into the shader | ||
float lightAngleScale = 1.0f / max(0.001f, cos(innerConeAngle) - cos(outerConeAngle)); | ||
float lightAngleOffset = -cos(outerConeAngle) * lightAngleScale; | ||
|
||
// Then, in the shader: | ||
float cd = dot(spotlightDir, normalizedLightVector); | ||
float angularAttenuation = saturate(cd * lightAngleScale + lightAngleOffset); | ||
angularAttenuation *= angularAttenuation; | ||
``` | ||
|
Binary file added
BIN
+20.2 KB
...ons/2.0/Khronos/KHR_lights_punctual/schema/examples/MODEL_ROUNDED_CUBE_PART_1/indices.bin
Binary file not shown.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change "manifest" to "scene description" to align with the core spec.