Dolphin, the GameCube and Wii emulator - Forums

Full Version: Zoom widescreen shader for letterboxed GC games (like Resident Evil 4)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
There are a few gamecube games like, Resident Evil 4, that play in 16:9 with letter boxing to fill out the 4:3 screen. I was playing Resident Evil 4 again today and was disappointed that Dolphin doesn't have an option to zoom the image to fill my monitor, and I couldn't find any solution online. So I wrote a post-processing shader to help with this. Maybe some day Dolphin will support this effect natively, but until then this is a quick and easy solution!

Just copy and paste the code below into a .gsl file in your "Dolphin Emulator/Shaders" folder, then enable the shader under Graphics > Enhancements > Post-Processing Effects (it will be called whatever you named the file).

Code:
// For games that are 16:9 and letterboxed to fit a 4:3 screen, this shader will
// help by zooming the image in to fill a widescreen monitor.
//
// To use, set the aspect ratio to force 16:9 in the graphics option, then
// enable this shader in Post-Processing Effects.

void main() {
    float2 coords = GetCoordinates() - float2(0.5, 0.5);
    float2 new_coords = float2(coords.x, coords.y*3/4);
    float2 sample_coords = new_coords + float2(0.5, 0.5);
    SetOutput(SampleLocation(sample_coords));
}

The way this works is by simply stretching the image along the vertical axis. Forcing 16:9 aspect ratio in the Dolphin settings will stretch the image horizontally, so as long as the vertical stretch matches the horizontal stretch the original aspect ratio will be preserved, and the image will fill the screen horizontally.

I'm sure there's room for improvement, but this was simple and worked.

Comparison screenshots.
Really nice sir, thank you.
I would rather have a game hack that fix this issue internally to use it on real hardware and avoid scaling artefacts but this is a good universal workaround.

btw I was wondering if RE4 was taking advantage of the letterbox by running the game on a lower vertical resolution, saving performance, or if it's running on the standard resolution and then letterboxed by post-processing.

Iron2004

(01-17-2019, 05:21 PM)Derek Wrote: [ -> ]There are a few gamecube games like, Resident Evil 4, that play in 16:9 with letter boxing to fill out the 4:3 screen. I was playing Resident Evil 4 again today and was disappointed that Dolphin doesn't have an option to zoom the image to fill my monitor, and I couldn't find any solution online. So I wrote a post-processing shader to help with this. Maybe some day Dolphin will support this effect natively, but until then this is a quick and easy solution!

Just copy and paste the code below into a .gsl file in your "Dolphin Emulator/Shaders" folder, then enable the shader under Graphics > Enhancements > Post-Processing Effects (it will be called whatever you named the file).


Code:
// For games that are 16:9 and letterboxed to fit a 4:3 screen, this shader will
// help by zooming the image in to fill a widescreen monitor.
//
// To use, set the aspect ratio to force 16:9 in the graphics option, then
// enable this shader in Post-Processing Effects.

void main() {
float2 coords = GetCoordinates() - float2(0.5, 0.5);
float2 new_coords = float2(coords.x, coords.y*3/4);
float2 sample_coords = new_coords + float2(0.5, 0.5);
SetOutput(SampleLocation(sample_coords));
}

The way this works is by simply stretching the image along the vertical axis. Forcing 16:9 aspect ratio in the Dolphin settings will stretch the image horizontally, so as long as the vertical stretch matches the horizontal stretch the original aspect ratio will be preserved, and the image will fill the screen horizontally.

I'm sure there's room for improvement, but this was simple and worked.

Comparison screenshots.

Well I suppose this is just because I'm using the android version of the dolphin. There is black borders in resident evil 4. I have tried what u wrote down there but it didn't work out.

tysard

(01-09-2022, 01:32 AM)Iron2004 Wrote: [ -> ]Well I suppose this is just because I'm using the android version of the dolphin. There is black borders in resident evil 4. I have tried what u wrote down there but it didn't work out.

Hello! This thread was the first result on Google when I was trying to find a solution to the letterboxing problem.
I'm also on android and got the same error as you but I fixed it by changing all the values in the code to floats and it seems to work now so I've made an account just to share this information. 

First of all, if anyone stumbles upon this looking for a solution and happens to be on mobile, the file goes in the following location:


\Android\data\org.dolphinemu.dolphinemu\files\Shaders

It should also be noted that it need to be a glsl file and not a gsl file as previously mentioned.

Here's the updated code:


Code:
void main()
{
   float2 coords = GetCoordinates() - float2(0.5f, 0.5f);
   float2 new_coords = float2(coords.x, coords.y*3.0f/4.0f);
   float2 sample_coords = new_coords + float2(0.5f, 0.5f);
   SetOutput(SampleLocation(sample_coords));
}

Best of luck!
(05-12-2022, 06:41 AM)tysard Wrote: [ -> ]Hello! This thread was the first result on Google when I was trying to find a solution to the letterboxing problem.
I'm also on android and got the same error as you but I fixed it by changing all the values in the code to floats and it seems to work now so I've made an account just to share this information. 

First of all, if anyone stumbles upon this looking for a solution and happens to be on mobile, the file goes in the following location:


\Android\data\org.dolphinemu.dolphinemu\files\Shaders

It should also be noted that it need to be a glsl file and not a gsl file as previously mentioned.

Here's the updated code:





Code:
void main()
{
   float2 coords = GetCoordinates() - float2(0.5f, 0.5f);
   float2 new_coords = float2(coords.x, coords.y*3.0f/4.0f);
   float2 sample_coords = new_coords + float2(0.5f, 0.5f);
   SetOutput(SampleLocation(sample_coords));
}

Best of luck!
hi sorry for bump

but any chance you could help rewrite this aethersx2 shader cas.glsl file to dolphin 's glsl format?

this is best crt shader
Contrast Adaptive Sharpening  (cas shapeness shader) any chance add it  to dolphin android? aethersx did it on 1/1/2023 before shutdown it make game at 1x res look like on real crt tv from year 2000.....
swear to god no other crt shader can beat this Contrast Adaptive Sharpening

https://abload.de/img/residentevil4-crtllit9.jpg
[Image: residentevil4-crtllit9.jpg]
// Based on CAS_Shader.glsl
// Copyright© 2019 Advanced Micro Devices, Inc.All rights reserved.
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

uniform uvec4 const0;
uniform uvec4 const1;
uniform ivec2 srcOffset;

layout(binding=0) uniform sampler2D imgSrc;
layout(binding=0, rgba8) uniform writeonly image2D imgDst;

#define A_GPU 1
#define A_GLSL 1

#include "ffx_a.h"

AF3 CasLoad(ASU2 p)
{
return texelFetch(imgSrc, srcOffset + ivec2(p), 0).rgb;
}

// Lets you transform input from the load into a linear color space between 0 and 1. See ffx_cas.h
// In this case, our input is already linear and between 0 and 1
void CasInput(inout AF1 r, inout AF1 g, inout AF1 b) {}

#include "ffx_cas.h"

layout(local_size_x=64) in;
void main()
{
// Do remapping of local xy in workgroup for a more PS-like swizzle pattern.
AU2 gxy = ARmp8x8(gl_LocalInvocationID.x)+AU2(gl_WorkGroupID.x<<4u,gl_WorkGroupID.y<<4u);

// Filter.
AF4 c;
CasFilter(c.r, c.g, c.b, gxy, const0, const1, CAS_SHARPEN_ONLY);
imageStore(imgDst, ASU2(gxy), c);
gxy.x += 8u;

CasFilter(c.r, c.g, c.b, gxy, const0, const1, CAS_SHARPEN_ONLY);
imageStore(imgDst, ASU2(gxy), c);
gxy.y += 8u;

CasFilter(c.r, c.g, c.b, gxy, const0, const1, CAS_SHARPEN_ONLY);
imageStore(imgDst, ASU2(gxy), c);
gxy.x -= 8u;

CasFilter(c.r, c.g, c.b, gxy, const0, const1, CAS_SHARPEN_ONLY);
imageStore(imgDst, ASU2(gxy), c);
}
here is aethersx2 shader glsl file from apk package
Hy friends,

Could a tech savvy person here add the Fxaa shader code, to the zoom+bloom shader in the link?
The idea is to have a single file with zoom+bloom+fxaa shader, if possible.

https://we.tl/t-16sbVNpIB6

It would make for the best image in Re4 GC, which has a little better overall resolution quality over the Wii version.

Thank you very much!
I would like to use this with this other CRT filter ( https://gist.github.com/mariodivece/dab2...dec28ef92b ) how to make it work together?
Neither of the code snippets above were working for me on RE4 on my retroid pocket 4. The code snippet seems to work for me, I just changed the line:
float2 new_coords = float2(coords.x, coords.y*3/4); to float2 new_coords = float2(coords.x, coords.y*3.0/4.0);

I guess openGL needs some help with floats on my setup, hope this helps someone else.

Code:
// For games that are 16:9 and letterboxed to fit a 4:3 screen, this shader will
// help by zooming the image in to fill a widescreen monitor.
//
// To use, set the aspect ratio to force 16:9 in the graphics option, then
// enable this shader in Post-Processing Effects.

void main() {
    float2 coords = GetCoordinates() - float2(0.5, 0.5);
    float2 new_coords = float2(coords.x, coords.y*3.0/4.0);
    float2 sample_coords = new_coords + float2(0.5, 0.5);
    SetOutput(SampleLocation(sample_coords));
}
Pages: 1 2