viromedia / virocore

ViroCore cross-platform AR/VR renderer
MIT License
365 stars 108 forks source link

Need Help with Loading PBR Model and Materials #52

Closed jacobvyn closed 6 years ago

jacobvyn commented 6 years ago

I am trying to render simple obj model in with PBR asset.zip

another assets https://poly.google.com/view/5vbJ5vildOq PBR enabled:

 RendererConfiguration config = new RendererConfiguration();
        config.setShadowsEnabled(true);
        config.setBloomEnabled(true);
        config.setHDREnabled(true);
        config.setPBREnabled(true);

        mViroView = new ViroViewARCore(this, this, config);

When model is loaded :

   @Override
    public void onObject3DLoaded(Object3D object3D, Object3D.Type type) {
        Log.e("Stand", "onObject3DLoaded");
        final List<Material> materials = object3D.getMaterials();
        for (Material material : materials) {
            material.setMetalness(0.6f);
            material.setRoughness(0.1f);
            material.setLightingModel(Material.LightingModel.PHYSICALLY_BASED);
            material.setTransparencyMode(Material.TransparencyMode.RGB_ZERO);
        }
    }

Environment:

   Texture environment = Texture.loadRadianceHDRTexture(Helper.getUri(ASSET_PATH));
        mArScene.setLightingEnvironment(environment);
        mArScene.setBackgroundTexture(environment);

Result: 1521215122671 Something wrong with material? Any help will be appreciated!

dthian commented 6 years ago

Hi @jacobwyn, do you have a screen shot on how the stand model from the asset.zip should look like?

I've attempted to loaded the model in an online viewer for verification and it looks similar to the screen shot you have posted - a mostly transparent table.

screen shot 2018-03-16 at 11 55 16 am

Thanks!

dthian commented 6 years ago

Here is another screen shot from the side - this looks very very similar to your screen shot above - is this expected?

screen shot 2018-03-16 at 11 58 34 am
jacobvyn commented 6 years ago

The stand model should be transparent, the material simulates a glass texture.

dthian commented 6 years ago

Thanks @jacobwyn, can you please provide a screenshot of your original model that you expect to see.

dthian commented 6 years ago

Can you also please explain what you meant by '50% of the cases'? By 50%, do you mean 50% of the times you have loaded this particular model, or did you mean instead 50% of the total number of models that you have? Note that: I am able to successfully load the piano asset provided above from the poly link: https://poly.google.com/view/5vbJ5vildOq. If you are experiencing failures, please provide other OBJs that are failing for you so that we can verify.

Finally, your stand Model with a transparent glass texture will require refractive shader support. Currently ViroCore does not support rendering refractive materials at the moment, i've filed story on the backlog for this feature request.

jacobvyn commented 6 years ago

Hi @dthian When I created this issue I hadn't prepared enough and have hurried with the result, so PBR works well with OBJ models... mainly ... but not with those two stand and piano ... let me explain in details. I'm trying to achieve such behaviour for glass material https://www.dropbox.com/s/kslrrdkzvaumzdg/204266800858148.mp4?dl=0 1521451277565 marked spots are reflected lights source from image I have loaded so

   Texture environment = Texture.loadRadianceHDRTexture(Helper.getUri(ASSET_PATH));
        mArScene.setLightingEnvironment(environment);
        mArScene.setBackgroundTexture(environment);

So when I say PBR, I mean this behaviour of material, sorry for previously confusing explanation and statements

dthian commented 6 years ago

Thanks @jacobwyn, the reflected light sources from the lighting environment only works with PBR materials (as it requires Metal and Roughness properties to perform lighting and reflection calculations). We've taken a look at the Lamborghini model and it looks like it doesn't have any PBR materials (and thus, doesn't reflect HDR textures) - can you please confirm if this is true?

There is a slight mitigation that you can do - you can try manually applying a pbr metal and roughness property to every material on the car. Thus you can specifically target the body of the car. Here's some pseudo code below. Note however: that due to the nature of your non-pbr car model, there is only one car material that encompasses the entire body of the car, called "body3". Because of this, both the car body, and as well as the the seats / windows / etc will all be shiny.

@Override
            public void onObject3DLoaded(final Object3D object, final Object3D.Type type) {
                final List<Material> materials = object.getMaterials();
                for (Material material : materials) {
                    if (material.getName().equalsIgnoreCase("Body3")){
                        material.setMetalness(0.1f);
                        material.setRoughness(0.2f);
                        material.setLightingModel(Material.LightingModel.PHYSICALLY_BASED);
                    } else {
                       // Wheels
                        material.setMetalness(0.1f);
                        material.setRoughness(0.9f);
                        material.setLightingModel(Material.LightingModel.PHYSICALLY_BASED);
                    }
                }
                object.setIgnoreEventHandling(true);
            }

Screen shot with manually modified 3D car with a custom lighting environment set.

device-2018-03-19-113133

jacobvyn commented 6 years ago

Hi @dthian

We've taken a look at the Lamborghini model and it looks like it doesn't have any PBR materials (and thus, doesn't reflect HDR textures) - can you please confirm if this is true?

PBR works good if I set manually all needed BPR staff on cars materials in onObject3DLoaded method. I don't have such problem with car's body.

The question is how to force custom model in my case the stands material to reflect light sources from the lighting environment. Previously you said that there is some troubles with shader for glass material(sorry for oversimplification), and we need to avoid of using glass, picture below shows the same stand but without glass material 1521707981435 It does not reflect lights from the lighting environment, but it DOES reflect SpotLights that I added to the scene manually 1521708363438

Therefore I have 2 question:

  1. Why setting manually PBR (Metal and Roughness properties, enabling lighting mode PHYSICALLY_BASED) stuff does not work always? In one view we see, that it works for car but does not work for stand (stand model stand.zip must say, I manually found steel.jpeg in web and applied to model in mtl file)
  2. After updating to 1.4.1 I have some problems with onClick listener, I did not get click events from models (from coloured buttons, see last pic.... all objects on stand are separated models ). I have suspicions it caused due to bounding box of each separate model
  3. Is not the question but rather a favour - could you be so kind to share the cars model with black glass material? :)
jacobvyn commented 6 years ago

Hey guys, still waiting for you advice.

VikAdvani commented 6 years ago

Hi @jacobwyn, We are looking into #2 now. Our designer is looking at 1 and 3. Will get back to you shortly.

saboteur111 commented 6 years ago

Hi @jacobwyn 1)I took a look and I believe the reason why the lambo displays in a more desirable manner is because its UV's have been laid out optimally. The stand was not laid out optimally: screen shot 2018-03-27 at 10 25 09 am You could see some principles of UV unwrapping here: http://www.republicofcode.com/tutorials/3ds/unwrap_uvw_mapping/

I unwrapped and laid out the UV's in an optimal layout. You can see the difference here: screen shot 2018-03-27 at 11 26 28 am

Also, if you can, it's a good idea to use a PBR app like Substance Painter to create PBR materials to easily create textures and get more expected results. I attached a PBR-enabled stand for you: stand_pbr.zip screen shot 2018-03-27 at 11 42 30 am

Here's the lambo w/ black glass as well: aventador_opaque.fbx.zip

Hope this helps!

achuvm commented 6 years ago

@jacobwyn,

Adding a click listener on your provided stand.obj model works, however, we don't have the models for your buttons.

Your suspicion about the bounding box of the stand potentially interfering with the click detection on the buttons is probably correct. You can try using setIngoreEventHandling to true in order to disable event handling on your stand in the hopes that the buttons then don't get their events eaten by the stand. Your buttons look small enough that they shouldn't interfere with each other.

Let us know if this works for you. If not, feel free to send us your positioning code + assets and we can dive in deeper.

jacobvyn commented 6 years ago

Thank you very much guys!!! I noticed that I am loosing ability to get click events if I put stand closer than 2.5 m to car, setting setIngoreEventHandling on a car - unfortunately does not help (just put stand near car and try to click on stand)... we need to pay attention on bounding box of surroundings models while propagating such events... in my case is not vital. About cars glass material - noticed that it does not reflect light sources from the lighting environment - I set all needed staff mentioned in the start of this thread, a question is pretty simple -why ? Once again - thank you for the help!

dthian commented 6 years ago

About cars glass material - noticed that it does not reflect light sources from the lighting environment - I set all needed staff mentioned in the start of this thread, a question is pretty simple -why?

Hey @jacobwyn, again as previously mentioned above, how reflective an object is depends on the PBR values that you have set for that material. As shown in my example above, I've set the metal and roughness of the car's body metal, so as to achieve the shiny reflective look. As such, you would have to do the same for the material that you have set for your car's windows (should be named with a string containing "Glass").

I noticed that I am loosing ability to get click events if I put stand closer than 2.5 m to car, setting setIgnoreEventHandling on a car - unfortunately does not help (just put stand near car and try to click on stand).

Unfortunately I am not able to reproduce this. I've tried setting a click listener on the stand with the car placed less than 2.5 meters behind it, and am able to still click the stand. Could you share your java code where you've placed, scaled and rotated the stand + car?

One possibility, is that this sounds like the ignoreEventHandling bug that is fixed in the latest ViroCore 1.5 build (just released today). Previously, only the root node of the 3D model would have the ignoreHandling property applied, and as such the child nodes of the 3D object would still catch events (bug). However, this should be fixed in the latest release. To upgrade, please follow our upgrade guidance here. Do let us know if you have any problems, or still see the issue after the upgrade.

Finally, I've also attempted to reproduce the bug by placing the pbr stand very near the car (closer than 2.5m) as shown below, but am unable to reproduce the bug (I am able to click on the stand). I've demonstrated this by setting a click listener on the stand, that when clicked, rotates the car (as shown below). Also as seen, the windows of the car is reflecting the set environment light as desired as well.

ezgif-5-18e064d959

jacobvyn commented 6 years ago

Hi @dthian , thanks for response! Bug with click events near big models is really fixed in version 1.5, thanks! Still cannot force cars glass material to reflect lighting environment, I have set PBR values - unfortunately it doesn't help

saboteur111 commented 6 years ago

Hi @jacobwyn. I think the easiest solution is tho convert the textures to PBR formatting rather than setting the values through code, so I did the conversion for you. Here's the FBX w/ textures embedded. Run it through the VRX tool and ignore the .DDS files it exports. You should be able to gain transparency through the windows and headlights as well with this format: screen shot 2018-04-04 at 5 40 50 pm

aventador_pbr.fbx.zip

jacobvyn commented 6 years ago

Hi @saboteur111 This model does not rendered, model is always transparent ... which is not surprising because there is a glass' shader bug ...see above Anyway, thanks for efforts!

saboteur111 commented 6 years ago

hey @jacobwyn. It seems something happened when I exported to FBX from Maya. I re-exported the model and it should work now. I included the VRX file for you as well. lambo.zip

jacobvyn commented 6 years ago

Hi @saboteur111, this model is rendered very well! Thanks a lot! But need to report one more bug, after launching 5-10 times app (launch, put some 3d models, press back, repeat few times) I am getting next error

04-06 10:42:57.072 16549-17330 E/Adreno-GSL: <gsl_memory_alloc_pure:2202>: GSL MEM ERROR: kgsl_sharedmem_alloc ioctl failed.
04-06 10:42:57.328 16549-17330 W/Adreno-GSL: <sharedmem_gpuobj_alloc:2318>: sharedmem_gpumem_alloc: mmap failed errno 12 Out of memory

And app is stuck, can reproduce it even in ARRetail I have a suspicion that it is somehow connected with bug 4 from here https://github.com/viromedia/virocore/issues/69 My app https://github.com/jacobwyn/augmentedReality

dthian commented 6 years ago

Hi @jacobwyn,

Thanks for reaching out, I've filed a separate github bug to track the crash at: https://github.com/viromedia/virocore/issues/73. Closing this issue as your model has been successfully rendered. Feel free to re-open if you have any additional issues.