Jump to content

Demul scanlines


caligari

Recommended Posts

Posted

Hi,

I've been playing around with the shader option in Demul, in order to add scanlines...

At first I used some shaders found on the net, but ended up writing my own ones (using the scanline-tv formulaes from mame plus)

Here are some screenshots (as you will see, there are different options, on based on the resolution you play in, you'll prefer using 2, 3 or 4 line modes)

1280x960, scanlines using 4 lines

bfe1817d-e32b-43f7-a2b2-26eefb56a33b.jpg

1280x960, scanlines on 3 lines

d06ffd8e-4642-4b1a-9c53-676f1055811d.jpg

1280x960, scanlines on 3 lines

606f9cc9-ea0a-4243-b04f-a40035fbf419.jpg

1280x960, scanlines using 2 lines

54dfb560-47c6-41ff-b3f6-217c4f135cb2.jpg

640x480, scanlines using 4 lines

68f174e5-c3ad-4b4a-837a-0ef53a0dc7d3.jpg

640x480, scanlines using 2 lines

9491b331-0ecb-41a5-bd34-487c79cd8d12.jpg

Now, to do that, you'll need two files (I saved them in a shaders subdirectory inside my Demul installation dir)

First file : scanlines.slv

You shouldn't have to change this one

uniform vec4 OGL2Param;
uniform vec4 OGL2Size;

void main()
{
float x = (OGL2Size.x/2048.0)*OGL2Param.x;
float y = (OGL2Size.y/1024.0)*OGL2Param.y;

gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1].xy = gl_TexCoord[0].xy + vec2( x, 0.0 );
}

Second file : scanlines.slf

It's in this file that you will decide to use 2, 3 or 4 lines

(As is, it's in 4 lines mode. If you want to change that, just uncomment the appropriate mode by removing the //)

You can adjust the intensity on the scanlines by playing with the gl_FragColor = rgb*??? : ??? indicates how dark it will be : ???=1.0 means the color of the line will be the same as the original, ???=0.0 means the color of the line will be pure black.

uniform sampler2D OGL2Texture;

void main()
{
vec4 rgb = texture2D(OGL2Texture, gl_TexCoord[0].xy);

// if x is even => smooth with next pixel
if (fract(gl_FragCoord.x*0.5)>0.5)
	rgb = ( rgb + texture2D(OGL2Texture,gl_TexCoord[1].xy) )*0.5;

// Test on 2 lines
//	float test = fract(gl_FragCoord.y/2);		
//	if (test>0.5)	gl_FragColor = rgb;
//	else     		gl_FragColor = rgb*0.5;

// Test on 3 lines
//	float test = fract(gl_FragCoord.y/3);		
//	if (test>0.666)		gl_FragColor = rgb;
//	else if(test>0.333)	gl_FragColor = rgb*0.75;
//	else     			gl_FragColor = rgb*0.5;

// Test on 4 lines
float test = fract(gl_FragCoord.y/4);		
if (test>0.75)		gl_FragColor = rgb;
else if (test>0.5)		gl_FragColor = rgb*0.75;
else if (test>0.25)	gl_FragColor = rgb*0.5;
else     			gl_FragColor = rgb*0.25;

}

  • 5 months later...
Posted

At one time, I got more but I don't think I still have them.

Anyway, I think they are more or less (it might need some tweaking) shaders made for ePSXe opengl2 plugin.

You can get more here

Anyway, I'll probably dig a little more on that matter during my holidays, I'm quite interested by this rendering. I'd like to use it in Mame too (which may be possible using SDLMame and the same shader technique)

  • 4 weeks later...
Posted

I got some time this week end, so I reopened this project of mine :)

Here are some results, to simulate the "barrel distorsion" effect.

Without scanlines:

1c1a5a37-295b-4393-9ad8-a1587a216e10.jpg 43fcf3a4-ba74-4942-82da-a1ee2e0191fe.jpg 0a3177d4-387f-49ba-b28d-e6fd4c29e277.jpg

(Note : the grid on the second screenshot was here for testing... I forgot to remove it before making the screenshot)

With scanlines (far from perfect, there are a lof of artifacts... Moreover the scanlines are not aligned on the game pixels)

157372a7-905a-4ab6-afd0-7c1d7cfd9a44.jpg bd617cde-db82-4f19-98bf-d386ea5921d6.jpg b3e74289-3ff4-43a2-9bdd-c9f0e192c54f.jpg a2998aa0-d847-4583-a19c-8b1a262370ad.jpg

Posted

Round 3 :)

I changed a few parameters, and I think it starts to look quite nice: the moire is still there but less noticable.

a06c1c4c-5011-4805-9bda-94436dd2042f.jpgbb5ebe79-eaa4-466c-9ece-cadc34f66a31.jpgfca3063d-e1af-436c-88c3-29c9228fa6a3.jpg

a641debf-ed78-438e-a926-142a6a0cca80.jpg0acad465-f540-4053-9903-cd804f083b60.jpgf8fb85be-0363-4521-add7-69f2753b3eb4.jpg

6090a7c4-44ad-4439-b915-31de4b1bf5ed.jpgc194d4c4-c153-48b4-aceb-b2f6c4b3e92f.jpg8efa1b8c-a6e8-44d4-8ff2-a3cfdff6f10a.jpg

  • 2 months later...
  • 2 weeks later...
Posted

Brilliant work, Caligari - thanks for sharing! I can't seem to find anywhere to enable shaders in Demul 0.5.6.. I have the files setup as described in your first post, but how are they enabled inside Demul?

  • 2 months later...
Posted
Round 3 :)

I changed a few parameters, and I think it starts to look quite nice: the moire is still there but less noticable.

a06c1c4c-5011-4805-9bda-94436dd2042f.jpgbb5ebe79-eaa4-466c-9ece-cadc34f66a31.jpgfca3063d-e1af-436c-88c3-29c9228fa6a3.jpg

a641debf-ed78-438e-a926-142a6a0cca80.jpg0acad465-f540-4053-9903-cd804f083b60.jpgf8fb85be-0363-4521-add7-69f2753b3eb4.jpg

6090a7c4-44ad-4439-b915-31de4b1bf5ed.jpgc194d4c4-c153-48b4-aceb-b2f6c4b3e92f.jpg8efa1b8c-a6e8-44d4-8ff2-a3cfdff6f10a.jpg

Amazing! Similar to the hlsl effects in the latest Mame(s). How did you achieve this? Sorry for bumpng :tee:

778883.png

Emumovieslifetimemember.gif

Posted
Amazing! Similar to the hlsl effects in the latest Mame(s). How did you achieve this? Sorry for bumpng :tee:

Well, it's more than similar, it's the same methods : we just add some pixel shaders :)

In Demul, it's done by:

1. Putting some shaders (two files: a .slf and a .slv) in a shaders subdirectory

2. Selecting the OpenGL Video plugin

3. In the plugin configuration, check the shader effects box and select the one you wish to use

Here are the one I have : shaders.zip

I did not touch them for a while (I worked more recently on them, but with bsnes*, see here and here) so I'm not sure which one is which.

The one from the last screenshots is probably one of the CRT-something.

Also, the screen size needs to be entered in the .slf files : you'll find in the first lines something looking like

static vec2 ScreenSize = vec2(1280.0, 960.0);

This means that to get the intended effect, you have to use Demul in 1280x960! If you want another resolution, change those number before launching the emulator!

(*) as a matter of fact, the first versions came from bsnes shaders that I ported to Demul.

(My last bsnes shaders are now better than the one I just posted, but need to be ported to to Demul!)

Posted

Those shaders are great caligari, thanks for your work on them

"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music."

RocketLauncher's Official Home

If you appreciate my work:
donate_button.png

My Apps:
Window Logger
Idle Volume Adjuster
ExplorerRestorer
Rom Folder Cleaner
Module Updater
My Guides:
How To Mod Guncons with Aimtrak

Posted
Well, it's more than similar, it's the same methods : we just add some pixel shaders :)

In Demul, it's done by:

1. Putting some shaders (two files: a .slf and a .slv) in a shaders subdirectory

2. Selecting the OpenGL Video plugin

3. In the plugin configuration, check the shader effects box and select the one you wish to use

Here are the one I have : shaders.zip

I did not touch them for a while (I worked more recently on them, but with bsnes*, see here and here) so I'm not sure which one is which.

The one from the last screenshots is probably one of the CRT-something.

Also, the screen size needs to be entered in the .slf files : you'll find in the first lines something looking like

static vec2 ScreenSize = vec2(1280.0, 960.0);

This means that to get the intended effect, you have to use Demul in 1280x960! If you want another resolution, change those number before launching the emulator!

(*) as a matter of fact, the first versions came from bsnes shaders that I ported to Demul.

(My last bsnes shaders are now better than the one I just posted, but need to be ported to to Demul!)

Thanks for the posting your shader effects! Though each time I try to load a game I get a little box that pops up saying "unable to compile fragment shader effects" I'm using Demul 0.5.6.

*Edit* I've only tried the CRT ones. Not sure if I get the error on the others.

778883.png

Emumovieslifetimemember.gif

Posted
Thanks for the posting your shader effects! Though each time I try to load a game I get a little box that pops up saying "unable to compile fragment shader effects" I'm using Demul 0.5.6.

*Edit* I've only tried the CRT ones. Not sure if I get the error on the others.

That may have to do with your graphic card... When I first wrote those shaders, I wasn't aware of some coding specifications, and on some ati(?) cards, they didn't work until the code was corrected to be compliant.

I should be able to correct that, but right now I don't have the time to do it, sorry!

Posted
That may have to do with your graphic card... When I first wrote those shaders, I wasn't aware of some coding specifications, and on some ati(?) cards, they didn't work until the code was corrected to be compliant.

I should be able to correct that, but right now I don't have the time to do it, sorry!

It could be my graphics card. I'm using an Ati Radeon 4670. Is it easy to correct? I'd try myself but wouldn't really know what to do :laugh:

778883.png

Emumovieslifetimemember.gif

Posted
It could be my graphics card. I'm using an Ati Radeon 4670. Is it easy to correct? I'd try myself but wouldn't really know what to do :laugh:

Well it's not really hard, it's just... painful.

For example, textures are stored (if I remember correctly) in vec4 structures: for each point you get one float for red, one for green, one for blue and one for alpha.

So a texture point T will have 4 float values : r,g,b,a.

Often in those shaders, we don't really care for the alpha value, and we will only manipulate r,g,b, so we work with T.rgb (it means red, green and blue componenents of T: we ditch the alpha value)

But by doing so, we manipulate a vec3 structure... and at some point, you are expected to output a vec4 structure.

I think that when asked to work with that, a nvidia card will accept the vec3 structure, and silently transform it into the expected vec4 by adding an alpha value of 1.0.

An ati card will say "this should be a vec4, you give me a vec3... No way!"

So basically, to fix this, one needs to use the correct structures where they are expected... Not difficult once you know what to look for.

(Also, this vec4/vec3 problem is just an example! There are similar problems with vec2 and other structures)

I don't really want to correct the above versions since the new ones I did for bsnes are better... It makes more sense to translate those!

Posted
Well it's not really hard, it's just... painful.

For example, textures are stored (if I remember correctly) in vec4 structures: for each point you get one float for red, one for green, one for blue and one for alpha.

So a texture point T will have 4 float values : r,g,b,a.

Often in those shaders, we don't really care for the alpha value, and we will only manipulate r,g,b, so we work with T.rgb (it means red, green and blue componenents of T: we ditch the alpha value)

But by doing so, we manipulate a vec3 structure... and at some point, you are expected to output a vec4 structure.

I think that when asked to work with that, a nvidia card will accept the vec3 structure, and silently transform it into the expected vec4 by adding an alpha value of 1.0.

An ati card will say "this should be a vec4, you give me a vec3... No way!"

So basically, to fix this, one needs to use the correct structures where they are expected... Not difficult once you know what to look for.

(Also, this vec4/vec3 problem is just an example! There are similar problems with vec2 and other structures)

I don't really want to correct the above versions since the new ones I did for bsnes are better... It makes more sense to translate those!

I see. Wow sounds difficult. I would give that a try but I'd be in over my head ha ha. I can wait till you translate your bsnes ones. Thanks for posting the info! At least my laptop has a decent Nvidia card I can always try it on that :tee:

778883.png

Emumovieslifetimemember.gif

  • 3 weeks later...
Posted

Well, you're in luck, I was on holidays so I had some time in the past days...

Now a few things:

* first, it's still a WIP, it needs some tuning

* I have other versions to port back from bsnes, some may give better results! I just had time for this one

* As before, you'll have to edit the first lines. The more important parameters are

- ScreenSize : it's the resolution you play in

- HWSize : it's the original resolution you want for the game (I wanted it to be 640x480 by default, but if your screen res is too low, you might want to reduce this one)

- DOT Size : this is what will decide the shape of the effect. Playing with this, you'll get scanlines, (horizontal or vertical), linear blending... Or very ugly things.

* There are a few other parameters... They are described in the file

* I tried to be careful, but I don't garanty this version will work on an ATI card, I didn't get the chance to test it on my cab...

File name: shaders_v2_wip.zip File size: 2.37 KB

Posted
Well, you're in luck, I was on holidays so I had some time in the past days...

Now a few things:

* first, it's still a WIP, it needs some tuning

* I have other versions to port back from bsnes, some may give better results! I just had time for this one

* As before, you'll have to edit the first lines. The more important parameters are

- ScreenSize : it's the resolution you play in

- HWSize : it's the original resolution you want for the game (I wanted it to be 640x480 by default, but if your screen res is too low, you might want to reduce this one)

- DOT Size : this is what will decide the shape of the effect. Playing with this, you'll get scanlines, (horizontal or vertical), linear blending... Or very ugly things.

* There are a few other parameters... They are described in the file

* I tried to be careful, but I don't garanty this version will work on an ATI card, I didn't get the chance to test it on my cab...

File name: shaders_v2_wip.zip File size: 2.37 KB

Awesome, thanks! I'll give this a shot! I'm also interested in bsnes stuff since I replaced my SNES emu with that one :)

778883.png

Emumovieslifetimemember.gif

  • 7 months later...
Posted

I apologize for bumping this thread. But I was wondering if you were still working on these shaders? I'm not sure if they are compatible with 5.7 but I still use 5.6 and would love to have HLSL effect in Demul for Naomi and Atomiswave. The only thing that seems to do the "curved" effect is the barrel shader.

778883.png

Emumovieslifetimemember.gif

  • 10 months later...
Posted
Round 3 :)

I changed a few parameters, and I think it starts to look quite nice: the moire is still there but less noticable.

a06c1c4c-5011-4805-9bda-94436dd2042f.jpgbb5ebe79-eaa4-466c-9ece-cadc34f66a31.jpgfca3063d-e1af-436c-88c3-29c9228fa6a3.jpg

a641debf-ed78-438e-a926-142a6a0cca80.jpg0acad465-f540-4053-9903-cd804f083b60.jpgf8fb85be-0363-4521-add7-69f2753b3eb4.jpg

6090a7c4-44ad-4439-b915-31de4b1bf5ed.jpgc194d4c4-c153-48b4-aceb-b2f6c4b3e92f.jpg8efa1b8c-a6e8-44d4-8ff2-a3cfdff6f10a.jpg

Salut caligari! Je souhaiterais mettre l'effet barrel distortion comme sur tes screenshots peux tu m'expliqué comment tu ajoutes cet effet, j'ai créer les deux fichier mais j'ai pas compris ceux que tu as fais pour avoir la distortion! Merci ^^

  • 11 months later...
Posted
Well, you're in luck, I was on holidays so I had some time in the past days...

Now a few things:

* first, it's still a WIP, it needs some tuning

* I have other versions to port back from bsnes, some may give better results! I just had time for this one

* As before, you'll have to edit the first lines. The more important parameters are

- ScreenSize : it's the resolution you play in

- HWSize : it's the original resolution you want for the game (I wanted it to be 640x480 by default, but if your screen res is too low, you might want to reduce this one)

- DOT Size : this is what will decide the shape of the effect. Playing with this, you'll get scanlines, (horizontal or vertical), linear blending... Or very ugly things.

* There are a few other parameters... They are described in the file

* I tried to be careful, but I don't garanty this version will work on an ATI card, I didn't get the chance to test it on my cab...

File name: shaders_v2_wip.zip File size: 2.37 KB

Hello, can anyone repost the shaders? Or any other decent CRT shader to add to demul ? Playing arcade on bare pixels should be prohibited.

or do you think SweetFX is a better option?

Posted

I've been trying to figure out how to use sweet fx with Demul for a while with no luck... If anyone can figure it out, It'd be much appreciated..

Atomiswave needs them scanlines!

Posted

Rick74, I got it working. Unzip files on demul root folder, delete dx9 dll file, demul only accepts 10 or 11 so it will use dxgi.dll. 32bit files is OK.

I'm going to upload some settings configurations here, do you too. Now on my 1280x1024 monitor screen, but tomorrow I will check on my HDReady TV.

edit: here my crt settings, I only enable bloom along this. I don't seem to find a perfect scanline resolution, but 1.2 is near though. Also CRTDistance makes an ugly ghosting effect, I don't know if that's on purpose. And, can't seem to set CRTAngleY to 0, or it will blank screen.

W3XQEGTs.png 9u8h7o3s.png

#define CRTAmount            0.5    //[0.00 to 1.00]  Amount of CRT effect you want

#define CRTResolution        1.2     //[1.0 to 8.0]    Input size coefficent (low values gives the "low-res retro look"). Default is 1.2
#define CRTgamma             1.5     //[0.0 to 4.0]    Gamma of simulated CRT (default 2.2)
#define CRTmonitorgamma      2.9     //[0.0 to 4.0]    Gamma of display monitor (typically 2.2 is correct)
#define CRTBrightness        2.5     //[1.0 to 3.0]    Used to boost brightness a little. Default is 1.0
#define CRTScanlineIntensity 2.0     //[2.0 to 4.0]    Scanlines intensity (use integer values preferably). Default is 2.0
#define CRTScanlineGaussian  1       //[0 or 1]        Use the "new nongaussian scanlines bloom effect". Default is on

#define CRTCurvature         1       //[[0 or 1]          "Barrel effect" enabled (1) or off (0)
#define CRTCurvatureRadius   2.0     //[0.0 to 2.0]       Curvature Radius (only effective when Curvature is enabled). Default is 1.5
#define CRTCornerSize        0.0300  //[0.0000 to 0.0020] Higher values, more rounded corner. Default is 0.001
#define CRTDistance          4.00    //[0.00 to 4.00]     Simulated distance from viewer to monitor. Default is 2.00
#define CRTAngleX            0.00    //[-0.20 to 0.20]    Tilt angle in radians (X coordinates)
#define CRTAngleY           -0.05    //[-0.20 to 0.20]    Tilt angle in radians (Y coordinates). (Value of -0.15 gives the 'arcade tilt' look)
#define CRTOverScan          1.00    //[1.00 to 1.10]     Overscan (e.g. 1.02 for 2% overscan). Default is 1.01
#define CRTOversample        1       //[0 or 1]           Enable 3x oversampling of the beam profile (warning : performance hit)

I think it would be wise to load a custom shader, cgwg made a nice one, just read here.

I was using retreoarch's shaders in custom.h and they seem to work if it wasn't for this error, so near, yet so far : (

SweetFX\Shaders\Custom.h(56,3): error X3086: the 'sampler2D' keyword is deprecated in strict mode; use 'SamplerState' instead
Posted
Rick74, I got it working. Unzip files on demul root folder, delete dx9 dll file, demul only accepts 10 or 11 so it will use dxgi.dll. 32bit files is OK.

I'm going to upload some settings configurations here, do you too. Now on my 1280x1024 monitor screen, but tomorrow I will check on my HDReady TV.

edit: here my crt settings, I only enable bloom along this. I don't seem to find a perfect scanline resolution, but 1.2 is near though. Also CRTDistance makes an ugly ghosting effect, I don't know if that's on purpose. And, can't seem to set CRTAngleY to 0, or it will blank screen.

W3XQEGTs.png 9u8h7o3s.png

#define CRTAmount            0.5    //[0.00 to 1.00]  Amount of CRT effect you want

#define CRTResolution        1.2     //[1.0 to 8.0]    Input size coefficent (low values gives the "low-res retro look"). Default is 1.2
#define CRTgamma             1.5     //[0.0 to 4.0]    Gamma of simulated CRT (default 2.2)
#define CRTmonitorgamma      2.9     //[0.0 to 4.0]    Gamma of display monitor (typically 2.2 is correct)
#define CRTBrightness        2.5     //[1.0 to 3.0]    Used to boost brightness a little. Default is 1.0
#define CRTScanlineIntensity 2.0     //[2.0 to 4.0]    Scanlines intensity (use integer values preferably). Default is 2.0
#define CRTScanlineGaussian  1       //[0 or 1]        Use the "new nongaussian scanlines bloom effect". Default is on

#define CRTCurvature         1       //[[0 or 1]          "Barrel effect" enabled (1) or off (0)
#define CRTCurvatureRadius   2.0     //[0.0 to 2.0]       Curvature Radius (only effective when Curvature is enabled). Default is 1.5
#define CRTCornerSize        0.0300  //[0.0000 to 0.0020] Higher values, more rounded corner. Default is 0.001
#define CRTDistance          4.00    //[0.00 to 4.00]     Simulated distance from viewer to monitor. Default is 2.00
#define CRTAngleX            0.00    //[-0.20 to 0.20]    Tilt angle in radians (X coordinates)
#define CRTAngleY           -0.05    //[-0.20 to 0.20]    Tilt angle in radians (Y coordinates). (Value of -0.15 gives the 'arcade tilt' look)
#define CRTOverScan          1.00    //[1.00 to 1.10]     Overscan (e.g. 1.02 for 2% overscan). Default is 1.01
#define CRTOversample        1       //[0 or 1]           Enable 3x oversampling of the beam profile (warning : performance hit)

I think it would be wise to load a custom shader, cgwg made a nice one, just read here.

I was using retreoarch's shaders in custom.h and they seem to work if it wasn't for this error, so near, yet so far : (

Keep me posted... I'd like to use RetroArch CRT_geom_flat.cg

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...