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
Thanks for your time…