Homepage › Forums › RetroPie Project › Video Output on RetroPie › help with OpelGL / barrel distortion
- This topic has 23 replies, 4 voices, and was last updated 9 years, 2 months ago by kraken0667.
-
AuthorPosts
-
09/16/2015 at 13:10 #106205kraken0667Participant
Hello
Im working on a project called PE358 and need some curvature / barrel distortion to simulate/mimic a CRT-monitor. I know this is possible through OpenGL programming, but that’s not my field, and I could use any help I can get. I’ve already tried the official RPI forum, and the people there wont help out due to my lack of programming knowledge. I simply need a programmer to make this happen, and I don’t know where to look. If there’s any one in here that would consider helping me out on this one, there’s a budget involved. For a visual idea of my project, please see [URL=”http://www.lovehulten.com/uploads/3/0/4/8/30489724/2451185_orig.jpg”%5Dhere%5B/URL%5D
09/16/2015 at 14:30 #106208dankcushionsParticipantthese already exist as shaders in retroarch:
https://github.com/libretro/common-shaders/tree/master/crt (see http://filthypants.blogspot.in/2015/04/more-crt-shaders.html for examples). you can view the source code for each: https://github.com/libretro/common-shaders/tree/master/crt/shadersi think for most of these you can remove the extra passes (scanlines, blurs, etc) within retroarch shader options until you’re left with just the curvature part of the shader, but even then i think it’s going to be way too slow.
perhaps someone with opengl experience can let you know if there’s any further optimisation possible, but it seems to be a fairly basic opengl warp operation so i’m not optimistic :(
09/16/2015 at 15:22 #106213kraken0667ParticipantYeah, that’s what I’ve heard too, way too demanding on the RPI. But then I got the answer below from a guy at RPI official forum:
Yes it’s possible. The HLSL shaders you’ve seen do a lot more than just barrel distortion and whilst the Pi might have problems implementing the full range of effects it should be easily able to do the barrel distortion and probably a few others as well.
It’s not complicated OpenGL ES to do this. It’s basically upload the image you want to display as an OpenGL texture, draw two triangles to make up the rectangle representing the full screen and run something like the above code in a fragment shader.
When this guy realized I couldn’t do programing myself, he didn’t want help out anymore.
09/16/2015 at 16:01 #106218dankcushionsParticipantbut my understanding is that these shaders split all the various functions into different passes – one shader preset is a load of separate passes, each with a different utility; eg, in a CRT shader, one pass will add scanlines, one will add blurring, one will add the curvature, etc. you can turn off all but the curvature pass, and achieve what the post is describing without touching any code. you can even save that as a new preset. this is exactly what i did when i wanted to use a LCD-type filter for GBA games, without killing my performance by including a load of extra passes i didn’t care for.
you might be in luck in that your project only needs a small resolution, i guess? if you set your retroarch output to that resolution (through the retropie launch menu), it may well cope with a single pass shader ok!
09/16/2015 at 16:41 #106222kraken0667ParticipantI’ve got a 3.5″ LCD with 320×240 res, and I’m gonna try this tomorrow when Im in the studio, thanks.
I’ve never played around with shaders before. Does all of the Retroarch shaders work with the lr-nestopia emulator? I’m basically going to play NES. And do you happen to know which ones using curvature for effect?
09/16/2015 at 18:03 #106228davejParticipantI’m the guy from the RPi forum who said it could be done.
The not wanting to help bit was mainly because I didn’t know what I would have been signing up to – it may have been hundreds of hours work for all I knew. That’s why I suggested you needed to provide people with more information about your project to interest them.
So, having got that out of the way…
That bit of information saying you only need 320×240 resolution is crucial.
The reason the RaspberryPi has problems running the shaders in retroarch is to do with how fast it’s GPU can access memory. Desktop GPUs, which retroarch shaders have been written for, have very fast memory access but, because accessing memory by GPUs is power hungry, mobile GPUs use a different design approach that minimises the amount of memory accesses they have to do to save power. Explanation why [url=http://blog.imgtec.com/powervr/a-look-at-the-powervr-graphics-architecture-tile-based-rendering]here[/url] if you’re interested in the details.
The multiple pass rendering technique that retroarch uses is pretty much the worst case scenario for mobile GPUs because it needs lots of memory accesses. When people say the Raspberry Pi is too slow running these shaders they are typically considering running them at desktop resolutions.
The fact that you only need such a small resolution makes a very big difference. The display you use takes up about 5% of the memory an emulator running at 1080 would. This means there is a good chance the Raspberry Pi could run some of those shaders at a decent frame rate.
dankcushions’s suggestion of trying just the curvature shader is a good one.
There’s a problem you need to consider when doing barrel distortion on a display that is so close in resolution to the game’s. When the vertical resolution after barrel distortion is less than the game’s vertical resolution, you will lose parts of the game screen. This may cause unacceptable problems – you might lose important bits of the game. You might be able to mitigate this with an anti-aliasing shader but they need lots of memory accesses so you might run into performance problems again.
09/16/2015 at 20:21 #106229kraken0667ParticipantHi again Dave
Thanks for the detailed info. I had no idea res was of such an importance. I will give this a shot tomorrow, and we’ll see. The issue of loosing bits in the games that you’re talking about would really go against what Im trying to achieve here though. My goal with barrel distortion is to prevent the loss of game information in the corners, when using a curved front panel / bezel like I am. Fingers crossed, and Thanks again!
[quote=106228]after b[/quote]
09/17/2015 at 16:12 #106259kraken0667ParticipantI’m not sure how to add new shaders to retroarch. There’s no default shader in there dealing with curature, so I wanted to try out GRT-Geom for example. Do I simply download the shader from
http://filthypants.blogspot.se/2012/07/customizing-cgwgs-crt-pixel-shader.html
and place it in the retroarch/shader directory?
Sorry for being a complete n00b.
09/17/2015 at 16:18 #106261dankcushionsParticipantthere are curvature shaders in there by default – just try the various ones in the shaders/CRT folder. that crt-geom one should already be there: https://github.com/libretro/common-shaders/tree/master/crt
you might have to update to the latest version of retroarch, depending on what version you’re running right now.
09/17/2015 at 17:05 #106266kraken0667ParticipantFound it, just had to change the directory from shader/ to shader/crt/
When I’m hot-key scrolling through the CRT shaders in-game, most of them seem to work, but there’s no curvature on anyone, at least not by default I guess.
As I said, most of them work, but the crt-geom.glsl(that suppose to have curvature by default?) just gives me an empty pink screen.
Maybe this is because Im trying it on a 1280 x 1024 LCD?
[quote=106261]there are curvature shaders in there by default – just try the various ones in the shaders/CRT folder. that crt-geom one should already be there: https://github.com/libretro/common-shaders/tree/master/crt
you might have to update to the latest version of retroarch, depending on what version you’re running right now.
[/quote]
09/17/2015 at 22:25 #106286dankcushionsParticipantAll but the first one have curvature for me. eg, crt-interlaced-halation. the curvature isn’t quite right, but i’ve fiddled with various display settings in my setup so it might be ok for you, or at other resolutions.
you’re right, cgcw-geom.glsl doesn’t seem to work, but the rest worked fine for me, at low framerates. i’ve attached a screenshot of an example:
[attachment file=”image1.JPG”]
(if you can’t see the image, go to https://www.petrockblock.com/wp-content/uploads/2015/09/image1.jpg – images don’t seem to be showing up for me)
09/18/2015 at 20:51 #106362kraken0667ParticipantThanks. I scanned though the crt sub folders and found some more shaders, but for me, only “crt-interlaced-halation” has curvature. It’s slowing the system down a lot as predicted, but this is on my 1280 x 1024 display. Might work better on the small 320×240 lcd Ive ordered. Btw, can you edit the curvature in crt-interlaced-halation? I would like more symmetry, not like the default, which is wider down the bottom(as your screenshot)
Or could you give an example of another curvature shader, cause for me, crt-interlaced-halation is the only one with curvature?
[quote=106286]crt-interlaced-halation[/quote]
09/21/2015 at 12:55 #106535davejParticipantI got bored and wrote a barrel distortion only shader.
It runs speedily on my original 256Mb model B, which matches a model A+ hardware wise, even on a 1080 screen.
It doesn’t do any sort of anti-aliasing so the results don’t look great by default – it has the image problems I described earlier. Because you are going to be using such a small screen however you can get a substantial image improvement by specifying that the input texture should have linear filtering rather than nearest. These two images show examples of the same screen with nearest and linear filtering.
[attachment file=”106536″]
[attachment file=”106537″]
I’ve tried adding it as an attachment but it doesn’t let me and code tags don’t seem to like it either so here it is – until the #endif:
#if defined(VERTEX)
uniform mediump mat4 MVPMatrix;
attribute mediump vec4 VertexCoord;
attribute mediump vec2 TexCoord;varying mediump vec2 TEX0;
void main()
{
TEX0 = TexCoord;
gl_Position = MVPMatrix * VertexCoord;
}
#elif defined(FRAGMENT)
uniform sampler2D Texture;
uniform vec2 InputSize;
uniform vec2 TextureSize;
varying vec2 TEX0;const mediump float BARREL_DISTORTION = 0.25;
const mediump float rescale = 1.0 – (0.25 * BARREL_DISTORTION);void main()
{
vec2 scale = TextureSize / InputSize;
vec2 tex0 = TEX0 * scale;
vec2 texcoord = tex0 – vec2(0.5);
float rsq = texcoord.x * texcoord.x + texcoord.y * texcoord.y;
texcoord = texcoord + (texcoord * (BARREL_DISTORTION * rsq));
texcoord *= rescale;if (abs(texcoord.x) > 0.5 || abs(texcoord.y) > 0.5)
gl_FragColor = vec4(0.0);
else
{
texcoord += vec2(0.5);
texcoord /= scale;
vec3 colour = texture2D(Texture, texcoord).rgb;gl_FragColor = vec4(colour,1.0);
}
}
#endif09/21/2015 at 15:52 #106544kraken0667ParticipantThat looks amazing Dave, just what I need. Thank you for being bored!!!
And sorry again for being a n00b. How do I turn this code into a shader, do I make it into a .glsl file somehow?
09/21/2015 at 16:36 #106548davejParticipantSave everything from the [b]#if defined(VERTEX)[/b] to the [b]#endif[/b] inclusive to a file with a name that ends in .glsl and copy it into the same directory as the other .glsl files. It should list it when you next try to pick a shader in retroarch.
You can tweak the amount of barrel distortion by altering the value in the BARREL_DISTORTION line. Changing it to 0.0 will produce no distortion, the 0.25 it’s currently set to is quite large to demonstrate the effect.
09/21/2015 at 21:12 #106559kraken0667ParticipantHi again Dave. Sorry, but I can’t get the shader to work. I copied everything from “#if defined(VERTEX)” to “#endif” and made a .glsl file, put it in there with the rest of the shaders. It’s listed, but without effect. Probably something stupid I missed. Any idea?
[quote=106548]Save everything from the <strong class=”d4pbbc-bold”>#if defined(VERTEX) to the <strong class=”d4pbbc-bold”>#endif inclusive to a file with a name that ends in .glsl and copy it into the same directory as the other .glsl files. It should list it when you next try to pick a shader in retroarch.
You can tweak the amount of barrel distortion by altering the value in the BARREL_DISTORTION line. Changing it to 0.0 will produce no distortion, the 0.25 it’s currently set to is quite large to demonstrate the effect.
[/quote]
09/22/2015 at 16:48 #106594davejParticipantI didn’t have to do anything that’s not included here. Once you select Apply Shader Changes you can see effect of the shader as the menu is semi-transparent.
09/22/2015 at 23:53 #106638kraken0667ParticipantI tried Apply Shader Changes in retroarch, no effect what so ever.
Maybe you can download my shader and and check if there something wrong with the file maybe?
09/23/2015 at 10:19 #106660davejParticipantI had a look at your file and found the problem. The forum has changed the minus signs to dashes – so OpenGL no longer thinks it’s a valid shader program.
Change them to minus signs and it should be OK.
09/24/2015 at 09:00 #106761kraken0667ParticipantThanks Dave, it’s working now and it looks PERFECT!
Just PM me if you’d want something in exchange for the help.
This is so appreciated!
09/28/2015 at 18:27 #107028dankcushionsParticipantthanks so much for this shader! i’ve tried it (with the – fix) and it works great, but i do get some slowdown. it’s strange – in something like sonic 1 you can see the screen hitching a little bit when it pans, when compared to without the shader. it’s annoying i can’t give better figures as the framerate counter in retroarch never seems to work for me! it is miles faster than the other CRT shaders, though.
i’m running a pi 2 at 1080p (including my retroarch render resolution, which is set to ‘video output’).
10/12/2015 at 14:42 #107747kraken0667ParticipantI have a problem. The shader(s) works when scrolling through the dir with hotkey, but I can’t seem to get the shader to load on startup
Am I doing something wrong? My retroarch.cfg looks like this:
video_shader = /opt/retropie/emulators/retroarch/shader/pe358shader.glsl
video_shader_enable = “true”
video_shader_dir = /opt/retropie/emulators/retroarch/shader/
10/12/2015 at 17:32 #107753petrockblogKeymasterdoes it make a difference if you remove the quotes from video_shader_enable ?
Can you put the full configurations you have edited somewhere (pastebin or similar)
10/13/2015 at 20:52 #107823kraken0667ParticipantNo change when removing the quotes, no.
I added a hotkey for scrolling through the shaders in-game, but that’s the only edit Ive made in retroarch.cfg really, other than editing the shader options as mentioned above.
-
AuthorPosts
- The forum ‘Video Output on RetroPie’ is closed to new topics and replies.