Posted: 27th Jun 2007 8:06
I'm using a modified version (with alpha) of Evolveds Normal Mapping 2.0 Shader. On textures with hair maps I'm using 8Bit alphas which I then combine with the color map, saving as A8R8G8B8 or DXT5 .dds files. Previewed in the DirectX SDK texture tool the maps look as they should. Inside the engine however the alpha seems to be handled as 1bit solid or transparent without any transparency levels. The shader wasn't modified by me, but playing with the alpharef values just increased the solid area but didn't help fading the opacity.
I'm thankful for any suggestions and help. I included a hair mesh with textures + shader for testing, just in case anyone wants to try. Thanks !
Posted: 27th Jun 2007 12:33
Just had a quick look at the shader and media.

Two comments:

1. The alpha component is almost entirely black or white so it will behave almost like 1bit alpha.

2. The pixel shaders include the following:

+ Code Snippet
	AlphaTestEnable = true;
	AlphaFunc = Greater;
	AlphaRef = 170;


This will (I think) make sure that only the highest alpha pixels get rendered - and they will virtually all be full alpha looking at your media.

Taken together I guess these will make the alpha blending look like all or nothing.
Posted: 27th Jun 2007 16:16
1. The alpha component is almost entirely black or white so it will behave almost like 1bit alpha.

True, only the strands should be slightly transparent to make it less look like the edges have been chewed off. I tried the same thing with a mostly grey alpha map which should make the mesh mainly transparent. However as you suggest it was still solid.

I did look up the command AlphaFunc= and found this "The 'alphafunc' avoids pixels being rendered (and updating the Z-buffer) that are mostly transparent"
However without these 3 lines of code, objects (for example the head) that are beneath the alpha would appear transparent as well.
Posted: 28th Jun 2007 0:16
However without these 3 lines of code, objects (for example the head) that are beneath the alpha would appear transparent as well.


Yes, I know. I remember the discussion from a few weeks ago.

I'm not quite sure what the whole story is yet - perhaps the two parts interfere with each other or one cancels the other. I'll try to find out.

In the meantime, could you post (or e-mail) some short code which displays your model and media with the effect? [No need to do this now - see edits below.] I tried earlier today but couldn't get the shader to display anything except black for your object - even with just the "Ambient" technique and ambient colour set to full white. I probably made a silly error somewhere or was using the wrong texture stages.

Edit Dammit! Just realised that the hair IS black, so I probably was seeing it after all!! Will have another look now that my brain is showing signs of coming to life ...

Edit2 I see what you mean now. Will make enquiries tomorrow or Friday. In the meantime, could you post a text file version of your "hair.x" file in case there are some clues in there?
Posted: 28th Jun 2007 3:53
As requested I have attached a text version of the mesh. I have tried to find some hints through google, but so far I had no luck.
Thanks !
Posted: 28th Jun 2007 11:34
Thanks. I'll have a look later today.

The other thing I can try is to make my own object and apply your media and FX to it to see if the same problem occurs. At the moment I'm having difficulty getting any textures to show correctly on the object (the original binary version).


More news later hopefully.

Edit:

Done some more testing using my own objects and I can't see much wrong with the shader. I suspect part of the problem is that your alpha map is just too bright so that you only see the hair and not what is underneath. Try reducing the contrast in your alpha map and see if that helps - e.g. try making the alpha of the hair (not the black parts of the alpha map obviously) various shades of grey till you find the levels you need.

One thing I tried was to load multiple copies of the shader and apply different copies to each limb (I guess - but haven't checked - that your object consists of various limbs such as "hair", "face", "scarf", etc). This means you can use different techniques, with their own effect constants, on different limbs. For example, you probably don't need alpha-mapping on the head. That way you might be able to remove the alpha test from the hair.

Let me know how you get on.
Posted: 29th Jun 2007 14:38
@Irradic

Any more thoughts yet?
Posted: 29th Jun 2007 16:00
The problem is pretty well defined here:

http://ati.amd.com/developer/gdc/Scheuermann_HairRendering.pdf

It's way beyond my abilities to try and implement it though.
Posted: 29th Jun 2007 18:45
It's way beyond my abilities to try and impliment it though.


And probably mine too.

That's an interesting and thorough article, with convincing images, and it might be possible to implement it. Not sure, at first glance, how the hair strand idea differs from the normal mapping idea. I also noticed that it seems to talk about full opacity/transparency - which seems to be the opposite of what Irradic was trying to achieve. I guess it comes down to image resolution - with high resolution you can paint individual strands of hair (fully opaque) with gaps (fully transparent) between them, but with low resolution you might need semi-transparency to get a reasonable effect.

Looks like just the sort of thing that lends itself to a procedural texture/texture shader solution. Food for thought ...

@Irradic

I tried the same thing with a mostly grey alpha map which should make the mesh mainly transparent. However as you suggest it was still solid.


It wasn't solid when I tried it using my media and test object - I could see through the hair. Will try to knock up a demo with your object when I get home from work.
Posted: 29th Jun 2007 19:04
Hi, sorry for the late reply been out of town yesterday.
Anyway, I had a quick look at the pdf and that's pretty much how it should look like, and actually does loook like in the realtime viewer but not with the normal mappe inside the game. I have attached screenshots for you to see the difference. Both are the same meshes, same textures, which has a resolution of 2048x2048 while the hair area is aprox. 512x512 on the map. However the single 2048 map is just temporary. It will consist of 3-4 512x512 maps later on.I've tested the hair with an almost total transparent alpha, but the hair didnt show any transparency, It was still completely visible.
Realtime viewer -how it should look like

Ingame - how it looks like in-game with the shader


I think I will take a look at the hair pdf file. If it's a material shader and if the complete source is included, then it shouldnt be too hard to make the necessary changes to make it funktion in dbpro. I guess that would be something from which others could benefit as well.
Posted: 29th Jun 2007 19:31
Thanks for those images - they've given me a clear idea of the problem and something to aim for. I'll post back as soon as I can - but probably not today.
Posted: 30th Jun 2007 15:36
Irradic

I've played around with this problem but haven't got any real solutions yet - and am not convinced there is a simple answer (see the correspondence between myself and Paul Johnston some time back in the *.txt file in the attached zip file).

I've been using the attached demo which is a trimmed down version of your problem. As you can see, removing the alpha test lines in the shader restores the hair to its correct appearance. However, as you noted earlier the different sections of hair don't get rendered in the correct order so, although the "head" in the demo (the inner cube) is rendered correctly, the hair isn't when viewed from some directions. The alpha test doesn't help this at all and just creates a new problem as your images demonstrate. You'll see that I've disabled zwrite in the shader - comment out those lines and you'll see that one problem is solved and another emerges. I'm temporarily (I hope ) lost for ideas - but if anything else occurs to me I'll post back.

I vaguely recall that Chris K found a way of dealing with the render order issue but I have no further details yet (I'll e-mail him about it).

Perhaps one of the shader experts could offer an answer?
Posted: 1st Jul 2007 19:48
Thanks for giving it a try. You are right, if one problem is solved a new one arises. I was trying to get some clues from other shaders that have proper alphas, but didn't have much sucess there.
I hope we can find a solution to this problem sooner or later.
Thanks GG !
Posted: 2nd Jul 2007 2:04
I hope we can find a solution to this problem sooner or later.


So do I!

I've heard from Chris K now and it seems that his solution might work in principle - but I suspect there will be a serious performance hit if your object has many vertices (and it will take a fair bit of programming - but it IS do-able ). The basic idea is to trick DBPro into rendering the polys of your object in the right order (this cannot be achieved perfectly in complicated objects because some polys might intersect, etc). This is done by re-ordering the vertices of the object - apparently the vertex order determines the order of rendering. I'm not sure this is practical in real time though.

The essence of Chris's idea is used in the Volumetric Cloud Shader demo which he has just posted on the WIP board.

Food for thought though.
Posted: 2nd Jul 2007 6:32
So it's pretty much like as it is written in the hair rendering whitepaper.
The object has to be rendered from the inside out. If I understood correctly this is beeing achieved in the hair shader by 4 render passes.
Sad that such a seemingly simple thing proves to be so difficult to implement.
Posted: 2nd Jul 2007 9:38
I found the Hair rendering shader, it is actually one of the example shaders of ATI's Render Monkey. I'll see if I am able to do the necessary changes to make it work with DBPro. But at first glance it's quiet a lot code. I'll take a look once I have some more time on my hands. I attached the shader, just in case you are curious.
Posted: 2nd Jul 2007 14:22
The object has to be rendered from the inside out.


From back to front seems more likely.

If I understood correctly this is beeing achieved in the hair shader by 4 render passes.


I haven't looked at the example carefully, but I can see how that might work. If I get time I'll try to give it a go. You would probably need the new features that come with Dark Shader before you can make effective use of that idea.

Sad that such a seemingly simple thing proves to be so difficult to implement.


Indeed.

I'll see if I am able to do the necessary changes to make it work with DBPro. But at first glance it's quiet a lot code.


I find the RenderMonkey FX files are a real pain to work with - the first thing I always do is replace their various variable and function names by simple short names. That alone usually makes the files much smaller and more readable.

I know why RM uses naming conventions like "MyFirstShader_MyFirstTechnique_MyFirstPass_PixelShader()" and "MyFirstShader_MyFirstTechnique_MyFirstPass_VertexShader()" - but it is very tiresome for those of us who want to work with single shaders manually.

The next thing is to remove all the redundant code and comments which are not used. Then you can actually see what you're doing. Good luck.

[But the RM demos do work nicely - and if you have the patience they are a useful source of ideas.]
Posted: 3rd Jul 2007 0:22
I find the RenderMonkey FX files are a real pain to work with
Indeed, the naming conventions are insanely long.
So far I find it easier to convert shaders from NVidia's FX Composer. Anyway, the hair that came with the example looks really great. Hope I can manage to get it working, it would be worth the effort.