![]() ![]() ![]() So, that was a lot of text to say “I don’t think the gamma space thing is the problem”. I don’t ever use sprites, so really I’m just guessing here.Īnd, again, this isn’t needed anyway since you likely should be in gamma color space for your project anyway. I might also be wrong and Unity’s sprites don’t do any correction. AFAIK Unity’s sprite renderers internally use a Color and not a Color32, so you should be able to apply the linear to gamma conversion in c# to counter the conversion back. Gamma 13/255 is just barely linear 1/255. Values 0/255 through 12/255 in gamma space are all represented as 0/255 in linear space. When you convert from, gamma to linear space and store those values as a Color32, you loose a lot of of data from quantization. Vertex colors are Color32 values and only have 256 steps of precision in each component. However for vertex colors, you’ve already lost if you’re trying to undo the initial gamma to linear conversion. If for some reason you were to use linear color space, the function you’d be wanting to use is LinearToGammaSpace(), as the shader is doing it’s math in linear space and you want the color values in the original gamma space used to define them. But I doubt you actually are using linear space as your sprite textures would have also needed this sRGB conversion to map property to the swap texture palettes, but they didn’t. If for some reason you were using linear color space, unless you’re using real time lighting, I’d suggest switching to gamma color space. ![]() An alpha of 0 will use the swap palette at the bottom of the texture.Ĭlick to expand.Is your project using linear color space? It’s unusual for a 2D project to be using anything but gamma space, and if you’re using gamma space then this isn’t an issue. That odd multiply and add ensures that the 0.0 to 1.0 range of IN.color.a that the shader sees gets remapped to the pixel centers of the texture.Īlso, one last thing to be mindful of. Vertex colors are stored as Color32 values, so each component only has 256 steps (0 - 255), so unless you start using multiple color channels that's as many as you can index anyway. The alpha does not have this problem, which is why I recommended using it.įor simplicity, I'd set the atlas to be 256 pixels high all of the time. Just be sure to stop using the vertex color in the shader, and make sure you're using gamma color space for your project or the vertex color's RGB values will need some additional handling to correct for sRGB when using linear color space. If you don't plan on coloring the sprite with the sprite renderer's color, you can use one of the other channels, red, green, or blue. This of course does mean you can no longer use the sprite's alpha to fade the sprite out. I'd recommend using the sprite's alpha value. Unfortunately, baring some possible gymnastics with custom sprite meshes, the vertex color is the only things you can really control on sprite renderers from script. ![]() For sprites, setting the color on the renderer changes the vertex colors of the sprite's mesh. Use one giant texture that holds all of the possible palettes you want and set that texture on the shared material, or potentially as a global texture so you're not modifying the material constantly.Ĭhange 2: Select which palette to use from the swap texture atlas by storing the "index" in the vertex color. So why did I say "yes" above"? Because you need to make two significant changes to both the script and the shader side of things for this to work.Ĭhange 1: Use an atlas for your swap texture. And Unity doesn't support sprite instancing out of the box, only batching, so that's moot. Instancing does allow for modifications of the material via material property blocks, if the shader is setup for it, and only numerical values, not textures. Batching requires all sprites / meshes to be using the exact same material as is. Any modification to the material at all prevents batching. You're applying a material property block to the sprite, that alone breaks batching. No change to the shader will prevent what you're doing from breaking batching, since it's not a problem stemming from the shader. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |