bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.2k stars 3.57k forks source link

Support for phong shading and lambert material #5425

Open heavyrain266 opened 2 years ago

heavyrain266 commented 2 years ago

What problem does this solve or what need does it fill?

Allow plugin authors to properly implement scene loaders for formats such as Autodesk's FBX or Pixar's USD. Other engines such as Unreal or Unity implements both for comformant asset support.

Of course each plugin can implement their own support but then we get collision if user will try to use both formats handled by different plugins in the same game.

What solution would you like?

Implement both, phong shading and lambert material.

What alternative(s) have you considered?

Not supporting both, but then each game or plugin which requires either phong or lambert, will have to fiddle around with custom implementation or just add another layer of PBR material directly from Bevy which definitely is not efficient nor perfomant method.

Additional context

As we talked with @robswain#0382 on discord, he said that it's good idea to have support in bevy directly. (see "bevy_fbx development" thread in #general on bevy discord)

IceSentry commented 2 years ago

Do you have some documentation of exactly what you would need that other engines have? A quick google search doesn't give me anything for unity.

IceSentry commented 2 years ago

Would it be something like this https://threejs.org/docs/#api/en/materials/MeshLambertMaterial?

IceSentry commented 2 years ago

I'm not sure why this is needed to load models. Phong shading and lambert material just seem like a more primitive model, but as far as I know you could map a lambertian material to a pbr material. The actual shader it ends up using doesn't seem related to the model loading. Using a phong based shader to render it seems more like an optimization for the purpose of having a simpler shading model.

heavyrain266 commented 2 years ago

I'm not sure why this is needed to load models. Phong shading and lambert material just seem like a more primitive model, but as far as I know you could map a lambertian material to a pbr material. The actual shader it ends up using doesn't seem related to the model loading. Using a phong based shader to render it seems more like an optimization for the purpose of having a simpler shading model.

It is surely related to loading scenes, for example FBX have hardcoded lambert material and phong for shading which has it's own PBR settings which are different from bevy... you cannot "convert" it, or swap material because FBX doesn't allow you to do so... USD also seems to use lambert and phong but also Pixar have it's own PBR but that is easy to map into bevy.

heavyrain266 commented 2 years ago

Do you have some documentation of exactly what you would need that other engines have? A quick google search doesn't give me anything for unity.

Problem with lambert is that, there are no docs other than propiertary SDK from Autodesk, some fbx2gltf converters and Unreal source code. Basically lambert is matte material but also have some own specific PBR settings.

Engines support lambert and phong, only to properly support loading complex scenes from Autodesk, Houdini and Pixar's tools.

IceSentry commented 2 years ago

I still don't get why a format is mandating the shading model. A scene is just a group of models and materials (and cameras/lights/etc) where a material is just input values for a shader right? Why would FBX mandates using a phong shader? What's the issue with rendering an FBX scene with pbr?

Also, I don't get the proprietary part. I get that the code to convert the contents of the file to something usable is proprietary, but clearly you are already able to read some of that data. Actually rendering that data isn't done in the file format, that's the job of the renderer.

Also, could you specify what you mean exactly when you say lambert and phong. I assumed you mean Lambertian reflectance and Phong shading where Lambertian reflectance is essentially the diffuse part of a phong shader, but the way you are describing it it sounds like it's a completely separate thing. Do you just want a material that is purely diffuse and another material using phong shading?

I feel like I'm missing something pretty fundamental here.

heavyrain266 commented 2 years ago

It's not just information which you read and interprete like with glTF, every data is hardcoded and imported in-game, must be looking like your render.

FBX is very specific:

As of we have talked on discord, you cannot convert that data to PBR, instead you have to support lambert material and it's own PBR format.

USD format is even worse because it's zip file with multiple other ASCII/Binary formats but support regular PBR, Pixar's PBR and Lambert PBR.

jtoy commented 8 months ago

+1 for openUSD support!