I'm looking for some kind help: a small shader for my arcade project

Hi everyone,

for one of my arcade projects I need the option to scale the image by adapting it to a precise area defined by the user (providing X & Y side in pixels). The optimum would be to also have the possibility of placing the image in a precise point of the display (coordinates provided by the user, again in pixels).

Now, RA has something like that in the aspect ratio settings section but unfortunately it doesn’t allow you to associate this function with a hotkey, which is what I desperately need.

The only solution I came up with is to resort to ReShade: Is there anyone so kind and experienced who is able and willing to compose a small shader for ReShade (.fx) that does the 2 things I wrote above?

I’m aware that maybe this isn’t the perfect place to ask but I don’t know where else I can go for help (the ReShade forum isn’t much alive…)

Many thanks in advance for the attention!

Why do you need a hotkey? You can associate aspect with a content directory.

I need to implement a complex feature that also includes a variable aspect ratio/viewing area: so I’m not looking for a way to set the aspect ratio for a certain core or game.

If you were a bit less vague about what you need, it’s possible the solution is already out there.

That’s pretty vague.

I have already clearly explained what I need: basically the same function that RA makes available in the customized aspect ratio menu, where you can enter both the X & Y offset in which the image appears on the display (starting from 0,0) and the dimensions (X & Y) to scale the image to.

All values expressed in pixels. I need exactly this but hotkeyable, so the solution is a shader for ReShade.

For someone who knows shader programming it should be child’s play…I found a little something that could theoretically be fine but unfortunately the scale and offset values of the image are expressed in strange multiples, which makes it rather difficult and certainly not so accurate the calibration I would like to do.

I could also post the shader I found here, if someone told me that it is possible to modify it so that the parameters can be expressed in pixels…

hello send your shader here already

bactino:

hello send your shader here already

I found 2 shader for ReShade that more or less do what I need. Below is the first of the two.

Positive points:

  • allows 90° rotation (actually any angle you like) which is another option I needed
  • allows you to position the image within the display area
  • allows image scaling

Negative points:

  • the rotation completely stretches the image along the entire horizontal axis of the display. You completely lose the original aspect ratio (and this is normal), but the internal rotation of RA does not cause the same disaster

  • the positioning of the image does not occur by entering coordinates (which is what I would like) but with a parameter that I don’t quite understand how it works: it seems to be 1 pixel (min.) shift and this more or less applies to the X axis but for the Y axis the math doesn’t add up. In essence, it is not possible to determine the position of the image exactly (the exact number of pixels shifted). Moreover it moves the image starting from its current position, while the RA option places the initial position of the image on coordinates XY 0,0 (rightly!) allowing a convenient calculation of the pixels to be shifted to obtain the desired position

  • I don’t quite understand how the scaling is expressed…seems a sort of strange multiplier but the essence is that it makes the work of setting a precise aspect ratio unnecessarily laborious, furthermore I need to set not only the aspect ratio but the exact number of pixels of the displayed area (X,Y)

  • almost forgot to say that the worst thing is even after you have managed with a lot of patience to obtain more or less the desired result, when you change the core (or even just the game!) you get a completely different result, so in the end the work done becomes useless (at least for my purpose) and the shader as it is is unusable. RA option produce the same result (view) regardless of core and loaded game.

I don’t want to bother with percentages and multipliers but simply set direct and clear measurements: pixels

There you go:

  #include "shared/cGraphics.fxh"

/*
    [Shader Options]
*/

uniform float _Angle <
    ui_label = "Rotation Angle";
    ui_type = "drag";
> = 0.0;

uniform float2 _Translate <
    ui_label = "Translation";
    ui_type = "drag";
> = 0.0;

uniform float2 _Scale <
    ui_label = "Scaling";
    ui_type = "drag";
> = 1.0;

/*
    [Vertex Shaders]
*/

VS2PS_Quad VS_Matrix(APP2VS Input)
{
    // Calculate the shader's HPos and Tex0
    // We modify the Tex0's output afterward
    VS2PS_Quad Output = VS_Quad(Input);

    float RotationAngle = radians(_Angle);

    float2x2 RotationMatrix = float2x2
    (
    	cos(RotationAngle), -sin(RotationAngle), // Row 1
    	sin(RotationAngle), cos(RotationAngle) // Row 2
    );

    float3x3 TranslationMatrix = float3x3
    (
    	1.0, 0.0, 0.0, // Row 1
    	0.0, 1.0, 0.0, // Row 2
    	_Translate.x, _Translate.y, 1.0 // Row 3
    );
    
    float2x2 ScalingMatrix = float2x2
    (
    	_Scale.x, 0.0, // Row 1
    	0.0, _Scale.y // Row 2
    );

    // Scale TexCoord from [0,1] to [-1,1]
    Output.Tex0 = Output.Tex0 * 2.0 - 1.0;

    // Do transformations here
	Output.Tex0 = mul(Output.Tex0, RotationMatrix);
	Output.Tex0 = mul(float3(Output.Tex0, 1.0), TranslationMatrix).xy;
	Output.Tex0 = mul(Output.Tex0, ScalingMatrix);

    // Scale TexCoord from [-1,1] to [0,1]
    Output.Tex0 = Output.Tex0 * 0.5 + 0.5;

    return Output;
}

/*
    [Pixel Shaders]
*/

float4 PS_Matrix(VS2PS_Quad Input) : SV_TARGET0
{
    return tex2D(CShade_SampleColorTex, Input.Tex0);
}

technique CShade_Transform
{
    pass
    {
        SRGBWriteEnable = WRITE_SRGB;

        VertexShader = VS_Matrix;
        PixelShader = PS_Matrix;
    }
}

I posted the shader as requested: so? Anyone who has an idea of how to modify it according to the criteria I explained? Any opinion will be very appreciated :slightly_smiling_face: