Screen position in pixel shader


#1

I’m trying to write a shader with logic dependent on fragment’s screen position.

Basically that’s what gl_Position is from vertex shader, which is usually a result of matrix_viewProjection * matrix_model * vertex_position.

In pixel shader screen position is expected to be calculated with something like this:
vec4 pos = matrix_viewProjection * vec4 (vPositionW, 1.0);

But that doesn’t produce the intended result. When testing it with code like this:
vec3 emission = pos.x > 0.5 ? vec3 (0.0, 1.0, 0.0) : vec3 (1.0, 0.0, 0.0);

I get colors split not in screen space, but with some virtual plane of sort:
bug

Here is the project:
https://playcanvas.com/editor/scene/779340

How do I achieve perfect screen space shader logic?