Skip to main content
GameDev.net gamedev.net
🔒 Locked

Blending 4 textures

Started by Tessellator Nov 22, 2003 at 6:05 PM 1 replies 500+ views
Original Post
Tessellator
Tessellator
Hi, I''m amazed I haven''t needed to do this before, but anyways.. What I''d like to achieve is to blend 4 textures together, each with a different weight i.e. (tex1 * w1) + (tex2 * w2) + (tex3 * w3) + (tex4 * w4) where w1 + w2 + w3 + w4 = 1 (or 255), depending how things are stored. Ideally, I''d like to do this in one pass and I''m open to using vertex and pixel shaders. Appologies in advance if this has been discused before - I tried to search but somethings not working right at the moment, all I got was an error. Many thanks, T
S1CA
S1CA
So you want to control how the RGB of four textures are blended together using a constant of some form for the weights.

Dead easy with a pixel shader. The following [untested] should do it where each of a,r,g,b in the c0 pixel shader constant are the weights. You could pass the weights in from somewhere else such a vertex colour if you wanted. Off the top of my head:

ps.1.1
// sample the 4 texture maps
tex t0
tex t1
tex t2
tex t3
// do the blend
mul r0.rgb, t0.rgb, c0.a
mad r0.rgb, t1.rgb, c0.r, r0.rgb
mad r0.rgb, t2.rgb, c0.g, r0.rgb
mad r0.rgb, t3.rgb, c0.b, r0.rgb


To achieve the same with the fixed function pipeline would be more tricky - though colour ops such as D3DTOP_MULTIPLYADD and D3DTOP_MODULATEALPHA_ADDCOLOR do most of what you want.


Multipass is even more tricky though a ONE:ONE blend works as an add and a blend such as ZERO:SRCCOLOR works as a multiply between passes.


--
Simon O'Connor
3D Game Programmer &
Microsoft DirectX MVP


[edited by - s1ca on November 22, 2003 9:49:57 PM]
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
Tessellator
Tessellator
Cheers for that Simon. I''ve got the pixel shader working no problem now (I pass in the weights per vertex). Getting the same thing working under the fixed function pipeline is proving to be harder (and with too much overhead), so I think i''m just going to scrap it altogether.

Cheers,
T

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.