• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Ardan

Weird artifacts with multi layered terrain

13 posts in this topic

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

1

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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

1

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
0

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

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
2

Share this post


Link to post
Share on other sites
Maybe this has to do with mipmapping. The hardware selects the mipmap level based on the texture coordinates used in 2x2 pixel groups. This means that it only works, if all the pixels of a 2x2 group sample the same textures. This is exactly not the case for the regions where the artifacts occure.
 
Maybe, just for testing this hypothesis, you can always sample and mix all textures and set the scaling factor to zero for those that you don't need.
 
 
Edit: Like so (Note that this could also be done without branches):
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;
 
    float ScaleSand = 0.0f;
    float ScaleGrass = 0.0f;
    float ScaleRock = 0.0f;


    if(fScale >= 0.0 && fScale <= fRange1)
        ScaleSand = 1.0f;
    else if(fScale <= fRange2)
    {
        fScale -= fRange1;
        fScale /= (fRange2-fRange1);

        float fScale2 = fScale;
        fScale = 1.0-fScale;

        ScaleSand = fScale;
        ScaleGrass = fScale2;

    }
    else if(fScale <= fRange3)
        ScaleGrass = 1.0f;
    else if(fScale <= fRange4)
    {
        fScale -= fRange3;
        fScale /= (fRange4-fRange3);

        float fScale2 = fScale;
        fScale = 1.0-fScale;

        ScaleGrass = fScale;
        ScaleRock = fScale2;
    }
    else
        ScaleRock = 1.0f;
 
    texColor = texture(sandTexture, texCoord) * ScaleSand +
			   texture(grassTexture, texCoord) * ScaleGrass +
			   texture(rockTexture, texCoord) * ScaleRock;

    out_Color = texColor * shade;

}
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

If you zoom in on the image you can see that the errors are not contiguous. It also looks like they might be in 2x2 blocks of pixels - most noticeable at the start of the grass to rock transition. There also seems to be two separate lines in the sand.
0

Share this post


Link to post
Share on other sites
Thinking more on this, I'm beginning to suspect you might have found a driver bug.

Fragments are rendered as screen aligned quads (2x2 pixels at a time) because it helps optimize texture access, derivatives calculation, z-culling and other things besides. If you zoom in on the errors in the image, you can see that they are in 2x2 pixel quads - the quads also appear aligned on even boundaries which also fits.

I'm wondering if the errors only appear when the four pixels in a quad do not all take the same execution path through the shader. When comfortably within the same range all the quad's pixels will pass/fail the same tests and so take the same path. If some pixels in a quad fall within different ranges they will take different execution paths - which might be the cause of the problem. This would explain why it works most of the time but only fails at the transition between ranges.

The fact that the errors don't always appear might also fit this explanation. Think of a situation where the transition between the layers occurs as a horizontal line. When the line and quads are aligned such that this line passes through a single quad, the pixels will fall within different ranges and follow different execution paths. If the horizontal line falls exactly between two quads, both quads will have all their pixels in the same range/execution path even though the two quads are in different ranges.

Try to rewrite the shader so all pixels follow the same execution paths regardless of the ranges they fall in. (Maybe try Ohforf sake's suggestion of always blend all the textures as a first quick test as this does seem to be texture related).
0

Share this post


Link to post
Share on other sites

Thanks for your suggestions, I will look into all you've said and I'll post back with my results.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0