Absolute world position... what exactly is it anyway?

Hello community,

I have been jumpping into shader maths and have been doing a bunch of vector maths to achive a variety of different shader effects.

I have been using the world position node as a starting point for most of my shader based vector maths. This is just because it seems to always to work when i decide i need an interactive mask from point a to point b

However, i dont really know what it does and thus makes it hard for me to creatively come up with ways to use it or debug why something isnt working.

my understanding that is is the location of the pixel in world space. My question is

  1. Which pixel? Is it a single pixel? An array of pixels that the shader is taking up on screen? What is it?

  2. How can pixels have a world space position are they not 2 dimensional and relative to the screen?

any infro would be great!!!

The shader is run for each individual pixel on the screen (for practical purposes), so the answer is “the pixel currently being processed by the shader”

By using the depth value of the surface that is being drawn into that specific pixel. Imaging that you are shooting a ray from the camera into the scene for each pixel: the absolute world position is the point hit by that ray.

3 Likes

How does the GPU know know the depth, and along what camera vector/angle the depth is being calculated for.

Very short overview of how a triangle gets drawn to the screen:

  • Each vertex is processed by a vertex shader, which calculates the final position on the screen (including depth) based on the camera matrices and object position/rotation/scale. Other per-vertex information like normals and texture coordinates are also output here.
  • The GPU calculates the interpolated values for position, normal, vertex color and texture coodinates for each pixel covered by the triangle and feeds this into the pixel shader. That’s where the depth information comes from.
4 Likes

Thank you for your very quick reply guys.

Let me make sure i have this right.

I work best with visual stimulus and context to these theories. So i’ve taken part of a node graph from a more complex material where i was faking the self shadowing of a volume.

  1. The absolute world position node is the world position for every visual pixel of the object that the shader is applied to (effectively the visual surface of the object).

For instance here i am taking the blue channel (Z Axis) of every single visual pixel for this cube in world position (this operation run millions of times a second). As the cube is at world 0,0,0 in the material editor and it’s origin is at the meshes centre it gives half positive z and half negative z values and looks like this.

I then subtract this from the object’s z position to localise the gradient so that even when the object moves in the world the gradient stays in the same place.

So if i were to visualise some of these vectors they would look like this. Straight lines coming from the objects centre to the visible pixels (or more simply the visible surface) of the object in world space.(Abs world position)


I am then taking the object radius. Which is the vector between an objects centre to the side of it’s bounding box ( which in the case of this cube the bounding box matches the shape) and using that to divide the abs world position and object position. To provide a fall off to the self shadowing.


Multiplying that over a colour value and lerp to white to control the amount of self shadowing gives this effect.

Are my concepts of absolute world position right? Please correct me on anything that I’ve said that may be wrong or misleading. I am defiantly not the authority on this i am just trying to give context and examples to the theories.

Hope to hear back soon :slight_smile:

5 Likes

Can anyone co sign this? Is my idea of world position right i literally just pulled this together from bits and pieces ive read on the internet

Also ive been calling it visual pixel its meant to be visible pixel my bad lol

Yes, you pretty much figured it out. It’s basically the absolute position of the surface point being currently drawn with that material. And yeah, since it’s done for every pixel, it can potentially run millions of times per second. GPUs are that crazy.

To expand on your experiment: the reason it looks fully white or fully black is because the values are in world units (so they are obviously much greater than 1.0 for positive and less than 0 for negative coordinates). When you divide it by the object radius, you created a gradient by making all surface points inside the object radius fall into values between 0 and 1.