Depth Check on produces fragments

Problems building or running the engine, queries about how to use features etc.
Post Reply
timmeey
Gnoblar
Posts: 3
Joined: Fri Dec 15, 2017 9:36 pm

Depth Check on produces fragments

Post by timmeey »

I'm trying to draw a couple of transparent cuboids which intersect each other. The camera is allowed to orbit freely around the center of the scene.
Initially, I got the following result (I set an alpha of 1.0 in these examples since my problem is visible more clearly in this case, the problem still remains with an alpha of e.g. 0.5, it's just harder to see in some cases).

There are two problems here:
  • The cuboids are drawn in the wrong order; each cuboid should be painted above all cuboids to its right.
  • The wireframe of the cuboid (which is a part of the mesh) is fully visible, even if it is on the back side.
After reading a couple of API pages and forum posts, I turned Depth Check on in the material file and got the following result:

This definitely fixes the draw order, but there are still parts visible which shouldn't be. How can I resolve this issue?
Note: I also tried Depth Writing, but it seems to behave just like Depth Checking in this case.
Further Note: The objects are manual objects which were converted to entities and they are all in the same render group (and should be)

I am using Ogre 1.9 with the Direct3D9 rendering engine. Other options are not viable since I need to display 3D graphics over a remote desktop connection to Hyper-V machines on a server without a GPU (yay).

The shader I'm using in the second example:

Code: Select all

vertex_program SampleVertexProgram hlsl
{
	source SampleVertexProgram.hlsl
	entry_point mainVertexProgram
	target vs_2_0
	default_params
	{
		param_named_auto worldviewproj_m worldviewproj_matrix
	}
}

fragment_program SampleFragmentProgram hlsl
{
	source SampleFragmentProgram.hlsl
	entry_point mainFragmentProgram
	target ps_2_0
	default_params
	{
		param_named_auto objectColour custom 0
	}
}

material SampleMaterial
{
	technique
	{
		pass
		{
			scene_blend alpha_blend
			depth_check on
			
			vertex_program_ref SampleVertexProgram
			{
			}
			
			fragment_program_ref SampleFragmentProgram
			{
			}
		}
	}
}
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5298
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: Depth Check on produces fragments

Post by dark_sylinc »

What you're trying to render is a complex problem that has no easy solution.

Alpha blending is order dependent, back to front, and your cubes would require switching order several times, in order to be rendered correctly. The solutions are:
  1. Use a blending mode that isn't order dependent, such as additive blending
  2. Use an OIT algorithm such as Weighted Blend Transparency or Linked lists (this is an advance topic)
  3. Split the cubes into two, so that the parts that are inside can be rendered in a different order from the parts outside
Post Reply