High performance scanlines + gamma correction?

I have had a hard time finding a CRT emulation I can live with. The best shader configs have multiple passes of performance intensive effect, which slows everything down and worse yet produces lots of input lag.

The pi and CRT apeture single pass shaders do perfectly acceptable scanlines and input lag seems fine. The problem is that it darkens the image too much. I want to add in a pass of another shader that can up the gamma or increase the brightness to offset the effect. To reduce lag it aught to be a single pass, low performance impact shader. Something that would be ok to use on a pi would be great. Any suggestions? Thanks :slight_smile:

misc/image-adjustment.glsl should do it.

1 Like

I don’t think it could get cheaper than this: Cg / GLSL.

Offline, cgc reports: # 4 instructions, 1 R-regs :slight_smile:

Ha, yeah, doesn’t get much lighter than that. :slight_smile:

If you can tell me which license you would like applied to it, I’ll add it to the repos.

Public Domain?. I don’t really mind :slight_smile:

Sounds good. That’s what I typically choose for mine, as well.

You PC users with your fancy shmancy GPUs that have hardware trig functions. :wink:

In other words - that might not be fast on Raspberry Pis and other things with low end GPUs.

Here’s some notes for crt-pi users if they want to brighten the image whilst using that shader:

You can change some of the parameters to make the image brighter but they do have downsides.

Increasing MASK_BRIGHTNESS will make the phosphor mask emulation less obvious. If you’re not bothered about phosphor emulation at all you could set MASK_TYPE to 0 which will disable it completely.

SCANLINE_WEIGHT governs how wide the dark lines are so decreasing it will brighten the image but makes scanlines less even.

SCANLINE_GAP_BRIGHNESS controls how bright the dark lines are. Increase this to brighten the image but the scanlines will be less prominent.

Increasing BLOOM_FACTOR will brighten the image at the expense of reducing the already limited bloom effect.

1 Like

So, sin() is expensive on Pis?. What about others like frac() and step()?.

I’m interested in a list of functions that are not hardware-implemented on the Pis, although I don’t have one.

The list of functions implemented in hardware by VC4 GPUs is very limited. You can find the details in the GPU documentation here.

As an example, it doesn’t even have a divide instruction! It does have a reciprocal instruction and the driver appears to implement a/b as (1/b)*a. This is why, when trying to squeeze the last bit of performance out of the chip for crt-pi I did apparently odd things like use *0.3333333 instead of /3.

hi dave_j, looking you are around I want to quickly ask something about crt-pi, it looks great in raspberry pi and PC at 1080p but it has weird scanlines on my android phone even when the resolution is 1080x1920, scanlines look good at the top and bottom but look uneven at the center… any idea how to fix this? Thanks.

@netux79 Are you using curvature? If so turn it off. Compared to a flat image, curvature compresses the image near the edges and bulges it near the centre - causing the line width to change.

If you get the problem without curvature try using integer scaling and putting up with borders or overscan. There shouldn’t be any difference between the way lines get displayed but your screen may be doing something. Integer scaling tends to reduce such effects.

No, I’m not using curvature to avoid performance penalties. Yeah, it works fine with integer scale but so much space is wasted. I was wondering why if it is the same screen resolution, game, aspect ratio, emulator, it is not displaying correctly.

I will continue researching the issue and if I can solve it I will post here the solution so anyone else with the issue know how to solve it.

Thank you very much for the help!

Keep in mind there’s no consistency between different screens in how they display things. I have three computer screens and a HD TV. All display crt-pi images differently - I can’t get non-integer even scan lines at all on my TV.

Integer scaling with overscanning might be a better option. You’ll lose a bit of the picture but shouldn’t lose any important info. - games were designed to run on CRT TVs that overscanned.

Will try that option of overscanning and see if that helps, thanks for your work on this shader!.