Jump to content
  • Advertisement
Sign in to follow this  
QNAN

SOLVED - Terrain: Problems with splatting transitions on multipass-rendering

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

First a picture:
terrainalpha_darkened_transitions.jpg:
I am rendering terrain, but since I am running on Shader model 3.0, I can use a maximum of 16 textures. Right now I mix together 6 terrain layers + normalmaps, which with splatting requires 2 alpha-maps, and lastly a shadowmap, for a combined 15 textures.

But I am not too happy with only 6 layers, and therefore I want to do multipass rendering instead, as I do not render the detailmaps (as you see here) in a very big distance around the player, and it therefore will not have a huge impact.

My problem is, that with the second rendering pass, the transitions darken. In the top-left picture you can see some sand areas. The blob closest to the camera has a darkened area around it. Compared to the same sand texture rendered in the first pass, which is its northern neighbour, the difference in transitions is huge.

In the lower images I rendered with the first renderpass as pure white, so the transitions could be seen more clearly on its own. I do believe, that also here it is darkened.

Here are the renderstates, that I use to render with:
m_device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE)
m_device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
m_device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
m_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
m_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
m_device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
m_device->SetRenderState(D3DRS_DESTBLENDALPHA, D3DBLEND_ONE);


If needed I can post my shader code (although it is quite long).


What am I doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
I made a silly mistake in the pixel shader, where I declared this:
float4 l_basecolor = float4(0.0f, 0.0f, 0.0f, 0.0f)

Then I would lerp() each layer with the l_basecolor, but since this was black to begin with, the result became "scorched" edges.
There is no chance anyone could have helped me without seeing the shader, and my suspicion, that it could be renderstates was wrong.

Thanks to all who took the time to read this.

EDIT:
Ok, it was not quite that simple. The alphamaps are now spread across several renderpasses, meaning that a specific point in a specific renderpass will not add up to 1.0f (as all the alphamaps combined will do so, and one pass will only have a subset of them).
When moving from singlepass to multipass I just copied the code and made a few adjustments, and scaling renderpass' local combined color to 1.0f, for the full color, was not one of them.

My code is now looking something like this (half-psudo:

float4 l_basecolor = float4(0.0f, 0.0f, 0.0f, 0.0f);
float l_layerfactor;
float l_combinedfactor = 0.0f;

for(...each layer...)
{
l_layerfactor = tex2D(...[relevant alphamap sampler]...);
l_combinedfactor += l_layerfactor;
l_basecolor += tex2D(...[relevant texture sampler]...) * l_layerfactor;
}
l_basecolor.rgb = l_basecolor.rgb * (1.0f / l_combinedfactor); // scale color to make up for less-than-1 combined alpha, as further alpha may be in another renderpass

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!