vsg-dev / VulkanSceneGraph

Vulkan & C++17 based Scene Graph Project
http://www.vulkanscenegraph.org
MIT License
1.32k stars 212 forks source link

using model matrix or view matrix in the shader #692

Closed MasonAlice closed 1 year ago

MasonAlice commented 1 year ago

I figured out that vsg use push constant to update projection matrix and modelview matrix. how can I just use model or view matrix in the shader.

robertosfield commented 1 year ago

If you can avoid using view and model matrices in shaders you can avoid precision problems that occur when the view matrix values become large. The VulkanSceneGraph is designed to handle really large to tiny worlds where ability handle precision issues are critical so use modelview matrix are the default.

Sadly lots of example shaders out there use separate model and view matrices are introduce this precision problem, then when developers trying to scale there worlds from toy examples into large real world scales they are hit by an intractable precision problems.

While it's technically possible to pass separate model and view matrices directly yourself, I would strongly recommend thinking about how to refactor shaders so they can work with modelview matrices that the VSG provides out of the box. We can help make suggestions, but wihtout knowing what might be in your shaders and what type of scene you are trying to render it's too open ended attempt.

robertosfield commented 1 year ago

I'm moving this "Issue" to the Discussion pages where it belongs as it's not a bug or build problem with the VSG itself.