Skip to content
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

[GSoC 2019] RetroPlayer: OpenGL back-end for shaders #114

Draft
wants to merge 5 commits into
base: feature_shaders_gl
Choose a base branch
from

Conversation

gusandrianos
Copy link

@gusandrianos gusandrianos commented Aug 23, 2019

Description

This PR extends the functionality #86 brought to RetroPlayer by introducing support for other platforms through an OpenGL implementation.
The code in this PR is part of this GSoC project

In short, this code adds support for multi-pass shader presets, as defined in the libretro spec, which opens a whole new world of customization to the look and feel of games, through the massive amount of presets available in this format.

While the spec is written with cg shaders in mind, it is also extended to GLSL and slang shaders.

You can read more about the current state of my solution, what works and what doesn't(yet), here.

Motivation and Context

Shaders can be used to:

  • Scale lower resolution games to higher resolutions
  • Emulate the look of CRT or other types of monitors
  • Apply noise reduction or anti-aliasing filters

Of course, the list goes on. Most importantly, shaders can be used to elevate the gameplay experience and make it more immersive. A game can either look like it's being displayed on a CRT or a Gameboy or an LCD monitor or be upscaled and viewed on a 4K monitor, the possibilities are endless.

Regarding the commits in this PR.

I should mention that the last commit that falls under the GSoC umbrella is this one. Anything that follows it should not be considered as part of the GSoC project.

Let's give you some context about each commit.
The first three commits are setting up the relevant parts of code for usage in the next commit.
The fourth commit contains all the work that involves the processing and rendering of the shader presets.
The fifth commit connects the code to RetroPlayer.

How Has This Been Tested?

I took a brute force approach by testing almost every preset in the glsl-shaders repo. It has only been tested on Linux and it is unknown if it works on other platforms that use OpenGL.

To test this code yourself

  • Build Kodi using the guides on the main repository
  • Download and install the game.shader.presets binary add-on
  • Get the latest glsl-shaders from libretro's repository
  • Extract the shaders in /your/kodi/directory/addons/game.shader.presets/resources/libretro/glsl
  • Replace the contents of ShaderPresetsDefault.xml in the resources directory with this file. This is a temporary workaround, I will update the add-on to choose the correct file depending on the situation.

Screenshots (if appropriate):

Here's a video that demonstrates what these changes do.
YouTube Demo

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • None of the above (please explain below)

Checklist:

  • My code follows the Code Guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the Contributing document
  • I have added tests to cover my change
  • All new and existing tests passed

@gusandrianos gusandrianos force-pushed the retroplayer-shaders-gsoc19 branch 8 times, most recently from e4c7260 to e6e3dab Compare August 23, 2019 22:28
@gusandrianos gusandrianos changed the title Retroplayer: OpenGL back-end for shaders RetroPlayer: OpenGL back-end for shaders Aug 24, 2019
@garbear
Copy link
Owner

garbear commented Sep 2, 2019

@KostasAndrianos can you cherry-pick these 7 commits? 327d997~7...327d997

@gusandrianos gusandrianos force-pushed the retroplayer-shaders-gsoc19 branch 5 times, most recently from f5e103b to def1361 Compare September 2, 2019 09:42

unsigned int numPasses = static_cast<unsigned int>(m_passes.size());

for (unsigned shaderIdx = 0; shaderIdx < numPasses; ++shaderIdx)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines from here to 267 are copied as-is from D3D and should be moved to common code since they're not backend specific. Probably just a method with the passes as input and the scaled size as output.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, will do that

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there's lots of places where common code can be factored out. The good news is duplication got us this far, and now these places are easy to find.

@gusandrianos gusandrianos force-pushed the retroplayer-shaders-gsoc19 branch from 79b1e74 to d23157e Compare October 11, 2019 20:16
@@ -76,6 +85,8 @@ namespace RETRO

virtual void Render(uint8_t alpha);

std::map<CRenderBufferOpenGL*, std::unique_ptr<RenderBufferTextures>> m_RBTexturesMap;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the header <memory>; added in gusandrianos#2

if (it != m_RBTexturesMap.end())
{
rbTextures = it->second.get();
} else {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style infraction; fixed in gusandrianos#2

@gusandrianos gusandrianos force-pushed the retroplayer-shaders-gsoc19 branch from e461396 to db8f7fc Compare October 18, 2019 16:51
namespace KODI
{
namespace RETRO
{
class CRenderContext;
class CRenderBufferOpenGL;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alphabetize to reduce likelihood of git conflicts

@garbear garbear force-pushed the feature_shaders_gl branch 4 times, most recently from 7d3fc5e to 7368539 Compare March 9, 2020 07:00
@garbear garbear force-pushed the feature_shaders_gl branch from d58a368 to b80fd1e Compare October 29, 2020 12:25
@gusandrianos gusandrianos force-pushed the retroplayer-shaders-gsoc19 branch from ecb8114 to b8b6546 Compare March 14, 2021 11:06
@gusandrianos gusandrianos marked this pull request as draft March 14, 2021 11:08
@gusandrianos gusandrianos force-pushed the retroplayer-shaders-gsoc19 branch from b8b6546 to f26aa57 Compare March 15, 2021 12:02
@garbear garbear force-pushed the feature_shaders_gl branch from b80fd1e to 341f52b Compare March 15, 2021 12:17
@KOPRajs
Copy link

KOPRajs commented Apr 2, 2024

@gusandrianos Hi there. It's been years, but I thought you might be interested to see our fixes to your code. Also any comments would be welcome. Since the code seems well-structured, the changes are mostly small.
I've written summary of the fixes here: https://forum.kodi.tv/showthread.php?tid=173361&pid=3189974#pid3189974
The code is available here: https://github.com/KOPRajs/xbmc/commits/video-shaders-v2/

If you've got any comments on the fixes, you can write it here or in the forum. Thank you.

@gusandrianos
Copy link
Author

@KOPRajs Thanks a lot for taking the time to do these changes! I am extremely rusty on my C++ and OpenGL but the changes look good as far as I can tell.
Feel free to go whichever way you like with this as I have extremely little time these days and I also don't have a personal machine with me because I relocated to another country.

@garbear garbear changed the title RetroPlayer: OpenGL back-end for shaders [GSoC 2019] RetroPlayer: OpenGL back-end for shaders May 10, 2024
@garbear
Copy link
Owner

garbear commented Aug 28, 2024

Just a note, I rebased shaders again for the Nth time in 7 years, and the work is really a drain. I'm looking to merge shaders into master for v22, even if it's not perfect. Expect a whopper PR with everything shaders in the upcoming future.

@KOPRajs
Copy link

KOPRajs commented Sep 5, 2024

@garbear Could you please try to fix the regression mentioned in the following post before the PR?
https://forum.kodi.tv/showthread.php?tid=173361&pid=3197778#pid3197778

The NTSC shaders were working fine in RP 19.4 build for Windows. It is a regression introduced in RP 20.0 alpha2. It is likely that it was caused by the move of the shader files to the game.shader.preset addon. It seems that RP is simply trying to find the shader includes in the original location (probably the path needs to be fixed). Unfortunately, I do not have the Windows development environment available anymore.

@garbear
Copy link
Owner

garbear commented Sep 5, 2024

Will look into it when I get a chance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants