Calculate gl_FragCoord in NME?

Hey all, I want to experiment with some screen space effects, but I’m struggling to get an equivalent of gl_FragCoord in NME.

Is there some some a way to calculate a pixel’s screen position from the camera, and view projection?

Basically I want to do something like this:
https://cyos.babylonjs.com/#BNND2X

The closest I got was something like this:

https://nme.babylonjs.com/#WS8303

but you can see with the cylinder and torus that the geometry is messing with the intended effect, I think we’re using the world coordinate of the fragment with respect to the view and projection rather than where the pixel would be on screen. Hmm…

You have todivide by uniform coord w to get correct projection. The output is not the same range as gl_FragCoord tho :slight_smile:

https://nme.babylonjs.com/#WS8303#2

2 Likes

the calculation of gl_fragCoord is the one side road that calculated before fragment shader
if you wanna calculate that from world+view+projectcion+camera direction you need some more parameter like camera target and camera fov and camera up vector after that you have just some result like matrix it is useless becasue it is easier you add that in NME and use standard shaders
** for someone wanna add that in NME dont forget gl_FragCoord.z is Depth too in modern browsers

1 Like

why don’t we just expose that in the Known System Values or what ever we called it?

1 Like

https://www.babylonjs-playground.com/#0M27Y4#13

2 Likes