Help with shader box-max.cg

Hi!!! first sorry ym english

I addapt this shader “box-max.cg” , to scale the neogeo pocket games from 160x152 to 320x152, my screen resolution is 640x240

if i mix this shader with a PNG overlay, i can get the game in middle of screen, and custom borders, and still have progressive in my CRT

The problem is that this shader only work in OpenGL, but i need to use Direct3D 9

In D3D9, the shader dont work, and dont do any scaling

Any ideas? im doing something wrong? if not… someone can addapt to D3D?

Thanks a lot

/*
   Author: Themaister
   License: Public domain
*/

struct input
{
   float2 video_size;
   float2 texture_size;
   float2 output_size;
   float  frame_count;
   float  frame_direction;
   float frame_rotation;
};

float min(float2 x)
{
   if (x.x > x.y)
      return x.y;
   else
      return x.x;
}

void main_vertex
(
   float4 position : POSITION,
   out float4 oPosition : POSITION,
   uniform float4x4 modelViewProj,

   float4 color : COLOR,
   out float4 oColor : COLOR,

   float2 tex : TEXCOORD,
   out float2 oTex : TEXCOORD,

   uniform input IN
)
{
   oPosition = mul(modelViewProj, position);
   oColor = color;
   
   float2 box_scale = floor(IN.output_size / IN.video_size);
   box_scale = float2(min(box_scale*2), min(box_scale));
   


   float2 scale = (IN.output_size / IN.video_size) / box_scale;
   float2 middle = 0.5 * IN.video_size / IN.texture_size;
   float2 diff = tex.xy - middle;
   oTex = middle + diff * scale;
}

float4 main_fragment (float2 tex : TEXCOORD, uniform sampler2D s0 : TEXUNIT0) : COLOR
{
   return tex2D(s0, tex);
}



Can you just force integer scaling from the video settings menu to get the same effect?

With integer scaling, I can get a 320x240 centered screen no less, and without, i can do a centered 320x152, but the screen get small, and with any option, i lost borders

The good side of this shader, is that just cenetered the image in a box, but without scaling whole screen, and i can use a png for background

Thanks

If your overlay cfg file includes a line: overlay0_full_screen = true then you should be able to get a border with integer scale enabled, but perhaps I’m misunderstanding the issue.

This screenshot was taken with only integer scaling and an overlay, no shaders (er… there’s a shader on it, just not a scaling one):

No hunterk, you not misunderstanding the issue… you understand it perfect, and your solution is right, THANK YOU

overlay0_full_screen = true did the trick :slight_smile:

Now i dont need to use any shader, and everything works perfect, like i need

Thanks again for your good help and your time

Awesome :smiley:

I’m glad that got you fixed up!