I need to get the rotation differences between the model and the camera. convert the values to radians/degrees and pass it to the fragment shader. for that I need to decompose and the Model rotation matrix and maybe the camera view matrix as well. Cannot seem to find a way to decompose mechanism suitable within a shader.
\$\begingroup\$
\$\endgroup\$
4
-
1\$\begingroup\$ We have existing Q&A about how to decompose a matrix into its translation, rotation, and scale components, and how to decompose a rotation matrix into Euler angles. These answers use only basic math functions available in shaders, so they should port directly. What part have you had difficulty applying within your shader? \$\endgroup\$– DMGregory ♦Commented Mar 24, 2022 at 8:30
-
\$\begingroup\$ I'm looking for a glsl specific answer if its out there. I already have the code on cpu side with libraries. looking for an answer hopefully accounting for gpu cost of functions and ways to minimize 'if' checks. I will give this a try. thank you. \$\endgroup\$– Sadern AlwisCommented Mar 24, 2022 at 8:38
-
\$\begingroup\$ Sounds to me like you should profile to determine whether the cost of applying this code directly in the vertex shader is actually a bottleneck for you. If it is, hyper-optimizing it is likely to give you less performance back than just pre-computing the values you need once per model/instance CPU-side and sending them as uniforms or members of a buffer. If it isn't, it isn't. \$\endgroup\$– DMGregory ♦Commented Mar 24, 2022 at 8:44
-
\$\begingroup\$ so what i have right now is the buffer approach, the last calculation portion I shifted to gpu gave me a boost from 17fps to 70fps. in reverse thats the cost of updating the buffer atm (4k instances). im looking to increase instance count as well. actually the second link you sent me looks simpler and promising. Im gonna try port that. \$\endgroup\$– Sadern AlwisCommented Mar 24, 2022 at 8:50
Add a comment
|