HLSL - shade pixel based on distance from camera

How in a shader would I map the luminosity of a pixel to the distance from the ‘camera’?

cheers

distance of each pixel that is

actually scratch that.

make it distance from a certain point, in world coordinates

:)

in the pixelshader write:

float dist = distance(yourPosInput, In.PixelPos) * someMappingInput;

where you have to put the world pos into the vs2ps struct in the vertex shader as another texture coordinate channel named PixelPos (or whatever you like call to it).

thank you!

and you can map that between Nearplane and Farplane.

CamDistance.zip (2.9 kB)