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

Naming temp values multiplied by GL fragcord #33

Closed Trainmaster9977 closed 1 year ago

Trainmaster9977 commented 1 year ago

Greetings, as another person researching the shader code.

While the annotated code is helpful, there's one change that's needed give everything proper clarity.

When most, if not all, input attributes are introduced, they are done so like this:

 temp_1 = in_attrN.x * gl_FragCoord.w;
 temp_2 = temp_1 * temp_0;

The improvement comes in due to the fact of what temp_0 is, at least in _PS shaders.

temp_0 = 1.0 / gl_FragCoord.w;

This means that the input attribute, in essence, is multiplied by gl_FragCoord.w; then divided by gl_FragCoord.w;.

Meaning that it ends up exactly where it started.

While it's relatively easy to go through the code and replace the temp_2 with in.attr8.x (though doing it for every input variable and making sure you only replace temp_2 instead of temp_2xx takes a bit) automatically doing so would save a lot of time, and simplify the code for reading.

ScanMountGoat commented 1 year ago

While this would simplify the code, the goal of the annotated dump is just to add parameter names. Modifying the expressions themselves is significantly more challenging. I'm also not confident that x * gl_FragCoord.w * (1.0 / gl_FragCoord.w) == x for all x due to how floating point numbers work. You're always free to make these assumptions when simplifying the code yourself of course.

Trainmaster9977 commented 1 year ago

Fair enough, I guess. Floating points do make things a bit more complicated. Though you could always make the second one modified- for example, instead of In_AttrN.X, maybe In.AttrN.GL.X? Just a thought.

On a more personal note, while I fully understand why you normally don't have DMs active on discord and leave the server, I do want to ask if I can try to compare notes with you/ask more questions. I'm analyzing the binary at this point, and I'd rather just ask you a couple things instead of spending a day figuring out things you already did the work for.

Thanks!