

We use the Vector2 node here to ensure that our Y coordinate is always 0. We can now use the previously calculated number to sample a color from our palette texture. We do this because to sample a texture, you need a value between zero and one. Lastly, we map the color back to a range of 0 to 1 by dividing by 3. Then we divide by 50 to receive the color in our desired range from 0 to 3. Then we subtract 105, so our color is in a range from 0 to 150. The conversion is done like this:Īs our texture is outputting color in a range of 0 to 1 we first multiply by 255 to map it to a range of 0 to 255. This range can then be used to sample our color palette texture. Next, we need to convert the color of the current pixel, which ranges from 255 to 105 to a range of 0 to 3. We will only be working with the red channel from now on, as the channels are all the same anyway. It will contain the four colors for each palette.įirst, we'll sample the main texture. The second texture will be our color palette, which has a height of 1 pixel and a width of 4 pixels. To make sure the SpriteRenderer understands that this is our main texture, the reference needs to be set to _MainTex like in the image. It is the texture that will be set in our SpriteRenderer later. Inputsįirst, we'll create two Texture2D inputs. To do this, you will need to have URP and the 2DRenderer setup in your Project. To create the shader, we'll be using shadergraph. Our assets should now look similar to this, with the color palette and the non-color palette part separated Starting from white, this corresponds to the colors: To make it mathematically simple but still easy to handle for artists, I chose to take every 50th color in RGB. We want to represent these colors as gray tones that will then be replaced by the shader later. One highlight, a mid-tone and two shadow colors.

Creating the assetsĪs you can see in the image, the trees in Hooked have four different colors. In this blog post, I want to walk you through the process of how I've implemented a color palette shader using shadergraph and URP. In Hooked, we wanted to do exactly this for the trees. Sometimes when creating pixel art assets for your games, you want to create a lot of different color variations quickly.
