michael-fadely / sadx-dc-lighting

Sonic Adventure 1 palette lighting for SADX PC.
MIT License
39 stars 3 forks source link

Palette Lighting API #43

Open michael-fadely opened 7 years ago

michael-fadely commented 7 years ago

As mentioned in other issues (such as #20), the Dreamcast mods would benefit greatly from an API allowing them to control palette selection and lighting parameters manually. With this issue, I intend to outline all the functionality required by such an API to determine feasibility and implementation method.

So far, we know that the following would be a great help (if I've forgotten anything, let me know @PiKeyAr):

As a bonus, the following would be nice for otherwise custom palette handling by misc. mods:

Some more ideas from @PiKeyAr:

PiKeyAr commented 7 years ago

Will palette selection allow me to hijack any material?

I was thinking of something like this: one bit in the unused material flags is picked up to tell whether custom palette selection is enabled or not. If it is, have the mod check a custom array that contains the materials and palette indices they need to use.

If the above is not possible, I guess we need to go back to the idea of using the unused material flags to indicate the palette pair number or something like that.

michael-fadely commented 7 years ago

Honestly, that could work. We could even take it a step further. For example, a single unused bit in the material flags could indicate that a callback is to be run, so all mods that registered a callback have a say in what to do with that material. It would be first come first serve though; the first to say "I got this, don't ask those other guys" gets to control the outcome.

michael-fadely commented 7 years ago

Fixed: no texture (rhino tank etc), sweep, and material specular alpha functioning as ignore specular.

michael-fadely commented 7 years ago

I've updated the checklist to include explicit multi-palette support. This would enable specific effects like the fading used in Sky Deck to mod developers. It will be a challenge to implement, but it would be very beneficial for Dreamcast mod accuracy and coolness factor. It would also help with material callbacks and such. As it stands now, Sky Deck tends to override changes made using the material callback system due to its multi-palette nature.

PiKeyAr commented 7 years ago

I've partially figured out how the game determines whether a material has forced white diffuse. It's absolutely related to the "ignore light" flag. Case in point: Egg Carrier model in Sky Chase 1. All objects with white diffuse that are part of that model follow this rule: if there's a material with "ignore light", all materials after it (only after, not before) have forced white diffuse. Another example is the palm trees near Tails' house. The trunks have white diffuse because their material is listed after the leaves, which ignore lighting. There are likely more conditions involved in this, because in Final Egg there is a model with several materials ignoring lighting, but white diffuse is forced only after the last one.

PiKeyAr commented 7 years ago

I've been running into a minor issue, but it's been pretty consistent so I thought I should report it. If an object is replaced in the mod like this: (NJS_OBJECT )0xwhatever = object_whatever; Then object_whatever's materials are parsed independently and the first material specular thing doesn't work with it.

michael-fadely commented 7 years ago

That's an interesting bug. It shouldn't change anything as long as the pointers to the materials are the same as the ones referenced by the models used in that object.

michael-fadely commented 6 years ago

Arbitrary palette index blending has been implemented. I'm considering the api stable enough to use, so I've merged it into master. After the next stable release, I'd like to implement explicit multi-palette management (e.g Sky Deck), and allow greater than 2 palettes for blending which would be addressable by using blend factors greater than 1.0f (Pretty straightforward, right?). At that point I'll consider it feature complete, ignoring of course the addition of overrides required for the accuracy of other Dreamcast mods.

PiKeyAr commented 5 years ago

A couple of new requests:

PiKeyAr commented 5 years ago

Re: White diffuse, I've almost figured out when it happens but at this point it looks inconsistent and honestly it's probably a fixed function pipeline bug like you said. So I'll be implementing it semi-automatically or manually for each model via the API. I don't think any other mods or vanilla SADX would benefit from white diffuse, so this "feature" of the original lighting system doesn't have to exist in this mod. I would really appreciate the function to replace a palette with a specific color though, not only for this "effect" but for other DC things, too.

PiKeyAr commented 3 years ago

I've added several new functions to the API related to replacing palettes. It should now be possible to replace a palette with a specified color, a color array, or a mix of an existing palette with a specified color.