NormandErwan / ArucoUnity

Bring augmented reality to Unity by tracking Aruco markers in real time.
https://normanderwan.github.io/ArucoUnity/
BSD 3-Clause "New" or "Revised" License
205 stars 38 forks source link

Use shaders for image undistortion #5

Open NormandErwan opened 6 years ago

NormandErwan commented 6 years ago

Instead of using the slow remap function on CPU, it would be better to undistort the camera image with a shader on GPU as Steptoe did with its AR-Rift : http://willsteptoe.com/post/67401705548/ar-rift-aligning-tracking-and-video-spaces-part for pinhole cameras

To shaders are needed : one for pinhole undistortion, and one for omnidir undistortion.

MatthewHallberg commented 3 years ago

I never got a chance to actually implement this correctly into the repo and make a pull request but I did make a shader for this which seemed to increase performance by a lot. This is only the omnidir one but using this one as a guide the pinhole one should be pretty straightforward. Just leaving this here in case it helps someone. https://github.com/MatthewHallberg/WalmartJarvis/blob/main/Assets/Shaders/UnDistort.shader

MatthewHallberg commented 3 years ago

Sorry forgot something, I was getting the inverse of the rectified cam matrices before passing it into the shader: https://github.com/MatthewHallberg/WalmartJarvis/blob/main/Assets/Scripts/Undistort.cs and the shader also uses this remap function: https://github.com/MatthewHallberg/WalmartJarvis/blob/main/Assets/Shaders/Interpolation.cginc Also, thank you for this amazing repo!