yzslab / gaussian-splatting-lightning

A 3D Gaussian Splatting framework with various derived algorithms and an interactive web viewer
Other
457 stars 38 forks source link

Rotation of Spherical harmonics data #26

Closed hardikdava closed 4 months ago

hardikdava commented 5 months ago

Great work @yzslab , is it possible to add support for rotation and scalling of spherical harmonics data with the transformation of 3dgs model?

yzslab commented 5 months ago

Sorry that not planning yet. Contributions are welcomed!

On Mon, Apr 29, 2024 at 14:39 Hardik Dava @.***> wrote:

Great work @yzslab https://github.com/yzslab , is it possible to add support for rotation and scalling of spherical harmonics data with the transformation of 3dgs model?

— Reply to this email directly, view it on GitHub https://github.com/yzslab/gaussian-splatting-lightning/issues/26, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEJZCPLHIMYFPESFZ3OFEDY7XTLFAVCNFSM6AAAAABG5XGE6WVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI3DQMRUGM2DGOI . You are receiving this because you were mentioned.Message ID: @.***>

yzslab commented 5 months ago

Rotate the first extra degree has been implemented. The calculation of the higher SH degrees are far more tedious, so only one degree currently.

hardikdava commented 4 months ago

@yzslab thanks a lot. Can you give me the direction how to achieve the rotation for 3 sh degree? I would like to try it out.

yzslab commented 4 months ago

@yzslab thanks a lot. Can you give me the direction how to achieve the rotation for 3 sh degree? I would like to try it out.

Already provided in the code comment: https://github.com/yzslab/gaussian-splatting-lightning/blob/098b0b7bb808f1127294d7248d0ee76452742be0/utils/gaussian_transform.py#L86-L96

hardikdava commented 4 months ago

@yzslab It's not possible to rotate higher degree of spherical harmonics without knowing camera matrix. Am I right?

P.S. I want to do it offline. Trained model -> rotate -> visualize

yzslab commented 4 months ago

@yzslab It's not possible to rotate higher degree of spherical harmonics without knowing camera matrix. Am I right?

P.S. I want to do it offline. Trained model -> rotate -> visualize

The camera matrix isn't required. The R is the matrix that rotate your scene.

hardikdava commented 4 months ago

@yzslab I tried your implementation and it's working perfectly for 1st degree. But still missing implementation for 2nd and higher degree.

yzslab commented 4 months ago

@yzslab I tried your implementation and it's working perfect for 1st degree. But still missing implementation for 2nd and higher degree.

The calculation of the higher SH degrees are far more tedious. But rotating the view direction vectors are more easier: R.T @ (means3D' - camera_center). I think you can modifying the rasterizer to get correct colors by this way.

yzslab commented 4 months ago

@yzslab I tried your implementation and it's working perfect for 1st degree. But still missing implementation for 2nd and higher degree.

The calculation of the higher SH degrees are far more tedious. But rotating the view direction vectors are more easier: R.T @ (means3D' - camera_center). I think you can modifying the rasterizer to get correct colors by this way.

Just need to modify the rasterizer to accept a rotation matrix R as a parameter, and apply it when calculating colors.

hardikdava commented 4 months ago

@yzslab I think there is an error with your formula. It will create dim mismatch error. Can you recheck it once?

yzslab commented 4 months ago

@yzslab I think there is an error with your formula. It will create dim mismatch error. Can you recheck it once?

Would you mind providing more details?

yzslab commented 4 months ago

@yzslab I think there is an error with your formula. It will create dim mismatch error. Can you recheck it once?

Would you mind providing more details?

The means3D' - camera_center is a column vector.

hardikdava commented 4 months ago

@yzslab I am using modified version of gsplat rasterizer. I have rotated first degree as you implemented. I modified the color computation as you suggested and I am getting following error:

    viewdirs = camera.camera_to_worlds.detach()[..., :3, :3].T @ (means_crop.detach() - camera.camera_to_worlds.detach()[..., :3, 3])
RuntimeError: mat1 and mat2 shapes cannot be multiplied (9x1 and 82214x3)
yzslab commented 4 months ago

@yzslab I am using modified version of gsplat rasterizer. I have rotated first degree as you implemented. I modified the color computation as you suggested and I am getting following error:

    viewdirs = camera.camera_to_worlds.detach()[..., :3, :3].T @ (means_crop.detach() - camera.camera_to_worlds.detach()[..., :3, 3])
RuntimeError: mat1 and mat2 shapes cannot be multiplied (9x1 and 82214x3)

The means3D and camera_center in Python code are row vectors. So the correct calculation in code should be:

(means3D` - camera_center) @ R

NOTE:

yzslab commented 4 months ago

have rotated first degree

Besides, you should not rotate SHs and the view direction together. Rotation should be applied either for SHs or view directions.

hardikdava commented 4 months ago

@yzslab You are right. I got it working for applying Rotation directly to view direction. How can I achieve rotation without modifying the rasterizer? Is it possible?

yzslab commented 4 months ago

How can I achieve rotation without modifying the rasterizer? Is it possible?

I think rotating the SHs is the only way to achieve this.

hardikdava commented 4 months ago

@yzslab can you send me references on how can rotate SH for higher degree if you have it?

yzslab commented 4 months ago

@yzslab can you send me references on how can rotate SH for higher degree if you have it?

I think the theory is the same as the 1st extra degree. Someone mentioned that it could be done with Wigner D-matrix: https://github.com/graphdeco-inria/gaussian-splatting/issues/176#issuecomment-1711876624 Here is an implementation: https://github.com/graphdeco-inria/gaussian-splatting/issues/176#issuecomment-2060513169 I don't know whether it is correct. The results of the 1st extra degree are differ to the calculation here.

hardikdava commented 4 months ago

@yzslab I tried the mentioned method. But It's not yielding good result.

yzslab commented 4 months ago

@yzslab I tried the mentioned method. But It's not yielding good result.

Thanks to MstXy, this problem has been solved now: https://github.com/graphdeco-inria/gaussian-splatting/issues/176#issuecomment-2147223570 I validated that the latest one is correct.

hardikdava commented 4 months ago

@yzslab Thanks for the support. I have also verified the result.