Sign in to follow this  

Terrain Texturing: HLSL PS 1.1 - 2 Textures in 2nd Pass

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

Hi all, In my first pass I have 3 textures. Now I like to add 2 textures per additional pass. No problem with one texture, but with two textures I've a problem: When I lerp the colors from texttureA and B, I have A sourrounding B where B is normally not surrounded by anything (in that pass). So instead of interpolating with LERP, I'd like to do something alike blending-on-top of it - dunno how to express. Like the blending is done in the frame-buffer through the passes. Anyone know how to do this? thx.

Share this post


Link to post
Share on other sites
Ok, I'm not sure I understand your question completely. You put down 3 textures in a first pass, then you want to

a) blend A and B together then blend that with the first pass?
b) blend A onto the first pass, then blend B onto the result?

or if I'm completely off base, let me know. And what API are you using?

Share this post


Link to post
Share on other sites
Hello ctoan,

thank you for your interrest.

I am using HLSL - directly in the development editor.
I am not using directly OpenGL or DX. The format is HLSL (fx),
where I can specifify the blend modes etc.

The effect shall consist of several passes using differen pixel shader (1.1). In the first pass a pixel shader combines 4 textures - 1 base and 3 additional according to a 'mask'-texture.
This is working fine - no problem with that.

Now I like to be able to add more 'terrain-texture-layers' based on the same or more masks.

So i switch state to ( for the second pass):

AlphaBlendEnable= TRUE;
DestBlend = INVSRCALPHA;
SrcBlend = SRCALPHA;

no problem so far.

A and B are already the result of the second (!) pass and thats were my problem is. You see the need to fade to alpha in order for the blending. Thats ok with the first texture, but when I combine the second texture with the first texture (in the second pass - using a different pixel shader (1.1)) - I am using LERP. But this creates a wrong fade-out of the second texture where it is not 'above'/'inside' the first one.

You can see in the picture, that B is always sourrunded by A - though it shouldn't where the flashes are pointing to.

So what I am looking for is a HLSL command or something, where
I can 'blend' the second texture pixel over the first texture pixel ( remember 2nd pass ;) ) - as LERP is producing the wrong result.

You now the same operation that I am getting with the blend of the second pass over the first pass - but now inside a pixel shader in order to do it with two textures/pixels there,

I hope it's clearer now.

Share this post


Link to post
Share on other sites
Dom77,

What are you using for lerp factor in your second pass? Essentially the lerp that you perform in your second pass and the blending that you do with the framebuffer after lerping are the same function. Both operations blend between two colors based on some other parameter (for alpha blending you are using the alpha component of the new pixel, for lerp it is whatever you have set for source0).

So to adjust how much each texture is going to be applied to the framebuffer you have to adjust the blending parameter - one of your mask textures in your case. So in your pixel shader just make sure that the output alpha value is proportional to the blend amount that you want.

Jason Z

Share this post


Link to post
Share on other sites
Hmm... look at it this way. You have 'n' textures (T) that you want to blend on a tile and 'n' coefficients (C) that you use to control how much each one blends, such that Sum(C(i)) for i=0..n = 1 (float) or 255 (ubyte) ... the result you want then is:

C1*T1 + C2*T2 + C3*T3 + ... + CN*TN

Your mask texture has for its RGB 3 coefficients (let's say C1,C2,C3 for the first pass) since you only get four textures in PS1.1.

So in the first pass you would set blend mode to (one,zero) and render out C1*T1 + C2*T2 + C3*T3

The next stage would output C4*T4 + C5*T5 + C6*T6 ... how do we want this to combine with the result of the first pass to get the appropriate result? We want to add it.. so the blend mode would be (one,one)... you can keep doing this same pass over and over until you blend everything you need (if you don't have three textures left for the last pass then you can just set C(i) to 0 for the textures you don't have...)

If there was any multiplicative operation you needed to do per pixel (like multiplying by some base color) you could do it each pass in the PS or as a final multiplicative blend pass (src=destColor, dest=zero)

Keep in mind the more passes you use, the more fillrate it eats up and will effect your framerate if you're fill limited. This is especially true for something like terrain that takes up a lot of screenspace. One way to reduce the number of passes would be to, per tile, sort the textures/coefficients from highest contribution to lowest and just take the first 3 or 6 textures, normalize the coefficients for them (meaning they add up to 255 or 1 depending on if you're doing them as bytes or floats, it's just like normalizing a vector). Make the mask textures and then render just those 3 or 6.

-nohbdy

Share this post


Link to post
Share on other sites

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