Skip to content

Commit

Permalink
Move stereoscopic debug options to Settings framework
Browse files Browse the repository at this point in the history
  • Loading branch information
bejado committed Nov 10, 2023
1 parent bf87121 commit 7fc416a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 31 deletions.
3 changes: 3 additions & 0 deletions libs/viewer/include/viewer/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ using TemporalAntiAliasingOptions = filament::View::TemporalAntiAliasingOptions;
using VignetteOptions = filament::View::VignetteOptions;
using VsmShadowOptions = filament::View::VsmShadowOptions;
using GuardBandOptions = filament::View::GuardBandOptions;
using StereoscopicOptions = filament::View::StereoscopicOptions;
using LightManager = filament::LightManager;

// These functions push all editable property values to their respective Filament objects.
Expand Down Expand Up @@ -192,6 +193,7 @@ struct ViewSettings {
VignetteOptions vignette;
VsmShadowOptions vsmShadowOptions;
GuardBandOptions guardBand;
StereoscopicOptions stereoscopicOptions;

// Custom View Options
ColorGradingSettings colorGrading;
Expand Down Expand Up @@ -231,6 +233,7 @@ struct ViewerOptions {
float cameraISO = 100.0f;
float cameraNear = 0.1f;
float cameraFar = 100.0f;
float cameraEyeOcularDistance = 0.0f;
float groundShadowStrength = 0.75f;
bool groundPlaneEnabled = false;
bool skyboxEnabled = true;
Expand Down
5 changes: 0 additions & 5 deletions libs/viewer/include/viewer/ViewerGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ class UTILS_PUBLIC ViewerGui {

int getCurrentCamera() const { return mCurrentCamera; }

float getOcularDistance() const { return mOcularDistance; }

private:
using SceneMask = gltfio::NodeManager::SceneMask;

Expand Down Expand Up @@ -268,9 +266,6 @@ class UTILS_PUBLIC ViewerGui {
SceneMask mVisibleScenes;
bool mShowingRestPose = false;

// Stereoscopic debugging
float mOcularDistance = 0.0f;

// 0 is the default "free camera". Additional cameras come from the gltf file (1-based index).
int mCurrentCamera = 0;

Expand Down
21 changes: 21 additions & 0 deletions libs/viewer/src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ static int parse(jsmntok_t const* tokens, int i, const char* jsonChunk, ViewSett
i = parse(tokens, i + 1, jsonChunk, &out->vsmShadowOptions);
} else if (compare(tok, jsonChunk, "postProcessingEnabled") == 0) {
i = parse(tokens, i + 1, jsonChunk, &out->postProcessingEnabled);
} else if (compare(tok, jsonChunk, "stereoscopicOptions") == 0) {
i = parse(tokens, i + 1, jsonChunk, &out->stereoscopicOptions);
} else {
slog.w << "Invalid view setting key: '" << STR(tok, jsonChunk) << "'" << io::endl;
i = parse(tokens, i + 1);
Expand Down Expand Up @@ -500,6 +502,8 @@ static int parse(jsmntok_t const* tokens, int i, const char* jsonChunk, ViewerOp
i = parse(tokens, i + 1, jsonChunk, &out->cameraNear);
} else if (compare(tok, jsonChunk, "cameraFar") == 0) {
i = parse(tokens, i + 1, jsonChunk, &out->cameraFar);
} else if (compare(tok, jsonChunk, "cameraEyeOcularDistance") == 0) {
i = parse(tokens, i + 1, jsonChunk, &out->cameraEyeOcularDistance);
} else if (compare(tok, jsonChunk, "groundShadowStrength") == 0) {
i = parse(tokens, i + 1, jsonChunk, &out->groundShadowStrength);
} else if (compare(tok, jsonChunk, "groundPlaneEnabled") == 0) {
Expand Down Expand Up @@ -572,6 +576,7 @@ void applySettings(Engine* engine, const ViewSettings& settings, View* dest) {
dest->setShadowType(settings.shadowType);
dest->setVsmShadowOptions(settings.vsmShadowOptions);
dest->setGuardBandOptions(settings.guardBand);
dest->setStereoscopicOptions(settings.stereoscopicOptions);
dest->setPostProcessingEnabled(settings.postProcessingEnabled);
}

Expand Down Expand Up @@ -646,6 +651,20 @@ void applySettings(Engine* engine, const ViewerOptions& settings, Camera* camera
camera->setFocusDistance(settings.cameraFocusDistance);
}
engine->setAutomaticInstancingEnabled(settings.autoInstancingEnabled);

// Eyes are rendered from left-to-right, i.e., eye 0 is rendered to the left side of the
// window.
// For testing, we want to render a side-by-side layout so users can view with
// "cross-eyed" stereo.
// For cross-eyed stereo, Eye 0 is really the RIGHT eye, while Eye 1 is the LEFT eye.
const auto od = settings.cameraEyeOcularDistance;
const auto eyeCount = engine->getConfig().stereoscopicEyeCount;
const mat4 rightEye = mat4::translation(double3{ od, 0.0, 0.0}); // right eye
const mat4 leftEye = mat4::translation(double3{-od, 0.0, 0.0}); // left eye
const mat4 modelMatrices[2] = { rightEye, leftEye };
for (int i = 0; i < eyeCount; i++) {
camera->setEyeModelMatrix(i, modelMatrices[i % 2]);
}
}

constexpr ToneMapper* createToneMapper(const ColorGradingSettings& settings) noexcept {
Expand Down Expand Up @@ -857,6 +876,7 @@ static std::ostream& operator<<(std::ostream& out, const ViewerOptions& in) {
<< "\"cameraISO\": " << (in.cameraISO) << ",\n"
<< "\"cameraNear\": " << (in.cameraNear) << ",\n"
<< "\"cameraFar\": " << (in.cameraFar) << ",\n"
<< "\"cameraEyeOcularDistance\": " << (in.cameraEyeOcularDistance) << ",\n"
<< "\"groundShadowStrength\": " << (in.groundShadowStrength) << ",\n"
<< "\"groundPlaneEnabled\": " << to_string(in.groundPlaneEnabled) << ",\n"
<< "\"skyboxEnabled\": " << to_string(in.skyboxEnabled) << ",\n"
Expand Down Expand Up @@ -894,6 +914,7 @@ static std::ostream& operator<<(std::ostream& out, const ViewSettings& in) {
<< "\"shadowType\": " << (in.shadowType) << ",\n"
<< "\"vsmShadowOptions\": " << (in.vsmShadowOptions) << ",\n"
<< "\"guardBand\": " << (in.guardBand) << ",\n"
<< "\"stereoscopicOptions\": " << (in.stereoscopicOptions) << ",\n"
<< "\"postProcessingEnabled\": " << to_string(in.postProcessingEnabled) << "\n"
<< "}";
}
Expand Down
10 changes: 3 additions & 7 deletions libs/viewer/src/ViewerGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,13 +1067,9 @@ void ViewerGui::updateUserInterface() {
ImGui::ListBox("Cameras", &mCurrentCamera, cstrings.data(), cstrings.size());
}

StereoscopicOptions stereoOptions = mView->getStereoscopicOptions();
ImGui::Checkbox("Instanced stereo", &stereoOptions.enabled);
if (stereoOptions.enabled) {
ImGui::SliderFloat("Ocular distance", &mOcularDistance, 0.0f, 10.0f);

}
mView->setStereoscopicOptions(stereoOptions);
ImGui::Checkbox("Instanced stereo", &mSettings.view.stereoscopicOptions.enabled);
ImGui::SliderFloat(
"Ocular distance", &mSettings.viewer.cameraEyeOcularDistance, 0.0f, 1.0f);

ImGui::Unindent();
}
Expand Down
19 changes: 0 additions & 19 deletions samples/gltf_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,25 +1003,6 @@ int main(int argc, char** argv) {
camera->setScaling({1.0 / aspectRatio, 1.0});
}

if (view->getStereoscopicOptions().enabled) {
Camera& c = view->getCamera();
auto od = app.viewer->getOcularDistance();
// Eyes are rendered from left-to-right, i.e., eye 0 is rendered to the left side of the
// window.
// For testing, we want to render a side-by-side layout so users can view with
// "cross-eyed" stereo.
// For cross-eyed stereo, Eye 0 is really the RIGHT eye, while Eye 1 is the LEFT eye.
const mat4 rightEye = mat4::translation(double3{ od, 0.0, 0.0}); // right eye
const mat4 leftEye = mat4::translation(double3{-od, 0.0, 0.0}); // left eye
const mat4 modelMatrices[4] = { rightEye, leftEye, rightEye, leftEye };
for (int i = 0; i < std::min(app.config.stereoscopicEyeCount, 4); i++) {
c.setEyeModelMatrix(i, modelMatrices[i]);
}
} else {
for (int i = 0; i < app.config.stereoscopicEyeCount; i++) {
view->getCamera().setEyeModelMatrix(i, {});
}
}
static bool stereoscopicEnabled = false;
if (stereoscopicEnabled != view->getStereoscopicOptions().enabled) {
// Stereo was turned on/off.
Expand Down

0 comments on commit 7fc416a

Please sign in to comment.