Skip to content

Commit

Permalink
Add Full-SbS 3D rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
oneup03 committed Mar 16, 2024
1 parent affac17 commit c2d784d
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/android/app/src/main/jni/default_ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ bg_blue =
bg_green =
# Whether and how Stereoscopic 3D should be rendered
# 0 (default): Off, 1: Side by Side, 2: Anaglyph, 3: Interlaced, 4: Reverse Interlaced, 5: Cardboard VR
# 0 (default): Off, 1: Side by Side, 2: Full Side by Side, 3: Anaglyph, 4: Interlaced, 5: Reverse Interlaced, 6: Cardboard VR
render_3d =
# Change 3D Intensity
Expand Down
2 changes: 1 addition & 1 deletion src/citra/default_ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ bg_blue =
bg_green =
# Whether and how Stereoscopic 3D should be rendered
# 0 (default): Off, 1: Side by Side, 2: Anaglyph, 3: Interlaced, 4: Reverse Interlaced
# 0 (default): Off, 1: Side by Side, 2: Full Side by Side, 3: Anaglyph, 4: Interlaced, 5: Reverse Interlaced
render_3d =
# Change 3D Intensity
Expand Down
5 changes: 5 additions & 0 deletions src/citra_qt/configuration/configure_enhancements.ui
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@
<string>Side by Side</string>
</property>
</item>
<item>
<property name="text">
<string>Full Side by Side</string>
</property>
</item>
<item>
<property name="text">
<string>Anaglyph</string>
Expand Down
9 changes: 5 additions & 4 deletions src/common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ enum class LayoutOption : u32 {
enum class StereoRenderOption : u32 {
Off = 0,
SideBySide = 1,
Anaglyph = 2,
Interlaced = 3,
ReverseInterlaced = 4,
CardboardVR = 5
FullSideBySide = 2,
Anaglyph = 3,
Interlaced = 4,
ReverseInterlaced = 5,
CardboardVR = 6
};

// Which eye to render when 3d is off. 800px wide mode could be added here in the future, when
Expand Down
31 changes: 26 additions & 5 deletions src/core/frontend/framebuffer_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,28 @@ FramebufferLayout SingleFrameLayout(u32 width, u32 height, bool swapped, bool up
bot_screen = MaxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO);
emulation_aspect_ratio = (swapped) ? BOT_SCREEN_ASPECT_RATIO : TOP_SCREEN_ASPECT_RATIO;
}
if (Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::FullSideBySide &&
!(Settings::values.layout_option.GetValue() == Settings::LayoutOption::SeparateWindows &&
swapped)) {
emulation_aspect_ratio /= 2;
}

float window_aspect_ratio = static_cast<float>(height) / width;

if (window_aspect_ratio < emulation_aspect_ratio) {
top_screen =
top_screen.TranslateX((screen_window_area.GetWidth() - top_screen.GetWidth()) / 2);
bot_screen =
bot_screen.TranslateX((screen_window_area.GetWidth() - bot_screen.GetWidth()) / 2);
if (Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::FullSideBySide &&
!(Settings::values.layout_option.GetValue() == Settings::LayoutOption::SeparateWindows &&
swapped)) {
top_screen =
top_screen.TranslateX((screen_window_area.GetWidth() / 2 - top_screen.GetWidth()) / 2);
bot_screen =
bot_screen.TranslateX((screen_window_area.GetWidth() / 2 - bot_screen.GetWidth()) / 2);
} else {
top_screen =
top_screen.TranslateX((screen_window_area.GetWidth() - top_screen.GetWidth()) / 2);
bot_screen =
bot_screen.TranslateX((screen_window_area.GetWidth() - bot_screen.GetWidth()) / 2);
}
} else {
top_screen = top_screen.TranslateY((height - top_screen.GetHeight()) / 2);
bot_screen = bot_screen.TranslateY((height - bot_screen.GetHeight()) / 2);
Expand Down Expand Up @@ -230,6 +244,9 @@ FramebufferLayout LargeFrameLayout(u32 width, u32 height, bool swapped, bool upr
small_screen_aspect_ratio = BOT_SCREEN_ASPECT_RATIO;
}
}
if (Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::FullSideBySide) {
emulation_aspect_ratio /= 2;
}

Common::Rectangle<u32> screen_window_area{0, 0, width, height};
Common::Rectangle<u32> total_rect = MaxRectangle(screen_window_area, emulation_aspect_ratio);
Expand All @@ -238,7 +255,11 @@ FramebufferLayout LargeFrameLayout(u32 width, u32 height, bool swapped, bool upr
Common::Rectangle<u32> small_screen = MaxRectangle(scaled_rect, small_screen_aspect_ratio);

if (window_aspect_ratio < emulation_aspect_ratio) {
large_screen = large_screen.TranslateX((width - total_rect.GetWidth()) / 2);
if (Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::FullSideBySide) {
large_screen = large_screen.TranslateX((width / 2 - total_rect.GetWidth()) / 2);
} else {
large_screen = large_screen.TranslateX((width - total_rect.GetWidth()) / 2);
}
} else {
large_screen = large_screen.TranslateY((height - total_rect.GetHeight()) / 2);
}
Expand Down
20 changes: 20 additions & 0 deletions src/video_core/renderer_opengl/renderer_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,15 @@ void RendererOpenGL::DrawTopScreen(const Layout::FramebufferLayout& layout,
top_screen_top, top_screen_width / 2, top_screen_height, orientation);
break;
}
case Settings::StereoRenderOption::FullSideBySide: {
DrawSingleScreen(screen_infos[0], top_screen_left, top_screen_top, top_screen_width,
top_screen_height, orientation);
glUniform1i(uniform_layer, 1);
DrawSingleScreen(screen_infos[1],
static_cast<float>(top_screen_left + (layout.width / 2)),
top_screen_top, top_screen_width, top_screen_height, orientation);
break;
}
case Settings::StereoRenderOption::CardboardVR: {
DrawSingleScreen(screen_infos[0], top_screen_left, top_screen_top, top_screen_width,
top_screen_height, orientation);
Expand Down Expand Up @@ -801,6 +810,17 @@ void RendererOpenGL::DrawBottomScreen(const Layout::FramebufferLayout& layout,
}
break;
}
case Settings::StereoRenderOption::FullSideBySide: {
DrawSingleScreen(screen_infos[2], bottom_screen_left, bottom_screen_top,
bottom_screen_width, bottom_screen_height, orientation);
if (Settings::values.layout_option.GetValue() != Settings::LayoutOption::SeparateWindows){
glUniform1i(uniform_layer, 1);
DrawSingleScreen(
screen_infos[2], static_cast<float>(bottom_screen_left + (layout.width / 2)),
bottom_screen_top, bottom_screen_width, bottom_screen_height, orientation);
}
break;
}
case Settings::StereoRenderOption::CardboardVR: {
DrawSingleScreen(screen_infos[2], bottom_screen_left, bottom_screen_top,
bottom_screen_width, bottom_screen_height, orientation);
Expand Down
19 changes: 19 additions & 0 deletions src/video_core/renderer_vulkan/renderer_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,14 @@ void RendererVulkan::DrawTopScreen(const Layout::FramebufferLayout& layout,
top_screen_top, top_screen_width / 2, top_screen_height, orientation);
break;
}
case Settings::StereoRenderOption::FullSideBySide: {
DrawSingleScreen(0, top_screen_left, top_screen_top, top_screen_width,
top_screen_height, orientation);
draw_info.layer = 1;
DrawSingleScreen(1, static_cast<float>(top_screen_left + (layout.width / 2)),
top_screen_top, top_screen_width, top_screen_height, orientation);
break;
}
case Settings::StereoRenderOption::CardboardVR: {
DrawSingleScreen(0, top_screen_left, top_screen_top, top_screen_width, top_screen_height,
orientation);
Expand Down Expand Up @@ -756,6 +764,17 @@ void RendererVulkan::DrawBottomScreen(const Layout::FramebufferLayout& layout,
}
break;
}
case Settings::StereoRenderOption::FullSideBySide: {
DrawSingleScreen(2, bottom_screen_left, bottom_screen_top, bottom_screen_width,
bottom_screen_height, orientation);
if (Settings::values.layout_option.GetValue() != Settings::LayoutOption::SeparateWindows){
draw_info.layer = 1;
DrawSingleScreen(2, static_cast<float>(bottom_screen_left + (layout.width / 2)),
bottom_screen_top, bottom_screen_width, bottom_screen_height,
orientation);
}
break;
}
case Settings::StereoRenderOption::CardboardVR: {
DrawSingleScreen(2, bottom_screen_left, bottom_screen_top, bottom_screen_width,
bottom_screen_height, orientation);
Expand Down

0 comments on commit c2d784d

Please sign in to comment.