Page 1 of 1
convert values stored in texDepth back to actual distance
Posted: 08 Jan 2013, 06:04
by lampuiho
Just wondering how since there is no documentation about the formula used to convert distance to color values.
Re: convert values stored in texDepth back to actual distanc
Posted: 08 Jan 2013, 12:44
by ENBSeries
There is no math for that, because camera near and far planes distances are not available in shader. The only thing you may use is convert data to linear space like this
result=depth/(max(1.0-depth, 0.000000001));
Re: convert values stored in texDepth back to actual distanc
Posted: 25 Jan 2013, 09:49
by lampuiho
ENBSeries wrote:There is no math for that, because camera near and far planes distances are not available in shader. The only thing you may use is convert data to linear space like this
result=depth/(max(1.0-depth, 0.000000001));
So the raw data is converted to the range of 0.0 to 1.0 with the formula f(x) = x/(x+c) (c is the curve) instead of clamping it to a maximum and minimum value (of b and a in the following formula) and linearly mapped to 0 to 1 like (x-a)/(b-a)?
Re: convert values stored in texDepth back to actual distanc
Posted: 26 Jan 2013, 16:26
by ENBSeries
Depth is in range 0..1, but linear result is not. I never thought how to map to 0..1 range without forcing limits.
Re: convert values stored in texDepth back to actual distanc
Posted: 31 Jan 2013, 04:26
by lampuiho
lim x->inf (x/(x+c)) should be equal to 1, where c is a constant, and it crosses the origin as well
so it does map any distance to the range 0 to 1.
And the inverse is c*x/(1-x) which is what you gave me. ( I didn't think of this before you gave me the formula so thanks a lot for that
)
A higher value of c should map higher input value better to that range because then the slope is not as steep and there is less rounding errors for higher distances.
Is there a way to debug with the enb plugin? I want to know what sort of values are going in and out.
Thanks.
Re: convert values stored in texDepth back to actual distanc
Posted: 31 Jan 2013, 07:08
by ENBSeries
Depth passed to external shaders are already in range 0..1, but non linear.
Debugging not available, almost don't have in debug build of the mod, don't need it actually.