-
Notifications
You must be signed in to change notification settings - Fork 37
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
Adds multiview to CubeXr #459
Open
GrantComm
wants to merge
6
commits into
google:main
Choose a base branch
from
GrantComm:cubexrmulti
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+49
−23
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b16e72f
Adds multiview to CubeXr
GrantComm dce5655
Removes redundant xr setting, utilizes xr_component for
GrantComm ca84ca9
Adds multiview knob flag
GrantComm 7ab283d
Renames multiview knob flag
GrantComm 10c46c2
Removes enable multiview from ApplicationSettings
GrantComm d3c7e60
Removes added xrcomponent functions, simplifies cubexr update uniform…
GrantComm 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
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
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 |
---|---|---|
|
@@ -38,7 +38,7 @@ void CubeXrApp::Setup() | |
// Uniform buffer | ||
{ | ||
grfx::BufferCreateInfo bufferCreateInfo = {}; | ||
bufferCreateInfo.size = PPX_MINIMUM_UNIFORM_BUFFER_SIZE; | ||
bufferCreateInfo.size = std::max(sizeof(UniformBufferData), (uint64_t)PPX_MINIMUM_UNIFORM_BUFFER_SIZE); | ||
bufferCreateInfo.usageFlags.bits.uniformBuffer = true; | ||
bufferCreateInfo.memoryUsage = grfx::MEMORY_USAGE_CPU_TO_GPU; | ||
|
||
|
@@ -68,12 +68,12 @@ void CubeXrApp::Setup() | |
|
||
// Pipeline | ||
{ | ||
std::vector<char> bytecode = LoadShader("basic/shaders", "VertexColors.vs"); | ||
std::vector<char> bytecode = LoadShader("basic/shaders", "VertexColorsMulti.vs"); | ||
PPX_ASSERT_MSG(!bytecode.empty(), "VS shader bytecode load failed"); | ||
grfx::ShaderModuleCreateInfo shaderCreateInfo = {static_cast<uint32_t>(bytecode.size()), bytecode.data()}; | ||
PPX_CHECKED_CALL(GetDevice()->CreateShaderModule(&shaderCreateInfo, &mVS)); | ||
|
||
bytecode = LoadShader("basic/shaders", "VertexColors.ps"); | ||
bytecode = LoadShader("basic/shaders", "VertexColorsMulti.ps"); | ||
PPX_ASSERT_MSG(!bytecode.empty(), "PS shader bytecode load failed"); | ||
shaderCreateInfo = {static_cast<uint32_t>(bytecode.size()), bytecode.data()}; | ||
PPX_CHECKED_CALL(GetDevice()->CreateShaderModule(&shaderCreateInfo, &mPS)); | ||
|
@@ -103,6 +103,8 @@ void CubeXrApp::Setup() | |
gpCreateInfo.outputState.renderTargetFormats[0] = GetSwapchain()->GetColorFormat(); | ||
gpCreateInfo.outputState.depthStencilFormat = GetSwapchain()->GetDepthFormat(); | ||
gpCreateInfo.pPipelineInterface = mPipelineInterface; | ||
gpCreateInfo.multiViewState.viewMask = GetXrComponent().GetDefaultViewMask(); | ||
gpCreateInfo.multiViewState.correlationMask = GetXrComponent().GetDefaultViewMask(); | ||
PPX_CHECKED_CALL(GetDevice()->CreateGraphicsPipeline(&gpCreateInfo, &mPipeline)); | ||
} | ||
|
||
|
@@ -201,11 +203,13 @@ void CubeXrApp::Setup() | |
|
||
void CubeXrApp::Render() | ||
{ | ||
PerFrame& frame = mPerFrame[0]; | ||
uint32_t imageIndex = UINT32_MAX; | ||
uint32_t currentViewIndex = 0; | ||
PerFrame& frame = mPerFrame[0]; | ||
uint32_t imageIndex = UINT32_MAX; | ||
uint32_t currentViewIndex = 0; | ||
XrComponent& xrComponent = GetXrComponent(); | ||
|
||
if (IsXrEnabled()) { | ||
currentViewIndex = GetXrComponent().GetCurrentViewIndex(); | ||
currentViewIndex = xrComponent.GetCurrentViewIndex(); | ||
} | ||
|
||
// Render UI into a different composition layer. | ||
|
@@ -269,20 +273,32 @@ void CubeXrApp::Render() | |
// Update uniform buffer. | ||
{ | ||
float t = GetElapsedSeconds(); | ||
float4x4 P = glm::perspective(glm::radians(60.0f), GetWindowAspect(), 0.001f, 10000.0f); | ||
float4x4 V = glm::lookAt(float3(0, 0, 0), float3(0, 0, 1), float3(0, 1, 0)); | ||
float4x4 M = glm::translate(float3(0, 0, -3)) * glm::rotate(t, float3(0, 0, 1)) * glm::rotate(t, float3(0, 1, 0)) * glm::rotate(t, float3(1, 0, 0)); | ||
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. Can we rework this logic a bit?
|
||
|
||
if (IsXrEnabled()) { | ||
const Camera& camera = GetXrComponent().GetCamera(); | ||
P = camera.GetProjectionMatrix(); | ||
V = camera.GetViewMatrix(); | ||
xrComponent.SetCurrentViewIndex(0); | ||
frame.uniform_buffer_data.M[0] = xrComponent.GetCamera().GetViewProjectionMatrix() * M; | ||
|
||
xrComponent.SetCurrentViewIndex(1); | ||
frame.uniform_buffer_data.M[1] = xrComponent.GetCamera().GetViewProjectionMatrix() * M; | ||
} | ||
else { | ||
const Camera& camera = xrComponent.GetCamera(); | ||
float4x4 P = camera.GetProjectionMatrix(); | ||
float4x4 V = camera.GetViewMatrix(); | ||
frame.uniform_buffer_data.M[0] = frame.uniform_buffer_data.M[1] = P * V * M; | ||
} | ||
|
||
// If multiview is active, we have one render pass with Left/Right poses loaded. | ||
// If not multiview, this entire render call will happen again, and we switch to current view index. | ||
|
||
if (!xrComponent.IsMultiView()) { | ||
frame.uniform_buffer_data.M[0] = frame.uniform_buffer_data.M[IsXrEnabled() ? xrComponent.GetCurrentViewIndex() : 0]; | ||
} | ||
float4x4 M = glm::translate(float3(0, 0, -3)) * glm::rotate(t, float3(0, 0, 1)) * glm::rotate(t, float3(0, 1, 0)) * glm::rotate(t, float3(1, 0, 0)); | ||
float4x4 mat = P * V * M; | ||
|
||
void* pData = nullptr; | ||
PPX_CHECKED_CALL(mUniformBuffer->MapMemory(0, &pData)); | ||
memcpy(pData, &mat, sizeof(mat)); | ||
memcpy(pData, &frame.uniform_buffer_data, sizeof(frame.uniform_buffer_data)); | ||
mUniformBuffer->UnmapMemory(); | ||
} | ||
|
||
|
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
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
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.
Can you find the spec language that says the view index is going to be 0 if there is not multiview in the shader? Otherwise maybe better to use VertexColors if there is no multiview?