Texture splatting?

BlitzMax Forums/BlitzMax Programming/Texture splatting?

Hi all,

Has anyone done texture splatting in BMax?

Basicly texture splatting means that you draw an image (texture) and use a separate source for alpha channel. See for example this article: http://www.gamedev.net/reference/articles/article2238.asp

I have never messed with Max2D internals so I don't dare to try to do it myself (don't know where to begin), but implementing the fixed function pipeline approach doesn't look too complicated.

-AF

I've done a bit with DX :
Strict
Graphics 800,600,0
Local image1:TImage = LoadImage("grass.png")
Local image2:TImage=LoadImage("blending.png")
SetClsColor 255,0,0
While Not AppTerminate() And Not KeyHit(key_escape)
	Cls
	SetBlend MASKblend
	If MouseHit(1) renderit(image1,image2)
	setmodnormal()
    SetAlpha 1.0
	DrawImage image1,MouseX(),MouseY()
	Flip
Wend
Function renderit(r_image1:TImage , r_image2:TImage)
        Local frame1:TD3D7ImageFrame=TD3D7ImageFrame(r_image1.frame(0))
        Local frame2:TD3D7ImageFrame=TD3D7ImageFrame(r_image2.frame(0))
'		If TD3D7Max2DDriver(D3D7Max2DDriver.SetActiveFrame(frame1))
	 		D3D7GraphicsDriver().Direct3DDevice7().SetTexture 0,frame1.surface
	   		D3D7GraphicsDriver().Direct3DDevice7().SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	   		D3D7GraphicsDriver().Direct3DDevice7().SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1);
	   		D3D7GraphicsDriver().Direct3DDevice7().SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
 	  		D3D7GraphicsDriver().Direct3DDevice7().SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG1 );
	 		D3D7GraphicsDriver().Direct3DDevice7().SetTexture 1 , frame2.surface
	   		D3D7GraphicsDriver().Direct3DDevice7().SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
	   		D3D7GraphicsDriver().Direct3DDevice7().SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_SELECTARG2);
	   		D3D7GraphicsDriver().Direct3DDevice7().SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
 	  		D3D7GraphicsDriver().Direct3DDevice7().SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG1 );
 	 		D3D7GraphicsDriver().Direct3DDevice7().SetTextureStageState( 1 , D3DTSS_ALPHAARG1 , D3DTA_TEXTURE ) ; 
'		EndIf
End Function
Function setmodnormal()
  		D3D7GraphicsDriver().Direct3DDevice7().SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE)
			D3D7GraphicsDriver().Direct3DDevice7().SetRenderState D3DRS_ALPHATESTENABLE,True
			D3D7GraphicsDriver().Direct3DDevice7().SetRenderState D3DRS_ALPHABLENDENABLE,False
 
End Function 


<edit> Depending on your machines (or target) multitexture capability you either use another texturestage to mix with another texture (singlepass multitexture) or create a new pass and use the output as input (multipass multitexture).
<edit2> I have some better examples but they all broke when DX driver was changed and I haven't got time to fix them.

Thanks!

It seems it was even more simple than what I thought!

-AF