Jump to content
  • Advertisement
Sign in to follow this  
sepul

Multipass artifacts

This topic is 4760 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using multipass to render an effect on a mesh. pass #1 - mesh is normally rendered pass #2 - same mesh is rendered using different shader (effect), with these states :
	_device->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
	_device->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );

	_device->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
	_device->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
but when you get close to the objects there are some annoying artifacts due to z-fighting. the depth of z-buffer is 16bit and when I increase the depth I get more artifacts. what should I do to fix this multipass problem ?

Share this post


Link to post
Share on other sites
Advertisement
Set the zfunction to D3DCMP_EQUAL. This will have the added advantage of speeding up the render time as unseen items will not be rendered - you'll essentially have done a depthfill pass.

Share this post


Link to post
Share on other sites
You need to be sure to send the exact same geometry in the exact same order to avoid all z fighting artifacts.

Also, if pass one is triangle strips, then pass two must also be triangle strips, no mixing lists & strips.

I have not experienced any issues making pass 1 an indexed triangle list and pass 2 a non-indexed triangle list.

Share this post


Link to post
Share on other sites
Quote:
Original post by Source
Set the zfunction to D3DCMP_EQUAL. This will have the added advantage of speeding up the render time as unseen items will not be rendered - you'll essentially have done a depthfill pass.


I would better go with D3DCMP_LESSEQUAL or D3DCMP_GREATEREQUAL, because assuming that 2 values in such unprecise z-buffer will equal is a bit odd :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

You can also disable Z-writes for the second (and third etc) pass.

Share this post


Link to post
Share on other sites
I've found the solution, by disabling z-writes and setting the z-function to ALWAYS :

_device->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
_device->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
_device->SetRenderState( D3DRS_ZFUNC, D3DCMP_ALWAYS );


thanks

Share this post


Link to post
Share on other sites
First off, two triangles rendered with the same transformations will be exactly the same in depth - so using an equal depth function will work perfectly - otherwise techniques such as depth fill passes would not work.

Also using D3DCMP_ALWAYS is essentially turning off depth-buffering, and you will probably get some weird visual artefacts as your object turns, unless you're rendering totally concave and back-face culled objects such as spheres.

Share this post


Link to post
Share on other sites
that was a good point "source", but I have tested with z-function = EQUAL, and I got the same artifacts, and meshes are exactly the same.
but luckily I have found the problem to the z fighting problem, the point is when I render the mesh in the first pass, vertex shader has WorldViewProjMatrix as input paramter and transform the vertex. and in the second pass, there is another vertex shader that has world, view and projection matrix seperated and multiplies them itself, and then transform the vertex.
here will rise a precision point problem, cuz I think the matrices that I multiply on the CPU are a little different than when multiplied on GPU.

Share this post


Link to post
Share on other sites
Quite possibly - you could try adding a small depth bias to your second pass to help it along a little by using D3DDevice->SetRenderState() with the D3DRS_DEPTHBIAS state (or this can be done inside an effect file) - or concatenate the transforms in both instances the same way (if you're currently using FFP for the first mesh you could use a dummy vertex shader which creates the transform - this will be slower but not by a great amount).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!