I have a 3D model that has a GLSL script, and I want to draw a line on each border of its polygons in the fragment shader.

What should I do? Note: I am using Ogre3D, so I can't use OpenGL's functions.

So far I have this (just assigns a texture to it):

void main(void)
  gl_FragColor = texture2D(texture1, gl_TexCoord[0].st); 

This means if I have a cube, I want to render 12 lines, on each border of the cube


You may be able to do it in a shader using the linked comment above.

But if that doesn't work, you can still do it by rendering a separate batch of lines after drawing your shape.

If this is just a debug mode thing, there is no need to do this particularly efficiently: just walk the triangles of the mesh and draw a line along each edge of each triangle.

If this is going to be a runtime thing, you need to eliminate the duplicate edges that will result from adjacent triangles.

  • 1
    \$\begingroup\$ For debug it's easier still to just set things in wireframe mode. Set polygon_mode to wireframe in the pass section of a .material file, in Ogre3D, or in other parts of the renderer if you don't want to use a custom pass for the effect. D3D and GL have their own lower level ways to set polygon display modes between wireframe or solid/fill. \$\endgroup\$ – Sean Middleditch Aug 17 '13 at 21:23

If you're using Ogre3D, then why don't you do add another pass to the material technique that is assigned to the model, as in (suppose "ball" is an Ogre::Entity):

Ogre::MaterialPtr ptr = ball->getSubEntity(0)->getMaterial();
Ogre::Pass * pass = ptr->getTechnique(0)->createPass();

This will add a red wireframe that gets drawn over the existing material. And if you just want a wireframe, not a wireframe on top of the current material, just substitute "getPass(0)" for "createPass()"

Or, if you would rather do it in the .material file:

material general/wireframe
    // first pass
      polygon_mode wireframe


http://www.ogre3d.org/docs/manual/manual_16.html#polygon_005fmode http://www.ogre3d.org/docs/manual/manual_14.html#Material-Scripts


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.