Skip to main content
replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/
Source Link

Due to thisthis question I have changed the method of rendering portals. Before I was using FBO and rendering to a texture, but somehow I failed. Now I switched to a stencil buffer method.

My problem is that I don't know how to set properly the stencil buffer parameters. I'm doing it like in this tutorial. I have done rendering virtual scenes to portals, but the problem is that the portals are visible always, even if they are behind the wall.

Here's my code:

glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_STENCIL_TEST); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthMask(GL_FALSE); glStencilFunc(GL_NEVER, 0, 0xFF); glStencilOp(GL_INCR, GL_KEEP, GL_KEEP); // here goes rendering the portal geometry // // here some other properties for rendering the virtual scene // in a portal, but that does not matter now // this part is important: glStencilFunc(GL_NOTEQUAL, 1, 0xFF); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // this shows image 1 glStencilOp(GL_ZERO, GL_KEEP, GL_KEEP); // this shows image 2 and 3 // here goes rendering main scene // 

Here are this images:

Image 1:

enter image description here

When changing the first glStencilOp to the second one I got it working:

enter image description here

But then problem occurs in other place like here:

enter image description here

How to deal with it?

Due to this question I have changed the method of rendering portals. Before I was using FBO and rendering to a texture, but somehow I failed. Now I switched to a stencil buffer method.

My problem is that I don't know how to set properly the stencil buffer parameters. I'm doing it like in this tutorial. I have done rendering virtual scenes to portals, but the problem is that the portals are visible always, even if they are behind the wall.

Here's my code:

glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_STENCIL_TEST); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthMask(GL_FALSE); glStencilFunc(GL_NEVER, 0, 0xFF); glStencilOp(GL_INCR, GL_KEEP, GL_KEEP); // here goes rendering the portal geometry // // here some other properties for rendering the virtual scene // in a portal, but that does not matter now // this part is important: glStencilFunc(GL_NOTEQUAL, 1, 0xFF); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // this shows image 1 glStencilOp(GL_ZERO, GL_KEEP, GL_KEEP); // this shows image 2 and 3 // here goes rendering main scene // 

Here are this images:

Image 1:

enter image description here

When changing the first glStencilOp to the second one I got it working:

enter image description here

But then problem occurs in other place like here:

enter image description here

How to deal with it?

Due to this question I have changed the method of rendering portals. Before I was using FBO and rendering to a texture, but somehow I failed. Now I switched to a stencil buffer method.

My problem is that I don't know how to set properly the stencil buffer parameters. I'm doing it like in this tutorial. I have done rendering virtual scenes to portals, but the problem is that the portals are visible always, even if they are behind the wall.

Here's my code:

glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_STENCIL_TEST); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthMask(GL_FALSE); glStencilFunc(GL_NEVER, 0, 0xFF); glStencilOp(GL_INCR, GL_KEEP, GL_KEEP); // here goes rendering the portal geometry // // here some other properties for rendering the virtual scene // in a portal, but that does not matter now // this part is important: glStencilFunc(GL_NOTEQUAL, 1, 0xFF); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // this shows image 1 glStencilOp(GL_ZERO, GL_KEEP, GL_KEEP); // this shows image 2 and 3 // here goes rendering main scene // 

Here are this images:

Image 1:

enter image description here

When changing the first glStencilOp to the second one I got it working:

enter image description here

But then problem occurs in other place like here:

enter image description here

How to deal with it?

deleted 74 characters in body
Source Link
Tom
  • 213
  • 2
  • 9

Rendering portals using stencil buffer method

Due to this question I have changed the method of rendering portals. Before I was using FBO and rendering to a texture, but somehow I failed. Now I switched to a stencil buffer method, and due to this method there is more problems than before.

My problem is that I don't know how to set properly the stencil buffer parameters for multiple portals. I'm doing it like in (here two)this tutorial. I think each portal geometry should save other numbershave done rendering virtual scenes to the stencil buffer. For example portal one should save numbers 1portals, and portal two should save numbers 2. Next how to renderbut the main scene, and what should I do when one portal imposes (in stencil buffer) other portal?

For now I am doing itproblem is that way:the portals are visible always, even if they are behind the wall.

  1. Render the portal one geometry to the stencil buffer
  2. Render virtual scene in portal one geometry
  3. Render the portal two geometry to the stencil buffer
  4. Render virtual scene in portal two geometry
  5. Render the main scene

Here's some pseudo-codemy code:

glClearStencil(0); // clear glClear(GL_STENCIL_BUFFER_BIT stencil| toGL_COLOR_BUFFER_BIT 0| // GL_DEPTH_BUFFER_BIT); glStencilFuncglEnable(GL_NEVER, 1, 1GL_STENCIL_TEST); glStencilOp glColorMask(GL_REPLACEGL_FALSE, GL_REPLACEGL_FALSE, GL_REPLACEGL_FALSE, GL_FALSE); // render portal one geometry // glDepthMask(GL_FALSE); glStencilFunc(GL_EQUALGL_NEVER, 10, 10xFF); glStencilOp(GL_KEEPGL_INCR, GL_KEEP, GL_KEEP);  // renderhere virtualgoes scenerendering tothe portal onegeometry //   glStencilFunc(GL_NEVER, 2, 2); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); // render portal two geometryhere // glStencilFunc(GL_EQUAL,some 2,other 2); glStencilOp(GL_KEEP,properties GL_KEEP,for GL_KEEP); //rendering renderthe virtual scene to portal two //  // herein Ia don'tportal, knowbut whichthat propertiesdoes shouldnot Imatter usenow  // it should bethis somethingpart likeis important: glStencilFunc(GL_NOTEQUAL, 1, 10xFF) and ; glStencilOp(GL_NOTEQUALGL_KEEP, 2GL_KEEP, 2GL_KEEP);    // but how to dothis that? glStencilFunc(GL_NOTEQUAL,shows 1,image 1);  glStencilOp(GL_KEEPGL_ZERO, GL_KEEP, GL_KEEP); // this shows image 2 and 3 // renderhere goes rendering main scene // 

Here are this images:

Image 1:

enter image description here

When changing the first glStencilOp to the second one I got it working:

enter image description here

But then problem occurs in other place like here:

enter image description here

How to deal with it?

Rendering portals using stencil buffer method

Due to this question I have changed the method of rendering portals. Before I was using FBO and rendering to a texture, but somehow I failed. Now I switched to a stencil buffer method, and due to this method there is more problems than before.

I don't know how to set the stencil parameters for multiple portals (here two). I think each portal geometry should save other numbers to the stencil buffer. For example portal one should save numbers 1, and portal two should save numbers 2. Next how to render the main scene, and what should I do when one portal imposes (in stencil buffer) other portal?

For now I am doing it that way:

  1. Render the portal one geometry to the stencil buffer
  2. Render virtual scene in portal one geometry
  3. Render the portal two geometry to the stencil buffer
  4. Render virtual scene in portal two geometry
  5. Render the main scene

Here's some pseudo-code:

glClearStencil(0); // clear stencil to 0 //  glStencilFunc(GL_NEVER, 1, 1); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); // render portal one geometry // glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // render virtual scene to portal one //   glStencilFunc(GL_NEVER, 2, 2); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); // render portal two geometry // glStencilFunc(GL_EQUAL, 2, 2); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // render virtual scene to portal two //  // here I don't know which properties should I use // it should be something like (GL_NOTEQUAL, 1, 1) and (GL_NOTEQUAL, 2, 2)   // but how to do that? glStencilFunc(GL_NOTEQUAL, 1, 1);  glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // render main scene // 

Rendering portals using stencil buffer

Due to this question I have changed the method of rendering portals. Before I was using FBO and rendering to a texture, but somehow I failed. Now I switched to a stencil buffer method.

My problem is that I don't know how to set properly the stencil buffer parameters. I'm doing it like in this tutorial. I have done rendering virtual scenes to portals, but the problem is that the portals are visible always, even if they are behind the wall.

Here's my code:

glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_STENCIL_TEST);  glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthMask(GL_FALSE); glStencilFunc(GL_NEVER, 0, 0xFF); glStencilOp(GL_INCR, GL_KEEP, GL_KEEP);  // here goes rendering the portal geometry // // here some other properties for rendering the virtual scene // in a portal, but that does not matter now  // this part is important: glStencilFunc(GL_NOTEQUAL, 1, 0xFF); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);  // this shows image 1 glStencilOp(GL_ZERO, GL_KEEP, GL_KEEP); // this shows image 2 and 3 // here goes rendering main scene // 

Here are this images:

Image 1:

enter image description here

When changing the first glStencilOp to the second one I got it working:

enter image description here

But then problem occurs in other place like here:

enter image description here

How to deal with it?

deleted 237 characters in body
Source Link
Tom
  • 213
  • 2
  • 9

Due to this question I have changed the method of rendering portals. Before I was using FBO and rendering to a texture, but somehow I failed. Now I switched to a stencil buffer method, and due to this method there is more problems than before.

First I have to take care with light and shadows. They should not pass to the virtual scene where the portal is, rather the virtual scene should have their own light and shadows. For now I don't know how to solve this problem.

Second I don't know how to set the stencil parameters for multiple portals (here two). I think each portal geometry should save other numbers to the stencil buffer. For example portal one should save numbers 1, and portal two should save numbers 2. Next how to render the main scene, and what should I do when one portal imposes (in stencil buffer) other portal?

For now I am doing it that way:

  1. Render the portal one geometry to the stencil buffer
  2. Render virtual scene in portal one geometry
  3. Render the portal two geometry to the stencil buffer
  4. Render virtual scene in portal two geometry
  5. Render the main scene

Here's some pseudo-code:

glClearStencil(0); // clear stencil to 0 // glStencilFunc(GL_NEVER, 1, 1); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); // render portal one geometry // glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // render virtual scene to portal one // glStencilFunc(GL_NEVER, 2, 2); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); // render portal two geometry // glStencilFunc(GL_EQUAL, 2, 2); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // render virtual scene to portal two // // here I don't know which properties should I use // it should be something like (GL_NOTEQUAL, 1, 1) and (GL_NOTEQUAL, 2, 2) // but how to do that? glStencilFunc(GL_NOTEQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // render main scene // 

Due to this question I have changed the method of rendering portals. Before I was using FBO and rendering to a texture, but somehow I failed. Now I switched to a stencil buffer method, and due to this method there is more problems than before.

First I have to take care with light and shadows. They should not pass to the virtual scene where the portal is, rather the virtual scene should have their own light and shadows. For now I don't know how to solve this problem.

Second I don't know how to set the stencil parameters for multiple portals (here two). I think each portal geometry should save other numbers to the stencil buffer. For example portal one should save numbers 1, and portal two should save numbers 2. Next how to render the main scene, and what should I do when one portal imposes (in stencil buffer) other portal?

For now I am doing it that way:

  1. Render the portal one geometry to the stencil buffer
  2. Render virtual scene in portal one geometry
  3. Render the portal two geometry to the stencil buffer
  4. Render virtual scene in portal two geometry
  5. Render the main scene

Here's some pseudo-code:

glClearStencil(0); // clear stencil to 0 // glStencilFunc(GL_NEVER, 1, 1); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); // render portal one geometry // glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // render virtual scene to portal one // glStencilFunc(GL_NEVER, 2, 2); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); // render portal two geometry // glStencilFunc(GL_EQUAL, 2, 2); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // render virtual scene to portal two // // here I don't know which properties should I use // it should be something like (GL_NOTEQUAL, 1, 1) and (GL_NOTEQUAL, 2, 2) // but how to do that? glStencilFunc(GL_NOTEQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // render main scene // 

Due to this question I have changed the method of rendering portals. Before I was using FBO and rendering to a texture, but somehow I failed. Now I switched to a stencil buffer method, and due to this method there is more problems than before.

I don't know how to set the stencil parameters for multiple portals (here two). I think each portal geometry should save other numbers to the stencil buffer. For example portal one should save numbers 1, and portal two should save numbers 2. Next how to render the main scene, and what should I do when one portal imposes (in stencil buffer) other portal?

For now I am doing it that way:

  1. Render the portal one geometry to the stencil buffer
  2. Render virtual scene in portal one geometry
  3. Render the portal two geometry to the stencil buffer
  4. Render virtual scene in portal two geometry
  5. Render the main scene

Here's some pseudo-code:

glClearStencil(0); // clear stencil to 0 // glStencilFunc(GL_NEVER, 1, 1); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); // render portal one geometry // glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // render virtual scene to portal one // glStencilFunc(GL_NEVER, 2, 2); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); // render portal two geometry // glStencilFunc(GL_EQUAL, 2, 2); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // render virtual scene to portal two // // here I don't know which properties should I use // it should be something like (GL_NOTEQUAL, 1, 1) and (GL_NOTEQUAL, 2, 2) // but how to do that? glStencilFunc(GL_NOTEQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // render main scene // 
Source Link
Tom
  • 213
  • 2
  • 9
Loading