Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (7th_zorro, Ayumi, AndrewAMD, Quad), 1,014 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How do I get the pixel's coords. #418622
02/27/13 15:09
02/27/13 15:09
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Hi, I've got a simple question:

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


POTATO-MAN saves the day! - Random
Re: How do I get the pixel's coords. [Re: Kartoffel] #418649
02/27/13 20:19
02/27/13 20:19
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
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

Re: How do I get the pixel's coords. [Re: Slin] #418654
02/27/13 21:14
02/27/13 21:14
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Thans a lot, vPos does the job:

float4 screenSpace : vPos // input semantic

float2 texSS = screenSpace.xy / vecViewPort.xy; // screenspace coordinates


POTATO-MAN saves the day! - Random
Re: How do I get the pixel's coords. [Re: Kartoffel] #418656
02/27/13 21:22
02/27/13 21:22
Joined: Mar 2006
Posts: 2,252
Hummel Offline
Expert
Hummel  Offline
Expert

Joined: Mar 2006
Posts: 2,252
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;
}


Re: How do I get the pixel's coords. [Re: Hummel] #418659
02/27/13 21:25
02/27/13 21:25
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
I just noticed some strange aliasing and found it out myself grin

Again, thank you very much!


POTATO-MAN saves the day! - Random
Re: How do I get the pixel's coords. [Re: Kartoffel] #418665
02/27/13 22:12
02/27/13 22:12
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
...and now my deferred lighting works grin


POTATO-MAN saves the day! - Random
Re: How do I get the pixel's coords. [Re: Kartoffel] #418682
02/28/13 13:41
02/28/13 13:41
Joined: Mar 2006
Posts: 2,252
Hummel Offline
Expert
Hummel  Offline
Expert

Joined: Mar 2006
Posts: 2,252
Nice! laugh

Re: How do I get the pixel's coords. [Re: Hummel] #418685
02/28/13 15:48
02/28/13 15:48
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
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?


POTATO-MAN saves the day! - Random
Re: How do I get the pixel's coords. [Re: Kartoffel] #418686
02/28/13 15:51
02/28/13 15:51
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
use the material event and a second stage
camera material renders only the scene, the second material only lights
just use ENABLE_RENDER


Visit my site: www.masterq32.de

Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1