Welcome, Guest.
Username: Password: Remember me

TOPIC: [HELP] Resolution Changer w/ aspect ratio

[HELP] Resolution Changer w/ aspect ratio 1 year 9 months ago #1

So, i was looking for a shader that allowed me to change the resolution of the game and center the image (AKA change its aspect ratio).
I tried porting one from a unity shader but the image never got centered (so it looked all weird if the res was small and it stretched always on the top.

Here, pictures speak more than words:

How it looks:

How it should look:

Code:
#include "ReShade.fxh";

uniform bool bGFXA_doResolution <
	ui_type = "combo";
	ui_label = "Custom Screen Resolution [GFX Adapter]";
> = false;

uniform bool bGFXA_screenStretch <
	ui_type = "combo";
	ui_label = "Stretch Screen [GFX Adapter]";
> = false;

uniform float screenPAR <
	ui_type = "drag";
	ui_min = -5.0; ui_max = 5.0;
	ui_label = "Pixel Aspect Ratio [GFX Adapter]";
> = 1.0;

uniform float iGFXA_resolutionX <
	ui_type = "drag";
	ui_min = 1.0;
	ui_max = BUFFER_WIDTH;
	ui_label = "Screen Resolution Width [GFX Adapter]";
> = 320;

uniform float iGFXA_resolutionY <
	ui_type = "drag";
	ui_min = 1.0;
	ui_max = BUFFER_HEIGHT;
	ui_label = "Screen Resolution Height [GFX Adapter]";
> = 240;

uniform float3 f3GFXA_backgroundColor <
	ui_type = "color";
	ui_label = "Background Color [GFX Adapter]";
> = float3(1,1,1);


float2 p_sh(float2 p_){

	float2 xx = float2(320.0, 240.0); //output screen res				
	float2 ar = float2(1.0,1.0); //final aspect ratio (calculated)
	
	xx = float2(iGFXA_resolutionX,iGFXA_resolutionY);
	ar = ar.xx;
	
	return 0.5 * float2(
		step(0.0, 1.0 - ar.y) * (1.0 - 1.0 / ar.y), 
		step(1.0, ar.y) * (1.0 - ar.y));
}

float3 PS_Resolutionizer(float4 pos : SV_Position, float2 uv : TEXCOORD0) : SV_Target {
        float2 p = uv; //this is Texcoord
	float2 p_ = p*float2((float)BUFFER_WIDTH,(float)BUFFER_HEIGHT);
	float2 xx = float2(320.0,240.0);
	float2 ar = float2(1.0,1.0); //final aspect ratio (calculated)
	
	ar = ar.xx;
	xx = ReShade::ScreenSize.xy;
	
	if (bGFXA_doResolution){
	
	xx = float2(iGFXA_resolutionX, iGFXA_resolutionY); //Resolution, in screenshots, it was 320x240
	
	if(bGFXA_screenStretch==0){
		float sar = ReShade::ScreenSize.x/ReShade::ScreenSize.y;
		float nar = xx.x/xx.y;
		ar = float2(1.0, nar/sar*screenPAR);						
	}	
		p_ = p;
		p_ *= ar;
		
	if(ar.y<1.0) p_ = p_*(1.0/ar.y);
			p_ = floor(p_*xx)/xx;
			p_ +=  p_sh(p_);
	} else {
		p_ = uv;
	}

        float3 col = tex2D(ReShade::BackBuffer, p_).rgb;
        return col;
}

technique Resolutionizer {
	pass Resolutionizer_Pass1 {
		VertexShader=PostProcessVS;
		PixelShader=PS_Resolutionizer;
	}
}
Last Edit: 1 year 9 months ago by matsilagi. Reason: Finished edits for now
The administrator has disabled public write access.

[REQUEST] Resolution Changer w/ aspect ratio 1 year 9 months ago #2

Will try as soon as I update LightDoF.

The following allows you to scale a texture coordinate while keeping it centered., if that's of any help.
Keep in mind higher scale means smaller texture on-screen.
uv -= 0.5;
uv *= scale;
uv += 0.5;

Now why you'd want that instead of just changing your resolution is beyond me.
Likes to reinvent the wheel.

My shaders repository: www.github.com/luluco250/FXShaders
The administrator has disabled public write access.

[REQUEST] Resolution Changer w/ aspect ratio 1 year 9 months ago #3

Works as long as its a square res.
If its not square (eg:120x240) it doesn't center.

EDIT:Fixed using the fix above plus lots of other crazy stuff.
I don't even know how :silly:
Last Edit: 1 year 9 months ago by matsilagi.
The administrator has disabled public write access.