FlailingFog / KK-Blender-Porter-Pack

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

Convert to Cycles #234

Closed poisenbery closed 1 year ago

poisenbery commented 1 year ago

Simple script that I use to prep models for cycles. This is irreversible so proceed with caution.

So far, all this does is remove the outline modifier and deletes the kage faces and eyelinedown mesh [what do those even do btw???].

import bpy

#remove outline modifier
for o in bpy.context.view_layer.objects:
    for m in o.modifiers:
        if(m.name == "Outline Modifier"):
            o.modifiers.remove(m)

####fix the eyelash mesh overlap

# deselect everything and make body active object
active = bpy.context.view_layer.objects.active
for o in bpy.data.objects:
    if o.name == "Body":
        active = o
    else:
        o.select_set(0)
# define some stuff
ops = bpy.ops
obj = ops.object
mesh = ops.mesh
context = bpy.context
object = context.object
# edit mode and deselect everything
obj.mode_set(mode='EDIT')
mesh.select_all(action='DESELECT')
# delete eyeline down verts and kage faces
object.active_material_index = 6
obj.material_slot_select()
mesh.delete(type='VERT')
object.active_material_index = 5
obj.material_slot_select()
mesh.delete(type='ONLY_FACE')
mesh.select_all(action='DESELECT')

One more problem you might notice is that the eyebrows cast a shadow on the face. This can be fixed by using a light path node's "Is Shadow Ray" as the factor into a mix shader, with the 2nd shader being a transparency shader. This effectively causes the eyebrow mesh to cast an invisible shadow. Screenshot (7) Screenshot (8)

I can possibly upload some pretty simple cycles materials, but it seems that the configuration of everything is largely subjective, since most of the toon shading techniques do not apply to PBR setups. [overlaying everything and slapping it on is not the correct approach for PBR Skin].

ONE OTHER PROBLEM That you may have is if you try to apply noise bump mapping to the skin. You'll notice that it is not correctly applied to the chest area. This is largely due to the fact that the game's normal maps seem to contain 0 height information at the nipples. This can be fixed by baking your own tangent space normal map, the old fashioned way, and use the Unity Tech Demo node group to combine it with your other normals [also courtesy of me lol]. [literally the only solution I could think of].

poisenbery commented 1 year ago

WIP

Subsurface mapping, can be applied to any character [correct me if im wrong] Screenshot (764)

Subsurface happens to be the reason adding everything together and shoving it into a Principled BSDF ends up looking drastically worse than the toon shader Screenshot (661)

Sampleface.exe Screenshot (6)

You can get pretty good results with the game textures [to my surprise actually].

SP-Size commented 1 year ago

Hey, quick question!

grafik

What specifically did you do to get her abs and muscle definition to look like that? Like, is that just the "skin type" or a normal map input as the displacement?

Because I can't manage to get my koikatsu models' bodies to look as muscular as that with just the game assets and the KKBP

poisenbery commented 1 year ago

What specifically did you do to get her abs and muscle definition to look like that? Like, is that just the "skin type" or a normal map input as the displacement?

It has to do with the body line mask. There's 2 normal maps: regular normal and Normal Map Detail [NMD from hereon]. The NMD is based on the line mask you choose for the body, so if you don't have a line mask, you will not get muscle definition like this.

For SPECIFICS: https://blog.selfshadow.com/publications/blending-in-detail/

I sort of use a custom shader setup for this. I haven't posted it here yet because it's very WIP and makes irreversible changes to the groups. Screenshot (964)

The "PB Normals" group is literally the "Unity Tech Demo" from the post.

poisenbery commented 1 year ago

I have decided to upload the shader groups I have and the script to make it all work.

This does a few things, mainly based on personal preference. One of the MAJOR changes between this and the regular shader setup is how it handles eyes. It basically swaps around the role of hitomi shader and sirome shader. It also adds a new vertex group in order to handle the way eyes move/blink. The vertex group is called "Blink Eyes" and ensures that the new eye setup doesn't get squashed during blinking.

Most of the maps for the body and face are not connected to anything. They're so low resolution and have seam issues, so IMO they're unusable for this. Baking your own textures is a soft requirement because it will look like garbage if you only use the vanilla textures.

How to use: You can either replace the KK shader blend file in the addon directory, or you can drop this file into the folder of the PMX you are trying to import. Once the character is successfully imported, SELECT THE BODY OBJECT and then run the "Convert Cycles.py" script

This basically sets everything up to be "Cycles ready" but this BY NO MEANS will make the characters suddenly photorealistic. You have to do the shading and textures yourself for that. KK Shader V6.0.blend.zip

poisenbery commented 1 year ago

Random Walk subsurface scattering method causes darkening around lips. I need to update the node group so that the skin uses Christensen-Burley.

This introduces a new issue where the transparent shadows from the nose, brows, and eyeline brighten the face under those areas. I have to update the script to separate those parts into separate objects, and then drive the shape keys from the face values.

poisenbery commented 1 year ago

@FlailingFog Random walk SSS cannot be used on these models. Mouth topology causes darkening that cannot be easily fixed. Suggest changing BSDF to "Christensen-Burley" method, and having separate Cycles groups for [very least] the face and the body, so that SSS can be used without affecting all objects. Here's no SSS compared to a small amount of Random Walk SSS. The mouth is darkened. Screenshot (993) Screenshot (992)

Also, for the cycles groups to work, the nose, eyeline, and eyebrows need to be separated into their own objects. The transparent shadows cause issues with Christensen-Burley SSS, but ONLY if it's part of the same mesh. When the Nose, Eyeline, and Eyebrows are separated into their own object, the issue goes away. Screenshot (994) Screenshot (995)

That makes it all fine and dandy, but now the shape keys from the new, separated mesh have to be driven from the body mesh. At the very least, the eyeline shape keys need to be linked to each other so that you don't end up with stuff like this: Screenshot (996)

poisenbery commented 1 year ago

Documents.zip Ok here are updated scripts:

Convert Cycles.py will make the necessary changes to prevent zbuffer issues with overlapping faces. Select the body and run the script.

KK Shapekey Drivers.py REQUIRES EASYBPY by curtis holt [i was having problems setting up drivers with regular BPY]: https://github.com/curtisjamesholt/EasyBPY

This will create drivers for the nose/eyeline/eyebrow shapekeys, so that they are synced with the face.

You MIGHT want to rename Body.001 to something else, like "Nose/Eyeline/Brows" when it's done.

I still have to update the shader nodes

poisenbery commented 1 year ago

Screenshot (1021)

Using blur techniques on the default face masks actually produces very good results. This is using the line mask as an input for some noise bump on the face.

poisenbery commented 1 year ago

I regret to announce that I have ceased all work on this project.

If anyone interested in pursuing this themselves and needs any help, I can be reached on discord poisenbery#1492