Problem with and blending

    May 26 2017 | 12:27 pm
    Hi. I'm using and need it to be partially transparent. In order to do it I need to turn on blending (blend_enable 1) on the target object. The problem is that after doing it, even before changing any transparency parameters of the material, the look of the object is now totally different. This is even affecting the rendering of the depth texture! Any solution to this? Bug?

    • May 26 2017 | 7:10 pm
      hi pedro. i see what you're seeing, but not sure what the problem is. you've changed the properties of the object and therefore it renders differently. if you start bringing the alpha component down of all the material properties, (mat_emission, mat_ambient, etc), you should be able to get what you want (transparency with a material).
    • May 29 2017 | 8:34 pm
      Hi, Rob. I hope you had a nice and deserved rest on this holiday weekend.
      you've changed the properties of the object and therefore it renders differently.
      I understand that changing properties usually results in things changing ;-) But "what things"? How? Why?
      When rendering using the fixed pipeline, blend_enable 0 or blend_enable 1 with blending mode "alphablend" renders exactly the same if the alpha channel of the object is totally opaque (1.).
      With that is not the case. Here, there's something funny happening with the alpha channels of the material properties, they're influencing each other. Searching in the forums, I've came across this post from Wesley Smith (December 2011): in its current incarnation sums that alpha of the emissive, ambient, diffuse, and specular components. Arguably, it should ignore the emissive and ambient components when calculating the alpha channel, but in its current incarnation it doesn't, so you may need to explicitly set them to 0 to get alpha effects.
      Is this still the case in 2017? To me, it doesn't make much sense to have the alpha component of the mat_ambient property affect the transparency of the mat_specular, for instance... If this is not considered to be a problem, could you briefly explain the rationale for the current implementation?
      Now, regarding the second problem I mentioned and demonstrated in the attached patch: I think we can both agree that whatever the visual aspect of the color rendering is, the depth texture shouldn't be different just because I change the blend_enable attribute. The objects have the same depth position independently of this property, but the depth rendering is radically different...
      Thanks in advance!
    • May 30 2017 | 5:38 pm
      here's the lighting calculation we use in (for one light with a diffuse texture):
      jit_Material.color += gl_FrontMaterial.emission;
      jit_Material.color += gl_FrontMaterial.ambient*(jit_Light[0].ambient+jit_LightModel.ambient);
      jit_Material.color += gl_FrontMaterial.diffuse*jit_Light[0].diffuse*mat_diffuse*diffuse_tex;
      jit_Material.color += gl_FrontMaterial.specular*jit_Light[0].specular*mat_specular;
      gl_FragColor = jit_Material.color;
      as you can see, each material component is added to the total. to enable transparency, each material component's alpha value must be zeroed out in order to not affect the alpha of the final, which you probably want to control via mat_diffuse alpha.
      beyond that, i can't really speak to what's happening in the GPU when blending is enabled.
      i'll take a look at the depth shader, and see if there's something to do to prevent blending from affecting its render.
    • May 31 2017 | 12:30 am
      Thank you Rob, for your explanation and for looking into the depth rendering problem.
      I thought that the material color components, before being added to the total, were scaled (multiplied) by their corresponding alpha channels, in order to have more control over the final result, like this:
      (diffuse_color * diffuse_alpha) + (specular_color * specular_alpha) + ...
      Thank you once more for your explanation.