osgjs icon indicating copy to clipboard operation
osgjs copied to clipboard

Adds the possibility to enable/disable StateAttribute per StateSet

Open jtorresfabra opened this issue 9 years ago • 2 comments

In OSG you have the possibility of disable lighting in a node via stateset mode using:

node->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF );

If I understood well, in OSG the default behaviour when no lighting is diffuse*texture + emissive. That's if the texture environment is set to MODULATE which is also the default.

If the TexEnv is DECAL then it should be texture+emissive.

jtorresfabra avatar Feb 19 '15 10:02 jtorresfabra

ON|OFF in osg is used to enable/disable a state on opengl, in opengl es 2.0 there are a few state that exists, but on the users point on view it makes sense to still control StateAttribute.


   /* EnableCap */
    const GLenum CULL_FACE                      = 0x0B44;
    const GLenum BLEND                          = 0x0BE2;
    const GLenum DITHER                         = 0x0BD0;
    const GLenum STENCIL_TEST                   = 0x0B90;
    const GLenum DEPTH_TEST                     = 0x0B71;
    const GLenum SCISSOR_TEST                   = 0x0C11;
    const GLenum POLYGON_OFFSET_FILL            = 0x8037;
    const GLenum SAMPLE_ALPHA_TO_COVERAGE       = 0x809E;
    const GLenum SAMPLE_COVERAGE                = 0x80A0;

So adding a full implementation of mode in State like osg seems a bit overkill. To keep the implementation simple, we could:

  • check in StateAttribute if there is a associated gl mode and apply it in State
  • in compiler check the mask from the stack to filter or not the attribute. https://github.com/cedricpinson/osgjs/blob/menu-3d/sources/osg/State.js#L90 Checking the last StateAttribute mask could not be enough, we would need to parse the stack to check the last ON|OFF used.

Others questions, what happens to those attributes if they can be ON|OFF

  • ShadowReceive
  • Skinning
  • Morph
  • ShadowTexture
  • Texture
  • Light
  • Material
  • Billboard

cedricpinson avatar Apr 18 '16 15:04 cedricpinson

Modifying a bit your idea... I would add the following:

  • Attributes could be associated to modes or not. ( typical case StateAttribute = BlendFunc and GLMode = BLEND )
  • GLModes should be treated separately, so they have also (ON|OFF|OVERRIDE|PROTECTED)
  • In Compiler we first check if the StateAttribute is ON | OFF, if it is ON then check if it has Modes associated. If that's true and the Mode is ON then generate the shader with this attribute active.
  • If the StateAttribute does not have modes associated then you only check if it is ON|OFF to generate the shader.
  • This way we can enable/disable modes globally or per StateSet (using ss->setMode() for example), and also enable/disable attributes.
  • Also we can have custom modes not present in GLES 2. ( For example Lighting/Texturing/etc. )

To implement this we would need to keep track of modes separately.

jtorresfabra avatar Apr 19 '16 09:04 jtorresfabra