Jump to content
  • Advertisement
Sign in to follow this  
conman

blending problem? [solved]

This topic is 4737 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

Hi, in the last days I posted some question that occured to me while working on my project, and this forum was always a big help and I want to say thanks that!! And I have a question again :) What I have now seems to be a small blending problem... Here you see a test scene for my zFail stencil shadow rendering - there are many things that are not rendered correctly, for example the plane I marked with a arrow should be opaque: But the blending states seem to be ok:
  // disable writing to color buffer
      device.SetRenderState( RenderStates.AlphaBlendEnable, true );
      device.SetRenderState( RenderStates.SourceBlend, (int)Blend.Zero );
      device.SetRenderState( RenderStates.DestinationBlend, (int)Blend.Zero );
           
      // diable lighting
      device.SetRenderState( RenderStates.Lighting, false );
      
      // depth (write and test)
      device.SetRenderState( RenderStates.ZEnable, true );
      device.SetRenderState( RenderStates.ZBufferWriteEnable, true );

      // stencil off
      device.SetRenderState( RenderStates.StencilEnable, false );

      //clear stencil buffer
      device.Clear( ClearFlags.Stencil, System.Drawing.Color.Black, 1.0f, 0 );
  
      System.Diagnostics.Trace.WriteLine("RENDERING: Pass 0 - zFill");
      this.passes[0].Render( device );

      //disable lighting 
      device.SetRenderState( RenderStates.Lighting, false );
 
      //turn on stencil buffer
      device.SetRenderState( RenderStates.ZBufferWriteEnable, false );
      device.SetRenderState( RenderStates.StencilEnable, true );
      device.SetRenderState( RenderStates.TwoSidedStencilMode, true );
      
      device.SetRenderState( RenderStates.StencilFunction, (int)Compare.Always );     
      device.SetRenderState( RenderStates.CounterClockwiseStencilFunction, (int)Compare.Always );
      device.SetRenderState( RenderStates.CounterClockwiseStencilZBufferFail, (int)StencilOperation.Increment );
      device.SetRenderState( RenderStates.StencilZBufferFail, (int)StencilOperation.Decrement );

      device.SetRenderState( RenderStates.CullMode, (int)Cull.None );

      //render the shadow volume geometry once to the stencil buffer
      System.Diagnostics.Trace.WriteLine("RENDERING: Pass 1 - Shadow");
      this.passes[1].Render( device );

      //reset any necessary states
      device.SetRenderState( RenderStates.TwoSidedStencilMode, false ); 

      //alter stencil buffer
      device.SetRenderState( RenderStates.StencilFunction, (int)Compare.GreaterEqual);
      device.SetRenderState( RenderStates.StencilPass, (int)StencilOperation.Keep );


      //turn on colour buffer
      device.SetRenderState( RenderStates.AlphaBlendEnable, true );
      device.SetRenderState( RenderStates.SourceBlend, (int)Blend.One );
      device.SetRenderState( RenderStates.DestinationBlend, (int)Blend.Zero );

      device.SetRenderState( RenderStates.ZBufferWriteEnable, true );
      device.Clear( ClearFlags.ZBuffer, System.Drawing.Color.Black, 1.0f, 0 );
    
      device.SetRenderState( RenderStates.Lighting, true );
      
      System.Diagnostics.Trace.WriteLine("RENDERING: Pass 0 - Paint Scene");
      this.passes[0].Render( device );
     
      //reset any necessary render states
      device.SetRenderState( RenderStates.StencilEnable, false );







Any ideas? Constantin [Edited by - conman on June 9, 2005 7:45:00 AM]

Share this post


Link to post
Share on other sites
Advertisement
This is more based on having spotted that the handle of the teapot appears to be partially showing "through": What are your zNear/zFar values? (for a projection matrix).

At least for the aforementioned observation, depth buffer resolution/config issues are quite possible. Might well be that it'd solve your other problem as well [smile]

hth
Jack

Share this post


Link to post
Share on other sites
Yes you are right, the handle is messed up too, but I guess the zNear/zFar is not the problem:

newDevice.Transform.Projection = Matrix.PerspectiveFovLH( 1.3f, ratio, 1.0f, 1000.0f )

also if I set zFar to 100.0f I get the exact same results...

Constantin

Share this post


Link to post
Share on other sites
whats the accuracy on your depth stencil?
i had a likley problem, and when i increased the stencil accuracy from 16 bits to 24 bits it worked..

Share this post


Link to post
Share on other sites
I use D24S8, so I have a 8 bit stencil buffer which should be sufficient.

I don't think that's the problem... also I guess my card only supports up to 8 bits stencil.

Share this post


Link to post
Share on other sites
Quote:

Are you mixing VS and FFP in different passes?


No, this is all done with FFP.

I updated the picture above. It is weird, if I comment out this 2 lines

device.SetRenderState( RenderStates.StencilFunction, (int)Compare.GreaterEqual);
device.SetRenderState( RenderStates.StencilPass, (int)StencilOperation.Keep );

I get a perfectly opaque rendered image (without shadow of cause), but if I uncomment these, I get this transparent plane (only one of both planes is transparent)

any ideas? I am completely clueless

Constantin

Share this post


Link to post
Share on other sites
Have you checked your shadow volume extrusion code? Maybe you're incorrectly drawing that which is leading to some odd values in the stencil buffer...?

Jack

Share this post


Link to post
Share on other sites
For testing I render only another translated sphere as my shadow volume.
So I guess ther is no problem.

If I render with Compare.Less I render exactly only the geometry inside the shadow volume. My reference is 0, so the picture above for Compare.GreaterEqual is fine, except for the transparent plane.

But what transparency effects can odd values in the stencil buffer have?
Is there maybe a connection I don't know?

Thanks,
Constantin

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!