sp614x / optifine

1.79k stars 418 forks source link

[Shader API] How do I get world coordinates of an object (in GLSL code)? #6786

Open sleirsgoevy opened 2 years ago

sleirsgoevy commented 2 years ago

For the blocks themselves, gl_Vertex contains the world coordinates directly, gl_ModelViewMatrix translates them into player-relative coordinates, and gl_ProjectionMatrix translates them into the OpenGL coordinates.

For entities however, gl_Vertex is relative to the entity model, and gl_ModelViewMatrix translates it straight into player-relative coordinates. It also seems to be impossible to reconstruct the world coordinates from those, as the player's yaw/pitch are not exported to shaders.

Please make some feature to get vertices' world coordinates from shader code.

fayer3 commented 2 years ago

use gbufferModelViewInverse * gl_ModelViewMatrix * gl_Vertex to get player space (centered at the player) if you want world space add cameraPosition if you have further questions you can ask them in the shaderLABS discord https://discord.gg/RpzWN9S

sleirsgoevy commented 2 years ago

Thanks for the solution, will check if it actually works.

And does that mean that to get actual yaw/pitch I have to do trigonometry on the inverse matrix coefficients?

fayer3 commented 2 years ago

And does that mean that to get actual yaw/pitch I have to do trigonometry on the inverse matrix coefficients?

no idea, never have done that.