Weird artifacts with multi layered terrain

Started by
12 comments, last by Ardan 10 years, 1 month ago

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

Advertisement

Can you show your shader code?

Cheers!

Possibly need a slight offset to your texCoords? Or maybe mipmapping is causing it?

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

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?

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

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Yeah I see where the problem occurs, but I dont understand why.

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);

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement