Skip to content

All polygons are rendered with same objectID after installing custom shader #2813

@pks23

Description

@pks23

osgEarth Version : 3.7.2

Description of the problem: Not able to handle polygon rendering from custom shader.

Added a custom shader for updating the color of a feature after selection.
Below is the code for the custom shader. However, after installing the custom shader, the selection of polygon features stops working. Upon investigation, it was found that the objectID for all polygon features becomes the same after installing the shader.

const char* highlight_shader = R"(
           #pragma vp_function check_for_highlight, vertex_clip
           uniform uint selectedFeatCount;
           uniform uint selectionIds[500]; 
           uint oe_index_objectid;      // Stage global containing object id
           flat out int selected;
           void check_for_highlight(inout vec4 vertex)
           {
selected =0;
              for(int i = 0; i < selectedFeatCount; i++)
                 {
                     uint val = selectionIds[i];
                     if(val == oe_index_objectid)
                       {
                           selected = 1;
                           break;
                       }
                 }
           }

           [break]
           #pragma vp_function highlight_fragment, fragment
           flat in int selected;
           void highlight_fragment(inout vec4 color)
           {


             if ( selected == 1 )
             {
              color = vec4(1.0, 0.0, 1.0, 1.0); // magenta highlight
             }
           }
       )";


void Osg::CGShader::Initialize()
{
 int attrLocation = Registry::objectIndex()->getObjectIDAttribLocation();

 // This shader program will highlight the selected object.
 VirtualProgram* vp = VirtualProgram::getOrCreate(stateSet);
 auto res = ShaderLoader::load(vp, this->shaderSource);

 // Since we're accessing object IDs, we need to load the indexing shader as well:
 res = Registry::objectIndex()->loadShaders(vp);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    supportSupport questions

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions