MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.42k stars 313 forks source link

WGLMakie cannot draw Mesh with Float64 normals. #3804

Open jacobleft opened 6 months ago

jacobleft commented 6 months ago

Construct the mesh of a cube using GeometryBasics.jl, explicitly computing the normals, and draw it with WGLMakie

using WGLMakie
import GeometryBasics

rect = Rect(Vec(0.0, 0.0, 0.0 ), Vec(1.0, 1.0, 1.0))
rect_faces = decompose(GeometryBasics.TriangleFace{Int}, rect)
rect_vertices = decompose(Point{3, Float64}, rect)
T = Float64 # Bug
## T = Float32 # OK
nls = GeometryBasics.normals(rect_vertices,rect_faces;normaltype=Vec{3,T})
rect_mesh = GeometryBasics.Mesh(GeometryBasics.meta(rect_vertices,normals=nls),rect_faces)

mesh(rect_mesh)

With T = Float64, the above example code gives the following errors:

┌ Warning: Error in Javascript: THREE.WebGLProgram: Shader Error No error - VALIDATE_STATUS false
│ 
│ Program Info Log:
│ Vertex shader is not compiled.
│ 
│ VERTEX
│ 
│ ERROR: 0:16: 'dvec3' : Illegal use of reserved word
│ ERROR: 0:16: 'dvec3' : syntax error
│ 
│ 
│   11: precision mediump usampler2D;
│   12: precision mediump usampler3D;
│   13: // Instance inputs: 
│   14: in vec3 position;
│   15: vec3 get_position(){return position;}
│ > 16: in dvec3 normals;
│   17: dvec3 get_normals(){return normals;}
│   18: 
│   19: // Uniforms: 
│   20: uniform uint object_id;
│   21: uint get_object_id(){return object_id;}
│   22: uniform vec3 specular;
│ 
│ Fragment log:
│ Vertex log:
│ ERROR: 0:16: 'dvec3' : Illegal use of reserved word
│ ERROR: 0:16: 'dvec3' : syntax error
│ 
│ )
└ @ Bonito ~/.julia/packages/Bonito/AipWx/src/serialization/protocol.jl:41
An exception was thrown in JS: Error: WebGL error: Invalid operation
Additional message: error initializing scene
Stack trace:
    Error: WebGL error: Invalid operation
        at eval (eval at <anonymous> (http://localhost:9385/assets/288836015a0b0c5d9685d3d72ba7c90f399308c9-Bonito.bundled.js:3563:27), <anonymous>:12:19)
┌ Warning: error while processing received msg
│   exception =
│    Three object should be ready after init, but isn't - connection interrupted? Session: Session{Bonito.SubConnection}:
│      id: 3b3ca2ec-d242-4da5-9ff0-ff51f5305dce
│      parent: Bonito.Session{Bonito.WebSocketConnection}
│      connection: open
│      isready: true
│      asset_server: Bonito.ChildAssetServer
│      queued messages: 0
│    , initialized: false
└ @ Bonito ~/.julia/packages/Bonito/AipWx/src/connection/websocket.jl:103

If T=Float32 or using GLMakie, the example code runs fine without errors.

ffreyer commented 6 months ago

This should get fixed in 0.21 with lines like https://github.com/MakieOrg/Makie.jl/blob/b7060f6fe349bd89df96111e19d1883aeebfb3c1/src/conversions.jl#L549 Ref #3650

ffreyer commented 5 months ago

This still errors so at least one conversion paths is not converting the normals. Should be fairly easy to fix by checking which ones get called and adding the decompose(Vec3f, n)