- Home /
Project a shape using a mesh
I want to be able to project a texture onto a surface, using a mesh as the "frustum" instead of simply a perspective or orthographic one, but I am unsure how to do this.
Consider the following:
This is a mockup made in Blender that tries to describe what I am looking to do. Instead of showing the texture of the floating mesh on the mesh itself, I want it to project (as shown by the green arrows) onto the surface below. This is a simple example with a flat surface, but I would also like it to to be able to project onto a bumpy surface, other objects in the way, etc.
I can't simply wrap the mesh over the surfaces I want to project onto, as the vertex resolution is almost guaranteed to not match the surfaces below.
I'm looking for a solution that uses some sort of projection shader, but all examples I have found of a projection shader use some form of a frustum to project. I could not find anything that would project using the vertices of a mesh like in the example above.
How could I go about getting the desired effect? I considered trying to make due with default projectors, but as the display area gets larger, the projection gets fuzzier. This is not desired; it should project as a decal.
The player would be creating these meshes, and they will very often have a curvature to them. The texture of the mesh they would be creating would be set to repeat (via UV manipulation during creation) As such, I need the area of projection to match the mesh the player is creating, and have it one for one projected onto the surface.
How could I go about getting this effect? Is a projector even the right thing for this?
This sounds like something you'd use a decal system for. There are some free ones on the asset store.
Another solution would be to figure out what parts of the mesh you're projecting onto you're over, and then set the UVs on that. That's a lot harder, and might be slower, but you'd get complete control over how things look.
id vote projector , just set the projector to exclude every other layer besides the layer the mesh is on , then use alpha cutoff shader so it only shows that shape.
@dudster: That won't work for me, as I use the uv's of the mesh I want to project from to create the desired image.
I'm thinking maybe the best thing I could do is create the mesh (which is procedural, and always flat), and hug it as close to all objects it is above as possible. I'm concerned about the resolution of the mesh not being perfect though.
I also thought about creating a mesh with volume that is used as a cookie cutter to create a real mesh that perfectly conforms to the triangles within it, but it feels daunting.
Your answer
Follow this Question
Related Questions
Project vertices on surface, make a shape 1 Answer
Shader to make a quad work like a canvas 0 Answers
Water on a non-planar mesh 0 Answers
Altering color / alpha on a Game Object 1 Answer
How to determine shader center? 0 Answers