H2xDev / GodotVMF

A VMF importer for Godot Engine
MIT License
84 stars 5 forks source link

Incomplete material data. #17

Closed SharkPetro closed 4 months ago

SharkPetro commented 4 months ago

Material importer ignores VMT properties other than $basetexture and VTF data other than the single image that is the base texture.

The biggest issue is the lack of mip texture export. Even with VTFs where mip textures are included, the importer ignores them.

It would be great if the most used properties changed Godot material properties such as $translucent turning transparency from disabled to alpha.

H2xDev commented 4 months ago

@SharkPetro Implemented native VTF support. Check feature/VTFTool branch and give a try :)

SharkPetro commented 4 months ago

@H2xDev Sorry for the delay, I couldn't really get to my PC. Here's what I found so far:

glasswindow005c is a texture that correctly gets identified as transparent as there's "$translucent" 1. VMT:

"LightmappedGeneric"
{
    // Original shader: BaseTimesLightmapAlphaBlend
    "$translucent" 1
    "$basetexture" "Glass/glasswindow005c"
    "$surfaceprop" "glass"
    "%keywords" "c17industrial"
}

glasswindow005b is incorrectly set as transparent, instead the alpha channel should control emission as there's "$selfillum" 1. VMT:

"LightmappedGeneric"
{
    // Original shader: BaseTimesLightmapSelfIllum
    "$basetexture" "Glass/glasswindow005b"
    "$selfillum" 1
    "$surfaceprop" "glass"
    "%keywords" "c17industrial"
}

EDIT: Also blendtextures don't work but you probably know that.

H2xDev commented 4 months ago

@SharkPetro Good. I fixed these problems i think. You can try test it. The same branch

About blendtextures. There need a separate material shader for it that can have two textures. I already implemented the shader but i need to create a new BaseMaterial3D resource that will work this this shader and use it during import. Actually i don't really know how to implement it now.

And there are some breaking changes regarding to config. Check the installation docs again :)

SharkPetro commented 4 months ago

I am stupid, sorry, clicking buttons accidentally, I didn't mean to close the issue.

Everything works good except transparency does not get applied to any materials at all and detail blend mode is all wrong because the detail maps were meant to be used with blend modes completely different from "mix" or any others that are in Godot.

Though to implement detail maps as they work in source there needs to be another custom shader. $detailblendmode parameter defines what exactly the detail map does. Most materials use "$detailblendmode" 0 which is a simple brightness effect. Colors below 128 darken the image, colors above brighten it. This mode is used on bricks and concrete alike, but most notably on damage impact decals, they are the reason textures don't look like blobby mess in valve games as the albedo maps themselves are pretty blurry. 1 is additive. 2 is a translucent detail map that gets drawn on top with transparency in consideration. 3 is the same as 2 but now instead of alpha, the blend value is used for transparency.

There's also mipblend parameter that controls the way detail maps interact with mip textures.

But these are just some examples, I think for now it'll be good enough to have one blend mode "$detailblendmode" 0 which most valve made materials use. If possible it should only take effect on surfaces that are currently drawn with mip level of 3 or less, which is one thing that mipblend can do. It'll be a very long time until you implement the entire material system as it is in source so an approximation is good enough.

Thank you for this update, the mipmaps alone are enough to make up for all else, and I have few enough transparent materials for it not to be an issue.

H2xDev commented 4 months ago

Could you share the map you trying to import? I’d like to use it as test case :)

SharkPetro commented 4 months ago

Sure thing. Github doesn't support this file type so here's google drive link: https://drive.google.com/file/d/1uXSS8ys_J-BdhOkxnxVrX4pnQ8rIYgnc/view?usp=drive_link.

It uses only Half Life 2 textures, all of which I stole from the game files.

I am currently just removing detail folder from materials to get around the issue, so the map is looking almost exactly as it does in source and I couldn't be happier.