How to use Smart Integer Scaling as a standalone shader? (giving up)

About the Smart Integer Scaling feature.

As far as I have checked, this is included in both “crt-guest-advanced.slangp” and “Mega_Bezel”. I have confirmed that this is the author of “guest.r”.

I would like to combine that Smart Integer Scaling feature in a single slang file with other shaders such as CRT-royal, any ideas to make this possible?

Smart Integer Scaling is dynamically switched, so it is quite effective and convenient for games such as SFC (SNES), PS1, SS, etc., where the in-game resolution changes frequently. For example, it’s wonderful that FF5, FF7 and “Street Fighter” can coexist.

1 Like

should be this from his code, probably easy to implement as standalone

add these 2 parameters

#pragma parameter TATE "          TATE Mode" 0.0 0.0 1.0 1.0
#define TATE         params.TATE     // Screen orientation

#pragma parameter IOS "          Integer Scaling: Odd:Y, Even:'X'+Y" 0.0 0.0 4.0 1.0
#define IOS          params.IOS     // Smart Integer Scaling

then add these in code

vec2 Overscan(vec2 pos, float dx, float dy){
	pos=pos*2.0-1.0;    
	pos*=vec2(dx,dy);
	return pos*0.5+0.5;
} 


	vec2 texcoord = TEX0.xy;
	if (IOS > 0.0 )
	{
		vec2 ofactor = OutputSize.xy/global.OriginalSize.xy;
		vec2 intfactor = (IOS < 2.5) ? floor(ofactor) : ceil(ofactor);
		vec2 diff = ofactor/intfactor;
		float scan = mix(diff.y, diff.x, TATE);
		texcoord = Overscan(texcoord, scan, scan);
		if (IOS == 1.0 || IOS == 3.0) texcoord = mix(vec2(TEX0.x, texcoord.y), vec2(texcoord.x, TEX0.y), TATE);
	}

then use texcoord for your texture

vec4 res = texture(Source, texcoord);

1 Like

Tested and works as standalone :wink:

1 Like

Thanks for any help.

But, Shader load fails. Am I missing something fundamentally?

copy this on an empty file, scale “default” and apply

#version 450

/*
   Smart Integer Scaling

   Copyright (C) 2018-2022 guest(r) - [email protected]
   Split by DariusG

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   
*/

layout(push_constant) uniform Push
{
	mat4 MVP;
	vec4 SourceSize;
	vec4 OriginalSize;
	vec4 OutputSize;
	uint FrameCount;
	float TATE;
	float IOS;
	float OVERSCALE;
} params;

#pragma parameter TATE "          TATE Mode" 0.0 0.0 1.0 1.0
#define TATE         params.TATE     // Screen orientation

#pragma parameter IOS "          Integer Scaling: Odd:Y, Even:'X'+Y" 0.0 0.0 4.0 1.0
#define IOS          params.IOS     // Smart Integer Scaling

#pragma parameter OVERSCALE "Overscale" 0.0 0.0 1.0 1.0
#define OVERSCALE params.OVERSCALE

#define SourceSize params.SourceSize
#define TEX0 vTexCoord
#define OutputSize params.OutputSize

layout(std140, set = 0, binding = 0) uniform UBO
{
	mat4 MVP;
} global;

#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;

void main()
{
   gl_Position = global.MVP * Position;
   vTexCoord = TexCoord * 1.00001;
}

#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 1) uniform sampler2D Source; 
	
vec2 Overscan(vec2 pos, float dx, float dy){
	pos=pos*2.0-1.0;    
	pos*=vec2(dx,dy);
	return pos*0.5+0.5;
} 

void main()
{
	vec2 texcoord = TEX0.xy;
	if (IOS > 0.0)
	{
		vec2 ofactor = OutputSize.xy/params.OriginalSize.xy;
		vec2 intfactor = (IOS < 2.5) ? floor(ofactor) : ceil(ofactor);
		vec2 diff = ofactor/intfactor;
		float scan = mix(diff.y, diff.x, TATE);
		texcoord = Overscan(texcoord, scan, scan);
		if (IOS == 1.0 || IOS == 3.0) texcoord = mix(vec2(TEX0.x, texcoord.y), vec2(texcoord.x, TEX0.y), TATE);
	}

	vec4 res = texture(Source, texcoord);
	FragColor = res;
}
1 Like

Thanks for any further help.
I copied this, saved it in slang instead of slangp, added it as a shader pass and it worked.

If you combine this with CRT-Royal

Based on CRT-Royal Which is correct, (Rrepend) or (Append) ?

If add (Rrepend)
"crt-royale-first-pass-linearize-crt-gamma-bob-fields.slang” of scale_type_x1 scale_type_y1 There was no change even if I set the to “viewport”.

If add (Append)
Smart Integer Scaling works well for this. but the CRT-Royal’s scanlines etc get a little weird. is this a good idea?

1 Like

Normally should be inside the shader slang to pass it’s coordinates to shader scanline function (?).

2 Likes

Does that mean inserting somewhere in the CRT-Royal slang shader on a screen like this? Or does it mean to fill in any slang with a text editor or the like?

Either way, I’m probably new to this and it’s going to take a long time.
I need to learn how slang shaders work.

1 Like

Here is a comparison of CRT-Royal only and when Smart Integer Scaling is added at the bottom of CRT-Royal. The scanline looks fine but the aperture grill doesn’t line up evenly.

CRT-Royal only
1
CRT-Royal+Smart Integer Scaling
2

Is it smarter for me to simply use the megabezel …
“DariusG” gave me this idea. thank you.

1 Like

Probably needs an adjustment to work only with y axis. Try set the aspect to 1:1 too

2 Likes

I give up on this completely.
My ability is lacking.

The motivation for doing this is I have
“BNES LUT Shader”,“GBA Color Shader”,“GBC Color Shader”, “Homebrew SGB 1-A LUT Shader”, “Sega-Mix Shader for Sega Console”, “Homebrew to Recreate TV Swan Shaders of”, etc…,
even if Megabezel is saved in a simple state, it seems that it is saved in a non-recommended format of Megabezel, and when Megabezel is updated, it no longer works.

So I was thinking of alternatives.
But I decided to give up completely.

Thank you very much.

1 Like

Have you had a conversation with @HyperspaceMadness about your issues. If it is user error, perhaps he can point you in the right direction.

If it is a Mega Bezel or shader system error, perhaps he can fix it.

1 Like

I’m still working on embedding smart integer scales on the CRT-Royal, but I’ll try to talk to him if I have time.

With the ability to add shaders in the UI added in RetroArch v1.15.0, you’ll probably be thrilled if chaotic combinations are possible with Megabezel as well.

It cannot be appended or prepended, the new passes need to be manually inserted in the middle somewhere.

I haven’t asked him yet,

Is it theoretically possible to combine a Megabezel with a CRT-Royal? It is “shaders_slang\crt\crt-royale.slangp” in the crt folder, not the Royal Clone of Megabezel.

1 Like

That is just the Guest Advanced configured to emulate the look of Royale.

Edit: read your post wrong. (There is a clone in the Mega Bezel.)

It is theoretically possible to integrate the Royale shader, though not by append or prepend.

Royale was once integrated in the Mega Bezel but all but the curvature was removed. It is very resource hungry and in the end, doesn’t offer anything that Guest does not.

3 Likes

I don’t know if you’re just looking to have the option in a shader, but do you know that in “Main menu > Video > Scaling” you have “Integer Scale” normal and overscaled, which affects everything you use.

I know that, but the problem is that FF456 or FF456 on SNES or PSX has black borders on the left and right.

Using guest-advanced or Mega Bezel’s Smart Integer Scaling will remove the black borders. And this splendor is that it can coexist with Street Fighter systems such as SNES and PSX.

Furthermore, this also has a positive effect in 3DO (left and right garbage disappears)

What I want to claim is that it automatically switches according to the in-game video source without changing the left and right of the screen or the zoom ratio for each game. In other words, you don’t have to set it for each game.

This is useful for hardware whose resolution changes frequently between games (like SNES, PSX, SS, 3DO)

1 Like

This is similar to the real-time overscan feature that automatically cuts out the black borders that came with high-end or flagship SDTV models (note: only home or consumer CRTs, not professional ones).

I really liked this. I have to thank the people who created this shader.

SNES example.

PSX example.

Supplementally, this is the Japan standard (NTSC-J), and I don’t know how it will work outside of Japan, but at least NTSC-J works well.

3 Likes