Оказание определенных частей экрана является задачей буфера трафарета. Если вы не хотите создавать новый вершинный буфер из пересечения (который может быть создан путем отсечения частей, что не так просто), использование буфера трафарета более эффективно.
Буфер трафарета - это буфер, содержащий целые значения. Вы должны создать его с буфером глубины, указав правильный формат (например, D24S8). Затем вы можете указать, когда пиксели отбрасываются. Вот идея:
Clear stencil buffer to 0
Enable solid rendering
Enable stencil buffer
Set blend states to not draw anything (Souce: 0, Destination: 1)
Disable depth testing, enable backface culling
Set the following stencil states:
CompareFunc to Always
StencilRef to 1
StencilWriteMask to 255
StencilFail to Replace
StencilPass to Replace
//this will set value 1 to every pixel that will be drawn
Draw the first cylinder
Now set the following stencil states:
CompareFunc to Equal
StencilFail to Keep //this keeps the value where the stencil test fails
StencilPass to Increment //this increments the value to 2 where stencil test passes
Draw the second cylinder
//Now there is a 2 in the stencil buffer where the cylinders intersect
Reset blend states
Reenable depth testing
Set StencilRef to 2 //render only pixels where stencil value == 2
Draw both cylinders
Возможно, вам потребуется изменить функцию сравнения до GreaterEqual перед последним шагом рендеринга. Если пиксели перекрываются, могут быть значения больше двух.
Возможный дубликат: http://stackoverflow.com/questions/10294286/get-world-coordinates-from-d3dxintersecttri – paiden