brian_tsim

Hi All,

I tried to draw few meshs in game. But i has some textures problem. The problem is a meshs collistion another mesh, textures alpha chennal has some problem. Below is capture screen. Who can tell me why How to fix this problem

http://hk.geocities.com/brian_tsim/error.PNG

Best regards,




Re: Game Technologies: General Mesh Alpha chennal problem?

Inaki Ayucar

Well, I think youí»re talking about the transparency issues in the borders of the Chinese (sorry if ití»s not chinese) characters. Arení»t you Thatí»s a common problem with using alpha blending.

As I see in your picture, you are using Alpha Testing to discard the parts of the texture you doní»t want to render. That one is a binary operation, in which pixels are accepted or rejected, basing on a comparing function (>, <, etc). Thatí»s fine and works flawlessly, but you are also using alpha blending to make the borders of the texture smoothly disappear with an alpha gradient. Arent you

Whe you use alpha blending, you have to deal with the drawing order, because the blend operation performs a mix up of the color of the pixels that ití»s going to render with the previously stored in the frame buffer. Thatí»s why the rendering order matters.

To workaround the problem, you can do two things:

1.- Doní»t use alpha blending (obviously), only alpha testing, which will produce harder borders. You can improve the result using higher resolution textures.

2.- Ensure that render first every object without transparencies (alpha blending). Then render alpha blended objects, from back to front (first the ones that are farther from the camera). This implies using a sort function based on the distance to the camera.

Hope this helps.






Re: Game Technologies: General Mesh Alpha chennal problem?

brian_tsim

Hi Inaki Ayucar

Yes, I am hong kong people, So my english not very well. ^_^

I tried disenable all alpha blending. But the texture alpha chennel to be change black color . below is capture screen. Please help.

http://hk.geocities.com/brian_tsim/error1.PNG

Best Regards,






Re: Game Technologies: General Mesh Alpha chennal problem?

Inaki Ayucar

What I can guess from that picture is that the alpha channel of your textures have a gradient (from white to black) in the border of the areas to render. Is that correct

As I told you, when you do the Alpha Test, a binary comparison is done between the alpha value of each pixel and a reference value, in order to decide if the pixel will be rendered or not. You can configure both the comparison function and that reference value ( > 0, >= 0, < 1, <= 0.5, whatever... Check the AlphaRef render state of the device)

Your problem is that your current alpha test operation is allowing some pixels to be drawn when they shouldní»t have been. You have two ways of fixing it:

1.- Play around with the reference value you are using for the Alpha Test comparison. You can try to put a higher or lower value and you will see how the black area grow or shrink. This one may fix your problem completely or not, depending on how your textures are done.

2.- Anyway, you should fix your textures, in photoshop or whatever. You should make the the alpha gradient of the borders inside the drawable parts of the texture. In other words, do not let the gradient go into the black areas of the bitmap, keep it always in the parts than can be rendered, so the alpha value is always zero in the black parts of your bitmap.

Im not sure to have been too clear. Is a bit difficult to explain this without pictures.

Please ask if you doní»t understand something.






Re: Game Technologies: General Mesh Alpha chennal problem?

brian_tsim

Hi Inaki Ayucar,

Sorry, I not very understand how to set alpha ref using c# Can give few example to me Below is my enable alpha test codeing.

renderer.Device.RenderState.AlphaTestEnable = true;
renderer.Device.RenderState.AlphaFunction = Compare.NotEqual;

Best Regards,






Re: Game Technologies: General Mesh Alpha chennal problem?

Inaki Ayucar

Sure ! Here it goes...

sorry, yesterday I said AlphaRef.... Ití»s ReferenceAlpha:

this.sampleFramework.Device.RenderState.ReferenceAlpha = 0x08; // Hexadecimal representation of 60

this.sampleFramework.Device.RenderState.AlphaFunction = DX.Direct3D.Compare.Greater;






Re: Game Technologies: General Mesh Alpha chennal problem?

brian_tsim

Hi Inaki Ayucar,

Yes, i success render normal image, Thanks.






Re: Game Technologies: General Mesh Alpha chennal problem?

Inaki Ayucar

You are very welcome.

If it helped, could you please mark my post as "answer"

Thanks a lot






Re: Game Technologies: General Mesh Alpha chennal problem?

Inaki Ayucar

Sorry,

Ií»ve seen in the example above, it says "hexadecimal representation of 60".

Obviously thatí»s not 60, ití»s an old comment. Just ignore it.

Thanks again.






Re: Game Technologies: General Mesh Alpha chennal problem?

SoopahMan

Thanks so much for explaining that! I have seen this drawing issue in game after game after game - Grand Theft Auto: San Andreas is a mess with this issue if you enable Anti-Aliasing.

So the rendering order would go like this to solve it:

1) Render all non-alpha-blended objects in the normal rendering order, which is front-to-back with Z-culling to avoid drawing unnecessary pixels, then

2) Render all alpha-blended objects back-to-front (reverse), potentially rendering the same pixel over and over again even when that area may be opaque - but importantly, rendering any alpha-blended pixels blended on top of each other.

If anti-aliasing is enabled, the edges of even opaque objects could present an issue here, no Or will the anti-aliasing just be repeated wherever the second-stage alpha-blended objects hit an anti-aliased pixel (may be very frequent...), with no visual errors




Re: Game Technologies: General Mesh Alpha chennal problem?

Inaki Ayucar

Youí»re welcome

About your point 2, yes you are right. The Z Buffer wont optimize much if you render from back to front, but is the only way to do alpha-blending properly, because the API blends between the current drawing object and the contents of the Frame Buffer.

Im no expert on anti-aliasing but, as fas as I know, it should not be affected by drawing order.

Regards,






Re: Game Technologies: General Mesh Alpha chennal problem?

SoopahMan

There is one more thing to consider here - in Quake 3, the Rocket Launcher left a trail of smoke which was represented by many - potentially a hundred - transparent smoke animations arranged in a line. If the player fired a rocket these all stacked on top of each other and the game would get progressively slower as the rocket made more and more smoke images all stacking. They rendered perfectly - probably using this back-to-front alpha blend approach - but each time you fired a rocket at long range and remained in place the game would slow to a crawl.

So, rendering back to front solves one problem but introduces a new one - a performance hit due to loss of z-culling.

Probably the best solution to the secondary problem is, for something as simple as a rocket trail, maintain the trail as a group and render it based on perspective, showing more blended images if the trail is parallel with the user's viewplane and less if it's perpendicular.

If you have a more complex scenario - for example say, the player is fighting a room full of transparent ghosts - you have a much harder problem to solve.

It's common to render the branches of a tree with alpha-blending to simplify the polygonal model, so rendering a forest could quickly run into this same "room full of ghosts" performance problem. I'm not sure how you'd solve that one.




Re: Game Technologies: General Mesh Alpha chennal problem?

Inaki Ayucar

Well, Ií»m not so sure the performance hit is due to the lack of ZBuffer optimization. Yes, that will have an impact, but not so much. The slowness you experimented is probably due to the costly alphaBlend operation.

Anyway, In my engine, Ií»ve got thousands of trees, sorted and rendered in back to front with alpha blending, and it runs fine.






Re: Game Technologies: General Mesh Alpha chennal problem?

SoopahMan

Yes, admittedly I haven't run Quake3 on modern hardware; perhaps today's hardware is fast enough for something a bit slower like this to work just fine.

Do those alpha-blended trees tend to stack (visually) a great deal Causing one pixel to have say 20 alpha blends to do to render the 1 pixel Or does the tree scenario result in much more controlled situations (a stack of 4 at most for a given pixel, say)

I'd play with this in code more but I'm off in DirectInput land right now... .




Re: Game Technologies: General Mesh Alpha chennal problem?

Inaki Ayucar

Hi,

No, Im not controlling at all how many trees are rendered one in the top of each other. I just distribute thousands of trees randomly in areas, and sort them from back to front every frame. They work great because it doesní»t matter how many trees are rendered. In fact, for each tree, an alpha blend operation with two operants is done. The first one is the tree being rendered and the second one is the contents of the frame buffer, regardless a thousand trees were rendered before.

Regards,