I think this approach is better:
As always we have to objects(models) on to be subtracted(A) we call this "base" and one to be knife(B) we do following :
1-Render A (base) using a depth map generator shader (simple camera-space Z > pixel brightness) and store result in a buffer for example "bdm" (stand for base depth map)
2-Render B same way and store result to a buffer named "kdm" (stands for knife depth map)
3- Do this :
for each bpx as pixel in bdm //for each pixel in base depth map
for each kpx as pixel in knm //for each pixel in knife depth map
if bpx == kpx //if the depth is equal
fill same pixel in stencil buffer
end
end
end
Now stencil buffer contains area where surfaces of A and B are overlaping
4-Render B with flipped normals using stencil buffer on screen
5-Invert stencil buffer
6-Render A using stencil buffer on screen
7-end
It seems it works better when base is a flat surface and knife is convex-shaped for example it can used for bullet hole ,so on. Any idea?
For collission : Every time C (third object) collides with A(base) and NOT collides whit B(knife) it (C) collides the way we want
For shadownig : I have no idea.