FlailingFog / KK-Blender-Porter-Pack

Plugin pack for exporting Koikatsu characters to Blender.
308 stars 29 forks source link

Automatic Color Import #31

Closed MediaMoots closed 2 years ago

MediaMoots commented 2 years ago

Here it is! The automatic system to find and convert colors from KK to blender.

22

What's new?

image Added a new step after 2a to Import, Convert and Apply colors.

How does it work?

First, it uses MC masks and Main textures exported by the PMX Exporter to find the original colors, then, it converts the colors with a LUT taken from KK, finally it sets all the Shaders to the converted colors. Then, since certain objects (Body nip, Face blush, Eyebrows, Eyelines and Hair) do not have a Main Texture generated by KK, we use a supplementary json file (color.json) to access those colors.

Note: For now, it uses LUT TimeDay for light colors, and LUT TimeNight for dark colors. Note 2: This script changes the scene color management to the following values: image

How to use?

  1. Follow the steps up to 2a
  2. Correctly set ALL MC Masks for all Shaders
  3. Setup color.json (Replace the values inside with yours)
  4. Copy color.json to the folder that PMX Exporter made (beside model.pmx)
  5. Import all the LUTs to blender and set fake user on them
  6. MAKE SURE YOU ARE PREVIEWING THE LUTS. (This is especially important, not doing so will make the script return black colors) Like so: image
  7. Click on 2b, chose the folder that PMX made (the same folder that color.json is in) and wait.
  8. All the colors should now be the same as KK, adjust intensities to taste.
  9. Profit

Known issues

Eyeline color: https://github.com/FlailingFog/KK-Blender-Shader-Pack/issues/22#issuecomment-913080208 Some accessories don't get new colors.

MediaMoots commented 2 years ago

WIP on Accessory colors

MediaMoots commented 2 years ago

@FlailingFog Fixed Accessories color import.

New workflow!

  1. Follow the steps up to 2a
  2. Correctly set ALL MC Masks for all Shaders
  3. Install the custom KK_MaterialEditor.dll plugin (it's in the plugins folder)
  4. Open the Character Creator and click on "Export Colors for KKBP" image
  5. Copy KK_Colors.json to the folder that PMX Exporter made (beside model.pmx)
  6. Change the face_blush_color value in KK_Colors.json (The first item)
  7. Import all the LUTs to blender and set fake user on them
  8. MAKE SURE YOU ARE PREVIEWING THE LUTS. (This is especially important, not doing so will make the script return black colors) Like so: image
  9. Click on 2b, chose the folder that PMX made (the same folder that KK_Colors.json is in) and wait.
  10. All the colors should now be the same as KK, adjust intensities/main textures to taste.
  11. Profit
MediaMoots commented 2 years ago

@FlailingFog Do you think this would be a better alternative to having Light/Dark colors? https://www.youtube.com/watch?v=sJTEJKQ0lYw

FlailingFog commented 2 years ago

I don't know if that'd work because it'd just multiply the color by a light grey instead of running it through the saturation process, right? I thought the point of the dark saturation filter was to run the colors through a "3D" process (each color goes through a different process) rather than a "1D" process (each color goes through the same process)

And again, this looks pretty amazing! Looking at your new workflow, does that mean you were actually able to get the skin/hair color values? I briefly tried out the first revision over the weekend but couldn't get it to work completely, so I'll try this out instead!

MediaMoots commented 2 years ago

Not really, since toon shading in unity works with a 1D Grey LUT for shadows. KK Does not have a separate lut/color for items in shadow.

Looking at your new workflow, does that mean you were actually able to get the skin/hair color values?

Yes, every single color is Imported/Converted with this workflow (except face_blush_color but you can just find the values for that and add it to the json.)

MediaMoots commented 2 years ago

I just realized, I didn't explain this very well. Haha.

Do you think this would be a better alternative to having Light/Dark colors?

What I meant was that the shading system could be changed to only need the one Light color. This idea is not related to this pr, so maybe I'll make a new issue about it.

MediaMoots commented 2 years ago

@FlailingFog Made a bugfix, please use the latest commit.

MediaMoots commented 2 years ago

@FlailingFog Also needed to change the texture import code to import the eye textures as RAW Fixed in latest commit.

FlailingFog commented 2 years ago

I tried the version with safety checks on Chika and this definitely works well! It looks like everything except the eyeline, eyebrows and nipples load correctly. I'm guessing the eyeline is loading the fade color for now and the eyebrows are because of what you noted in #22, but the nipples seem to be loading a much darker color. 255, 204, 193 in the json file is getting converted to 76, 20, 0. Your code near line 442 seems pretty airtight, so not sure what that could be.

Also, it looks like you can convert the raw view transform back to the standard view transform with a 0.455 gamma shift. It'd probably be better to work in standard because working in the raw transform prevents you from using the eyedropper tool (for example, let the code set the skin color, then load a screenshot and try to set the skin color again using the eyedropper tool and you'll see that the colors come out much darker).

Not really, since toon shading in unity works with a 1D Grey LUT for shadows. KK Does not have a separate lut/color for items in shadow.

So I guess I've been misunderstanding how it works... I thought the shadow colors were being generated automatically by the night LUT, but you're right that doesn't seem to be the case. How does it work then?

I'd like to keep the light / dark color slots because it gives you freedom to change either color if something looks off

MediaMoots commented 2 years ago

nipples seem to be loading a much darker color

Interesting, did you also get a green tint on the detail color in the body shader, or did that have no issues? Is the world color bright?

Also, it looks like you can convert the raw view transform back to the standard view transform with a 0.455 gamma shift.

Yes... ha-ha, didn't think about that, thanks :) I will do that.

So I guess I've been misunderstanding how it works... I thought the shadow colors were being generated automatically by the night LUT, but you're right that doesn't seem to be the case. How does it work then?

I think these 2 examples explains what I think goes on in KK (IMO may be wrong) https://github.com/Unity-Technologies/com.unity.toonshader#:~:text=Unity%20Toon%20Shader%20(UTS3)%20is,feature%20of%20Unity%20Toon%20Shader. https://www.youtube.com/watch?v=sJTEJKQ0lYw

Thanks again for taking the time to review this.

MediaMoots commented 2 years ago

All right, so I tried with Chika, and it didn't have the nipple issue.

What body mc are you using? Did you have the luts in view (as shown above)? Strange stuff.

MediaMoots commented 2 years ago

@FlailingFog Found an issue that is present in Chika (or in other girls like this), the colors for clothes with patterns applied can't be found and converted with this system.

So, I see two possible options here, tell ppl to remove patterns before exporting, or make a small color converter panel for users to use.

What do you think?

FlailingFog commented 2 years ago

Interesting, did you also get a green tint on the detail color in the body shader, or did that have no issues? Is the world color bright?

Oh, for some reason I thought the green tint was the default on the shader. Yeah I'm getting that. The world color didn't change from gray. It also looks like the tongue is being set as the wrong color, similar to the nipples.

What body mc are you using? Did you have the luts in view (as shown above)?

I'm using the mc from /koikatsu/abdata/chara/oo_base.unity3D (female one). I copied the setup you had above and ran the script from the panel in the 3D view portion of the setup.

I think these 2 examples explains what I think goes on in KK (IMO may be wrong)

Sorry, but I still don't get it... This looks like they're just multiplying by a color to get the result. Changing the left end of the color ramp from black to blue and doing the multiplication could get you the dark version of one color, but it doesn't seem to do the trick for all colors.

So, I see two possible options here, tell ppl to remove patterns before exporting, or make a small color converter panel for users to use.

Would body/clothes overlays cause an issue too? If so, a button that just disables them might be easier to use.

MediaMoots commented 2 years ago

@FlailingFog The latest commit changes the color management to Standard and fixes an issue with getting a green tint in detail on body

MediaMoots commented 2 years ago

Oh, for some reason I thought the green tint was the default on the shader. Yeah I'm getting that. The world color didn't change from gray. It also looks like the tongue is being set as the wrong color, similar to the nipples.

Ok, fixed the green issue. As for the tongue and nipples, well: image Taken straight after the script (just need to adjust the detail intensity) (Nipples are also normal) All looks good to me.

The world color is not scripted to change, but if you want to see the colors as they would look in KK, set the world color to white/light grey.

I'm using the mc from /koikatsu/abdata/chara/oo_base.unity3D (female one). I copied the setup you had above and ran the script from the panel in the 3D view portion of the setup.

Ok cool, that should work then.

Sorry, but I still don't get it... This looks like they're just multiplying by a color to get the result. Changing the left end of the color ramp from black to blue and doing the multiplication could get you the dark version of one color, but it doesn't seem to do the trick for all colors.

It's kind of like this, a 1D ramp is used as a brightness/saturation table. Depending on the amount of shadow, the color is darkened according to the ramp. Game engines like UE4 or Unity just need one color, it then uses the ramp decide how much any color should be darkened in shadow.

MediaMoots commented 2 years ago

Anyways, we can always just make the TimeDay lut image darker in gimp or something and use that as the dark color lut, it might not be 100% accurate to KK's "in shadow" colors but with a bit of tweaking it would be close.

So, from here, what do you feel needs to be finished/fixed before release? Things in my to-do list:

Anything else? Overlays? (I feel this one can just be dealt with by the user, it's quite easy for a person to turn off overlays in KK)

FlailingFog commented 2 years ago

All looks good to me.

I dunno, the color_to_KK function as a standalone is even returning the correct color. I guess it doesn't matter since someone is going to have to set the intensities anyway, so if they get whatever this glitch is they can just correct the color too.

It's kind of like this, a 1D ramp is used as a brightness/saturation table

So something like this? image

Anyways, we can always just make the TimeDay lut image darker in gimp or something and use that as the dark color lut

That could work too

I feel this one can just be dealt with by the user

Okay, I'll note it in the new workflow then.

Anything else?

I have nothing, thank you for putting so much into this! Let me know when you want it to be merged.

MediaMoots commented 2 years ago

I dunno, the color_to_KK function as a standalone is even returning the correct color. I guess it doesn't matter since someone is going to have to set the intensities anyway, so if they get whatever this glitch is they can just correct the color too.

oops, I assumed the colors you got were correct in the latest version. Is the glitch still present?

Thank you for taking the time to check this out too :)

MediaMoots commented 2 years ago

Possibly more like this: image

MediaMoots commented 2 years ago

Since the .blend file in the latest commit is unfinished, please let me know when it's done, so then I can make this code compatible with it (Node names, etc.). Thanks.

MediaMoots commented 2 years ago

New Plugin and code to fix an edge case where the hair has an accessory built in (eg. ribon).

FlailingFog commented 2 years ago

Is the glitch still present?

Yeah it's still happening. I forgot if I tried this latest commit so I'll try that as well. edit: Looks like I did try it

please let me know when it's done

I think I'm finished editing it for now. I added a shadow color toggle and shadow colors to the Template General shader. I'll keep the hair node names the same when I add the alphamask to the hair. I didn't know the light/dark groups weren't named so I standardized them. I might remove the "Light color detail intensity" sliders but since you don't seem to be touching those it shouldn't matter.

Also, can this new method be applied to maintex images as well? Or should the pillow code + KK.cube from before be used for that instead? Asking because I tried looping the color_to_KK function over a small image and blender blew up. The pillow code worked fine for the same image though.

Possibly more like this:

Sorry to pull a 180 on you, but now I don't think it matters too much if the dark colors are accurate to koikatsu. I added the saturation based multiplication I showed above to the Template General shader as an optional slider on the top of the dark color group, so they can be set per-material like material editor lets you do. You can get a similar look to the one you showed above by using two black shadow colors, or the exact look you showed above by disabling the shadow slider entirely and lowering the Maintex Value on the node group to like 0.3. I guess which one you want to use depends on the look you're trying to go for. Here's an example of both: b

MediaMoots commented 2 years ago

Yeah it's still happening. I forgot if I tried this latest commit so I'll try that as well. edit: Looks like I did try it

So strange, does it happen on other cards? Such as the girl from the YouTube tutorials you made?

I think I'm finished editing it for now.

Thank you, I'll work on this soon.

Also, can this new method be applied to maintex images as well?

Yes, no problem, just need to tweak the C code. I plan to overhaul this PR when I get the Plugin for KK done.

Sorry to pull a 180 on you, but now I don't think it matters too much if the dark colors are accurate to koikatsu.

Cool, so we can keep the TImeNight lut?

FlailingFog commented 2 years ago

So strange, does it happen on other cards?

I'll try it on a few more cards to make sure

edit: I tried it on these three, chika and the tempest card. It actually worked with the blonde girl card but not the others. cards.zip

Cool, so we can keep the TImeNight lut?

That or just use the TimeDay lut for both and get the dark color through one of the other two processes above.

MediaMoots commented 2 years ago

edit: I tried it on these three, chika and the tempest card. It actually worked with the blonde girl card but not the others.

Thank you, I'll try to fix this.

cards.zip

image Open up! lol

MediaMoots commented 2 years ago

Preview of the new Plugin + KKBP scripts This was produced fully automatically. image

PS: How to make the stockings semi-transparent?

MediaMoots commented 2 years ago

Superseded by PR #43