Attract-Mode Support Forum

Attract-Mode Support => Themes => Topic started by: Luke_Nukem on September 19, 2018, 11:26:58 PM

Title: Theme to demonstrate CRT shaders
Post by: Luke_Nukem on September 19, 2018, 11:26:58 PM
UPDATED: Split shaders in to own themes for easier viewing.

I ended up finally finishing off some other stuff I started years ago - namely, a small theme just to show videos using a few different types of CRT shaders.

Gitlab link (https://gitlab.com/Luke-Nukem/crt-shader-theme)

You'll need to play around with things to get nice settings for yourself.

Link to high quality photos of running on an 4:3 LCD machine (https://drive.google.com/open?id=1QVMXu5mfV1h4dXcEwQcYu8f35I5Mz55R)
Title: Re: Theme to demonstrate CRT shaders
Post by: iOtero on September 20, 2018, 01:20:11 AM
Change "movie" to "snap", or nothing will be seen... 8)
Title: Re: Theme to demonstrate CRT shaders
Post by: Luke_Nukem on September 20, 2018, 01:44:44 AM
Change "movie" to "snap", or nothing will be seen... 8)

Lol! It's been a while. I still have some 3 year old settings floating around.
Title: Re: Theme to demonstrate CRT shaders
Post by: Luke_Nukem on September 20, 2018, 01:53:47 AM
Attached scaled photo of Lottes CRT shader - this is the better one, also used in flat_blue theme, but without the curvature or rounded corners.
Title: Re: Theme to demonstrate CRT shaders
Post by: Luke_Nukem on September 20, 2018, 01:55:25 AM
Attached scaled photo of CGWG CRT shader - this is the "CRT" labelled one.
Title: Re: Theme to demonstrate CRT shaders
Post by: Luke_Nukem on September 20, 2018, 05:14:35 PM
UPDATED: Split shaders in to own themes for easier viewing.

Attachment replaced in OG post. Also added to attractmode-extra, awaiting merge.
Title: Re: Theme to demonstrate CRT shaders
Post by: zpaolo11x on September 21, 2018, 12:04:21 AM
This is really nice, I'm planning to add some lotte shaders to my theme, for the "info" page where you can see a larger version of the game movie, adding this CRT effect would look great. I wish I had more time to dedicate to theme making, but real work needs to be done sometimes :D
Title: Re: Theme to demonstrate CRT shaders
Post by: Luke_Nukem on September 21, 2018, 02:56:28 AM
This is really nice, I'm planning to add some lotte shaders to my theme, for the "info" page where you can see a larger version of the game movie, adding this CRT effect would look great. I wish I had more time to dedicate to theme making, but real work needs to be done sometimes :D

I've added yet another shader to the collection, a Halation style one. Which is sort of the cgwg one with extra effects. It really requires an input of a previous frame, which I can't get from AM unless I dive in to the source further.

No new archive, you'll need to get it from the git.

Sounds like your theme will be good!
Title: Re: Theme to demonstrate CRT shaders
Post by: zpaolo11x on September 24, 2018, 01:42:46 AM
I'm playing with your CGWG shader implementation (that's much better than my own CRT shader of course) but is there a way to have a transparent background instead of black?

Title: Re: Theme to demonstrate CRT shaders
Post by: Luke_Nukem on September 24, 2018, 02:13:36 AM
I must not have noticed due to using a black background for testing. I'll see what I can come up with, ours probably missing the alpha channel.
Title: Re: Theme to demonstrate CRT shaders
Post by: zpaolo11x on September 24, 2018, 10:39:45 AM
probably missing the alpha channel.

Yes, indeed the last line of the fragment shader is:

gl_FragColor = vec4(mul_res*brightmult, 1.0);

so basically the alpha is disregarded.
Title: Re: Theme to demonstrate CRT shaders
Post by: zpaolo11x on September 27, 2018, 05:59:17 AM
I must not have noticed due to using a black background for testing. I'll see what I can come up with, ours probably missing the alpha channel.

I found how to do it: just change the last line of the fragment shader to:

  gl_FragColor = vec4(mul_res, cval);

instead of

  gl_FragColor = vec4(mul_res, 1.0);
Title: Re: Theme to demonstrate CRT shaders
Post by: Luke_Nukem on September 27, 2018, 08:00:34 AM
I must not have noticed due to using a black background for testing. I'll see what I can come up with, ours probably missing the alpha channel.

I found how to do it: just change the last line of the fragment shader to:

  gl_FragColor = vec4(mul_res, cval);

instead of

  gl_FragColor = vec4(mul_res, 1.0);

Glad you found it yourself. Sorry I haven't had much time to update things yet.
Title: Re: Theme to demonstrate CRT shaders
Post by: zpaolo11x on October 01, 2018, 12:55:10 AM
You can also apply a similar modification to the Lotte shader, just replace the void function at the end with this:

Code: [Select]
void main(void)
{

#ifdef CURVATURE
    vec2 pos = radialDistortion(texCoord);//CURVATURE
    //FINAL//
    gl_FragColor.rgb = Tri(pos) * Mask(gl_FragCoord.xy) * vec3(corner(pos));
#else
    vec2 pos = gl_TexCoord[0].xy;
    gl_FragColor.rgb = Tri(pos) * Mask(gl_FragCoord.xy);
#endif

#ifdef YUV
    gl_FragColor.rgb = vec3(dot(YUVr,gl_FragColor.rgb), dot(YUVg,gl_FragColor.rgb), dot(YUVb,gl_FragColor.rgb));
    gl_FragColor.rgb = clamp(ToSrgb(gl_FragColor.rgb), 0.0, 1.0);
#endif
 
#ifdef GAMMA_CONTRAST_BOOST
    gl_FragColor.rgb=brightMult*pow(gl_FragColor.rgb,gammaBoost )-vec3(blackClip);
#endif

    gl_FragColor.a = corner(pos);

}
Title: Re: Theme to demonstrate CRT shaders
Post by: jedione on October 04, 2018, 07:09:11 PM
any one know how to add a line to make these shaders work with the Fade module
thanks.......
Title: Re: Theme to demonstrate CRT shaders
Post by: zpaolo11x on October 05, 2018, 02:31:58 AM
any one know how to add a line to make these shaders work with the Fade module
thanks.......

I don't know the fade module well enough, I guess that it uses alpha channel to fade objects... my experience is that if you apply alpha values to the "mother" surface it works, while on the image itself it doesn't...
Title: Re: Theme to demonstrate CRT shaders
Post by: keilmillerjr on December 09, 2018, 05:46:34 AM
Tested on:
10.13.6 (17G3025)
iMac (27-inch, Mid 2011)
2.7 GHz Intel Core i5
12 GB 1333 MHz DDR3
AMD Radeon HD 6770M 512 MB

CRT-CGWG: pass
CRT-Halation: pass with errors
  Failed to compile fragment shader:
  ERROR: 0:1: '' :  version '130' is not supported
  Failed to compile vertex shader:
  ERROR: 0:1: '' :  version '130' is not supported
CRT-Lottes: pass
CRT-Lottes-Multipass: fail
  Failed to compile vertex shader:
  ERROR: 0:1: '' :  version '130' is not supported
  Failed to compile vertex shader:
  ERROR: 0:1: '' :  version '130' is not supported
Title: Re: Theme to demonstrate CRT shaders
Post by: zpaolo11x on December 09, 2018, 07:52:21 AM
CRT-CGWG: pass
CRT-Halation: pass with errors
  Failed to compile fragment shader:
  ERROR: 0:1: '' :  version '130' is not supported

This is because of OpenGL support on MacOS, I got the same error in my tests. MacOS doesn't allow to mix versions of OpenGL, and furthermore AFAIK XQuartz only support OpenGL 1.2
Title: Re: Theme to demonstrate CRT shaders
Post by: Luke_Nukem on December 09, 2018, 10:19:19 AM
CRT-CGWG: pass
CRT-Halation: pass with errors
  Failed to compile fragment shader:
  ERROR: 0:1: '' :  version '130' is not supported

This is because of OpenGL support on MacOS, I got the same error in my tests. MacOS doesn't allow to mix versions of OpenGL, and furthermore AFAIK XQuartz only support OpenGL 1.2

Changing the version number in the shaders works fine for macOS
Title: Re: Theme to demonstrate CRT shaders
Post by: zpaolo11x on December 10, 2018, 12:31:24 AM
Changing the version number in the shaders works fine for macOS

Good to know! I know it's not good practice but I discovered that to keep portability it's better to develop for the older OpenGL standard...
Title: Re: Theme to demonstrate CRT shaders
Post by: keilmillerjr on December 10, 2018, 03:21:28 AM
My iMac that I had to take a loan out for is now officially obsolete due to Mac OS X changing video requirements. I wish Apple would stop all these GUI enhancements and kept it simple like OS9. I don’t need 10 ways to open an app. I would much prefer clicking shutdown and having an instant black screen like on my 333mhz and 433mhz macs with os9.
Title: Re: Theme to demonstrate CRT shaders
Post by: keilmillerjr on December 11, 2018, 05:30:01 AM
CRT-CGWG: pass
CRT-Halation: pass with errors
  Failed to compile fragment shader:
  ERROR: 0:1: '' :  version '130' is not supported

This is because of OpenGL support on MacOS, I got the same error in my tests. MacOS doesn't allow to mix versions of OpenGL, and furthermore AFAIK XQuartz only support OpenGL 1.2

Changing the version number in the shaders works fine for macOS

If I change #version 130 to #version 120 on each shader with crt-lottes-multipass, I get the following errors:

Code: [Select]
Failed to compile fragment shader:
ERROR: 0:101: Invalid call of undeclared identifier 'texture'

Failed to compile fragment shader:
ERROR: 0:103: Invalid call of undeclared identifier 'texture'
ERROR: 0:309: Invalid call of undeclared identifier 'texture'
Title: Re: Theme to demonstrate CRT shaders
Post by: zpaolo11x on December 11, 2018, 05:40:17 AM

If I change #version 130 to #version 120 on each shader with crt-lottes-multipass, I get the following errors:


What if you get rid of the #version 120 line completely?
Title: Re: Theme to demonstrate CRT shaders
Post by: keilmillerjr on December 11, 2018, 12:01:36 PM

If I change #version 130 to #version 120 on each shader with crt-lottes-multipass, I get the following errors:


What if you get rid of the #version 120 line completely?

Commented out or removed:

Code: [Select]
Failed to compile fragment shader:
ERROR: 0:59: '==' does not operate on 'float' and 'int'
ERROR: 0:67: '==' does not operate on 'float' and 'int'
ERROR: 0:77: '==' does not operate on 'float' and 'int'
ERROR: 0:85: '==' does not operate on 'float' and 'int'
ERROR: 0:101: Invalid call of undeclared identifier 'texture'

Failed to compile fragment shader:
ERROR: 0:61: '==' does not operate on 'float' and 'int'
ERROR: 0:69: '==' does not operate on 'float' and 'int'
ERROR: 0:79: '==' does not operate on 'float' and 'int'
ERROR: 0:87: '==' does not operate on 'float' and 'int'
ERROR: 0:103: Invalid call of undeclared identifier 'texture'
ERROR: 0:309: Invalid call of undeclared identifier 'texture'
Title: Re: Theme to demonstrate CRT shaders
Post by: zpaolo11x on February 13, 2019, 07:13:55 AM
Ok just a quick update, I've noticed that as they are set sometimes the scanlines don't correspond 1:1 with the pixel resolution of the snaps. For the CGWG shader there are a lot of "resolution" parameter I can't get to grips with, but what's sure is that in the vertex shader there's a division by 200, so all snaps have 200 scanlines. I think you can pass the texture_height to that shader to fix this.

On the other hand I've found how to fix Lotte shaders with this respect. Notice that your layout file has this lines:

Code: [Select]
        video.shader.set_param("color_texture_sz", vidSurf.width/4, vidSurf.height/4);
        video.shader.set_param("color_texture_pow2_sz", vidSurf.width/4, vidSurf.height/4);

To make it work better I changed the first line so that it passes actual texture size to the shader, and also added support for vertical scanlines using the "vert" parameter. I didn't care to calculate the power of 2 texture for the other field, but it seems to work well anyway. Substitute the two lines with these:

Code: [Select]
        video.shader.set_param("vert", (video.texture_width > video.texture_height ? 0.0 : 1.0));
        video.shader.set_param("color_texture_sz", video.texture_width, video.texture_height);
        video.shader.set_param("color_texture_pow2_sz", video.texture_width, video.texture_height);

In this way you'll get correct scanlines that are exactly the same number as the vertical resolution, while aperture mask will be calculated as always at full resolution.