-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft of FB_materials_lightmap extension
- Loading branch information
Showing
3 changed files
with
156 additions
and
0 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,86 @@ | ||
# FB\_materials\_lightmap | ||
|
||
## Contributors | ||
|
||
* Alfred Young, Facebook, [@idorurez](https://github.com/idorurez) | ||
* Pär Winzell, Facebook, [@zellski](https://twitter.com/zellski) | ||
|
||
## Status | ||
|
||
Draft | ||
|
||
## Dependencies | ||
|
||
Written against the glTF 2.0 spec. | ||
|
||
## Overview | ||
|
||
This extension adds an additional annotation to a material, providing a means to introduce a lightmap to be applied in the same scope. | ||
|
||
Some proven real-world applications for this information: | ||
1. Having multiple variations of lighting scenarios without having to bake lighting into a single, original base color/texture. | ||
2. Specify a separate UV channel (texCoord), to vary the new texture texel resolution with respect to the texture it's being applied to. | ||
3. Modulate the intensity of a lightmap, dimming or increasing it's effect. | ||
|
||
## Color | ||
|
||
### RGB | ||
|
||
Color is stored in the RGB channels, with no accommodation for an alpha channel. No restriction is placed on the the values. | ||
|
||
### Color Space | ||
|
||
We'll refer to Unity's guidelines regarding Color Space: "When Linear Color Space is used, the lightmap texture is marked as sRGB and the final value used by the shaders (after sampling and decoding) will be in Linear Color Space. When Gamma Color Space is used, the final value will be in Gamma Color Space." | ||
|
||
## Specifying Material extension | ||
|
||
The data is defined as an optional extension to a glTF `materials`, by adding an `extensions` property and defining a `FB_materials_lightmap` property with a `lightmapTexture` node inside it: | ||
|
||
```javascript | ||
"materials" : [ | ||
{ | ||
"name" : "material_test", | ||
"pbrMetallicRoughness" : { | ||
"baseColorTexture" : { | ||
"index" : 0, | ||
"texCoord" : 0 | ||
} | ||
}, | ||
"extensions" : { | ||
"FB_materials_lightmap" : { | ||
"lightmapTexture" : { | ||
"index" : 1, | ||
"texCoord" : 1, | ||
}, | ||
"lightmapFactor" : [ | ||
1, | ||
1, | ||
1 | ||
] | ||
} | ||
} | ||
} | ||
], | ||
``` | ||
|
||
## Sample Implementation | ||
|
||
In it's simplemest form, Lightmap implementation predominantely involes a base, unlit texture or color in a material, and the supplied lightmap texture is sampled and multiplied against that unlit texture/color. | ||
|
||
```javascript | ||
lowp vec4 lightmapColor = texture2D(LightmapTexture, oLightmapTexCoord); | ||
color.rgb *= (LightmapFactor.rgb * lightmapColor.rgb); | ||
|
||
``` | ||
|
||
## Limitations | ||
This does not define how the lightmap will be applied, just that one exists. | ||
|
||
## lightmapTexture properties | ||
| Property | Description | Required | | ||
|:-----------------------|:------------------------------------------| :--------------------------| | ||
| `index` | Texture descriptor index. | :white_check_mark: Yes | | ||
| `texCoord` | Texture coordinate index, aka UV set | No, Default: `0` | | ||
| `lightmapFactor` | A 3-component vector describing the attenuation of the lightmap before baseColor application. | No, Default: `[1.0, 1.0, 1.0]` | | ||
|
||
|
35 changes: 35 additions & 0 deletions
35
extensions/2.0/Vendor/FB_materials_lightmap/schema/lightmap.schema.json
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,35 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema", | ||
"title": "lightmap properties", | ||
"type": "object", | ||
"allOf": [ | ||
{ | ||
"$ref": "glTFProperty.schema.json" | ||
} | ||
], | ||
"properties": { | ||
"index": { | ||
"type": "number", | ||
"description": "The texture index of which this lightmap refers to", | ||
"minimum": 0, | ||
"minItems": 1, | ||
"maxItems": 1 | ||
}, | ||
"texCoord": { | ||
"description": "The texture coordinate (uv set) that this lightmap texture uses", | ||
"type": "number", | ||
"items": { | ||
"type": "number" | ||
}, | ||
"default": 0, | ||
"minimum": 0, | ||
"minItems": 1, | ||
"maxItems": 1 | ||
}, | ||
"extensions": {}, | ||
"extras": {}, | ||
"required" : [ | ||
"index" | ||
] | ||
}, | ||
} |
35 changes: 35 additions & 0 deletions
35
.../Vendor/FB_materials_lightmap/schema/material.extension.FB_materials_lightmap.schema.json
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,35 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema", | ||
"title": "FB_materials_lightmap material extension", | ||
"type": "object", | ||
"allOf": [ | ||
{ | ||
"$ref": "glTFProperty.schema.json" | ||
} | ||
], | ||
"properties": { | ||
"lightmapTexture": { | ||
"description": "The texture information for the lightmap.", | ||
"allOf": [ | ||
{ | ||
"$ref": "lightmap.schema.json" | ||
} | ||
] | ||
}, | ||
"lightmapFactor": { | ||
"description": "The rgb component-wise factor that should be applied to the lightmap before applying to the base color", | ||
"type": "array", | ||
"items": { | ||
"type": "number" | ||
}, | ||
"default": [1, 1, 1], | ||
"minItems": 3, | ||
"maxItems": 3 | ||
}, | ||
"extensions": {}, | ||
"extras": {} | ||
}, | ||
"required": [ | ||
"lightmapTexture" | ||
] | ||
} |