The problem is of course that you cannot do palette-swaps on a texture with bilinear filtering because the colors are all blended together. Here and here are a couple of open-source shaders using this technique. Luckily there is a way of scaling pixel-art that looks much smoother without taking away the crispness, which is to use a texture with bilinear filtering enabled but only use interpolated colors on the boundary between pixels. However, in the game there is quite a lot of floating-point camera scaling and movement going on, resulting in choppy-looking visuals when using nearest-neighbor filtering. (These effects are used in a very dynamic way, which is why they are done using a shader instead of, say, a separate texture-atlas for each color palette). Simple stuff as long as you use nearest-neighbor filtering on the texture. Most of these effects work by comparing the color of a texture coordinate with a reference color, and if they match then the color is swapped for another. Content of the shader is below, although I think the outlining part of the shader may not be functioning as expected in U5.I am creating a pixel-art game in MonoGame, and have written a shader to perform various effects on a sprite when rendering it, such as performing palette swaps, highlighting outlines, etc. It's an example of using a shader published in the Unity Wiki to do pretty much what you're after. I'm kind of new to shaders, specially in Unity, and I just can't figure out how to make it work properly.ĭoes this video cover the basics? It's an illustration of creating a few different styles of outline and silhouette from the shaders that people have already published. A faster alternative is a pattern or noise dither, or a good old fashioned threshold if your sprites all have fairly sharp edges.ģ) Add third pass to occludable objects that draws the occlusion color using the z-test and make sure it's drawn as a final pass. The quality of that won't be great, but it's the best you can do. You can't use the z-buffer to make soft z-tests without using MSAA and alpha-to coverage. I tried to follow these tips someone gave me, but I'm unable to get it to work:ġ) Leave the pass that renders the sprites as is.Ģ) Add a pass that writes to the z-buffer, but has a shader that uses clip() to discard pixels based on alpha. But if I leave it as Transparent, the character is drawn in the correct order, but the silhouette is never seen. I guess this is because setting the queue to Transparent+1. The character appears infront the rest of the elements, even if it is behind them. Being behind a transparent part of the sprite shouldn't create the silhouette. The silhouette is created when the character is behind a sprite, even if that part of the sprite is transparent. Transparent parts shouldn't create a silhouette. The silhouette is drawn all over the character, even the parts that are transparent. One should create the silhouette effect, and the other one should behave like normal.įor occluding elements that create the silhouette I enable ZWrite, and disable it for elements that doesn't.įor the character I tried setting the queue of the shader to transparent+1, and added this pass: Pass There are 2 kind of elements that occlude the character.Sprites are using alpha blending, and sprites have transparent areas.In my specific scenario there are a couple of requirements: I want to achieve in Unity a see through effect like the one in these examples:
0 Comments
Leave a Reply. |