Gamestudio Links
Zorro Links
Newest Posts
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 962 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 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