- Home /
Baking decals into a texture
Hi. I'm currently developing a top down 2d shooter in Unity that's mainly focused around decals (e.g splats, scorches etc). At the moment I'm using simple planes for each decal and, as you can imagine, a lot of them start to hinder performance (even when combined to one draw call).
Is the a method of baking them into the ground texture at any position using Texture2d.SetPixels and Texture2d.GetPixels?
Thanks.
SetPixels will just change the color of a block of pixels - so it won't work unless you just want a coloured blocky shape on your mesh. The method I see everyone use is the same: Instantiate("splatObject") followed by a timed (Destroy("splatObject")
Thanks for the reply. I've actually managed to duplicate a texture from one object to another using GetPixels and SetPixels (with alpha) and it looks perfect. So what I need to know is how to bake the decal at any position on the ground.
If that's the case wouldn't something like texpix=tex.GetPixels();splatPix=splat.GetPixels();for(var i:int=0;jtex.width+startX+j](1-splatPix[j*splat.width+i].a)+splatPix[j*splat.width+i]*splatPix[j*splat.width+i].a;tex.SetPixels(texPix); do the trick? just decide where you want the splat, iterate through the texture and splat arrays, blending the values and then set the pixels to the blended values.
Answer by peacemaker · Nov 25, 2010 at 03:40 PM
If you are still having problems with this I came across a Unity Decal Framwork here:
Might be of use! Good luck :)
Edit: I added this link YEARS ago and it's just come to my attention that the original website has since shut down and been replaced by a spyware/spam site so I have removed the link.
The link goes to malicious page, I recommend it be changed or removed.
Thanks for pointing this out @Coltenney and @raxxilion. It was originally a nice framework but it seems it has since gone out of business so I have updated this.
Answer by yoyo · Dec 03, 2010 at 07:18 PM
If you only need a limited number of decals per object you could potentially place them with additional texture inputs to a custom shader. Use a uv-transform (scale/offset) to place the decal on top of the base.
I once did a (non-Unity) demo project like this to make ants crawl across a face. Probably not the best solution (makes for expensive pixel shaders), but it's a neat technique.
Answer by LawyerOfGod · Sep 11, 2014 at 09:46 PM
There is a way to bake decals shadows (only shadows) into lightmap..
1) Go to asset store and get "Simple Decals" (for free) and install it into your project 2) open the scene contained on the package you just installed 3) select one of the decals that are in scene, drag and drop it into the project folder (to create a prefab) 4) return to your scene where you want to put decals in, drag the prefab you have created into sene and adjust it to fit 5) mark the decal object as "static" on the property panel. 6) reduce the decal´s material alpha value to 25% (so the baked decal won´t look so bold) 7) bake scene ..
Shadows are B/W not textured..
this is good to make a dirty implementation on the scene.