Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 11 Jul 2013
Offline Last Active Mar 26 2015 09:48 AM

Topics I've Started

Weird winding behavior porting to GLES

10 March 2015 - 08:37 AM



I'm working on porting a graphics application from OpenGL 2.1 to GLES 3.0.  I have a sky dome which renders fine on OSX, but will not render on Android unless I reverse the culling mode (i.e. switch to GL_FRONT).  However, if I do this the sky dome will no longer render on OSX.


Since my understanding is that both of these systems should have the same default culling behavior, I'm wondering if I missed something in initialization?  Or is there something else that can cause this behavior?

Enabling a buffer but not using it

27 October 2014 - 02:43 PM



I'm pretty new to OpenGL, so I'm curious as to what the performance hit might be for enabling a buffer and the not using it.  For example, what if I were to enable GL_TEXTURE_COORD_ARRAY and then never use textures?   My guess is very little and I plan on profiling it when I get the chance, but it'll be a little bit before I can do that and google hasn't helped me dig up an answer yet.



HLSL discard and PIX

18 September 2014 - 12:10 PM



Just a general question.  In my PS 2.0 shader I was using discard on certain pixels and noticed a bunch of other pixels being discarded as well.  When I used PIX to try to determine what was happening, it didn't show the shader being ran for these pixels.  I know the problem was in the shader (because I've fixed the problem), but I'm wondering if this is normal behavior for PIX (or a bug)?

Stencil Buffer

03 September 2014 - 02:45 PM



Here's a greatly simplified version of what I'm trying to accomplish: 


Imagine I have a gently sloping terrain (triangle strip).  At an arbitrary position on the terrain I want to put a cardboard box (with no lid).  The box will live at the base-Y position of the terrain, but the terrain might be slightly higher at this point, making the box appear to be partially buried.  This is exactly what I want.  Now imagine the camera looks down into the box.  I want to show the box contents, or simply just the bottom of the box.


I thought the best way to accomplish this would be with a stencil buffer, however I'm struggling to get it to work (following Chapter 13 in Introduction to 3D Game Programming).  Here's what I'm doing:


Step 1:  Set up the stencil buffer

   gpDeviceInterface->SetRenderState(D3DRS_STENCILENABLE, true);
   gpDeviceInterface->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
   gpDeviceInterface->SetRenderState(D3DRS_STENCILREF, 0x1);
   gpDeviceInterface->SetRenderState(D3DRS_STENCILMASK, 0xFFFFFFFF);
   gpDeviceInterface->SetRenderState(D3DRS_STENCILWRITEMASK, 0xFFFFFFFF);
   gpDeviceInterface->SetRenderState(D3DRS_ZWRITEENABLE, false);
   gpDeviceInterface->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
   gpDeviceInterface->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO);
   gpDeviceInterface->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

Step 2:  Build a polygon to represent the top plane of the box.  Render the polygon.


Step 3:  Render the terrain.

// According to Luna, the stencil buffer should be filled with 0x1 where the box "top" was
// rendered and 0x0 everywhere else.  So, LESSEQUAL should perform the stencil test on
// the entire scene/target
gpDeviceInterface->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_LESSEQUAL);

// If the test failed, replace the 0x0 with 0x1 so the terrain pixel will render

// If the test passed, keep the pixel
gpDeviceInterface->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);

// If the depth test failed, the pixel is behind the stencil, so reject it
gpDeviceInterface->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_ZERO);

// Draw the terrain and reset D3DRS_STENCILENABLE...

I don't think I'm grokking Luna, because at this point the only terrain that renders is what's under the box "lid" (i.e. the stencil mask).  Can anyone spot what might be going on?

atan2 inconsistencies

19 March 2014 - 12:19 PM



I'm using atan2 from math.h and I'm getting weird results.  I call it once using a set of parameters and I get the result of 0 degrees (which is correct), but when I call it again with the exact same parameters I get the result of -180 or +180 degrees.  Is this a known issue and are there work arounds?