Clipping Planes in Metal?

Greetings friends, I have run into a stumbling block and I look to this community for help. I was very excited to build a game that works with Metal, I just hope I can get past this stumbling block.


How do I do this in Metal? I have tried Scissor rects, and nothing seems to clip. I, however, would like to TRANSFORM 4 clipping planes to work with model view and projection matrices. I have tried ViewPort and ScissorRect. I have never seen any clipping work. If I set the scissor rect to (100, 100, 100, 100) and draw a full-screen image, the image still occupies the whole screen.


Also, is there a way to enable / disable clipping / scissor rect. Ultimately, this is cool, I am having fun with Metal.


OpenGL code:


void Graphics::Clip(float pX, float pY, float pWidth, float pHeight) {

cClipPlane[0][0] = 0.0f;

cClipPlane[0][1] = 1.0f;

cClipPlane[0][2] = 0.0f;

cClipPlane[0][3] = 0.0f;


cClipPlane[1][0] = 1.0f;

cClipPlane[1][1] = 0.0f;

cClipPlane[1][2] = 0.0f;

cClipPlane[1][3] = 0.0f;


cClipPlane[2][0] = -1.0f;

cClipPlane[2][1] = 0.0f;

cClipPlane[2][2] = 0.0f;

cClipPlane[2][3] = pWidth;


cClipPlane[3][0] = 0.0f;

cClipPlane[3][1] = -1.0f;

cClipPlane[3][2] = 0.0f;

cClipPlane[3][3] = pHeight;


glClipPlane(GL_CLIP_PLANE0, cClipPlane[0]);

glClipPlane(GL_CLIP_PLANE1, cClipPlane[1]);

glClipPlane(GL_CLIP_PLANE2, cClipPlane[2]);

glClipPlane(GL_CLIP_PLANE3, cClipPlane[3]);

}





MTLViewport aViewPort = {

pX, pY, pWidth, pHeight, -1024.0f, 1024.0f

};

[gMetalEngine.renderCommandEncoder setViewport: aViewPort];




MTLScissorRect aScissor = {

pX, pY, pWidth, pHeight

};

[gMetalEngine.renderCommandEncoder setScissorRect: aScissor];



Thanks,

Nick Raptis

Replies

This is an OpenGL framework that is being ported to metal. I would like to be able to clip 3-D and 2-D content both with scissor rect or clipping planes.