Second rendering pass of my material do nothing

Problems building or running the engine, queries about how to use features etc.
Post Reply
shorky
Gnoblar
Posts: 1
Joined: Wed Jul 31, 2019 10:51 am

Second rendering pass of my material do nothing

Post by shorky » Wed Jul 31, 2019 1:18 pm

Ogre Version: : Ogre 2.1 :
Operating System: : Ubuntu 18.04:
Render System: : GL 4.3:

Hello
I'm new with Ogre and 3D programming in general and i got a problem understanding material in Ogre way.
I've made a little application where i can load model, select it and few other basic operation like move in the scene, scale the object ect...
I would like to create a material to make an outline effect during the selection of a model.
First of all i have a lot of difficulty to understand the HLMS template material ( how to build it and integrate it ). So i decide to do the "old" way in full C++.
I've understand that to make my outline effect i need to use shader in my material and no texture.
The method i found consist of 2 step of rendering : the first one will scale the object to render the object in background. And the second step just consist to re render the basic model in front of the first render pass. ( i found this method on many example for making the outline effect but is this correct ? ).
In Ogre i've understand ( i think ) that it can be accomplished by declaring a material, attach some shader and use 2 pass in the technique of my material (again i would like to know if i really understand material in ogre or if i'm really far away from the real things X) ).
And here i am, i have created my material with 1 technique and 2 pass, the first pass work pretty well, the render of my object seems to be scale like i wanted but i see no result of my second render pass. The real problem is at this point i don't really know how to investigate on the cause of the problem since i'm not very familiar with rendering engine and i have a lot of problem finding a solution on the internet/Ogre forum.
Here is the way i created my shader :

Code: Select all

  /*Ogre::MaterialPtr material;
  material = Ogre::MaterialManager::getSingleton().load(
        "Outline",
        Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME).staticCast<Ogre::Material>();*/
  const std::string outline_shader_frag_name = "Outline_frag";
  const std::string outline_shader_frag =
      "// simple fragment shader\n"
      "void main()\n"
      "{\n"
      "   gl_FragColor = vec4(1.0, 0.0, 0.0, 0.5);"
      "}\n";

  const std::string outline_shader_vert_name = "Outline_vert";

  const std::string outline_shader_vert =
      "uniform mat4 worldViewProjMatrix;"
      "void main()\n"
      "{\n"
      "   vec3 pos = gl_Vertex.xyz * 2.0;"
      "   gl_Position = worldViewProjMatrix * vec4(pos, 1.0);"
      "}\n";

  Ogre::MaterialPtr outline_material = Ogre::MaterialManager::getSingleton().create("Outline", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

  Ogre::Technique* tp;
  Ogre::Pass* pp;
  Ogre::HighLevelGpuProgramPtr vp;
  Ogre::HighLevelGpuProgramPtr fp;
  //~ ----------------------------------------------------------------
  tp = outline_material->getTechnique(0);
  pp = tp->getPass(0);

  Ogre::HlmsMacroblock* myMacroBlockOutline = new Ogre::HlmsMacroblock();
  myMacroBlockOutline->mCullMode = Ogre::CULL_ANTICLOCKWISE;
  pp->setMacroblock(*myMacroBlockOutline);

  vp = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(
         outline_shader_vert_name, Ogre::ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME,
         "glsl", Ogre::GPT_VERTEX_PROGRAM);
  vp->setSource(outline_shader_vert);
  vp->load();
  pp->setVertexProgram(outline_shader_vert_name);

  fp = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(
         outline_shader_frag_name, Ogre::ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME,
         "glsl", Ogre::GPT_FRAGMENT_PROGRAM);
  fp->setSource(outline_shader_frag);
  fp->load();
  pp->setFragmentProgram(outline_shader_frag_name);
  pp->getVertexProgramParameters().get()->setNamedAutoConstant("worldViewProjMatrix", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);

  //std::cout << "is first pass loaded : " << std::boolalpha << pp->isLoaded() << std::endl;
  //~ ----------------------------------------------------------------
  //Seconde Pass
  const std::string basic_shader_frag_name = "Basic_frag";
  const std::string basic_shader_frag =
      "void main()\n"
      "{\n"
      "   gl_FragColor = vec4(0.0, 0.0, 1.0, 0.5);"
      "}\n";

  const std::string basic_shader_vert_name = "Basic_vert";
  const std::string basic_shader_vert =
      "uniform mat4 worldViewProjMatrix;"
      "void main()\n"
      "{\n"
      "    gl_Position =  worldViewProjMatrix * gl_Vertex;"
      "}\n";

  //Ogre::Technique* tpBasic;
  Ogre::Pass* ppBasic;
  Ogre::HighLevelGpuProgramPtr vpBasic;
  Ogre::HighLevelGpuProgramPtr fpBasic;
  //~ ----------------------------------------------------------------
  ppBasic = tp->createPass();

  vpBasic = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(
         basic_shader_vert_name, Ogre::ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME,
         "glsl", Ogre::GPT_VERTEX_PROGRAM);
  vpBasic->setSource(basic_shader_vert);
  vpBasic->load();
  ppBasic->setVertexProgram(basic_shader_vert_name);

  fpBasic = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(
         basic_shader_frag_name, Ogre::ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME,
         "glsl", Ogre::GPT_FRAGMENT_PROGRAM);
  fpBasic->setSource(basic_shader_frag);
  fpBasic->load();
  ppBasic->setFragmentProgram(basic_shader_frag_name);
  ppBasic->getVertexProgramParameters().get()->setNamedAutoConstant("worldViewProjMatrix", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
  outline_material->compile();


  //std::cout << "is PBasic loaded : " << std::boolalpha << ppBasic->isLoaded() << std::endl;
  std::cout << "Material Outline : " << outline_material.get()->getNumTechniques() << " techniques , " << outline_material->getTechnique(0)->getNumPasses() << " pass dans technique0" << std::endl;
}
Any help, comment or other link would be great ^^
0 x

Post Reply