Sign in to follow this  
TMC

Scaling antes shading

Recommended Posts

TMC    122
My video texture is sampled by a couple of pixel shaders resulting in the output video image. Input texture, texture render targets and back buffer are all of the same size and it works fine. Now I need to scale the image. So e.g. my input 800x400 needs to be displayed in 1200x600. However, the image must be stretched (scaled) BEFORE the shaders are executed. The shaders output must not be disturbed (scaled). Suppose the shader makes every even pixel (x-axis) black. The original shows an image with black bars every even pixel. In the scaled image however, the bars or gaps are 2 pixels wide (but not always). This looks like the scaling is done after the shading. I started by just maping the texture coords to a bigger vertex buffer. Then I tried creating render target textures and back buffer of the required destination size. Now I'm just lost. How do I scale the image before the pixel shaders ?

Share this post


Link to post
Share on other sites
eq    654
The pixel shader process one OUTPUT pixel so the scaling is done berfore the shader.
I think your problem comes from how you determine what is even and odd lines.
Are you using a texture for that?
Make sure that the texture coordinates for that "mask" texture matches the OUTPUT positions. My guess is that you're simply using a 800x400 texture as a mask. Since this is getting scaled also you're getting into trouble.
Either use a 1200x600 texture for the mask, or even better use some pixel-shader magic to determine if a line is even or odd.
For instance:
* Pass the row (as 0 - 600) to the pixel shader.
* Multiply this value by 0.5 (could be done before passing it to the shader).
* Use the frc instructions to get into [0, 1] interval. (Now < 0.5 means even else odd).
* Use the cmp instruction to get a mask.


Share this post


Link to post
Share on other sites
TMC    122
Pffff, I can't believe I fell for that...
I think my calculation is about the same:
if ( ( ( (PixelPosition.x * TextureWidth ) + 0.5) %2) < 1.0 ) -> even

Problem was I was uploading the TextureWidth of the original texture.
Thanx eq for pointing me in the right direction.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this