[SOLVED] ShaderTerrainMesh - Weird issue?

Hello everyone,
I found this shader-terrain sample and tried to use it in C++;

Here the code; (I tried to convert it as much as i could.)

void Background::LoadTerrain(string _mapname) {
	const string _heightmap_file = "bin/neuera/maps/" + _mapname + "/heightmap.png";
	const string _texmap_file_1 = "bin/neuera/maps/" + _mapname + "/texmap1.png";
	const string _texmap_file_2 = "bin/neuera/maps/" + _mapname + "/texmap2.png";
	const string _texmap_file_json = "bin/neuera/maps/" + _mapname + "/texmap.json";
	const string _areadata_file = "bin/neuera/maps/" + _mapname + "/areadata.json";

	std::ifstream f(_texmap_file_json);
	json _texmap = json::parse(f);
	//std::ifstream f(_areadata_file);
	//json _areadata = json::parse(f);

	ShaderTerrainMesh* terrain_node = new ShaderTerrainMesh();
	Texture* heightfield = Engine::loadTexture(_heightmap_file);
	heightfield->set_wrap_u(SamplerState::WM_clamp);
	heightfield->set_wrap_v(SamplerState::WM_clamp);
	terrain_node->set_heightfield(heightfield);
	terrain_node->set_target_triangle_width(10.0);
	terrain_node->generate();

	NodePath terrain = window->get_render().attach_new_node(terrain_node);
	terrain.set_scale(1024, 1024, 200);
	terrain.set_pos(0, 0, -200.0);
	terrain.set_shader(Shader::load(Shader::SL_GLSL, "bin/neuera/shaders/terrain.vert.glsl", "bin/neuera/shaders/terrain.frag.glsl"));
	terrain.set_shader_input("camera", window->get_camera_group().get_child(0));

	std::vector<std::string> _textures = getMapTextures(_texmap);
	int _tex_order = 1;
	for (std::vector<std::string>::iterator it = _textures.begin(); it != _textures.end(); ++it) {
		const string _shader_input = "detail_tex" + std::to_string(_tex_order);
		const string _tex_file = "bin/neuera/tex/diffuse/" + *it;
		Texture* _tex = Engine::loadTexture(_tex_file);
		_tex->set_minfilter(SamplerState::FT_linear_mipmap_nearest);
		_tex->set_magfilter(SamplerState::FT_linear);
		_tex->set_anisotropic_degree(4);
		terrain.set_shader_input(_shader_input, _tex);
		_tex_order++;
	}

	terrain.set_shader_input("atr1", Engine::loadTexture(_texmap_file_1));
	terrain.set_shader_input("atr2", Engine::loadTexture(_texmap_file_2));
}

And it worked! But i have some weird issue;

What is this and why this happening? Do you have any idea?
Im working with 512x512 heightmap. I dont want to increase heightmap file size :frowning:
Thanks for your time…

It looks like chunks are being culled for some reason…

I don’t use ShaderTerrainMesh myself, so I’m just guessing here, but what happens if you use the same position-offset that the sample uses?

That is, you have “terrain.set_pos(0, 0, -200)”–what happens if, as in the sample, you instead use “terrain.set_pos(-512, -512, -70)”? (Or (-512, -512, -150)?)

Another thought: What happens if you only change the z-offset, like so: “terrain.set_pos(0, 0,-150)”?

1 Like

I found the problem, i was using 8-bit heightmap but ShaderTerrainMesh supports 16-bit :slight_smile:

1 Like

This is not related to this topic, but I will ask something; As you can see in the video, the colors are very faded. How can I make it more lively? I mean what should i do? Is there any way to increase contrast?

I’m glad that you solved the problem! :slight_smile:

As to the colours, do I take it that the input textures are more vibrant? If not, then that might be the place to start.

If not that… then it does look a bit like distance-haze–near the middle of the video you can see the same effect, but stronger, being applied to more-distant geometry.

If that is the case, then there might be parameters somewhere that control that haze–but where they are specifically I don’t know, I’m afraid.