Sign in to follow this  
Endemoniada

Post Processing Coordinate System

Recommended Posts

Endemoniada    430
Hi guys,

I'm rendering my scene to a texture, then applying that texture to a screen-sized quad that's rendered onto the back buffer. What coordinate system should I be using ? Ultimately I'd like to do full-screen blurring but I'm taking it one step at a time.

Thanks.

Share this post


Link to post
Share on other sites
ryan20fun    2635
[quote name='Endemoniada' timestamp='1306129942' post='4814466']
Hi guys,

I'm rendering my scene to a texture, then applying that texture to a screen-sized quad that's rendered onto the back buffer. What coordinate system should I be using ? Ultimately I'd like to do full-screen blurring but I'm taking it one step at a time.

Thanks.
[/quote]

i dont quite get what you mean, but i think i kinda know.
why not just draw it as a texture ?
useing ID3DXSPRITE ?

Share this post


Link to post
Share on other sites
Hodgman    51221
[quote name='Endemoniada' timestamp='1306129942' post='4814466']I'm rendering my scene to a texture, then applying that texture to a screen-sized quad that's rendered onto the back buffer. What coordinate system should I be using ? Ultimately I'd like to do full-screen blurring but I'm taking it one step at a time.[/quote]It depends on your current projection matrix.

Or, assuming your vertex shader doesn't use a projection matrix, or your projection matrix is set to identity, then you're working in Normalized Device Coordinates (x/y range from -1 to +1).

Which graphics API are you using? In D3D9, you've also got to [url="http://msdn.microsoft.com/en-us/library/bb219690(v=vs.85).aspx"]nudge your vertices slightly[/url] in order to get texels and pixels to line up correctly.

Share this post


Link to post
Share on other sites
Endemoniada    430
Hi, I should have explained this better.

I'm using D3D9. I wrote a quick shader that does no transform in the vertex shader, so I set my quad to (-1,1) coordinates. I read that I should nudge the quad by (-0.5) but it doesn't make sense with the coordinate system I'm using, so should I be using screen coordinates instead, or maybe some other way ?

Thanks.

Share this post


Link to post
Share on other sites
Texus    248
I think the easiest way is working with sprites. (ryan20fun already mentioned these).

You can make the sprite with D3DXCreateSprite.

Finally you can draw the texture with the following method.
This allows you to scale, rotate and clip the image. You can even alphablend by using this code.

[code]
D3DXMATRIX mat;
D3DXVECTOR2 spriteCentre = D3DXVECTOR2(Width/2.0f, Width/2.0f); //You will rotate the image over this coordinate. Usually the center of the image
D3DXVECTOR2 scaling(1.0f, 1.0f); //You can scale the image with changing these numbers
D3DXVECTOR2 trans=D3DXVECTOR2(0.0f, 0.0f); //Draw the image on position (0, 0) on the backbuffer (uppur left cornder of the backbuffer)

RECT rect;
rect.left = 0; rect.top = 0; //Do not clip the image on the upper side or the left side
rect.right = Width; rect.bottom = Height; //Draw the whole image, no clipping on the right side or at the bottom

float Rotation = 0.0f; //Rotation in radians
D3DXMatrixTransformation2D(&mat, NULL, 0.0f, &scaling, &spriteCentre, Rotation, &trans);

Sprite->SetTransform(&mat);

COLORREF Color = 0xffffffff; //ARGB color. White -> draw normal. Changing the color to 0x80ffffff will alphablend the image 50%.
Sprite->Draw(mTexture, &rect, NULL, NULL, Color);
[/code]
I think this is the easiest way to draw an image in D3D9.
- You don't even need shaders or a projection matrix for this.
- The screen coordinates are easy: (0, 0) is the upper left corner, (400, 300) would be the center on a backbuffer with width 800 and height 600.
- If you draw the image to a position, then the upper left corner of the image will be at that position.

If you use this method then don't forget to call Sprite->Begin(D3DXSPRITE_ALPHABLEND) before drawing and Sprite->End() after drawing.

Share this post


Link to post
Share on other sites
Maddius    146
The way I do sprites in my application is to create a standard plane or quad that is drawn without a view matrix, this means that the geometry of the quad will appear to be attached to the front of the 'lense'. You can then apply textures to this geometry in the standard manner, I built up the class so that the corners of the quad are projected onto the viewport so that you can get their screen space positions relative to the current resolution. This allows you to place and scale the sprites relative to the current resolution, but this all depends on how much you are going to be using screen alighned sprites in your program, if the quick option is all you need then I suppose the premade sprite classes should suffice.

Hope that helps,

Maddius.

Share this post


Link to post
Share on other sites
Hodgman    51221
The above sprite methods are over-kill for a simple full-screen quad, and also aren't taking the half-pixel offset into account (meaning you end up with slightly blurred results).[quote name='Endemoniada' timestamp='1306167070' post='4814628']I'm using D3D9. I wrote a quick shader that does no transform in the vertex shader, so I set my quad to (-1,1) coordinates. I read that I should nudge the quad by (-0.5) but it doesn't make sense with the coordinate system I'm using, so should I be using screen coordinates instead, or maybe some other way ?[/quote]You need to nudge by half a pixel, so you need to find out how big a pixel is in your coordinate system.
If the screen ranges from -1 to 1 horizontally, then it's 2 units wide. If your post-processing texture is 1280 pixels wide, then 1 pixel == 0.0015625 units (2/1280).

So instead of drawing from -1 to 1, you want to draw from -1.00078125 to + 0.99921875 ([i]i.e. [/i][font="Courier New"]-1-(2/1280)*0.5 to 1-(2/1280)*0.5[/font]).
Then do the same calculations vertically.

Obviously change these depending on the resolution of the textures that you're blitting.

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