- Home /
Project vertices on surface, make a shape
Hi all,
I am trying to implement a sort of decal system for projecting very simple 2d figures onto other surfaces. If I understand correctly, the most indicated way to do this is with rendertextures, but I don't have the Pro version, and I was looking for an alternative, even if it's resource intensive, inefficient, and whatnot, since performance is not an issue.
So let's think of a sample case: I have a mesh of a five pointed star, and I need to project that onto the terrain, from Vector3.Up
The "easy" part is raycasting all points down to ground, and actually "projecting" the mesh, but this is frequently a bad approach since projecting on a cone or other bumped surfaces will correctly deploy the vertices of the star, but the star's surface would not adapt to the geometry.
Sadly, projectors don't seem to accomodate a mesh as the cookie source, so I don't know which way to go from here.
I thought about shaders for a second, but I'm illiterate in the field so I don't really know what can be done in that direction.
Any advice is welcome.
Answer by Winterblood · Jan 02, 2012 at 02:34 PM
Presumably your mesh is going to deform in some unusual way? Because if it was just rotating and scaling you'd be able to make a star texture offline and rotate/scale the projector.
If it's deforming in a consistent way, and memory is no object, you could render off the deformation into a texture atlas and have the projector project the animation by adjusting the UVs.
Otherwise you may have to roll your own projector, but that will probably take days to do and weeks to iron the bugs out of :/
It's not a matter of deformation, but rather the fact that the meshes are created on the fly, by the user. So there's no way to anticipate what will be created or how it will be painted into the surfaces.
In the absence of render-to-texture, you could manually rasterize the mesh to a texture one pixel at a time (see http://unity3d.com/support/documentation/ScriptReference/Texture2D.html). Slow but doable if you only update it when the user modifies the shape.
Depends on the use-case - if it's unlimited user-generated shapes projecting across a landscape for miles, it might be better to write your own projector and avoid using textures altogether.
@Winterblood This could do, since once the shape is created, it won't change, but I have trouble figuring out HOW you're supposed to perform the process. I mean, I was hoping to find something similar to 'drawline' and 'fill' with the texture2d object, but there's nothing like that. Do you possibly know if this can be achieved by a shader in some manner?
Not that I'm aware of. Shaders only do per-vertex or per-pixel micro-calculations, not macro-level shape drawing.
A crude method would be to iterate through every pixel in the texture, do a "raycast" (or comparable test) to decide if it's inside or outside your shape, and colour it accordingly. Could do multisamples to reduce aliasing if necessary. That's the best I can suggest without knowing the parameters of the user-designed shape editor...
Your answer
Follow this Question
Related Questions
Project a shape using a mesh 0 Answers
Mesh Decal System 0 Answers
Shader that only shows mesh at the point where it is colliding with terrain? (A projector?) 0 Answers
What is the best way of drawing/projecting dynamic trajectory on a ground surface 1 Answer
What is the best way to create realistic surfing waves? 0 Answers