Skip to content
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

Serialize lights into gfx-replay json format. #1857

Merged
merged 8 commits into from
Sep 28, 2022

Conversation

0mdc
Copy link
Contributor

@0mdc 0mdc commented Sep 7, 2022

Motivation and Context

This changeset adds light serialization to the gfx-replay format.

Lights are serialized incrementally - they are only written to the json file when lighting changes occur. We assume that the keyframes are always read sequentially.

`GfxReplayTest::testLightIntegration` Replay File
{
    "keyframes": [
        {
            "lightsChanged": true,
            "lights": [
                {
                    "vector": [
                        1.5,
                        2.0,
                        2.5,
                        1.0
                    ],
                    "color": [
                        1.5,
                        2.0,
                        5.0
                    ],
                    "model": "global"
                },
                {
                    "vector": [
                        -10.0,
                        4.25,
                        10.0,
                        1.0
                    ],
                    "color": [
                        5.0,
                        5.0,
                        0.0
                    ],
                    "model": "camera"
                }
            ]
        },
        {
            "lightsChanged": true,
            "lights": [
                {
                    "vector": [
                        0.0,
                        1.2,
                        -4.0,
                        1.0
                    ],
                    "color": [
                        4.0,
                        4.0,
                        4.0
                    ],
                    "model": "object"
                }
            ]
        },
        {},
        {
            "lightsChanged": true,
            "lights": [
                {
                    "vector": [
                        0.1,
                        0.2,
                        -0.3,
                        0.0
                    ],
                    "color": [
                        0.0,
                        0.0,
                        1.0
                    ],
                    "model": "global"
                }
            ]
        },
        {
            "lightsChanged": true
        }
    ]
}

How Has This Been Tested

  • New unit test (GfxReplayTest::testLightIntegration).

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@0mdc 0mdc self-assigned this Sep 7, 2022
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Sep 7, 2022
@0mdc 0mdc force-pushed the replay-light-test branch 3 times, most recently from 9f1befe to 96431df Compare September 9, 2022 15:16
@0mdc 0mdc force-pushed the replay-light-test branch 2 times, most recently from 1f571f1 to 8a65ae5 Compare September 14, 2022 21:14
@0mdc 0mdc changed the title [WIP] Add lights to gfx-replay format. Serialize lights into gfx-replay json format. Sep 16, 2022
@0mdc 0mdc force-pushed the replay-light-test branch 2 times, most recently from 5ccb0bf to 07694ba Compare September 16, 2022 19:24
src/tests/GfxReplayTest.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@eundersander eundersander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far. I left a few comments.

src/esp/gfx/replay/Keyframe.h Outdated Show resolved Hide resolved
src/esp/io/JsonEspTypes.cpp Outdated Show resolved Hide resolved
src/esp/io/JsonEspTypes.cpp Outdated Show resolved Hide resolved
src/esp/io/JsonEspTypes.cpp Outdated Show resolved Hide resolved
src/esp/io/JsonEspTypes.cpp Show resolved Hide resolved
@@ -55,6 +55,7 @@ struct Keyframe {
std::vector<std::pair<RenderAssetInstanceKey, RenderAssetInstanceState>>
stateUpdates;
std::unordered_map<std::string, Transform> userTransforms;
Cr::Containers::Optional<std::vector<LightInfo>> lights;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little torn on serializing our entire quirky LightInfo struct (including LightPositionModel). I talked in the design doc about wanting gfx-replay to be agnostic to the renderer, and most renderers IMO won't offer "object-local" or "camera-local" lights. I think we only need to support lights specified in global space. Also, I don't think anybody is using object-local or camera-local lights in Habitat. I don't think we'll bother implementing them in the new batch renderer.

See also this discussion here: https://cvmlp.slack.com/archives/G0131KVLBLL/p1660649432149979 .

It is probably fine to leave this as-is, but let's beware introducing unneeded complexity into the gfx-replay format in general.

Copy link
Contributor Author

@0mdc 0mdc Sep 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely agree.

I feel like it doesn't hurt to leave the LightPositionModel field as-is for now. We should look into specifying a standard light data layout as we integrate them with the batch renderer.

I am still unfamiliar with the batch renderer, but if we are following a pure ECS approach, we might want to separate the transform component from the light data.

I think we only need to support lights specified in global space.

Object-local lights may be occasionally useful (e.g. if the simulated agent has a light). However, I don't think that we are doing anything like that at the moment.

I don't know how camera-local lights would be useful.

Magnum::Vector3 vec3;
for (rapidjson::SizeType i = 0; i < 3; ++i) {
if (obj[i].IsNumber()) {
vec3[i] = obj[i].GetDouble();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vector3 stores floats right? Why do we keep calling getDouble? Are we also serializing it as a double? These storing floats as doubles add up.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON's only numeric type is doubles, yes. Not sure if rapidjson even has 32-bit-float APIs, usually there isn't any significant difference in parsing as a float or a double.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh darn, didn't know that about JSON. Yet another reason to avoid using it for our dataset.jsons in Habitat-Lab. 0-0 You can set the max decimal places in RapidJSON globally it appears, but other than that no. :(

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrade's Utility::Json has an option to switch between floats / doubles (and 32/64bit integer types), but not even there it makes any difference memory-usage-wise (it abuses the IEEE floating-point layout to store integers inside a double representation, and in all cases it's stored directly in parsed token memory that just has to be of certain size), and until I have my own optimized floating-point parser that has a dedicated code path for 32bit floats, it won't make any difference for parsing speed either. It's there purely for convenience.

But limiting decimal places (or excessive line wraps / indentation for arrays) could make a difference in subsequent parsing time, yes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related: see usePrettyWriter and maxDecimalPlaces in writeJsonToFile. I added this in a half-hearted attempt to minimize the filesize of gfx-replay files.

Copy link
Contributor

@eundersander eundersander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@0mdc 0mdc merged commit 71ec44f into facebookresearch:main Sep 28, 2022
@0mdc 0mdc deleted the replay-light-test branch June 14, 2023 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants