Looking for who fixes this texture projection matrix

Hello,

recently I read an article about a cutout shader that creates fake holes in meshes. @Evgeni_Popov helped me a lot to make the function work as I need it: Cutout shader to remove vertices of mesh

It is nearly perfect but one single step is missing. The texture is projected by an orthographic matrix that goes through the hole scene. This leads to the fact that the hole is cut at all walls that are hit by the matrix. One solution would be to use different meshes and different materials for each wall. But since I want to use just one mesh for all walls it is necessary to adapt the matrix. The matrix has to project the texture from inside to outside. So it is necessary that the texture projection will project from the position vector to the given direction: https://playground.babylonjs.com/#9UU80W#68

I would really like to use this method wherefore I am willing to pay someone who is able to solve this problem.

Please let me know.

Best

1 Like

I have something for you:

https://playground.babylonjs.com/#9UU80W#72

The trick is to put the spot at the center of the target (the glass) and use in the shader code strq.z >= -${wallHalfThicknessShader} to have the projection only on the right wall.

Note that each light is using a uniform buffer in the shader code and you only have a limited number of such buffers (depending on your card - often 16 or 18). So, having a single mesh for the whole house may not work if you have too many windows: you may need to avoid merging the meshes to be on the safe side.

4 Likes

@Evgeni_Popov is awesome

1 Like

Indeed, you are awesome!! Thank you very much. So I am able to use approximately 16 spotlights per material. That is more than enough for me.

If you take any donations I would love to give you a tip!

Not so much because the system also uses one buffer for the scene, one for the mesh, one for the material.

Note that one way to use less spot lights is to make the windows inside the texture: don’t fill it all red but draw red rectangles corresponding to the windows. This way, you should be able to use a single spot per wall. You will need to update the spot projection matrix if you go this way.

1 Like

Even though 13 spotlight per material is enough for me I will definitely tweak the rectangles of the texture to create multiple static holes with one spotlight. For some parts I will still use one spotlight per hole. This way I can easily drag the object including the spotlight and move everything. That is way cleaner than using csg :slight_smile: But spotlight aren’t too expensive anyway, am I right?

EDIT:

I implemented it into my project. Dragging the windows around feels so good. Thanks again!

Not so much, but there’s still some computations going on. That would be better to have something like “projectors” because we don’t need the lighting part of the spot, but that’s something that don’t exist for the time being.

I am looking forward for this. But using spotlights also works fine so it is okay :slight_smile: