Search Unity

How to draw a given texture the a specific place on an object?

Discussion in 'Shaders' started by Compressed, Mar 8, 2016.

  1. Compressed

    Compressed

    Joined:
    Sep 20, 2014
    Posts:
    59
    I have some model which I imported from blender, and add my custom material with my shader on this model.
    I add a collider to this model. The collider detects a collision at some position on the model and I have a texture with transparent background which I want to render in the place of the collision on that model. (Kind of like bullet impacting on a force field and creating a ripple in the place of the impact, except the force field isn't flat so i can't just slap a plane with the texture in that spot, the texture needs to bend to sit on the model well.)

    How can I achieve this with a shader? The biggest part I have a problem with, is drawing the texture in the correct position with the shader, as in, how do i take a world position coordinates of the collision and give them to the shader so it knows where to render stuff on the model...?

    thanks for any advice
     
  2. drudiverse

    drudiverse

    Joined:
    May 16, 2013
    Posts:
    218
    on flat or regular round surfaces, that's easy. on irregular surfaces, it's not a trivial task, and time is best spent on other kinds of special effects... take the problem from a different viewpoing, say you had a complex glass vase and yuo wanted to place cracks on it depending on what zone it was hit from... it's not something you see done with textures in games. it's possible but it takes ages of annoying random array arrangements. if it's a simple model you can make a transparent copy of the model a tiny bit larger and try to place a texture on the XY UV closest to where it was hit. that seems like the simplest plan but it can be a bit difficult.

    For a start, someone has written a good particles array tutorial recently, making graphs with particles, it's one solution.

    Also you can do procedural modifications of textures. probably best done on a copy of the mesh overlaying the first, it saves time compared to copying all the triangles in a boundary into a new mesh...

    procedural mods means you take a transparent version and do some volumetric pattern extending from a point in local space like some shells of different colors and it will make an effect of radial rings from the hit poing, its kindof fun but it does take a day also. you can overlay the procedural hit pattern or multiply the color with what's under it to merge it a bit better or transforum the underneathcolor like multiply etc different overlay modes.

    perhaps you can use layers, with a sphere that is over the object hit and has a pattern on it multiplied only by the mesh underneath that makes some pattern that you want...

    generally game devs dont waste time on these thigsn so you volumetric hit effects, particles, vertices, you may find some cool stuff in the library, but to do exactly what you want is a case of making a copy of the mesh or surrounding triangles, working their indices out, writing complex code for them, generally not synergetic use of coding time.
     
  3. Compressed

    Compressed

    Joined:
    Sep 20, 2014
    Posts:
    59
  4. drudiverse

    drudiverse

    Joined:
    May 16, 2013
    Posts:
    218
    nice find. That's something like a multilayer shader. someone else can maybe tell you better. It looks like quite a lot of work. you have to send hitpoint infos to the shader and make the shader deal with N hitpoints, there is probably a maximum like 20 of them per object. then there is also a secondary script which makes each hitpoint have an intensity and a radius after it was hit.

    I cant say for sure but i think it's a secondary shader that is transparent all over the object and that inputs hit points and outputs localized radius where colors change around each hitpoint. For an experienced programmer that takes 2 3 days, that package must have taken 4 5 days to get that quality of effect and then some more days to make it into a unitypackage. best thing is searching around. if you had some money you could buy that one :D