Commit 20d7dfb2 authored by cjgrant's avatar cjgrant Committed by Commit bot

Add VR gradient and grid background to non-WebVR scene.

- Add the floor, ceiling and grid quads.
- Add the content backplane to avoid reticle jumping around the edges.
- Configure the scene reticle distance limit based on content.

BUG=715573
TEST=Verified background on regular page; no background in WebVR.

Review-Url: https://codereview.chromium.org/2844313002
Cr-Commit-Position: refs/heads/master@{#467814}
parent f8ef156d
......@@ -113,9 +113,6 @@ struct UiElement : public WorldRectangle {
// Valid IDs are non-negative.
int id = -1;
// Name string for debugging and testing purposes.
std::string name;
// If a non-negative parent ID is specified, applicable transformations
// are applied relative to the parent, rather than absolutely.
int parent_id = -1;
......
......@@ -146,10 +146,18 @@ bool UiScene::HasVisibleHeadLockedElements() const {
return !GetHeadLockedElements().empty();
}
void UiScene::SetBackgroundColor(const vr::Colorf& color) {
background_color_ = color;
}
const vr::Colorf& UiScene::GetBackgroundColor() const {
return background_color_;
}
void UiScene::SetBackgroundDistance(float distance) {
background_distance_ = distance;
}
float UiScene::GetBackgroundDistance() const {
return background_distance_;
}
......
......@@ -62,8 +62,11 @@ class UiScene {
std::vector<const UiElement*> GetHeadLockedElements() const;
bool HasVisibleHeadLockedElements() const;
void SetBackgroundColor(const vr::Colorf& color);
const vr::Colorf& GetBackgroundColor() const;
void SetBackgroundDistance(float distance);
float GetBackgroundDistance() const;
bool GetWebVrRenderingEnabled() const;
void OnGLInitialized();
......
......@@ -19,16 +19,26 @@ namespace {
static constexpr int kWarningTimeoutSeconds = 30;
static constexpr float kWarningDistance = 0.7;
static constexpr float kWarningAngleRadians = 16.3 * M_PI / 180.0;
static constexpr float kPermanentWarningHeight = 0.226;
static constexpr float kPermanentWarningWidth = 0.078;
static constexpr float kTransientWarningHeight = 0.512;
static constexpr float kTransientWarningWidth = 0.160;
static constexpr float kContentHeight = 2.4;
static constexpr float kContentWidth = 1.6;
static constexpr float kContentWidth = 2.4;
static constexpr float kContentHeight = 1.6;
static constexpr float kContentDistance = 2.5;
static constexpr float kContentVerticalOffset = -0.26;
static constexpr float kBackplaneSize = 1000.0;
static constexpr float kBackgroundDistanceMultiplier = 1.414;
static constexpr float kSceneSize = 25.0;
static constexpr float kSceneHeight = 4.0;
static constexpr int kFloorGridlineCount = 40;
static constexpr vr::Colorf kBackgroundHorizonColor = {0.57, 0.57, 0.57, 1.0};
static constexpr vr::Colorf kBackgroundCenterColor = {0.48, 0.48, 0.48, 1.0};
// Tiny distance to offset textures that should appear in the same plane.
static constexpr float kTextureOffset = 0.01;
} // namespace
......@@ -36,15 +46,20 @@ UiSceneManager::UiSceneManager(UiScene* scene)
: scene_(scene), weak_ptr_factory_(this) {
std::unique_ptr<UiElement> element;
// For now, use an ID range that does not conflict with the HTML UI.
int id = 1000;
CreateBackground();
CreateContentQuad();
CreateSecurityWarnings();
}
UiSceneManager::~UiSceneManager() {}
void UiSceneManager::CreateSecurityWarnings() {
std::unique_ptr<UiElement> element;
// Permanent WebVR security warning.
// TODO(mthiesse): Programatically compute the proper texture size for these
// textured UI elements.
element = base::MakeUnique<PermanentSecurityWarning>(512);
element->id = id++;
element->name = "Permanent security warning";
element->id = AllocateId();
element->fill = vr_shell::Fill::NONE;
element->size = {kPermanentWarningWidth, kPermanentWarningHeight, 1};
element->scale = {kWarningDistance, kWarningDistance, 1};
......@@ -57,10 +72,8 @@ UiSceneManager::UiSceneManager(UiScene* scene)
permanent_security_warning_ = element.get();
scene_->AddUiElement(std::move(element));
// Transient WebVR security warning.
element = base::MakeUnique<TransientSecurityWarning>(1024);
element->id = id++;
element->name = "Transient security warning";
element->id = AllocateId();
element->fill = vr_shell::Fill::NONE;
element->size = {kTransientWarningWidth, kTransientWarningHeight, 1};
element->scale = {kWarningDistance, kWarningDistance, 1};
......@@ -70,20 +83,86 @@ UiSceneManager::UiSceneManager(UiScene* scene)
element->lock_to_fov = true;
transient_security_warning_ = element.get();
scene_->AddUiElement(std::move(element));
}
void UiSceneManager::CreateContentQuad() {
std::unique_ptr<UiElement> element;
// Main web content quad.
element = base::MakeUnique<UiElement>();
element->id = id++;
element->name = "Content";
element->id = AllocateId();
element->fill = vr_shell::Fill::CONTENT;
element->size = {kContentWidth, kContentHeight, 1};
element->translation = {0, kContentVerticalOffset, -kContentDistance};
element->visible = false;
main_content_ = element.get();
browser_ui_elements_.push_back(element.get());
scene_->AddUiElement(std::move(element));
// Place an invisible but hittable plane behind the content quad, to keep the
// reticle roughly planar with the content if near content.
element = base::MakeUnique<UiElement>();
element->id = AllocateId();
element->fill = vr_shell::Fill::NONE;
element->size = {kBackplaneSize, kBackplaneSize, 1.0};
element->translation = {0.0, 0.0, -kTextureOffset};
element->parent_id = main_content_->id;
browser_ui_elements_.push_back(element.get());
scene_->AddUiElement(std::move(element));
// Limit reticle distance to a sphere based on content distance.
scene_->SetBackgroundDistance(main_content_->translation.z() *
-kBackgroundDistanceMultiplier);
}
UiSceneManager::~UiSceneManager() {}
void UiSceneManager::CreateBackground() {
std::unique_ptr<UiElement> element;
// Floor.
element = base::MakeUnique<UiElement>();
element->id = AllocateId();
element->size = {kSceneSize, kSceneSize, 1.0};
element->translation = {0.0, -kSceneHeight / 2, 0.0};
element->rotation = {1.0, 0.0, 0.0, -M_PI / 2.0};
element->fill = vr_shell::Fill::OPAQUE_GRADIENT;
element->edge_color = kBackgroundHorizonColor;
element->center_color = kBackgroundCenterColor;
element->draw_phase = 0;
browser_ui_elements_.push_back(element.get());
scene_->AddUiElement(std::move(element));
// Ceiling.
element = base::MakeUnique<UiElement>();
element->id = AllocateId();
element->fill = vr_shell::Fill::OPAQUE_GRADIENT;
element->size = {kSceneSize, kSceneSize, 1.0};
element->translation = {0.0, kSceneHeight / 2, 0.0};
element->rotation = {1.0, 0.0, 0.0, M_PI / 2};
element->fill = vr_shell::Fill::OPAQUE_GRADIENT;
element->edge_color = kBackgroundHorizonColor;
element->center_color = kBackgroundCenterColor;
element->draw_phase = 0;
browser_ui_elements_.push_back(element.get());
scene_->AddUiElement(std::move(element));
// Floor grid.
element = base::MakeUnique<UiElement>();
element->id = AllocateId();
element->fill = vr_shell::Fill::GRID_GRADIENT;
element->size = {kSceneSize, kSceneSize, 1.0};
element->translation = {0.0, -kSceneHeight / 2 + kTextureOffset, 0.0};
element->rotation = {1.0, 0.0, 0.0, -M_PI / 2};
element->fill = vr_shell::Fill::GRID_GRADIENT;
element->center_color = kBackgroundHorizonColor;
vr::Colorf edge_color = kBackgroundHorizonColor;
edge_color.a = 0.0;
element->edge_color = edge_color;
element->gridline_count = kFloorGridlineCount;
element->draw_phase = 0;
browser_ui_elements_.push_back(element.get());
scene_->AddUiElement(std::move(element));
scene_->SetBackgroundColor(kBackgroundHorizonColor);
}
base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
......@@ -91,7 +170,12 @@ base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() {
void UiSceneManager::SetWebVRMode(bool web_vr) {
web_vr_mode_ = web_vr;
main_content_->visible = !web_vr_mode_;
// Make all VR scene UI elements visible if not in WebVR.
for (UiElement* element : browser_ui_elements_) {
element->visible = !web_vr_mode_;
}
ConfigureSecurityWarnings();
}
......@@ -117,4 +201,8 @@ void UiSceneManager::OnSecurityWarningTimer() {
transient_security_warning_->visible = false;
}
int UiSceneManager::AllocateId() {
return next_available_id_++;
}
} // namespace vr_shell
......@@ -26,9 +26,13 @@ class UiSceneManager {
void SetWebVRMode(bool web_vr);
private:
void CreateSecurityWarnings();
void CreateContentQuad();
void CreateBackground();
void ConfigureSecurityWarnings();
void OnSecurityWarningTimer();
void OnGLInitialized();
int AllocateId();
UiScene* scene_;
......@@ -40,6 +44,10 @@ class UiSceneManager {
bool web_vr_mode_ = false;
bool secure_origin_ = false;
int next_available_id_ = 1;
std::vector<UiElement*> browser_ui_elements_;
base::OneShotTimer security_warning_timer_;
base::WeakPtrFactory<UiSceneManager> weak_ptr_factory_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment