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

Ogre Next (aka v2) JSON material support #178

Merged
merged 2 commits into from
May 7, 2023

Conversation

jamieson
Copy link
Contributor

@jamieson jamieson commented May 6, 2023

Basic support for a metallic workflow producing OGRE Next JSON materials. Closes issue #148

Changes and dependencies outside of the new materialsv2json module:

  • Depends on material.gather_metallic_roughness_texture() from PR Export Metal-Roughness maps #172, any change to that function will need to test JSON material export.
  • Implements channel separation in util.image_magick(). Done with a kwarg, so should have no impact.
  • Adds the config parameter MATERIALS_V2JSON and checks it inside scene.dot_scene().

JSON Materials features:

  • Sets the diffuse, emissive, metalness, roughness, specular (colour), transparency, alpha_test, two_sided and workflow as required
  • Leaves default the blendblock, macroblock, sampler, shadow_const_bias, brdf, detail_diffuse[x], detail_normal[x], detail_weight[x], fresnel, receive_shadows, reflection
    See the notes in MaterialsJSON.md for the rational.

Metalness texture fetching expects a single image with the metal texture in the Blue channel and the roughness texture in the Green channel. The channels are expected to have been split via a 'Separate RGB' node before passing to the Principled BSDF. This is in line with the glTF standard setup. Doing something else will have sub-par results or simply fail. It can't handle more complicated node setups.

This code will always attempt an export but it will have poor results if given a specular workflow material.

 - Added ogre.materialsv2json module with dot_materialsv2json() with
   same usage as ogre.material.dot_materials()
 - Added config option MATERIALS_V2JSON to switch to v2 materials
 - Support for a metallic workflow only via PrincipledBSDFWrapper
   - Sets the diffuse, emissive, metalness, roughness, specular,
     transparency, alpha_test, two_sided and workflow as required
   - Leaves default the blendblock, macroblock, sampler,
     shadow_const_bias, brdf, detail_diffuse[x], detail_normal[x],
     detail_weight[x], fresnel, receive_shadows, reflection

 - Uses material.gather_metallic_roughness_texture()
 - Implements channel separation in util.image_magick()
@sercero
Copy link
Collaborator

sercero commented May 7, 2023

How does this work?

From what I have seen it seems that you check the option "MATERIALS_V2JSON" and now blender2ogre exports the OgreV2 material .json as well as a OgreV1 material definition.

@paroj do you think that perhaps it would be better if it was a combo list selection?

Something like material_output: ogrev1 / ogrev2json?

Because it seems to me that if you are using Ogrev2 you're not using v1 and vice versa.

@jamieson
Copy link
Contributor Author

jamieson commented May 7, 2023

The config variable stops the v1 generation at scene.py:196. If MATERIALS_V2JSON is True it will call dot_materialsv2json() instead of dot_materials().

I defer to you two about whether it should be a picklist or not, I have no preference and would be willing to write the change.

I also see the CI is failing. I have only tested this with Blender 3.5. It looks like emission_strength_texture was added to node_shader_utils in this commit from Sep 2020 which appears to be first included in blender v2.91.0.

Is there a desire to ensure compatibility with a specific version of Blender? If so is there a preferred way of handling features not usable in older versions?

@sercero
Copy link
Collaborator

sercero commented May 7, 2023

I don't know what is the official support list, but I think that at least the following versions should be supported:

  • blender-2.83.x (LTS+EOL)
  • blender-2.93.x (LTS)
  • blender-3.3.x (LTS)
    (all the LTS versions so far)

So, there should be a check to see if emission_strength_texture feature is present or not and act accordingly.

I also think that the config variable to export the material version should be a picker.

Let's see what @paroj thinks of this...

io_ogre/config.py Outdated Show resolved Hide resolved
@paroj
Copy link
Member

paroj commented May 7, 2023

Is there a desire to ensure compatibility with a specific version of Blender?

CI must not fail. Therefore blender 2.82 must work for now.

If so is there a preferred way of handling features not usable in older versions?

Not use the feature - otherwise it is untested which equals to broken after some time

Per review:
 - Check detect_converter_type() instead of config param
 - Remove MATERIALS_V2JSON config param
 - Remove emission_strength_texture support (Blender 2.9+ only)
 - Update README and MaterialsJSON.md to reflect changes
@jamieson
Copy link
Contributor Author

jamieson commented May 7, 2023

Updated branch as per review, using detect_converter_type() and removed emission_strength_texture usage.

@paroj paroj merged commit fc22b3e into OGRECave:master May 7, 2023
1 check passed
@paroj
Copy link
Member

paroj commented May 7, 2023

thanks

@jamieson jamieson deleted the pr/v2jsonmaterials branch May 7, 2023 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants