Sign in to follow this  
Sebastien_

size of a pixel

Recommended Posts

Hello all, I have one strange question about size of a pixel use in shader to cacl offset of filter, or half pixel offset (D3D). At firts I was thinking like everybody that size of a pixel was: float2 invScreenDim(1 / RenderTargetSizeX, 1 / RenderTargetSizeY) Then I can use this value in my shader for case like the following: (from http://diaryofagraphicsprogrammer.blogspot.com/2008/09/calculating-screen-space-texture.html) Float4 vPos = float4(0.5 * (float2(p.x + p.w, p.w – p.y) + p.w * invScreenDim.xy), pos.zw) Here "p.w * invScreenDim.xy * 0.5" allow to apply the half pixel offset. However, when looking at some 3D Engine, I found few which define size of a pixel as (2 / RenderTargetSizeX, 2 / RenderTargetSizeY). For sample in Nebula3 engine (http://flohofwoe.blogspot.com/): frameposteffect.cc (...) // compute a half pixel offset SizeT w = this->renderTarget->GetWidth(); SizeT h = this->renderTarget->GetHeight(); Math::float4 pixelSize(2.0f / float(w), 2.0f / float(h), 0.0f, 0.0f); Math::float4 halfPixelSize = pixelSize * 0.5f; (...) and in a shader: float3 sampleOffsetWeights[13] = { { -1.5, 0.5, 0.024882 }, { -0.5, -0.5, 0.067638 }, (...) float4 psMain(const vsInOut psIn) : COLOR { float4 sample = float4(0.0, 0.0, 0.0, 0.0); int i; for (i = 0; i < 13; i++) { sample += sampleOffsetWeights[i].z * tex2D(SourceBufferSampler, psIn.uv0 + sampleOffsetWeights[i].xy * pixelSize.xy); } return sample; } So, is someone can explain me why a pixel is (2 / RenderTargetSize), or in which case it must be 2 ? Cause Nebula3 is not the only case where I see this. Thanks for any explanation. Seb

Share this post


Link to post
Share on other sites
After some though, I still be disagree with something.

For the following code:
Float4 vPos = float4(0.5 * (float2(p.x + p.w, p.w – p.y) + p.w * invScreenDim.xy), pos.zw)

I am OK to set pixel size as 2 / RenderTarget.
In fact we are in screen coordinate [-1..1] transform to [0..w] then we divide by W in pixel shader to get [0..1] which allow to get texture coordinate.
So the value of invScreenDim.xy on W. Engel blog are wrong and on Gamedev thread too (http://www.gamedev.net/community/forums/topic.asp?topic_id=506573) ?

but for the nebula3 case, where we just sample in a texture without conversion between screen coordinate and texture coordinate (which have same size as a screen) which is [0..1], I still don't understand. If we have a texture of 1280x720, then 1280 x 2 / RenderTargetSizeX => 2

I think I miss something.
Any help.

Thanks

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