Jump to content
  • Advertisement
Sign in to follow this  
Ardan

Weird artifacts with multi layered terrain

This topic is 2040 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've implemented a terrain in my application and I wanted to use several textures to render it with. I found a tutorial on the web http://www.mbsoftworks.sk/index.php?page=tutorials&series=1&tutorial=24 which used 3 textures and transitioned between them.

 

I've got everything working except that i get weird lines on the heights that the mixing occurs.

What could be the cause of this?

 

I've attached an image showing the problem

Share this post


Link to post
Share on other sites
Advertisement

Oh yes sorry, here it is:

#version 330

out vec4 out_Color;
uniform sampler2D sandTexture;
uniform sampler2D grassTexture;
uniform sampler2D rockTexture;

uniform float TerrainHeight;

//From vertex shader
in vec2 texCoord;
in vec3 normal;
in vec3 position;

vec4 texColor = vec4(0);
float shade;

void main(void)
{
	const vec3 light = vec3(0.5, 1, 0.5);
        shade = dot(light, normalize(normal));

	const float fRange1 = 0.01f;
	const float fRange2 = 0.1f;
	const float fRange3 = 0.5f;
	const float fRange4 = 0.9f;

	float fScale = position.y/TerrainHeight;
	if(fScale >= 0.0 && fScale <= fRange1)
		texColor = texture(sandTexture, texCoord);
	else if(fScale <= fRange2) 
	{
		fScale -= fRange1; 
		fScale /= (fRange2-fRange1); 
     
		float fScale2 = fScale; 
		fScale = 1.0-fScale;  
     
		texColor += texture(sandTexture, texCoord)*fScale; 
		texColor += texture(grassTexture, texCoord)*fScale2; 
	}
	else if(fScale <= fRange3)
		texColor = texture(grassTexture, texCoord);
	else if(fScale <= fRange4) 
	{ 
		fScale -= fRange3; 
		fScale /= (fRange4-fRange3); 
 
		float fScale2 = fScale; 
		fScale = 1.0-fScale;
 
		texColor += texture(grassTexture, texCoord)*fScale;
		texColor += texture(rockTexture, texCoord)*fScale2;
	}
	else
		texColor = texture(rockTexture, texCoord);

	out_Color = texColor * shade;
}

Basically its the same as the fragment shader in the tutorial

Share this post


Link to post
Share on other sites

They look like stitching artefacts to me, not a texturing problem. Are they running north to south, and east to west?

 

How are you rendering your terrain?

Edited by mark ds

Share this post


Link to post
Share on other sites

The problem don't occur when i use a single texture or when just coloring the terrain

Share this post


Link to post
Share on other sites
The problem is related to the blending of textures somehow.
The artifacts all occur at the same respective heights as they circle the mountain. The bottom artifact is always at the point where the sand begins to fade to grass (look carefully; there is an artifact in the sand as well).
Then when the sand ends completely and grass begins fully.
Then when grass starts to fade to rock, and again when the fading stops and there is only pure rock.

4 bands of artifacts, each at a “blending split”.

I would say it makes it quite obvious where to look for the problem and what the nature of the problem is.


L. Spiro

Share this post


Link to post
Share on other sites

It might be a numerical problem.


fScale -= fRange1;

fScale /= (fRange2-fRange1);

In this case, if fScale equals to fRange2, you should get 1.0 or 0.0 if it equals fRange1. To ensure that you dont have a numerical precision problem clamp the fScale value to 0.0..1.0.

 

fScale = clamp(fScale,0.0,1.0);

Share this post


Link to post
Share on other sites
I was thinking numerical issue too, but not seeing where one could exist based off his code. The values for the ranges are constants on top and seem to be well defined.

I also looked for division by 0 but it seems impossible as well.

Still, a clamp would not hurt.


Also, provide a screenshot of a close-up of one of the artifacts. I need to see one of them up close to get an idea of what type of numerical issue it could be.


L. Spiro

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!