bo3b / 3Dmigoto

Chiri's DX11 wrapper to enable fixing broken stereoscopic effects.
Other
688 stars 109 forks source link

Not dumping all vertex buffers in some games #165

Closed eArmada8 closed 1 year ago

eArmada8 commented 1 year ago

Hi,

A couple of folks reached out to me to figure out why my vb merge script is missing elements, and looking through the frame dump log, it seems that 3DMigoto isn't always dumping all the vertex buffers - at least that is my theory. For example, in Samurai Maiden, a frame dump results in a mesh with vb0 and vb1, but there are a bunch of garbage semantics on vb0, all at +000 so it's re-reading the position offset over and over. The numbers don't match only because they're being read as UNORM instead of FLOAT.

vb0[0]+000 POSITION: -0.227301419, 0.975348532, 0.19180724 vb0[0]+012 NORMAL: -0.895824492, -0.412160307, -0.0837205425 vb0[0]+024 TANGENT: 0.41560325, -0.826716423, -0.346219867, -1 vb0[0]+000 TEXCOORD1: 0.70588237, 0.75686276, 0.407843143, 0.745098054 vb0[0]+000 TEXCOORD2: 0.70588237, 0.75686276, 0.407843143, 0.745098054 vb0[0]+000 TEXCOORD3: 0.70588237, 0.75686276, 0.407843143, 0.745098054 vb0[0]+000 TEXCOORD4: 0.70588237, 0.75686276, 0.407843143, 0.745098054 vb0[0]+000 TEXCOORD5: 0.70588237, 0.75686276, 0.407843143, 0.745098054 vb0[0]+000 TEXCOORD6: 0.70588237, 0.75686276, 0.407843143, 0.745098054 vb0[0]+000 TEXCOORD7: 0.70588237, 0.75686276, 0.407843143, 0.745098054 vb0[0]+000 BLENDWEIGHTS: 0.70588237, 0.75686276, 0.407843143, 0.745098054 vb0[0]+000 BLENDINDICES: 0.70588237, 0.75686276, 0.407843143, 0.745098054

vb1[0]+000 COLOR: 0, 0.200000003, 0, 1 vb1[0]+004 TEXCOORD: 0.724121094, -0.0352172852

Looking at the log, there should be a vb2, if I am interpreting the log correctly:

000009 IASetVertexBuffers(StartSlot:0, NumBuffers:8, ppVertexBuffers:0x000000A12A4CCA50, pStrides:0x000000A12A4CCA28, pOffsets:0x000000A12A4CCA08) 0: resource=0x000002133F27A5B0 hash=9b069090 1: resource=0x000002133F27A2B0 hash=47fb6650 2: resource=0x000002133F27EEF0 hash=899413c0

Strangely the ShaderUsage.txt log states it should have a stride of 32 and the missing elements (5-13) are all R8G8B8A8_UNORM so that adds up to 36 for me, so I might be barking up the wrong tree. Regardless, the blendweights and blendindices information is consistently missing, and I suspect it's somewhere in the 3rd input slot (vb2). The third resource is consistently not dumped (899413c0 for this example).

Another example can be seen here in the first post of this issue on my repo.

Thank you very much!

log.txt ShaderUsage.txt 000009-ib=7eda3a35-vs=630fd39564579813-ps=b49d7ea1173ff7ad.txt 000009-vb0=9b069090-vs=630fd39564579813-ps=b49d7ea1173ff7ad.txt 000009-vb1=47fb6650-vs=630fd39564579813-ps=b49d7ea1173ff7ad.txt

DarkStarSword commented 1 year ago

Whenever I've seen those extra offset 0 semantics it's because that's literally what the game told DirectX, and can be verified by reading them in the shader and noting they are identical to the position, i.e. that's the game doing something weird constructing their input layouts, not 3DMigoto misinterpreting them.

vb2 probably isn't being dumped out because the InputLayout doesn't refer to it (i.e. there is no InputSlot: 2 listed in any semantic). You can still dump this out via dump=vb2 buf if you think there might actually be something useful there, but generally seeing extra unused vertex buffers and semantics like this is just an artefact of how the game engine has been coded.

eArmada8 commented 1 year ago

Ahh, I see. That's a bummer. Thank you for the quick and insightful explanation! It is pretty strange to me that the GPU can animate the model without weights, so I suspected there might be something wrong with the frame dump itself. Alas, I do not own this game (the frame was sent to me by a user of my script) and I'm not motivated enough to purchase it just to confirm that the game engine is wonky.

By the way, thank you very much to you and the entire 3DMigoto team, I've gotten a lot of use out of this software (and your Blender plugin)!

DarkStarSword commented 1 year ago

There's a few games (UE4 comes to mind) that have some of their vertex data in unusual places, like structured / regular buffers bound to the vertex shader that have the data in an array that is indexed by vertexID

eArmada8 commented 1 year ago

Ahh, I see. Is this something I could see in the frame dump log, or should I be dumping constant buffers / decompiling vertex shaders to try to track down this data? (I apologize, despite my contributions I am still a beginner, and am just beginning to understand the rendering pipeline. I appreciate your patience!)

EDIT: I was able to obtain and analyze the constant buffers, and none of them were of the correct length or had any data that would match the bind pose position, weights, vertex groups, etc. I have to come to the conclusion that meshes in this game cannot be modified using 3DMigoto.