OpenCOLLADA icon indicating copy to clipboard operation
OpenCOLLADA copied to clipboard

Effect opacity messed up when previous effect has transparent texture

Open scurest opened this issue 4 years ago • 0 comments

Suppose I have two effects in the library_effects. The first has a <transparent> with a texture and a <transparency> of 0.4, and the second has neither <transparent> nor <transparency>.

Example library_effects
  <library_effects>
    <effect id="White-effect">
      <profile_COMMON>
        <newparam sid="surface">
          <surface type="2D">
            <init_from>my_image</init_from>
          </surface>
        </newparam>
        <newparam sid="sampler">
          <sampler2D>
            <source>surface</source>
          </sampler2D>
        </newparam>
        <technique sid="common">
          <lambert>
            <diffuse>
              <color sid="diffuse">0.8 0.8 0.8 1</color>
            </diffuse>
            <transparent>
              <color>1 1 1 1</color>
              <texture texture="sampler" texcoord="UVMap"/>
            </transparent>
            <transparency>
              <float sid="transparency">0.4</float>
            </transparency>
          </lambert>
        </technique>
      </profile_COMMON>
    </effect>
    <effect id="Blue-effect">
      <profile_COMMON>
        <technique sid="common">
          <lambert>
            <diffuse>
              <color sid="diffuse">0 0.32 0.8 1</color>
            </diffuse>
          </lambert>
        </technique>
      </profile_COMMON>
    </effect>
  </library_effects>

Then when I look at the second effect:

  • getOpaqueMode will be ALPHA_ONE
  • getOpacity will be 0.4 0.4 0.4 0.4
  • getTransparent will be none (this is correct)
  • getTransparency will be 0.4

ie. it's reporting stale value from the first effect! If the first effect is modified so its <transparent> is a color instead, the second effect will show the correct values.


This is caused by an early return in calculateOpacity

https://github.com/KhronosGroup/OpenCOLLADA/blob/6031fa956e1da4bbdd910af3a8f9e924ef0fca7a/COLLADASaxFrameworkLoader/src/COLLADASaxFWLLibraryEffectsLoader.cpp#L299-L301

The early return skips the rest of the function, including the code that resets values for the next effect

https://github.com/KhronosGroup/OpenCOLLADA/blob/6031fa956e1da4bbdd910af3a8f9e924ef0fca7a/COLLADASaxFrameworkLoader/src/COLLADASaxFWLLibraryEffectsLoader.cpp#L382-L385

so the next effect gets the stale values.

scurest avatar May 14 '21 00:05 scurest