Help With Projection Textures

I’m new to the framework but I’ve been messing around with ways to projecting 2d images onto 3d models. The way that i was attempting to use was by projecting the texture with a spotlight using a projectionTexture. The way the image wraps on top of the model is exactly what i want but is there any way to make the texture its projecting completely opaque so that you are unable to see behind it?
Ex:

If not is there anything I can read up on that may be able to help me achieve this effect? I’ve tried using Decals but the wrapping around wasn’t quite what im looking for and many of the models I work with arent a single coherent mesh that would allow for decals to work properly from my understanding.

1 Like

Hello and welcome!!
Maybe you can set your texture in the reflectionTexture channel of the material and use the coordinatesMode set to PROJECTION_MODE?
something like that: https://www.babylonjs-playground.com/#11JINV#1

Interesting, so if I’m trying to do this to a gltf model then would i need to go in and add this to each mesh in the model? And would i have to set this property to each new mesh/object i add into the scene? Thanks so much for all the help, that seems to be exactly what im needing.

You will do it per material but basically yes you will have to do it for all materials that need to have the effect applied :slight_smile:

Sorry for the late reply I’ve been playing around with it for a while and that doesn’t quite do what I’m trying to accomplish. It seems to add a reflection texture onto where the camera is looking, the thing I’m trying to accomplish is to use the spotlights almost as decal generators. in order to simulate a film projector type thing. I’ve had better success in clarifying the image projected by the spot light by changing the diffuse color, but i was trying to make it so that the image being projected was more present and overpowering the model its being projected onto without adding additional glare from the intensity.

To help you further I would recommend providing a repro in the playground

Here is an example of what I’m trying to do (I essentially want to do something to decals with these projection textures) the issue being i found decals often wrap around things if there is an abstruction and i want the image to back project behind those obstructions. I was trying to make the light project more rectangular and opaque in order to make the projected images more visible and easier to discern

https://www.babylonjs-playground.com/#J2FUPK#10

Ok so I see your cat on the house :slight_smile: It seems to work. So what issues are you facing?

I was just wondering if there was a way to modify the light to make the cat more opaque in order to make it more visible at higher ambient light levels (or even independent of outside light levels). If i increase the intensity it obviously increases the glare and causes more image distortion. If not is there something else to create the same effect with another technique.

Well I think you can use the emissiveTexture directly and play with uv offset but you will need to provide a good uv mapping and that could be tricky

Maybe we could add an option to set the light in some kind of “decal” mode where it will just add the projection texture and not do any lighting

That would be really helpful, I’m working on a project where I’m syncing up models to a video being projected by the spotlight. I originally tried using decal but found issues of it wrapping around in unpredictable ways as well as moving objects going in and out of the “projectors” field of view. Is there something i could do in a custom shader to make override what is currently occuring in the spotlight?

Very unlikely as the shaders we use are quite complex.

But if you don’t mind creating a feature request in the repo I will try to find time to add that feature for you

Will do, and thank you so much for the replies and being patient with my dumb questions.

1 Like

Sorry for my bad first idea :slight_smile:
So here is another one:
https://www.babylonjs-playground.com/#11JINV#65

I create an emissive texture, set it to clamp and then move it with uvOffset

1 Like

If you have a 3d model of the thing you are trying to project onto you could map its surface to a planar projection and then calculate the projector position by calculating the projectors output ratio to your mapping plane and treat that like a camera frustum/position thing (it would be the same essentially but a reverse of the light) and you should get the position you would have to place your projector in the real world.

1 Like

I’ll give that a try, do you have any tutorials (whether their in babylon or opengl) or further reading I can go through to get a better handle on the math required?

Yes. How good are you at going through code?

Pretty decent, I’ve not done graphics specific stuff in a while so some of the more complicated matrix math and shader code is still a little difficult for me, but reading and understanding general source code i can usually figure out.

ok cool, well then here let me point you to this.
http://pryme8.com/keeyah-a-procedural-ninja/

Is how you could project the plane and then now you would need to calculate the “camera” position from the by using the plane as the frustum.

If you were going to make a plane fit exactly into the “camera frustrum” here is the math for that:

var c = scene.activeCamera;
c.position.z = -1;
var fov = c.fov;
var aspectRatio = engine.getAspectRatio(c);
var d = c.position.length();
var y = 2 * d * Math.tan(fov / 2);
var x = y * aspectRatio;
var output = BABYLON.MeshBuilder.CreatePlane("output-plane", {width: x, height:y}, scene);

reverse that and you can get the position of the projector I believe. Off the top of my head I forget the exact math. Maybe some wizard will chime in with a real algo for you after seeing this.

1 Like

You might also be able to use a spotlight with a projection texture:
https://www.babylonjs-playground.com/#FARGN3#2

1 Like