Game Development Community

Has someone encontered this problem?

by ChenJian · in Torque Game Engine Advanced · 07/10/2007 (2:42 am) · 4 replies

Problem 1:

I got a tree dts from the network, and I'd like to apply this model into my mission. This tree uses a dds texture to render its trunk and branches, the texture like this:

lh4.google.com/chenjianjack/RpNKSYyPlLI/AAAAAAAAAC4/FGtUe11eUoo/trunk.JPG
I add a Materials.cs file alongside this texture inorder that this model can take the translucent effect. First I write this:

new Material(trunk2)
{
baseTex[0] = "trunk2.dds";
};

And I get a screenshot like this:

lh4.google.com/chenjianjack/RpNKMYyPlJI/AAAAAAAAACo/ZVH4_evK2RE/black.JPG?imgmax=800
It is obviously that the branches do not get a translucent effect. And I rewrite the materials.cs file like this:

new Material(trunk2)
{
baseTex[0] = "trunk2.dds";
translucent = true;
translucentBlendOp = AddAlpha;
};

The screenshot becomes as follows:

lh6.google.com/chenjianjack/RpNKQ4yPlKI/AAAAAAAAACw/dWVKihJGnaw/strange.JPG?imgmax=800
Ok, The branches do take the translucent effect, however, the trunk also becomes translucent, it looks so strange.Could anyone can tell me how to fix this problem?

Problem 2:
This time I want to place an fish model into a pool, the fish model usese two png file as its skin. First I did not add the materials.cs file and after I placed the model into the pool, I can see the fish upon-water, as follows:

lh4.google.com/chenjianjack/RpNTnYyPlMI/AAAAAAAAADE/25Lo4uibpd0/fish.JPG?imgmax=800
Inorder to apply the translucent effect, I then add a materials.cs file which is wroten like this:

new Material(goldenshinera)
{
baseTex[0] = "goldenshinera";
translucent = true;
translucentBlendOp = LerpAlpha;
};

This brings a big problem : I can not see the fish upon-water any more, although I can see it underwater and it do take the translucent effect.

lh6.google.com/chenjianjack/RpNTq4yPlNI/AAAAAAAAADM/_pQ2ZuDssQg/see.JPG?imgmax=800
Thanks, and any idea is grateful.

#1
07/10/2007 (9:42 am)
The first one is because it applies the Transparency to the entire DDS texture file. Try separating the leaves and trunk into separate textures, or assign them as different materials in the modeling program then use the "mapTo" field on the Material entry to specify which part gets the Transparency.

I'm not entirely sure about the 2nd problem, but try turning the "transluscentZWrite" flag to TRUE and see what you get there. I'm thinking it's probably a Z sorting issue.
#2
07/10/2007 (10:12 am)
Re" problem 2

It may be possible using shaders to do certain kinds of transparency that don't require z-sorting, but generally with realtime graphics, transparency is faked using alpha blending which requires that transparent objects be drawn in farthest-to-nearest order. A big downside of this is that a transparent object cannot be both in front of and behind an object at the same time. This situation comes up when dealing with water. The water surface is one big transparent object. If you want to half-submerge a transparent object in the water, then what you want is to have your object in front of and behind the water surface at the same time and this is not possible.

In games where this comes up a lot, it's possible to use two objects for each half-submerged object, and very carefully manage drawing order and z-buffer value setting. Basically, underwater transparent objects are drawn first, then water, then above water transparent objects and you do something special with setZWriteEnable() that I can't precisely recall. (I did this several years ago for a non-torque based fishing game.) If camera goes under water, you have to switch the order around.

It is possible to make this work, but unless half-submerged transparent objects are a real common feature in your project, it's not worth it. You're better off keeping your fish submerged, or building a fish that doesn't require transparent textures.
#3
07/10/2007 (7:48 pm)
Thanks, Mark and Jeff, I have solved the first problem by accident. In the materials.cs file, I just add this statement:
emissive[0] = true; And then the problem went away with a surprise.

Jeff, I do not clearly understand your mean. Is that to say only half-submerge will bring in this issue? But when the fish whole-submerged in the water, I still can not see it. Maybe you are right, the best way is not to build a fish with transparent textures, and it seems as if I can only do that at present :)
#4
07/10/2007 (8:23 pm)
The water has collision right? Could you not script a change in model for above water and below water. Is that kind of what Jeff is getting at? or maybe you can do it with one...I understand what Jeff is saying, im assuming that is because the way rendering is set up for the water, he mention the ordering in-which things get rendered. I'm just a beginer programmer but I'm sure a you can write a shader that will render what you need and in what order you need it rendered....on the other hand it seems like a lot of work for fish:)