ScanMountGoat / Smush-Material-Research

Smash Ultimate material and rendering information
https://scanmountgoat.github.io/Smush-Material-Research/
MIT License
19 stars 8 forks source link

How FP_C1 works, add in annotation? #48

Closed Trainmaster9977 closed 3 weeks ago

Trainmaster9977 commented 1 year ago

Hello! I'm here to deliver some big exciting findings that might be new, even to you.

While FP_C1 has been an enigma, not really being in the metadata like the rest, and confusing basically all of us, I've found out how it works, and it's actually surprisingly simple.

This is all thanks to GDK on the ryujinx discord, who recently informed me of all of this.

After the main code in each shader, there is a block of bytes. for example,

codeandblock

Those bytes are the constant buffer. Or as we know it, fp_c1.

They're formatted as float32s, or 4 byte long floats. We can check this in Renderdoc - the first 4 bytes here, if we take it as a float, is 1.14999997615814. And if we look at it in Renderdoc, we see a rounded 1.15. If you choose to export the fp_c1 buffer as bytes, you also get an identical output to the constant buffer in the corresponding shader. (At least, for the bytes that the shader actually accesses. When in Renderdoc, it seems to go on for a while after that with other stuff)

image

Again, this is all due to GDK on the Ryujinx discord, who informed me of all of this!

Point is, now that we know all of this, would you be able to update the shader annotation to include it, in the same fashion as the other annotations?

Thanks!

ScanMountGoat commented 1 year ago

Interesting find. Thanks. The long term plan is to move the annotation and analysis code into a separate library (#49). The library can support all the current annotation options as well as constant buffers like you mentioned. I'll try and add the actual value as a comment for clarity.

float constant_var = fp_c1.data[0].x; // 1.0

I'm still working on dealing with per material shaders for other games, so I may not get to updating the Ultimate related code for a while. Feel free to make a pull request for ssbh_data or smush_materials if you want to make an attempt at reading or annotating the constant buffer data.

Trainmaster9977 commented 1 year ago

Thanks, that works! Good luck on those other games!