Recovering distance from distanceBased depth map

Software: Away3D 4.x

Jonathan, Newbie
Posted: 24 April 2014 05:04 PM   Total Posts: 7

As the title says I would like to recover the original distance from a distance based depth map. I understand that the code used to generate the map is located in distanceMapPass.as but I have a hard time finding the code necessary to revert from the tex component back to the original distance.

Anyone can help with this?

code = “dp3 ft2.z, v0.xyz, v0.xyz \n” +
  “mul ft0, fc0, ft2.z \n” +
  “frc ft0, ft0   \n” +
  “mul ft1, ft0.yzww, fc1 \n”;

if (_alphaThreshold > 0) {
  code += “tex ft3, v1, fs0 <2d,”+filter+”,”+wrap+”>\n” +
  “sub ft3.w, ft3.w, fc2.x\n” +
  “kil ft3.w\n”;
}

  code += “sub oc, ft0, ft1 \n”;

   

Jonathan, Newbie
Posted: 25 April 2014 04:22 AM   Total Posts: 7   [ # 1 ]

Nevermind, a simple dot product is all it took.

   

Avatar
theMightyAtom, Sr. Member
Posted: 25 April 2014 08:21 AM   Total Posts: 669   [ # 2 ]

I thought the pixel value was the distance?

   

gonchar, Newbie
Posted: 25 April 2014 05:01 PM   Total Posts: 7   [ # 3 ]

Please check out Filter3DHDepthOfFFieldTask class

override protected function getFragmentCode():String
  {
   
var code:String;
   var 
numSamples:uint 1;
   
   
// sample depth, unpack & get blur amount (offset point + step size)
   
code =
    
"tex ft0, v0, fs1 <2d, nearest> \n" +
    
"dp4 ft1.z, ft0, fc3    \n" +
    
"sub ft1.z, ft1.z, fc1.z   \n" // d = d - f
    
"rcp ft1.z, ft1.z   \n" // screenZ = -n*f/(d-f)
    
"mul ft1.z, fc1.w, ft1.z   \n" // screenZ = -n*f/(d-f)
    
"sub ft1.z, ft1.z, fc0.w   \n" // screenZ - dist
    
"mul ft1.z, ft1.z, fc2.x   \n" // (screenZ - dist)/range
    
    
"abs ft1.z, ft1.z     \n" // abs(screenZ - dist)/range
    
"sat ft1.z, ft1.z     \n" // sat(abs(screenZ - dist)/range)
    
"mul ft6.xy, ft1.z, fc0.xy   \n";
   
   
code += "mov ft0, v0 \n" +
    
"sub ft0.x, ft0.x, ft6.x\n" +
    
"tex ft1, ft0, fs0 <2d,linear,clamp>\n";
   
   for (var 
x:Number _realStepSize<= _maxBlur+= _realStepSize{
    code 
+= "add ft0.x, ft0.x, ft6.y \n" +
     
"tex ft2, ft0, fs0 <2d,linear,clamp>\n" +
     
"add ft1, ft1, ft2 \n";
    
    ++
numSamples;
   
}
   
   code 
+= "mul oc, ft1, fc0.z";
   
   
_data[2] 1/numSamples;
   
   return 
code;
  
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X