Hey Guys, Im going to try and figure out how to simulate a blast area by turning the pixel area darker…This is possible-right? As I understand it, its by using getpixel and setpixels, correct? Im going to try and figure this out -I know it will take time, but I was interested to see if anyone has some starting directions?
I figure it will go something like(Psuedocode)
Function OnCollisionEnter(other:collider){
var texture = new Texture2D(128, 128);
other.renderer.material.mainTexture = texture;
var color = Color.black;
texture.SetPixel (color);
texture.Apply();
}
I searched a few posts here, and it looks fairly technical-is anyone instantiting decals? I anticipate flickering with planes but havent tried yet
With planes you most likely will get flickering as they have to be so close to the actual object.
As for the pixel way, it could be done but the tricky part would be getting the proper pixels at the actual blast area and effecting the right pixels at the right radius, in other words, it probably wouldn’t look very good without a lot of work, and either way it would probably be slow. I have never done it myself, so I cannot really help any more than this I am afraid.
A way to cheat would be to swap out textures. Less realistic, but still could work depending what you are doing. You could even choose different textures with different damage depending on the objects distance to the blast, or a better but harder idea would be to apply some random dirt/burn effect to the whole texture. Maybe perlin noise or fractal or whatever. Hard to do, but could work.
I spent about two weeks working on a decent decal solution. It never really worked. What I did was copy and paste all geometry near the splat area, then applied funky planar style uv mapping depending on surface normals and vertex positions.
The problem is it really needs extreme optimization to run at an acceptable speed, and doing it with Unity’s mesh class in Unity’s javascript or C# will never be fast enough for anything but very very simple geometry.
I will see if I can dig up the project. It probably will help you understand some things about splats.
Edit: Oh it looks like drJones dug up my old thread. Beat me to it in a way.
Yep this is a hard row to hoe, but down the track it will be good info…
Jeremy Said:
This is probably the quickest solution. Ive got a lightmapped scene, with a pile of crates which are static(1 big meshcollider, kinematic rigidbody) and I am looking at how I can launch an attack on that area. and switch out the crates for dynamic replcements. I think I’ll create objects that drop bombs inspecific places, and swap the ground texture so the blast mark reflects those locations. because the lightmapping wont look right once objects start moving, I will create heaps of kaos, big burn marks etc to distract the player from realising the shadows have gone. I dont know if this will be convincing…And then theres other shadow prospects in unity’s future…
Dr J- Cheers for those links, I’ll be reading lots of posts-those included. Ethans splatter package might do nicely too. And I’ll sus out that shader. Good stuff man.
Yoggy thanks heaps, I’m downloading your example. the example I made took ages to calculate, so I hear you about speed. In my ideal world I’d like a lightmapped Bumped shader, that changes the lightmap texture to add the blast, then I could keep my main (tiled) texture unchanged, and only darken the lightmap texture. Oh and a fast version of this
Anyways this is great work and a big help, thank you.
Aaron
Well, that already exists; it’s called the lightmapped bumped shader. You’d want to change the texture rather than the shader, so what you’d do is find the coordinates somehow to draw into the lightmap using SetPixel. (Maybe just hit.textureCoord; that would be fairly easy…or can you do that with the second UV set?)
If you had a more or less flat area like some terrain, you could use the blob shadow projector too. Maybe something sort of like this. (Move cursor with mouse, click to bomb. Not a game, but kinda fun for a few minutes…) Attached is the project…mostly I just adapted the BunkerBehavior script from Unity Invaders somewhat since it’s basically the same idea. You can change the size of the affected area by changing the projector’s orthographic size, though that also makes the splat texture get relatively larger or smaller along with it. It would look better with some randomly selected splat textures so the scorch marks don’t all look the same. Or better yet, a procedurally generated scorch mark. With some smoke, etc…and have some particle dirt thrown into the air…then you could deform the terrain too…or am I getting carried away here?
Edit: updated project folder so it works with Unity 2.0 (mostly just replaced the Blender files so they’ll load, also removed the script that turns off particles since that’s not necessary anymore), and updated SplatTexture script so it’s faster.
Not one but two excellent packages posted to help me! Woot!Woot!
Eric i like your idea. I will try and emulate it…Somehow you have a bunch of projected shadows in the scene, but only one in the hieracy?-I will be able to figure it out, Im sure, but I really want to say thanks for such a great example like Yoggy’s was too. Mega helpful. i also like the red target morphng over the landscape-Im sure that will be useful in time also.
Cheers Y’all!
Aaron
PS-Eric, I wonder if your going to make a unity build of Pac-man to go with your collection of casual games?Hee hee, seed sown! (I wasnt hinting that you should for my sake btw)
Nope, just one. If you look at the code, you see that basically the small “splat” texture gets drawn into the big shadow texture at the appropriate spot. So the texture is altered every time a bomb hits. The target is just the standard blob shadow projector, but with a different texture.
Not exactly, but stay tuned. (Just make sure you’re not holding your breath…)
I’ve heard a lot about using blob shadow projectors to do highlighting and giving textures certain unique looks, would it be possible to adapt for a game board that has individual tiles that need to have a highlight effect applied to them when selected?
Also has anyone seen solid information on unity projectors? It seems like they can do a lot but maybe I’m overlooking a solid explanation on them. I feel like I still don’t fully understand them other than casting against the normal of a surface? Any explanation for a projector noob would be awesome. Thanks.