Hey there!Can someone please explain me how to create textures using Shaders or direct me to an article,please?I have searched for quite a while now,but nothing about this…
In Scripting is pretty easy using for loops.But eats up CPU :[ …How would you do it in CG?
You would use a 2D art application such as gimp, photoshop, or genetica. (http://www.spiralgraphics.biz/genetica.htm) Then import it into Unity and create a material. After that you would drag your texture to the “texture” slot in the material editor and choose an effect for the material. I can create a youtube tutorial if you need further assistance.
To do this with shaders, you would set up whatever geometry you want rendered in front of a camera, make a RenderTexture the active render target using RenderTexture.active, and use Camera.Render() to manually render once to that texture. Then all your geometry will be rendered to the RenderTexture in the same way as things are usually rendered to the screen.
Just one more question : How would i get the coords of an actual texture that i assign (from the Properties{} ) , so it can be later read by a script using GetPixel()?
Sorry if the questions sound silly,but i am very new to CG
mgear’s examples are just regular shaders that don’t happen to use textures as inputs. They do not write to a texture any more than any other shader. If you actually want to create a texture with a single shader, your best bet is to use Graphics.Blit(), which is a shortcut for what I outlined above, but using a single quad with a single Material instead of an arbitrary Camera view.
If you want to read pixel values in a script, you will have to make a copy using Texture2D.ReadPixels().
Unfortunately there is no simpler way, like a “run this shader once on a texture of this size” function. This is because shaders run on the GPU, which is separate hardware and memory from the CPU, where scripts run. Graphics.Blit() is about as easy as you’re going to get.