Sign in to follow this  
DaN1maL

Multi-rendering with 4 textures + 4 alpha masks

Recommended Posts

DaN1maL    136
Ok, I'm working with splatting-like technique with my terrain and I want to be able to have up to 4 layers per quad. (ex: dirt, grass, rock...etc) .... In my example I'll be using 3 layers. Each texture layer has a corresponding alpha texture (8bit.. GL_ALPHA) say i have these... dirt texture + dirt alpha mask grass texture + grass alpha mask rock texture + rock alpha mask I don't want to have to use 6 texture units... and I don't know if I'd even be able to set it up correctly with multi-texturing if I used six units. What I'd like to do is first combine the dirt texture with its alpha mask, then the grass with its alpha mask, then the rock with its alpha mask... Once they are all combined, I want to render the 3 results together using three texture units. Is this possible? ... All I really want to do is take the alpha right out of the mask and apply it to the texture just before I render. Can this be done? Do I have to just manually copy out the alpha from the mask into the texture? And if so, is that even possible? I know there is some solution to this... Because games such as FarCry are doing this.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Why don't you mix color and alpha in oone 32 bit texture (RGBA)?

Share this post


Link to post
Share on other sites
DaN1maL    136
Quote:
Original post by Anonymous Poster
Why don't you mix color and alpha in oone 32 bit texture (RGBA)?


The map is 1024 x 1024 quads.

Each quad can have different layers with different masks. So I cannot store that many high detail textures. I simply want to combine each layer with its corresponding mask on the fly.

Unless what you mean is .... Take the RGB from the texture and combine it with the alpha (from the mask) every frame.... Which is what I'd like to do. And then once they are combined..... Multi-texture that with the other layer+mask combinations for that quad.

Share this post


Link to post
Share on other sites
zedzeek    529
this is very easy to do (in one pass if the hardware has 6 texture units) with glsl.
alternatively i think u could get it working with multitexture + combine (and various passes thus will also need to enable blending)

tex0.rgb * tex1.a
+ blending the result over whats already in the framebuffer

Share this post


Link to post
Share on other sites
DaN1maL    136
Quote:
Original post by zedzeek
this is very easy to do (in one pass if the hardware has 6 texture units) with glsl.
alternatively i think u could get it working with multitexture + combine (and various passes thus will also need to enable blending)

tex0.rgb * tex1.a
+ blending the result over whats already in the framebuffer


Do you think it would be possible to somehow merge the layer texture with the alpha texture (without using blending) ..... essentially over-writing the layer texture's alpha channel.... and then using multitexturing to blend the 3 layers? That way I could do all the blending in one pass, and only have to use 3 texture units. (basically, i dont want to have to use a texture unit for a simple alpha mask.. when all I really want to do is grab the alpha out of it.. and not really do any "blend")

Would that even be possible? I want the speed of multi-texturing (versus multipass), but I don't want to use so many texture units.

Also, would getting access to the texture bits and writing out the alpha bytes to the texture every frame be a possibility? And if so, would it be too slow? ... I'm not sure if this is even possible, and if it was.. I'm thinking that it would be too slow because it would have to transfer the alpha bytes over the system bus. (and that wouldnt be good every frame...)

Share this post


Link to post
Share on other sites
zedzeek    529
is it not possible for each dirt RGB texture to make a RGBA texture (ie already containing the alpha) that would simplfy things considerably

Share this post


Link to post
Share on other sites
DaN1maL    136
Quote:
Original post by zedzeek
is it not possible for each dirt RGB texture to make a RGBA texture (ie already containing the alpha) that would simplfy things considerably


Nope :( The same grass texture will be used over the entire terrain, but different masks will be applied.

Share this post


Link to post
Share on other sites
DaN1maL    136
Here's a diagram I just put together with photoshop of what I'm trying to do using multi-texturing with 5 texture units...

Click here for diagram!!

As you can see I put parenthases in the diagram to represent the "order of operations" or should I say "order of blends".

I'm having difficulties getting things to blend correctly.. I'm not putting the right parameters for the textenv. Can anyone lead me in the right direction?

Seems like I need to do in each stage is blend the destination alpha with the source color..? ... I just don't know :(

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
I want to also....

zedzeek,can you sent to yjh1982yjh@yahoo.com.cn?
thanks very much!

Share this post


Link to post
Share on other sites
DaN1maL    136
I got the code working in my project... But I found out most of my problems were because of the way I was creating my alpha mask texture. I was using GL_ALPHA for the format.. Even though that should work, it doesn't. So I had to put GL_LUMINANCE.

I have everything working, only problem is that it's too slow. Is there anyway to get this all in one pass?

[Edited by - DaN1maL on August 10, 2004 12:05:09 AM]

Share this post


Link to post
Share on other sites
DaN1maL    136
I'm going to be using a pbuffer now to cache the quads around my position so i dont have to do all the rendering every frame....

But I'd still like to get all the layers rendered in one pass using a texture unit per layer. Do you know how this could be accomplished? Possible?

Share this post


Link to post
Share on other sites

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