How do I get the pixel's coords.

Posted By: Kartoffel

How do I get the pixel's coords. - 02/27/13 15:09

Hi, I've got a simple question:

How do I calculate / get the screen-space coordinates of a pixel in an object shader?
Posted By: Slin

Re: How do I get the pixel's coords. - 02/27/13 20:19

screenpos = (mul(matModelWorldProj, pos).xy*0.5+0.5);

or what should also work is VPOS: http://msdn.microsoft.com/en-us/library/windows/desktop/bb509647(v=vs.85).aspx#VPOS
Posted By: Kartoffel

Re: How do I get the pixel's coords. - 02/27/13 21:14

Thans a lot, vPos does the job:

float4 screenSpace : vPos // input semantic

float2 texSS = screenSpace.xy / vecViewPort.xy; // screenspace coordinates
Posted By: Hummel

Re: How do I get the pixel's coords. - 02/27/13 21:22

Dont forget the half-pixel offset!
That's what I use:
Code:
float2 calc_ScreenPos(float4 pPos)
{
	return (float2(pPos.x,-pPos.y)/pPos.w+vecViewPort.zw)*0.5+0.5;
}

Posted By: Kartoffel

Re: How do I get the pixel's coords. - 02/27/13 21:25

I just noticed some strange aliasing and found it out myself grin

Again, thank you very much!
Posted By: Kartoffel

Re: How do I get the pixel's coords. - 02/27/13 22:12

...and now my deferred lighting works grin
Posted By: Hummel

Re: How do I get the pixel's coords. - 02/28/13 13:41

Nice! laugh
Posted By: Kartoffel

Re: How do I get the pixel's coords. - 02/28/13 15:48

But now I've got the problem that I need to render the deferred lights into a specific texture, not the camera's .bmap smirk
Does anyone know a good method to do this?
Posted By: MasterQ32

Re: How do I get the pixel's coords. - 02/28/13 15:51

use the material event and a second stage
camera material renders only the scene, the second material only lights
just use ENABLE_RENDER
© 2024 lite-C Forums