Cutout shader to remove vertices of mesh

For 1/ this one will work, I did not see the usage of the sampler in the code: https://playground.babylonjs.com/#9UU80W#56

For 2/ I don’t see any other solution than to have a different material for wall 2. If you want to have a window on the second wall at a different location than in wall 1, you will need a different material, anyway.

Thanks for the fix.

Oh I see. So one mesh can only process the projection texture of one spotlight. But even if I split all walls into separated meshes I can only cut one hole per wall, is that correct?

I had in mind to create a spot light for each object that I want to place at the wall. Isn’t it possible to discard all fragments that are proj.r == 1. regardless of which specific spotlight is bringing this red value? All objects will have a distance to each other so the value can’t interfere but it would be really good to be able to use two different spot light with two different positions for the same wall.

You can make multiple holes with multiple spots this way:

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

Also, you can change your dynamic texture so that it has multiple red rectangles, so multiple holes in the wall in the end.

There can be some artifacts:

However I can’t see a way around it as what you see is the thickness of one glass through the other glass.

Yes, that is very handy. To have more freedom regarding unique rotations of the target meshes I will go with using one spotlight per target. But I definitely keep that in mind adding more rectangles to the same texture for other scenes.

I am fine with the artifacts since I will add a frame and other parts around the glass so you won’t be able to see it anyway.

Does the shader follow any pattern which textureProjectionMatrix is used? In my pg I added four spotlights but somehow only textureProjectionMatrix 2 & 3 is used - 1 & 4 are not working: https://playground.babylonjs.com/#9UU80W#61. And is there a limit or am I able to add as many if statements as I want for more spotlights?

Regarding the problem with cutting the wall on the opposite side due to the orthographic projection: Is it possible to project from a specific point like the position of the spotlight to the given direction? Like a regular spotlight just without the angle. Then I would be able to place the spotlights inside of the room and spare splitting the walls into several meshes with a material for each of them.

I forgot the index #0:

Also, the index depends on the number of lights declared in the scene before the spots. Basically, this value is the index in scene.lights of the spot. If you want to be safe, create as much #if define(PROJECTEDLIGHTTEXTUREX) blocks than the total number of lights you will have in the scene.

I don’t know how… Maybe someone with better math background will be able to help.

That makes sense. The pg has a hemi and direct light already so I would need to ask for PROJECTLIGHTTEXTURE 2-5 to use four spotlights. But if the hemi & direct lights are enabled the holes are still not created for two spotlights. Only if I disable them all spotlights are working: https://playground.babylonjs.com/#9UU80W#63

I will play around with it and maybe someone else can give advise. You were very helpful already.

That’s because by default only 4 lights can be defined per material. You can raise the value:

    wall.material.maxSimultaneousLights = 6;

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

2 Likes

Yes, that’s perfect :slight_smile:

Is it possible to move the window after its been created? I tried changing window position and spotlight position but it does not change the position of the whole in the wall

Yes, see earlier PG in the thread: https://playground.babylonjs.com/#9UU80W#56

Using the same technic with the latest PG:
https://playground.babylonjs.com/#9UU80W#81

1 Like