I'm currently playing with geometry nodes in Blender 3.0.0. I have a plane and in Geometry nodes I first scattered some points and then using a Geometry Proximity node to measure distances to the nearest of these points and finally deforming the surface around those points (sinusoidal function) to create some "Pores". That works fine.
The problem is: I also wanted to colorize the deformed mesh according to the actual depth of those pores. Therefore I connected the distance output from the Proximity node to an output socket (also tried other values, e.g. the actual depth). Now it looks like the values received by my shader nodes are not the ones actually calculated in the Geometry node while deforming the mesh, but they seem to be calculated by a second run(?) where the mesh is already deformed. In my screenshot below, the pores should be bright yellow in the middle and turning to red with higher distances. What I see instead is that the deeper parts of each pore are also red and AFAICS that is because they are moved away from the scattered points. The problem is reduced if the pores are extremely flat (see second screenshot), but that's not a solution.
Why is it like this and how could I achieve what I am looking for (preferably without using a second non deformed copy of the same mesh just to calculate the proximity again)
What I have tried so far was e.g. to first output to a vertex group and create an attribute actually readable by the shader Attribute node only by a second Geometry modifier. But the effect stays the same.
Edited:
Corrected version using a Capture Attribute node as suggested in the accepted answer: (Additional change: I now use the actual displacement for the color, not the distance to the next scatter point)
Edited II:
If someone is interested in the results (still work in progress, but already quite close to what I was hoping for): Left without, right with pores (and some pimples) created by Geometry Nodes as described above with a few improvements (render: Eevee). I'm using the depth in my material nodes to make the skin a little bit darker and reduce subsurface scattering in those pores.