Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surface normals not properly transformed by markersize scaling. #3702

Closed
kbarros opened this issue Mar 14, 2024 · 0 comments · Fixed by #3722
Closed

Surface normals not properly transformed by markersize scaling. #3702

kbarros opened this issue Mar 14, 2024 · 0 comments · Fixed by #3722
Labels
bug CairoMakie This relates to CairoMakie, the vector backend for Makie based on Cairo. GLMakie This relates to GLMakie.jl, the OpenGL backend for Makie. good first issue WGLMakie This relates to WGLMakie.jl, the Web-based WebGL backend for Makie.

Comments

@kbarros
Copy link
Contributor

kbarros commented Mar 14, 2024

To draw an ellipsoid, one can start with a sphere mesh and apply an anisotropic scaling via markersize:

using GLMakie
pts = Point3f[[0,0,0], [1,0,0]]
markersize = Vec3f[[0.5, 0.2, 0.5], [0.5, 0.2, 0.5]]
rotations = [qrotation(Vec3f(1,0,0), 0), qrotation(Vec3f(1,1,0), π/4)]
meshscatter(pts; markersize, rotations, color=:yellow)
image

The shading is wrong because the surface normals have not been properly transformed. @ffreyer pointed out on Slack that only one line of the GLMakie vertex shader should be changed:

This line should read vec3 N = normals / s;. That is, it should include an element-wise division by the scaling factors. With this fix, I get the correct visual result:

image

Presumably a similar change is needed for WGLMakie and CairoMakie, on these lines:

frag_normal = N;

ns = map(n -> normalize(normalmatrix * n), meshnormals)

Below is a derivation explaining why its appropriate to divide by the scale factors.

image

@kbarros kbarros added the bug label Mar 14, 2024
@ffreyer ffreyer added good first issue GLMakie This relates to GLMakie.jl, the OpenGL backend for Makie. WGLMakie This relates to WGLMakie.jl, the Web-based WebGL backend for Makie. CairoMakie This relates to CairoMakie, the vector backend for Makie based on Cairo. labels Mar 14, 2024
singularitti added a commit to singularitti/Makie.jl that referenced this issue Mar 20, 2024
SimonDanisch pushed a commit that referenced this issue Mar 21, 2024
* Fix transforming surface normals

Fixes #3702

* Fix missing rotation in `normalmatrix`

See #3722 (comment)

* Add reference test "Ellipsoid marker sizes" in ReferenceTests/src/tests/examples3d.jl

* Add a record in CHANGELOG.md

* change 1:3 to Vec(1,2,3)

* tweak changelog entry

---------

Co-authored-by: ffreyer <frederic481994@hotmail.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug CairoMakie This relates to CairoMakie, the vector backend for Makie based on Cairo. GLMakie This relates to GLMakie.jl, the OpenGL backend for Makie. good first issue WGLMakie This relates to WGLMakie.jl, the Web-based WebGL backend for Makie.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants