cnr-isti-vclab / 3DHOP

3D Heritage Online Presenter
http://www.3dhop.net
GNU General Public License v3.0
157 stars 42 forks source link

Model illumination (normals) #13

Closed gmiguelr87 closed 5 years ago

gmiguelr87 commented 5 years ago

Hello!

I'm back here again, delighted with 3DHop! I have a problem that I don't know if I could solve it. When I see models without normal on my mobile (Huawei P10), the lighting is on the right side (external part of the 3D model). However, if I see the same model from my wife's mobile (Huawei G8), the lighting is on the opposite side. I would not like to show the normal ones, because in the models made with photogrammetry you can see too much distortions and I prefer to hide them. What can be the solution?

Thank you very much!

potenziani commented 5 years ago

Hi @gmiguelr87, in 3DHOP 4.2 we added the possibility to switch off the global lighting (see the "enableSceneLighting(state)" presenter function, or read the "camera and lighting setup" HOW TO.

Actually, if you are loading a 3D model (Ply or Nexus) without normal vectors, 3DHOP automatically switch off the global lighting, so what you are reporting is a strange issue...

Could you provide some more information about your scene setup? Are you loading a Ply or a Nexus model? Mesh or PC? With "wrong" normal vectors or without?

gmiguelr87 commented 5 years ago

Hi @potenziani,

First of all, thanks for your quick response! I'm using a mesh in nexus format, without normals (I use the --no-normals parameter when I convert from ply to nxs).

I used the new version of 3DHop. When it has normal, I see the lighting correctly, but also the defects I was talking about... if I modify the lighting, I see the main part dark again, and the part behind the model illuminated.

Something curious is that I've tried 4 mobiles, the two that look good carry GPU Mali, and the two that look bad carry GPU Adreno. I don't know if this information is of any use...

Thanks again!

potenziani commented 5 years ago

So @gmiguelr87, you are in this situation:

Now, some questions to better understand your issue with this latter case (if you could provide also some screenshots of that it would be great):

gmiguelr87 commented 5 years ago

Hi @potenziani

First of all, sorry for taking so long to respond, but I've been a little busy with other things and couldn't until now, and yes, you are right about my situation.

Regarding the questions...

  1. You get part of the model dark and part illuminated, am I right? Exactly, depending on the device I can see illuminated either the inside or the outside of the model. The correct thing is to see the external face. In the attached images you can see two Huawei mobile phones showing the same model. In the mobile phone on the right (Huawei P10 Lite) you see correctly the model, a fountain with a squirrel on top, with lighting on the outside, however, in the mobile phone on the left (Huawei GX8), you see how the lighting is shown incorrectly, on the inside. photo_2019-04-01_13-36-18

  2. Also, the parts of the model dark and illuminated change if you change device... is it right? That's right, as I define in the previous answer.

  3. Does this wrong lightning happens just on mobile devices, or also on desktop solutions? I detected it on mobile phones, but I want to tell you something. I have 3DHop mounted on a localhost (apache) and last week a friend visited me. He connected from his MacBook PRO and the models came out without lighting, on either side, but it's something I have to study calmly because I've never seen it before.

  4. Are you able to dynamically change the lighting direction with the light control tool provided in the default 3DHOP toolbar? Yes, I am able to change it using the control, but it does not modify the illuminated face.

  5. What happens when you rotate the model (the lighting stays coherent with the scene or dark/illuminated zones "rotate" with the model)? Nothing happens, the model rotates perfectly and everything works well, except that the illuminated face is still the wrong one.

  6. If you generate a Nexus model with the default conversion (so WITH the normals) and you switch off the 3DHOP scene lighting in real time with the "presenter.enableSceneLighting(false)" function, do you get the same issue in the lighting? Exactly @potenziani, we could say that absolutely everything works normally, except that the illuminated face of the model is the wrong one, as seen in the attached image on the left mobile phone.

I think I've answered all your questions. Any other doubt you have, tell me and I will send you what you need.

Thank you very much for everything. Best regards!

potenziani commented 5 years ago

Hi @gmiguelr87 , looking at the attached images it seems that your problem may be related to the boolean gl_FrontFacing variable used in the fragment shader for verifying whether a primitive is front or back facing. For some strange reason in your Huawei GX8 this variable assumes a reversed value. Because of this, the system paints in red the front/external side of your model instead of the back/internal side. We do not have other reports about this issue. Also, we didn't find anything about possible troubles concerning gl_FrontFacing and WebGL. For these reasons this strange behavior seems to be related to your specific device hardware, and not to a generic bug in 3DHOP.

Clearly, we cannot consider a viable option to add an hardware-specific fixing to the 3DHOP code. However, this doesn't mean you cannot add a specific fix to your source code if you want. Some hints for doing that:

Alternatively, you can say to 3DHOP to stop painting in red the back of your models. For doing this, you have just to add to your model instance definition the special "backfaceColor" field, setting its values to [1.0, 1.0, 1.0, 0.0]:

presenter.setScene({
    ...
    modelInstances : {
        "your_instance_id" : { 
            mesh : "your_mesh_id",
            backfaceColor : [1.0, 1.0, 1.0, 0.0]
        }
    },
    ...
});

With this setup, you will get front and back faces of your model painted in the same way.

PS: from the attached pictures it seems that your model may have not normal vectors, or your scene may have the lighting disabled (I would propend for the first option, since a model without normals matches with what you previously wrote, i.e. multiresolution model generated forcing nexus not calculating normals). This is the reason why your 3D scene is not responsive to dynamic changes in the lighting direction. However, the gl_FrontFacing issue has nothing to do with normal vectors. So, if you want, you can re-add normals to your 3D models.

PPS: if you are doing tests on MacOS systems, please update the 3DHOP code to the last DEVELOPMENT release, since we have just uploaded a new version fixing a critical issue in many MacOS devices.

gmiguelr87 commented 5 years ago

I really appreciate your response @potenziani ,

I've been trying what you told me (put backfacecolor: [1.0, 1.0, 1.0]) but the same thing keeps happening to me. Any other ideas?

Thanks again, I'm very passionate about your project!

potenziani commented 5 years ago

So, even if your instance setup include the string "backfaceColor : [1.0, 1.0, 1.0, 0.0]", you continue to have part of the model painted in red... this is very strange! Are you sure you are using the last DEV version of 3DHOP (you should get the log "3DHOP version: 4.2.8" in your browser console)? And if yes, did you try to modify the backface setup with any other values? (this is just for checking if your system responds to your scene setup customization...)

gmiguelr87 commented 5 years ago

Hi @potenziani ,

Sorry, I have several versions of 3DHop and I was using version 4.1. The instructions you gave me work perfectly, but not only for the last DEV, but also for the master branch. Sorry again for my mistake.

Thank you!!!

gmiguelr87 commented 5 years ago

I now write this comment separately in case you think it should go somewhere else.

I'm investigating the possibility of including some tool to remove parts from the model (imagine an option to remove noise from a 3D model). I have managed to select a series of points generating a polygon and "eliminate" that part of the model, but my knowledge is not very advanced and I don't know how to continue. The problem is that I don't know how to switch to SLGL language more information than a 4x4 matrix can store.

Could you guide me? Thanks again!!