ucupumar / ucupaint

Ucupaint is Blender addon to manage texture layers for Eevee and Cycles renderer.
GNU General Public License v3.0
874 stars 31 forks source link

Channel can bake as vertex color and can be previewed using “Use Baked” #83

Closed morirain closed 3 months ago

morirain commented 5 months ago

This is an unfinished commit, it needs testing or other changes. 2024-01-15 170206 2024-01-15 170238

Added a new channel option, when enabled, the "Bake All Channels" option will bake that channel into vertex color, you can preview the baked vertex color after turning on "Use Baked"

ucupumar commented 5 months ago

Thanks for the PR! After testing it, there are several things come to mind.

morirain commented 5 months ago

After careful consideration, I believe that vertex color requires a separate preview mode, not only for the baked vertex color. Therefore, the vertex color preview mode should be independent. 2024-01-18 172735 On the UI, I suggest having four buttons, representing R, G, B, and A. Users can combine or view one channel individually. This is due to the characteristics of vertex color, which make it very suitable for storing special data on the model in the workflow, rather than just for painting.

This is common in the NPR rendering of game engines. I will give you two examples.

The first example is that people will calculate the smoothed normals of the entire model and store them in the vertex color data, using the RGB channel. Then they use the smooth normal data to extrude the model, thereby make the anime outline of the model. These operations prevent the outline lines from breaking. Later, some people will also use the Alpha channel to control the width of the outline.

2024-01-18 173057 The second example is that some people use vertex color to blend different materials, which is common in making Landscape. These people need to be able to preview the four color channels independently.

Anyway, I would like to hear your opinion. Do you think these changes are necessary?

ucupumar commented 5 months ago

I see. you can also use custom textures for those purposes, it's not specific vertex color features.

I still don't think vertex color needs special preview mode, but individual 'R' G' B' in preview mode can still be really useful and it should work with any RGB data, whether it's from vertex color, textures, or any generated ones. To make things simpler, I think it's better to focus on vertex color baking to channel results first rather than the preview mode.

For your use cases, they're very similar to issue #8, which when implemented can provide combined channels into single textures or vertex colors. So, the solution for that issue can be implemented in another pull request.

morirain commented 5 months ago

@ucupumar check my new changes, I removed the individual vertex color preview mode, then added an option to switch between vertex color and texture, and now I can view them using the Channel Preview Mode.

ucupumar commented 5 months ago

Ok, thanks for the update! I just tested it quickly, I think the target vertex color name (bake_vcol_name) should be filled automatically if the user leaves it empty. For example 'Color' channel will automatically create a new vertex color named 'Baked Color' after baking and set it back as channel's 'bake_vcol_name'. I hope that's understandable.

ucupumar commented 5 months ago

Sorry for the late reply. It has been a busy week. I just tested it again, it's still not working for me. The target vertex color is still empty after baking. image Can you show me a video demo or something?

morirain commented 4 months ago

The problem has been fixed, I forgot that it can sometimes be None.

ucupumar commented 4 months ago

I just tested it and okay, it works, but how does it work again? The target vertex color name is already filled from the start, I never knew something like this before

morirain commented 4 months ago

I'm immersed in my own work these days, I'm sorry that my reply wasn't very timely :).

Let me explain how it works. The key points is in the Property declaration. According to the documentation, I overloaded the getter function. When trying to access the property (from the UI or elsewhere), I check if it is empty and assign the default value.

get (function) – Function to be called when this value is ‘read’, This function must take 1 value (self) and return the value of the property.

bake_vcol_name : StringProperty(
            name='Target Vertex Color Name',
            description='Target Vertex Color Name',
            default='', get=get_channel_vcol_name, set=set_channel_vcol_name)

def get_channel_vcol_name(self):
    # When you open an existing blend project, the Property may be None instead of the default empty string, so I did a double check.
    name = self.get('bake_vcol_name', '')
    if name == '':
        # Access Property based on strings, This does not perform any getters and setters, preventing infinite loops.
        self['bake_vcol_name'] = 'Baked ' + self.name
    return self['bake_vcol_name']
ucupumar commented 4 months ago

Sorry for always replying late. 🙏 Oh I see, I never knew blender API had set get event. I thought it only had update event. I think this PR is almost done. One thing is the 'First force index' still looks weird to me. I'm thinking how about the baked vcol channels always use the first few indices according to the channel order?

morirain commented 4 months ago

Your idea is great, but I have some concerns. Of course, we can move the specified channel to the top level so it can be exported safely, but the user is not aware of this. If we add this feature, we need to include an extra note (probably weirder?). So I think we should keep the "First Force Index" option because it's simple. I have been using this feature recently and I use it to ensure that certain vertex colors are exported correctly.

ucupumar commented 4 months ago

Hmm, I see, but the problem is each channel has its own settings. How about moving the setting to bake all channels operator instead? Maybe it's only visible if there is any channel that enables 'bake as vertex color'.

morirain commented 4 months ago

That's a good solution. I'll update the code later.

ucupumar commented 4 months ago

Ok, thank you!

morirain commented 4 months ago

@ucupumar I've finished uploading the changes. 😁

ucupumar commented 4 months ago

Ok, I'll test it soon. Thank you!

morirain commented 4 months ago

I just realized that I should add a default option so that the user doesn't change the order of the vertex color. I also forgot about the UI display below version 3.20, I'll fix later.

ucupumar commented 4 months ago

Ok, I just tested it a bit, few things to note:

Thanks for the great work! 🙏

ucupumar commented 4 months ago

Oh yeah, almost forgot. I don't think it makes much sense to bake normal channel to vertex color. I think you can make the normal channel have no option for bake as vertex color. One more thing, if the user is checking 'Bake as vertex color', wouldn't it be better if 'Use Vertex Color' is also enabled? So the bake result immediately uses vertex color instead of image.

morirain commented 4 months ago

Updated, check it out👌

ucupumar commented 4 months ago

Ok, thank you! I'll check it more thoroughly tomorrow 👍

ucupumar commented 4 months ago

Ok, I just tested the PR again. There are still a few things to note again:

I think that's probably all that is left, hopefully, thanks for the great work!

morirain commented 4 months ago

@ucupumar Maybe when the user deletes a channel, if the channel has vertex colors enabled, then the user should be asked if they want to delete the vertex colors as well. I think deleting things without prompting is a bad idea, what do you think?

ucupumar commented 4 months ago

Sorry, I've been busy today, I'll check ucupaint usual behavior tomorrow because that kind of issue is not only specific to vertex color, a baked image can also be lost if you delete the channel.

ucupumar commented 4 months ago

I just checked again, yeah you can add an option to prompt the user to also delete the vertex color since the default behavior will not delete it. I think the baked image is fine since it will detect if the image has more than one user before deleting it. Anyway, 'Use Vertex Color' in kinda redundant since it has the same function as 'Bake As Vertex Color', I think it's fine to remove 'Use Vertex Color', and to know which data is used, you can add '(Active)' beside the baked data name. image

morirain commented 4 months ago

@ucupumar Done👌

ucupumar commented 3 months ago

Ok, already tested it, there are still some things that need to be cleaned up, but I think I'll do it myself after merging. Thank you for the good work!