Jump to content
  • Advertisement
Sign in to follow this  
yuppies

texture splatting question

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

I have read the article about texture splatting at gamedev (http://www.gamedev.net/reference/articles/article2238.asp) i have one question for this one my concern is on the function void RenderWithoutShader(); heres the body:
void RenderWithoutShader() {
	// Alphamap: take the alpha from the alphamap, we don't care about the color
	g_Direct3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
	g_Direct3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

	// Texture: take the color from the texture, take the alpha from the previous stage
	g_Direct3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
	g_Direct3DDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
	g_Direct3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
	g_Direct3DDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);

	// Disable textures from the pixel shader mode
	g_Direct3DDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
	g_Direct3DDevice->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

	// Disable the pixel shader
	g_Direct3DDevice->SetPixelShader(NULL);

	g_Direct3DDevice->SetTexture(0, g_Alphamap1);
	g_Direct3DDevice->SetTexture(1, g_Texture1);
	g_Direct3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_Vertices, sizeof(QuadVertex));

	g_Direct3DDevice->SetTexture(0, g_Alphamap2);
	g_Direct3DDevice->SetTexture(1, g_Texture2);
	g_Direct3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_Vertices, sizeof(QuadVertex));

	g_Direct3DDevice->SetTexture(0, g_Alphamap3);
	g_Direct3DDevice->SetTexture(1, g_Texture3);
	g_Direct3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_Vertices, sizeof(QuadVertex));

	g_Direct3DDevice->SetTexture(0, g_Alphamap4);
	g_Direct3DDevice->SetTexture(1, g_Texture4);
	g_Direct3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_Vertices, sizeof(QuadVertex));
}



what thus this mean? Its in the code that the function DrawPrimitiveUP was called 4 times to get the effect( for the 4 textures and 4 alphamaps). Now if im going to use this in a terrain lets say for example Geomipmapping terrain does it mean im going to call my render function for the entire terrain for N times(costly!) depending on the number of my texture and alpha map? Or im misssing something here? pls englighten me thanks [Edited by - yuppies on August 29, 2005 3:16:05 AM]

Share this post


Link to post
Share on other sites
Advertisement
Well, basically what they do is set up the correct renderstates for rendering a single terrain type (i.e. texture) and render the terrain for each terrain type with its associated alpha map. The main reason for this approach is probably hardware support, because just about all cards support at least 2 texture stages. Aside from that, this approach is easier to implement than setting up the stage states for rendering all textures at once and it is more flexible.

I haven't looked into this myself, but it should be possible (from my understanding) to set up the texture stage states so all 4 textures can be rendered in one pass. You'll need hardware that can support 8 stages for this though, but this is rather common nowadays. If I'm correct you should be able to continue with the next texture 'splat' with the following code:

[source lang=cpp]
... // 1st splat


g_Direct3DDevice->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
g_Direct3DDevice->SetTextureStageState(2, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

// Texture: take the color from the texture, take the alpha from the previous stage
g_Direct3DDevice->SetTextureStageState(3, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA ); // blend tex alpha op, right?
g_Direct3DDevice->SetTextureStageState(3, D3DTSS_COLORARG1, D3DTA_TEXTURE);
g_Direct3DDevice->SetTextureStageState(3, D3DTSS_COLORARG2, D3DTA_CURRENT);
g_Direct3DDevice->SetTextureStageState(3, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
g_Direct3DDevice->SetTextureStageState(3, D3DTSS_ALPHAARG1, D3DTA_CURRENT);


... // next 'splat'


// set textures/alpha maps for all states
// render terrain once





I'm not entirely sure about this, but it's worth a shot. If anyone can shed some first-hand light on this, that'd be great.

Edit:

After re-reading my code, this won't work at all, because the D3DTA_CURRENT argument I want to blend with is the alpha map for the 2nd stage. Light shedding on this would be much appreciated :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!