Using a shader on GeoMipTerrain (C++)

Hi guys, I’m new to Panda3D ( have been working with Irrlicht for some years ) and I would like some advice.

First of all, engine seems very nice. Using the API examples it took only some days to get a couple of nice working small (learning) programs to work.

There is one thing I don’t seem te be able to get running, not even after hours of browsing through the manual and the forum:

Is there some ‘special’ way to activate shaders in C++ ?

I can set up shaders, load them and they actually compile (since I can see shader compiler errors in the console when I make a typo)

But I cannot get it to give me any result. I’m using the example code found on the forum at

discourse.panda3d.org/viewtopic … thsculptor

and translated it into C++.

The program is running, there are no errors in the console, but the terrain is simply showing some texture stages, not caring for the shader.

Even when I change the fragment shader to output o_color as a red (or any) color, it still shows the textures. Just seems like the shader is activated at all.

Here is the basic thing setting up the shader:

window->get_graphics_window()->get_active_display_region(0)->set_clear_color(Colorf(0.4, 0.5, 0.7, 1));
Texture* tex0 = TexturePool::load_texture(Filename("VPB_ProjectFiles/EarthSculptor/default_d.png")); 
Texture* tex1 = TexturePool::load_texture(Filename("VPB_ProjectFiles/EarthSculptor/grayRock.png")); 
Texture* tex2 = TexturePool::load_texture(Filename("VPB_ProjectFiles/EarthSculptor/hardDirt.png")); 
Texture* tex3 = TexturePool::load_texture(Filename("VPB_ProjectFiles/EarthSculptor/bigRockFace.png")); 
Texture* tex4 = TexturePool::load_texture(Filename("VPB_ProjectFiles/EarthSculptor/shortGrass.png")); 
Texture* tex5 = TexturePool::load_texture(Filename("VPB_ProjectFiles/EarthSculptor/default_c.png")); 
Texture* tex6 = TexturePool::load_texture(Filename("VPB_ProjectFiles/EarthSculptor/default_l.png")); 
tex0->set_minfilter(Texture::FilterType::FT_linear_mipmap_linear);
tex1->set_minfilter(Texture::FilterType::FT_linear_mipmap_linear);
tex2->set_minfilter(Texture::FilterType::FT_linear_mipmap_linear);
tex3->set_minfilter(Texture::FilterType::FT_linear_mipmap_linear);
tex4->set_minfilter(Texture::FilterType::FT_linear_mipmap_linear);
tex5->set_minfilter(Texture::FilterType::FT_linear_mipmap_linear);
tex6->set_minfilter(Texture::FilterType::FT_linear_mipmap_linear);

terrain =  new GeoMipTerrain("myDynamicTerrain");

terrain->set_heightfield(Filename("/c/Panda3D-1.6.2/VPB_ProjectFiles/EarthSculptor/default.png"),0);	
terrain->set_bruteforce(true);
terrain->set_block_size(32);
terrain->set_near(40);
terrain->set_far(100);
terrain->set_focal_point(camera);
NodePath root = terrain->get_root();
root.set_z(0);
root.set_pos(0,0,0);
root.set_scale(1,1,50);
root.reparent_to(window->get_render()); 
terrain->generate();

TextureStage *stage0=new TextureStage("tex0");	terrain->get_root().set_texture(stage0,tex0,0); 
TextureStage *stage1=new TextureStage("tex1");	terrain->get_root().set_texture(stage0,tex1,0); 
TextureStage *stage2=new TextureStage("tex2");	terrain->get_root().set_texture(stage0,tex2,0); 
TextureStage *stage3=new TextureStage("tex3");	terrain->get_root().set_texture(stage0,tex3,0); 
TextureStage *stage4=new TextureStage("tex4");	terrain->get_root().set_texture(stage0,tex4,0); 
TextureStage *stage5=new TextureStage("tex5");	terrain->get_root().set_texture(stage0,tex5,0); 
TextureStage *stage6=new TextureStage("tex6");	terrain->get_root().set_texture(stage0,tex6,0); 

PT(Shader) myShader;
myShader->load(	Filename("/c/Panda3D-1.6.2/VPB_ProjectFiles/Shaders/terrain.sha") ); 
root.set_shader(myShader,0);

taskMgr->add(new GenericAsyncTask("Updates terrain", &UpdateTerrain, (void*) NULL));

I could post the shader as well but it is the same as in the given link.
Would appreciate any help , thanks in advance.

Hm, I can spot a few issues in your code. First of all, you should wrap a Texture and TextureStage inside a PT() rather than using an ordinary pointer.

Also, this code is wrong:

PT(Shader) myShader;
myShader->load( Filename("/c/Panda3D-1.6.2/VPB_ProjectFiles/Shaders/terrain.sha") );
root.set_shader(myShader,0);

Not only probably shouldn’t set the priority to 0, you are also not using the Shader interface properly. Try this instead:

PT(Shader) myShader = Shader::load( Filename("/c/Panda3D-1.6.2/VPB_ProjectFiles/Shaders/terrain.sha") );
root.set_shader(myShader);

Rdb, thanks a million, that was the problem.