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

Improved Alpha channel and Transparency for exporting JSON material #185

Merged
merged 7 commits into from
Nov 9, 2023

Conversation

knn217
Copy link
Contributor

@knn217 knn217 commented Nov 7, 2023

_Images plugged into "Principled BSDF" 's Alpha will combine with Images at BaseColor as the alpha channel (Since Ogre use 1 image for both color and alpha).

_More options for texture's BlendBlock, controlled by Blender's 3 Blend modes:

  • Alpha Clip = just Blend Type: REPLACE
  • Alpha Blend = a BlendBlock with custom setting, very transparent
  • Alpha Hashed = a BlendBlock with custom setting but less transparent than Alpha Blend

_There was also plan for supporting other texture nodes aside from image, but I couldn't find a way to get the node's color matrices

Edit: The image texture needs to be plugged in the "Value" input a "map range" node and then connect "Result" to the Alpha channel (like how metallic and roughness texture is plugged in through a "separate colore" node).
This is so that "Map range" 's "To Max" value can be used to modify the Transparency strength, which is determined by ["Transparency"]["value"] in the .material.json file.

Here's what my setup look like for combining Base Color texture and Alpha texture:
image

And here are the results for the 3 Blend mode setting:
*Alpha Clip
image
*Alpha Blend
image
*Alpha Hashed
image

Alpha Blend is very hard to see, but is definitely there

  • Also note that these Blend modes just decide the "style" of Blending, not the Transparent strength even if they look like they do. The Transparent strength is decided by the "To Max" value of "Map range node". These 3 modes also output the same combined texture.

_Images plugged into "Principled BSDF" 's Alpha will combine with Images at BaseColor as the alpha channel (Since Ogre use 1 image for both color and alpha).

_More options for texture's BlendBlock, controlled by Blender's 3 Blend modes:
* Alpha clip = just Blend Type: REPLACE
* Alpha Blend = a BlendBlock with custom setting, very transparent
* Alpha Hashed =  a BlendBlock with custom setting but less transparent than Alpha Blend

_There was plan for supporting other texture nodes aside from image, but I couldn't find a way to get the node's color matrices
@paroj paroj requested a review from sercero November 7, 2023 13:15
some changes in prepare_texture affected the JSON config for metalness and roughness's texture paths
Users now have another option to plug metalness and roughness textures into the corresponding channels, aside from using the same texture and separate RGB
@paroj
Copy link
Member

paroj commented Nov 8, 2023

Here's what my setup look like for combining Base Color texture and Alpha texture: image

I dont think there is much value for supporting a separate alpha texture. We should rather assume that the alpha channel of the base texture is used, if present.

@paroj
Copy link
Member

paroj commented Nov 8, 2023

* Alpha Clip = just Blend Type: REPLACE

* Alpha Blend = a BlendBlock with custom setting, very transparent

* Alpha Hashed =  a BlendBlock with custom setting but less transparent than Alpha Blend

this does not make sense. Alpha clip should map to alpha_rejection or whatever it is called in ogre next.

Alpha Hashed must be equal to Alpha Blend.

@knn217
Copy link
Contributor Author

knn217 commented Nov 8, 2023

Here's what my setup look like for combining Base Color texture and Alpha texture: image

I dont think there is much value for supporting a separate alpha texture. We should rather assume that the alpha channel of the base texture is used, if present.

Yes, the code also support this!
If you plugged the Alpha channel of Base Color texture into Map Range, it will also work:
image

The "Map Range" node is required since the code uses this to determine ["Transparency"]["value"], this was originally determined by the alpha channel's default value of Principled BSDF, but it is overwritten if plugged in so I changed this to "Map Range" so that the effects are more in sync between Blender and Ogre.

@knn217
Copy link
Contributor Author

knn217 commented Nov 9, 2023

* Alpha Clip = just Blend Type: REPLACE

* Alpha Blend = a BlendBlock with custom setting, very transparent

* Alpha Hashed =  a BlendBlock with custom setting but less transparent than Alpha Blend

this does not make sense. Alpha clip should map to alpha_rejection or whatever it is called in ogre next.

Alpha Hashed must be equal to Alpha Blend.

Yes, I think it is "alpha_test" in Ogre-next.
You are right about Alpha clip, it actually doesn't need a BlendBlock, I just need to set "Transparency" mode to "None" but I was copy pasting that code section since it have the same effect, but yeah this might confuse the user, I'll change it back.

About Alpha Hashed, I also thought its basically the same as Alpha Blend, so I made it have a different Blend type to make use of this slot. I can change it back to be the same as Alpha Blend tho.

…AQUE

_BLEND and HASHED generate the ssame settings now
_CLIP only enable "alpha_test"
_OPAQUE doesn't have alpha_test or transparency
diffuse value is a vector3
…alue

_If you plugged in an Alpha texture, but Principled BSDF's "Base Color" is not plugged in, a new diffuse image will be exported, with color channels from "Base color" values and Alpha channel from the alpha texture.

_The new image will only have as many details as your Alpha texture, so it should be used on stuff with detailed Alphas but simple color channels - like hair cards

_Quick fix: change the condition of combining diffuse texture and alpha texture (from different file names to different paths)
@knn217
Copy link
Contributor Author

knn217 commented Nov 9, 2023

I also added in a feature that can combine alpha texture with "base color" value if there's no diffuse texture, so a setup like this:

image

will give you this:

image

The combined texture can be detailed (depends on the Alpha texture) but didn't look very good, so I combined the effects from metallic, roughness and normals. Here's what it looks like without these effects:

image

This is a convenient way to create assets for users since all you really need is an image to use as Alpha texture, which doesn't even need the alpha channel since black/white image can use the color channel instead. So all the user need is 1 image, like so:

image

@paroj
Copy link
Member

paroj commented Nov 9, 2023

sorry for not being clear previously: I think that we explicitly should not handle the cases that you are currently implementing, particularly:

I also added in a feature that can combine alpha texture with "base color" value if there's no diffuse texture, so a setup like this:

and

The "Map Range" node is required since the code uses this to determine ["Transparency"]["value"]

this complicates code that needs to be maintained moving forward and is only specific to one usecase. This should rather be offloaded to the user before the exporter is run.

Also note, that imagick presence is optional so you cannot rely on being able to use it for fixing things. The export should succeed even without imagick.

@paroj paroj self-requested a review November 9, 2023 15:24
io_ogre/ogre/material.py Outdated Show resolved Hide resolved
io_ogre/ogre/materialv2json.py Outdated Show resolved Hide resolved
io_ogre/ogre/materialv2json.py Outdated Show resolved Hide resolved
@knn217
Copy link
Contributor Author

knn217 commented Nov 9, 2023

OK, so only remove the alpha texture code right?

The remaining utils are:
_Blendblocks types support
_Standalone metallic and roughness texture support
@knn217
Copy link
Contributor Author

knn217 commented Nov 9, 2023

Changes were applied, please check to see if I missed anything.

@paroj paroj merged commit 86e4ecc into OGRECave:master Nov 9, 2023
1 check passed
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.

2 participants