- Home /
Newbie shader question for displacement/ gradient of a texture
Hi all,
I am in the process of learning shaders. As a first 'project' I would like to perform what I hope is a very basic shader, that fades out a texture to the right, that basically makes a gradient of it.
I am unable for some reason to upload images, however please figure there's a transparent image with a red square in the middle. I would like my shader to take that square, and 'translate' it to any given direction, with reduced alpha.
Point is, I have -no idea- of where to start. I have read the unity docs already, but honestly can't figure out -which- type of shader is needed, even (pixel, vertex, surface?).
ANY help is appreciated, and of course if you can point to any such shader example, it'd be great.
Thanks in advance.
Answer by Owen-Reynolds · Apr 07, 2012 at 01:49 PM
For just slide and fade, you don't need a shader. Can set renderer.color=new Color(1,1,1,0.5f);
and renderer.material.mainTextureOffset=new Vector2(0,0.1f);
Things to know are: colors in code are from 0-1. If you select 128 for red in the color picker, the code sees it as 0.5. white (1,1,1) is the "no change" color. The 4th slot of color is extra transparency, from 0-1. Most people fade using color of (1,1,1,A) where A goes from 1 to 0 over time. But, check your shader. If it starts with color grey, that probably means (0.5,0.5,0.5) is the "base" color.
Offset goes from 0-1, as the number of tiles. So, setting it to (-5,47) will appear to do nothing -- it slides the texture 47 full tiles down, but that 48th copy you see looks exactly the same as the 1st one. To get a little wiggle, make some variable go from 0 to 0.2 to -0.2 over time (0.2 means to slide over 20%.)
But, if what you need does eventually need a shader, you can do this is the fragment part of a surface shader -- the one with the page of Unity examples using a soldier's bust.
Thanks for the thorough explanation, I didn't know about textureoffset!
Your answer
Follow this Question
Related Questions
Shader gradient moving with object 1 Answer
Sync up Gradient Noise Node and Script in shader graph 1 Answer
Slice-9-grid gradient shader 0 Answers
Shader Graph | How to create gradient from scratch 1 Answer
Colour gradient shading 1 Answer