Page 1 of 1

Proper transparency for leaves and grass

PostPosted: Sat Jun 04, 2011 4:03 am
by tachzusamm
You know, we can't just model trees or grass with separated leaves, one by one: the Age would explode (I mean: lag) because of too many verticies.
So to get a dense vegetation, one should put an image of many leaves on a plane, containing an alpha channel for the transparent parts between the leaves, and place these planes either crossed (like an X) or circled (like an O) into the Age. Many of such planes. This is how Cyan does it as well. For example, in Relto, Eder Tsogahl, or Siralehn.
An example is shown here in the Wiki: http://www.guildofwriters.com/wiki/Planting_Some_Grass

Well, that's the theory. I never got this looking good, for months. It drove me totally crazy.

First, you may say: "Hey, that's obvious. Instead of ZTransp and Zoffs, now PassIndex in the Object Panel should be used for PyPRP 1.6!"
You're right, that's true. And you are right as well, if you recommend reading the "Managing Transparent Objects" chaper in the Wiki: http://www.guildofwriters.com/wiki/Mana ... nt_Objects

But, still, it did not look good for me. Even the wiki-chapter "Alpha Textures Removing Edge" did not really help much in my case. When we avoid the ZTransp setting, sometimes the leaves get surrounded with a shimmery border. Let's call this "alpha artifacts". It seems that at the boundary between the opaque part (the leave) and the transparent part, the alpha value influences the faces behind as well - which lets the background shine through our plants.

Here's an example:
Img1_Before.jpg
Img1_Before.jpg (80.18 KiB) Viewed 2950 times


Now, if we re-enable ZTransp and set some Zoffs, this effect is gone (well, mostly) - but now the planes are no longer sorted by Plasma in URU! The camera then renders leaves behind front leaves sometimes in front of them, which looks ugly.

Now you may say, that's just the limitations of computer graphics, or at least Plasma; and I began to believe this as well.
BUT. Have a look at Eder Tsogahl, or Siralehn. There is plenty of grass, without problems, just looking pretty good.

So is this just because those are Cyan Ages, and we have no chance to look behind the curtains? I decided to not believe that, did some research (well, lots of), and today I found the trick.
It's just a flag in the Blend Flags, which is named "kBlendAlphaTestHigh" (0x4000000).
This flag was set for the grass in Siralehn, but never in any of my exports.
Unfortunatelly PyPRP never sets this flag, and it does not have any of Blender's properties assigned to it.

So, I used PRPShop to set the flag "BlendAlphaTestHigh" manually after export - and that did it:
Img2_After.jpg
Img2_After.jpg (73.38 KiB) Viewed 2950 times



But beeing lazy, I did not want to patch my Age each time manually, so I patched the PyPRP sources a bit.
I think the best way to map this flag to is the property "premul" in the Image panel (Texture => Image => Premul), because:
a) it belongs to / influences exacly that image, and
b) it's exacly the same button (Premul) you have to use in Blender when you experience similar effects when rendering a scene,
c) it was previously unused and does not change anything in existing Ages, because it defaults to unchecked.

If you like, you can use this patched version of prp_MatClasses.py to replace the one in the official PyPRP 1.6:
prp_MatClasses.zip
(22.74 KiB) Downloaded 399 times

(this is based on the latest prp_MatClasses.py from Trunk, just added the alpha artifacts patch)

If it still does not come out as you expect - I used these setting for the other panels:
ZTransp: OFF, Zoffs: 0.00
Material: Shadeless
Object: PassIndex 3
Object- Draw: Transp ON

Happy blending, umm, Age Writing,
tach


(I hope this switch will be available in the new PyPRP 2 as well. Developers: Hint, hint! Please.)

Re: Proper transparency for leaves and grass

PostPosted: Sat Jun 04, 2011 6:56 am
by Corvus
Awesome! Your 2nd picture looks exactly like I tried in vain to make my plants look. This will make many age builders very happy I guess. Will have to try your fix as soon as possible. Thank you.

Re: Proper transparency for leaves and grass

PostPosted: Sun Jun 05, 2011 2:32 am
by diafero
Nice detective work :)

Re: Proper transparency for leaves and grass

PostPosted: Sun Jun 05, 2011 3:38 am
by Rabenschwinge
Great! That solves a lot of problems!
While inspecting ages, I´ve found this problem over and over again, many ages have it - and the writers aren´t really responsible for it, right? :D

A question to the PyPRP-developers: would it be possible to publish a new version of PyPRP 1.x, so that we all have a working solution, until 2.0 is ready?

Re: Proper transparency for leaves and grass

PostPosted: Sun Jun 05, 2011 10:56 pm
by ametist
Great work tach, thanks a lot!! :) Now to implement it /me rubs hands together

Re: Proper transparency for leaves and grass

PostPosted: Fri Jun 17, 2011 7:41 am
by Calena
I downloaded and implemented the your patch last night. What a fabulous tool :P . It worked like a charm. Thank you, thank you, thank you :) :) :) .