I am using sampler2DShadow + shadow2DProj() to perform shadow mapping. However, I need to fetch the distance value contained in that depth map texture, but shadow2DProj() only returns whether I'm in shadow or not.
As the sampler comparison function has been configured as GL_COMPARE_R_TO_TEXTURE, using texture2D() from GLSL to fetch the distance stored in the depth map won't work.
So, do I need to use two different shaders (and thus two different passes) and disabling the GL_COMPARE_R_TO_TEXTURE in the second pass to fetch the contents of the depth map?
Do I need to replicate the depth map configuring it with different GL_COMPARE_R_TO_TEXTURE models and assigning them to different texture units to be able to use both shadow2D() and texture2D() ?
In practice is there a huge difference in performance using texture2D() instead of shadow2D()?
Thank you in advance.