Skip to main content
Update info on alpha blending
Source Link
OriginalDaemon
  • 3.5k
  • 19
  • 20

Transformation In Batching

When the geometry your batching is simple enough - such as with sprites where only 4 vertices are used - you usually translate to a shared coordinate system before putting the vertices in a batch. Often this is camera space or screen space.

The simplicity of the geometry means that doing this operation CPU side is still a negligible process and is easily parallelised. As the geometry becomes more complex the cost/benefit ratio drops and suddenly separate draw calls looks more appealing.

One solution to this, which I haven't tried, is to supply your vertex shader with the worldview matrix for each mesh your batching and tag each vertex with an id so you know which one to use for each vertex.

Alpha Blending

I'm not quite sure what you mean by "achieve depth" but as far as I know. You can still leave depth testing and writing to the depth buffer is never filled when renderingturned on in this instance but this would cause transparent geometry (when blending is on)to occlude other geometry unless the other geometry was drawn first. The reasonIn other words a window might stop some things being thatdrawn to the screen. For more information check out this article by Shawn Hargreaves.

So it's typical, when drawing transparent geometry, to disable writing to the depth buffer is used to reject occluded, but keep depth testing active. This means the transparent geometry before doing a fragment shader pass on it and blendedcan still be occluded by opaque geometry can'tbut will not occlude anything itself. You have to be careful though, if you draw the transparent geometry, without writing to the z-buffer, then draw opaque geometry, you might end up drawing over the top.

Imagine drawing a skybox and then a window. If you drew a tree behind the window later with no alpha blending it would be drawn over the top of the window.

As Shawn states;

The most common approach:

  1. Set DepthBufferEnable and DepthBufferWriteEnable to true
  2. Draw all opaque geometry
  3. Leave DepthBufferEnable set to true, but change DepthBufferWriteEnable to false
  4. Sort alpha blended objects by distance from the camera, then draw them in order from back to front

Transformation In Batching

When the geometry your batching is simple enough - such as with sprites where only 4 vertices are used - you usually translate to a shared coordinate system before putting the vertices in a batch. Often this is camera space or screen space.

The simplicity of the geometry means that doing this operation CPU side is still a negligible process and is easily parallelised. As the geometry becomes more complex the cost/benefit ratio drops and suddenly separate draw calls looks more appealing.

One solution to this, which I haven't tried, is to supply your vertex shader with the worldview matrix for each mesh your batching and tag each vertex with an id so you know which one to use for each vertex.

Alpha Blending

I'm not quite sure what you mean by "achieve depth" but as far as I know the depth buffer is never filled when rendering transparent geometry (when blending is on). The reason being that the depth buffer is used to reject occluded geometry before doing a fragment shader pass on it and blended geometry can't occlude anything.

Transformation In Batching

When the geometry your batching is simple enough - such as with sprites where only 4 vertices are used - you usually translate to a shared coordinate system before putting the vertices in a batch. Often this is camera space or screen space.

The simplicity of the geometry means that doing this operation CPU side is still a negligible process and is easily parallelised. As the geometry becomes more complex the cost/benefit ratio drops and suddenly separate draw calls looks more appealing.

One solution to this, which I haven't tried, is to supply your vertex shader with the worldview matrix for each mesh your batching and tag each vertex with an id so you know which one to use for each vertex.

Alpha Blending

I'm not quite sure what you mean by "achieve depth". You can still leave depth testing and writing to the depth buffer turned on in this instance but this would cause transparent geometry to occlude other geometry unless the other geometry was drawn first. In other words a window might stop some things being drawn to the screen. For more information check out this article by Shawn Hargreaves.

So it's typical, when drawing transparent geometry, to disable writing to the depth buffer, but keep depth testing active. This means the transparent geometry can still be occluded by opaque geometry but will not occlude anything itself. You have to be careful though, if you draw the transparent geometry, without writing to the z-buffer, then draw opaque geometry, you might end up drawing over the top.

Imagine drawing a skybox and then a window. If you drew a tree behind the window later with no alpha blending it would be drawn over the top of the window.

As Shawn states;

The most common approach:

  1. Set DepthBufferEnable and DepthBufferWriteEnable to true
  2. Draw all opaque geometry
  3. Leave DepthBufferEnable set to true, but change DepthBufferWriteEnable to false
  4. Sort alpha blended objects by distance from the camera, then draw them in order from back to front
Source Link
OriginalDaemon
  • 3.5k
  • 19
  • 20

Transformation In Batching

When the geometry your batching is simple enough - such as with sprites where only 4 vertices are used - you usually translate to a shared coordinate system before putting the vertices in a batch. Often this is camera space or screen space.

The simplicity of the geometry means that doing this operation CPU side is still a negligible process and is easily parallelised. As the geometry becomes more complex the cost/benefit ratio drops and suddenly separate draw calls looks more appealing.

One solution to this, which I haven't tried, is to supply your vertex shader with the worldview matrix for each mesh your batching and tag each vertex with an id so you know which one to use for each vertex.

Alpha Blending

I'm not quite sure what you mean by "achieve depth" but as far as I know the depth buffer is never filled when rendering transparent geometry (when blending is on). The reason being that the depth buffer is used to reject occluded geometry before doing a fragment shader pass on it and blended geometry can't occlude anything.