Hi, as the title says I’m trying to create a 2d shader that does the following:
- takes an image
- makes the white pixels of such image and make them cycle through colors creating a rainbow effect
- leaves every other part of the texture that is not white alone
How would one go about creating an script that achieves this? I’m not looking for precoded or market place solutions because I want this to be a learning experience. Any kind of guidance or help would be appreciated.
You will need to create a shader that uses the fragment portion of the shader to test if the current pixel is white and replace it with rainbow color. Once you have the shader, you can create a material with it and apply it to the renderer you are using to display your image.
If you’re unsure where to start, use the right-click menus to create a new unlit shader and start editing the function at the bottom called “frag”. The value you return from that function is the color the current pixel will be. Start simple by testing if the current pixel is white using if statements and return your rainbow color if it is. To get the rainbow color, you can either pass the changing colors into the shader properties using a C# script, or you can create the color in your shader using “_Time.y” to change the color over time.
Shaders are too complicated for me to give you a full rundown of what to do here, but I’m happy to answer questions if you get stuck. I recommend you try simple approaches to get things working before you try to optimize. Here are some good resources:
I would give it go to shader graph.
You can create different effects.
Then you can see actual code.
Is hard to get wrong.
Good for learning with sense of progression.
Thanks for the help, I have some decent coding experience, but I’m completely new at shaders. What I might need in this case is a rundown of how they work.
Is there any good documentation for beginners I can read before I continue bothering all of you with questions?
My best bet would be, to look here
Graphics
https://forum.unity.com/categories/graphics.75/
Choose area of your interest, and make sure, you check out pinned threads.
Sry to necro, but we got Color Mask Node | Shader Graph | 6.9.2 Color mask node now gamers!