Hi RTB and everyone.
Here is material building function improvements.
- better maps assignment with proper composites
- added managment for Shadow map, Ambient Occlusion Map, Damage Map, Emissive Mask Map
- it doesn't recreate an existing common material
- i discovered what the unknown "TexAttSelUnk2" value seems to be: it defines the material finishing, such Matte or Glossy/standard (I simulate Matte with common map for Diffuse channel and Specular Color channel).
Enjoy
Here is material building function improvements.
- better maps assignment with proper composites
- added managment for Shadow map, Ambient Occlusion Map, Damage Map, Emissive Mask Map
- it doesn't recreate an existing common material
- i discovered what the unknown "TexAttSelUnk2" value seems to be: it defines the material finishing, such Matte or Glossy/standard (I simulate Matte with common map for Diffuse channel and Specular Color channel).
Code:
fn buildMat matName: tSelOff: RtnTexAS: tCount: tFormat: tPath: = (
local PolyMat
for sm in sceneMaterials where sm.name == matName do PolyMat = sm
if PolyMat == undefined do(
PolyMat = standardMaterial name:(matName as string) showInViewport:true twoSided:false
fseek f tSelOff#seek_set
printDebug(PolyMat.name + " uses the following textures:")
local isMatteMat=false, damaged
fn addLayer layer mode ch=(
ch.mapList[ch.mapList.count+1]=layer
ch.blendMode[ch.mapList.count]=mode
ch
)
for t = 1 to tCount do(
TexSelNameOffset = ReadOffset f
FTEXPos = ReadOffset f
RtnTexSel = ftell f
fseek f TexSelNameOffset#seek_set
TexSelName = readstring f
fseek f RtnTexAS#seek_set
TexAttSelUnk1 = readlong f #unsigned
TexAttSelUnk2 = readlong f #unsigned
TexAttSelUnk3 = readlong f #unsigned
TexAttSelUnk4 = readlong f #unsigned
TexAttSelNameOff = readOffset f
TexAttSelNum = readlong f #unsigned
RtnTexAS = ftell f
fseek f TexAttSelNameOff#seek_set
TexAttSelName = readstring f
fseek f RtnTexSel#seek_set
if tglDebug.state do(
Finishing=case TexAttSelUnk2 of(
3328: "Glossy"
3580: "Matte"
default: TexAttSelUnk2
)
format"#%: %, %, Unk1= 0x%, Finishing=%, Unk3=0x%, Unk4=%\n" TexAttSelNum TexSelName TexAttSelName (bit.intAsHex TexAttSelUnk1) Finishing (bit.intAsHex TexAttSelUnk3) TexAttSelUnk4
)
local tm=stringstream""
format"%%%" tPath TexSelName tFormat to:tm
tm = bitmapTexture fileName:(tm as string)
case TexAttSelName of (
-- _a = Albedo Map
-- _ao = Ambient Occlusion Map
-- _b = Bake Map
-- _cc = "2CL" Map
-- _e = Emissive Map
-- _em = Emissive Mask Map
-- _g = Secondary Bake Map?
-- _l = Light Map
-- _n = Normal Map / (Bump Map?)
-- _p = Paper Map
-- _r = Reflection Map
-- _rn = Roughness Map
-- _rt = Phong Warp Map?
-- _s = Specular Map
-- _sd = Shadow Map
-- _t = "TRM" Map
-- _tc = Team Color Map
-- _x = Reflection Map
-- sampler = temporary map copy? (eg. occurs with "npc_zelda_miko_body_damage_alb" map)
-- TexAttSelUnk2 --
-- d00 / 3328 = Standard/Glossy ?
-- dfc / 3580 = Matte ? (specular color = diffuse)
default:(printDebug(TexAttSelName + " not applied!"))
"sampler0":()
"_a0":( -- Diffuse Map --
tm.alphaSource = 2
tm.monoOutput = 1
PolyMat.diffuseMap = PolyMat.opacityMap = tm
isMatteMat = (TexAttSelUnk2==3580)
)
"_a1":( -- Damage Map --
ch = PolyMat.diffuseMap
if classOf ch == bitmapTexture do ch = compositeTextureMap mapList:#(ch)
PolyMat.diffuseMap = addLayer tm 5 ch
damaged = tm
)
"_ao0":( -- Ambient Occlusion Map --
tm = Color_Correction Map:tm rewireMode:1 rewireR:0 saturation:-100
ch = PolyMat.diffuseMap
if classOf ch == bitmapTexture do ch = compositeTextureMap mapList:#(ch)
PolyMat.diffuseMap = addLayer tm 5 ch
)
"_sd0":( --Shadow Map --
ch = PolyMat.diffuseMap
if classOf ch == bitmapTexture do ch = compositeTextureMap mapList:#(ch)
PolyMat.diffuseMap = addLayer tm 5 ch
)
"_e0":( -- Emissive Map --
PolyMat.useSelfIllumColor = on
tm = compositeTextureMap mapList:#(ColorMap solidcolor:white, tm) blendMode:#(0,5) -- TODO: find how to get light color data
if damaged != undefined do tm = addLayer damaged 5 tm
PolyMat.selfillumMap = tm
)
"_em0":( -- Emissive Mask Map --
PolyMat.selfillumMap = addLayer tm 5 PolyMat.selfillumMap
)
"_n0":(
PolyMat.bumpMap = Normal_Bump normal_map:tm
)
"_s0":( -- Specular Map --
PolyMat.specularLevelMap = tm
)
"_r0":(
tm.alphaSource = 0
PolyMat.glossinessMap = tm
)
"_rn0":(PolyMat.glossinessMap = tm)
"_x0":(
tm.alphaSource = 0
PolyMat.reflectionMap = tm
)
"_b0":(printDebug(TexAttSelName + " (Bake Map) not applied!"))
"_g0":(printDebug(TexAttSelName + " (Alt. Bake? Map) not applied!"))
"_l0":(printDebug(TexAttSelName + " (Light Map) not applied!"))
"_p0":(printDebug(TexAttSelName + " (Paper Map) not applied!"))
"_rt0":(printDebug(TexAttSelName + " (Phong Warp? Map) not applied!"))
"_t0":(printDebug(TexAttSelName + " (TRM? Map) not applied!"))
"_tc0":(printDebug(TexAttSelName + " (Team Color Map) not applied!"))
)
)
if isMatteMat do PolyMat.specularMap = PolyMat.diffuseMap
)
PolyMat
)
Enjoy