1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
  • 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
1
\$\begingroup\$

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();
pass->setDiffuse(1,0,0,0); 
pass->setAmbient(1,0,0);  
pass->setPolygonModeOverrideable(true);
pass->setPolygonMode(Ogre::PM_WIREFRAME);

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
{
  technique
  {
    // first pass
    pass
    {
      polygon_mode wireframe
      ...

See:

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

\$\endgroup\$

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.