DepthWithColor-D3D.fx question RRS feed

  • Question

  • Hi,

    I am looking at the code in DepthWithColor-D3D.fx and don't understand the following convertion

        // remove player index information and convert to meters
        float realDepth = depth / 4000.0;

    Shouldn't it be 

        float realDepth = (depth >> 3) / 4000.0;

    After I change this line the projected image becomes a lot smaller. Not sure how to compensate for this. Is it possible to get some more additional explanation how the scaling factors and coordinates are computed?

    Thanks a lot!

    Friday, July 27, 2012 1:02 PM

All replies

  • My copy of this file has a division by 8000.0. Are you sure your copy says 4000.0?

    float realDepth = depth / 8000.0;

    Since right-shift by 3 is the same as division by 8, this is effectively the same as:

    float realDepth = (depth >> 3) / 1000.0;

    ...but it is accomplished in one operation, which should be faster.

    K4W Dev

    Monday, July 30, 2012 11:07 PM
  • +1 on John's response, and generally it is preferred to do floating point math over integer math in shaders for performance reasons.

    Monday, July 30, 2012 11:13 PM