Skip to content

Commit

Permalink
Add transition band between the focus and peripheral views.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbucchia committed May 27, 2023
1 parent e0bc178 commit 3b4f844
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
11 changes: 9 additions & 2 deletions pimax-openxr/AlphaBlending.hlsli
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
float4 processAlpha(float4 input, int mode) {
float4 processAlpha(float4 input, uint2 pos, uint2 widthHeight, int mode) {
float4 output = input;
if (mode & 1) {
output.a = 1;
}
if (mode & 2) {
if (mode & 4) {
float2 transitionArea = 0.1 * widthHeight;
float2 s = smoothstep(float2(0, 0), transitionArea, pos) -
smoothstep(widthHeight - transitionArea, widthHeight, pos);
output.a = max(0.5, s.x * s.y);
// RGB need premultiplication (below).
}
if (mode & 6) {
output.rgb = output.rgb * output.a;
}
return output;
Expand Down
6 changes: 4 additions & 2 deletions pimax-openxr/AlphaBlendingCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ cbuffer config : register(b0) {
Texture2D in_texture : register(t0);
RWTexture2D<float4> out_texture : register(u0);

[numthreads(8, 8, 1)]
[numthreads(32, 32, 1)]
void main(uint2 pos : SV_DispatchThreadID) {
out_texture[pos] = processAlpha(in_texture[pos], mode);
uint width, height;
in_texture.GetDimensions(width, height);
out_texture[pos] = processAlpha(in_texture[pos], pos, uint2(width, height), mode);
}
6 changes: 4 additions & 2 deletions pimax-openxr/AlphaBlendingTexArrayCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ cbuffer config : register(b0) {
Texture2DArray in_texture : register(t0);
RWTexture2D<float4> out_texture : register(u0);

[numthreads(8, 8, 1)]
[numthreads(32, 32, 1)]
void main(uint2 pos : SV_DispatchThreadID) {
out_texture[pos] = processAlpha(in_texture[float3(pos, 0)], mode);
uint width, height, size;
in_texture.GetDimensions(width, height, size);
out_texture[pos] = processAlpha(in_texture[float3(pos, 0)], pos, uint2(width, height), mode);
}
12 changes: 7 additions & 5 deletions pimax-openxr/d3d11_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ namespace pimax_openxr {
uint32_t layerIndex,
uint32_t slice,
XrCompositionLayerFlags compositionFlags,
bool isFocusView,
std::set<std::pair<pvrTextureSwapChain, uint32_t>>& committed) {
// If the texture was never used or already committed, do nothing.
if (xrSwapchain.slices[0].empty() || committed.count(std::make_pair(xrSwapchain.pvrSwapchain[0], slice))) {
Expand All @@ -463,7 +464,7 @@ namespace pimax_openxr {
layerIndex > 0 && !(compositionFlags & XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT);
const bool needPremultiplyAlpha = (compositionFlags & XR_COMPOSITION_LAYER_UNPREMULTIPLIED_ALPHA_BIT);
const bool needCopy = xrSwapchain.lastProcessedIndex[slice] == lastReleasedIndex ||
(slice > 0 && !(needClearAlpha || needPremultiplyAlpha));
(slice > 0 && !(isFocusView || needClearAlpha || needPremultiplyAlpha));

if (needCopy) {
// Circumvent some of PVR's limitations:
Expand All @@ -480,7 +481,7 @@ namespace pimax_openxr {
xrSwapchain.slices[0][lastReleasedIndex].Get(),
slice,
nullptr);
} else if (needClearAlpha || needPremultiplyAlpha) {
} else if (isFocusView || needClearAlpha || needPremultiplyAlpha) {
// Circumvent some of PVR's limitations:
// - For alpha-blended layers, we must pre-process the alpha channel.
// For alpha-blended layers with texture arrays, we must also output into slice 0 of
Expand Down Expand Up @@ -523,7 +524,8 @@ namespace pimax_openxr {
D3D11_MAPPED_SUBRESOURCE mappedResources;
CHECK_HRCMD(m_pvrSubmissionContext->Map(
xrSwapchain.convertConstants.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResources));
*(uint32_t*)mappedResources.pData = (needClearAlpha ? 0x1 : 0) | (needPremultiplyAlpha ? 0x2 : 0);
*(uint32_t*)mappedResources.pData =
(needClearAlpha ? 0x1 : 0) | (needPremultiplyAlpha ? 0x2 : 0) | (isFocusView ? 0x4 : 0);
m_pvrSubmissionContext->Unmap(xrSwapchain.convertConstants.Get(), 0);
m_pvrSubmissionContext->CSSetConstantBuffers(0, 1, xrSwapchain.convertConstants.GetAddressOf());

Expand All @@ -535,8 +537,8 @@ namespace pimax_openxr {
m_pvrSubmissionContext->CSSetUnorderedAccessViews(
0, 1, xrSwapchain.convertAccessView.GetAddressOf(), nullptr);

m_pvrSubmissionContext->Dispatch((unsigned int)std::ceil(xrSwapchain.xrDesc.width / 8),
(unsigned int)std::ceil(xrSwapchain.xrDesc.height / 8),
m_pvrSubmissionContext->Dispatch((unsigned int)std::ceil(xrSwapchain.xrDesc.width / 32),
(unsigned int)std::ceil(xrSwapchain.xrDesc.height / 32),
1);

// Unbind all resources to avoid D3D validation errors.
Expand Down
3 changes: 3 additions & 0 deletions pimax-openxr/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ namespace pimax_openxr {
i,
proj->views[viewIndex].subImage.imageArrayIndex,
frameEndInfo->layers[i]->layerFlags,
viewIndex >= xr::StereoView::Count,
committedSwapchainImages);
layer->EyeFov.ColorTexture[pvrViewIndex] =
xrSwapchain.pvrSwapchain[proj->views[viewIndex].subImage.imageArrayIndex];
Expand Down Expand Up @@ -594,6 +595,7 @@ namespace pimax_openxr {
i,
depth->subImage.imageArrayIndex,
0,
false,
committedSwapchainImages);
layer->EyeFovDepth.DepthTexture[pvrViewIndex] =
xrDepthSwapchain.pvrSwapchain[depth->subImage.imageArrayIndex];
Expand Down Expand Up @@ -670,6 +672,7 @@ namespace pimax_openxr {
i,
quad->subImage.imageArrayIndex,
frameEndInfo->layers[i]->layerFlags,
false,
committedSwapchainImages);
layer->Quad.ColorTexture = xrSwapchain.pvrSwapchain[quad->subImage.imageArrayIndex];

Expand Down
1 change: 1 addition & 0 deletions pimax-openxr/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ namespace pimax_openxr {
uint32_t layerIndex,
uint32_t slice,
XrCompositionLayerFlags compositionFlags,
bool isFocusView,
std::set<std::pair<pvrTextureSwapChain, uint32_t>>& committed);
void ensureSwapchainSliceResources(Swapchain& xrSwapchain, uint32_t slice) const;
void ensureSwapchainIntermediateResources(Swapchain& xrSwapchain) const;
Expand Down

0 comments on commit 3b4f844

Please sign in to comment.