Sign in to follow this  

Is there a way to use alpha in .X files? Continued quest for random trees

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

Hello. Once again thanks for reading this. I want to create an .x file with a single plane, a texture w/ alpha, and NO materials. Am I out of my mind? Any ideas on how I would do this? I'm trying to create some realistic trees. I've been exploring methods for creating random trees and so far I keep winding up in places where I really don't want to go. I've looked at: 1. Hundreds of randmon billboards, copying the MS DX billboard sample. These look like crap from directly overhead and because they are not meshes (they are quads) it looks like collision detection is going to be a pain and I can't include them easily in my mesh array. 2. Low poly tree meshes...I don't have the patience or the artistic skill to make them and I can't find anything free on the net. 3. Turning the billboards in #1 into meshes, but then I have to manually manipulate all the vertex buffers, index buffers, and attribute tables (?), most of which I don't really understand and the damn trees are a minor comoponent of my game and I'd like to finish them some time this LIFE. 4. Creating the random billboards and writing them all to one big mesh, but this still entails all of the problems listed in #3. 5. So now I'm looking at either creating a bunch of varying sized and colored trees with .X files, or creating .X files with 2 or 3 different meshes and accessing the vertex buffer to randomize the size and color. Again, just like the DX Billboard sample, but with collision detection. Comments, suggestions, and even public humiliation would be MOST welcome. Thanks again.

Share this post


Link to post
Share on other sites
Quote:
Original post by danromeo
I want to create an .x file with a single plane, a texture w/ alpha, and NO materials. Am I out of my mind? Any ideas on how I would do this? I'm trying to create some realistic trees.

Well that's easy. What is the problem? I'm not sure I understand what you mean, no materials. And I don't know if an alpha-textured-plane will look extremely realistic, but that's how a lot of games do it. You could always create branches+leaves with the planes, and randomly build the trees with those. That's how I plan to do it, minus the random part.

The biggest pain is sorting the transparent quads. Do you already have support for that in your engine? That amount of work makes the rest look pretty easy.

Share this post


Link to post
Share on other sites
Jiia, thanks for the reply, and thanks for letting me know how easy it is....but can you give me some subtle hint as to HOW to do it? So far all of my efforts have only created a black box.

Share this post


Link to post
Share on other sites
Quote:
Original post by danromeo
Jiia, thanks for the reply, and thanks for letting me know how easy it is....but can you give me some subtle hint as to HOW to do it? So far all of my efforts have only created a black box.

I was trying to ask what part you're having trouble with. I mean you explained the whole process of creating trees, 5 different ways. Where is your trouble when just loading in a plane with an alpha mapped texture?

Alpha textures are no different than normal textures, when using D3DX. Just set alpha-enabled to true and render it. You will have to sort them, but the results can be seen without that effort. Nothing on the plane must be modified. It's all in the texture and it's states. You can use a single plane, and just modify it's scale (and possibly it's uvs) to make different branches.

What part is giving you trouble? [disturbed]

Share this post


Link to post
Share on other sites
OK, thanks for following this, I really appreciate it.

I'm using 3ds Max to create a plane and attach a texture to it. In 3ds Max, you attach a texture to a material and then attach the material to the texture. When I render, there's that material creating a big ugly black box. I tried editing the material out of the .x file, but I still get the same results.

After editing the .x file, there's nothing in it but the vertex coords and the texture coords, so I don't see how manually creating the .x file would be any different.

I know this is dumb...but I was hoping to take the easy way out and get an answer here rather than spend days trying to render a few trees.

I hope this makes more sense. Thanks again

Share this post


Link to post
Share on other sites
The material is only going to affect what's drawn when lighting is enabled, so my first suggestion is disable lighting and see if the black box goes away. There is always SOME material applied, so you can't just turn it off. But you can create a general material that reflects white light, has no ambiance and no specular highlights.

I suspect it won't fix your problem though. What kind of texture are you using? Does it support alpha, i.e. is it TGA or something else? Also, are you setting your render states properly? You have to tell the texture stage to use the TEXTURE color for alpha (if it is indeed a texture that is alpha-capable). Is the texture (the plane) just showing up solid black or is it semi-transparent? Do you load the texture with a color key?

You might check out Tree Magik also, it's a very cool randomizing tree generation program, and you can pick it up for around 50.00. It might be worth the time saved.

Chris

Share this post


Link to post
Share on other sites
I don't think color keys are needed for alpha-transparent textures. I also don't think any material settings will affect the transparency of the texture. Make sure these render states are on when you render the tree branches:

Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

The first two states can be turned on and left on when you start the system. You may want to turn the third state off after transparent objects have been rendered.

Also, as Supernat02 suggests, make sure you're setting a texture with an alpha mask. I would suggest using the PNG format unless you use Photoshop to save the TGA files.

Share this post


Link to post
Share on other sites

This topic is 4838 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this