Page 1 of 4 1234 LastLast
Results 1 to 10 of 31

Thread: Transparent and transparency revisited

  1. #1
    Junior Member
    Join Date
    Nov 2008
    Location
    Lancaster - UK
    Posts
    24

    Transparent and transparency revisited

    I am currently reviewing the support for transparent materials that I put into the OpenSceneGraph Collada plugin about a year ago. I realise that I need to do some more work on it to make alpha blended texture maps work. I have some questions I need answering if possible. So here goes.

    1. Am I correct in assuming that the default for the opaque attribute of the transparent element at version 1.4.1 is A_ONE (an alpha value of 1 is opaque) and at the 1.5.1 the default has changed to A_ZERO (an alpha value of 0 is opaque)?

    2. YOU CAN IGNORE THIS QUESTION FOR THE TIME BEING, I NEED TO REPHRASE IT!!!! I was assuming that the colour referred to in the specification of the transparent element was the colour supplied by that element. But some implementations(e.g. Sketchup) do not seem to produce Collada documents that agree with that. Can someone confirm the source of the colour in the following circumstances.
    i. The transparent element present and specifiying a colour and no other colours or texture elements present.
    ii. The transparent element present and specifiying a colour, but with, for instance a diffuse colour or texture element also present.
    iii. The transparent element present and specifiying a texture and no other colours or texture elements present.
    iv. The transparent element present and specifiying a texture, but with, for instance a diffuse colour or texture element also present.
    v. The transparent element not present, but the transparency element present and say, a diffuse colour element present.

    3. Other posts in this forum say that in a situation where both a diffuse texture and a transparent texture are present some sort of multitexturing should be performed. But taking the phong technique as an example no specification of how this should be performed is given. The phong equation given in the specification does not have a term for the refracted colour. Can any one give me any hints how this should be done in OpenGL terms.

    Help!

    Roger

  2. #2
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771

    Re: Transparent and transparency revisited

    Quote Originally Posted by rogerjames99
    1. Am I correct in assuming that the default for the opaque attribute of the transparent element at version 1.4.1 is A_ONE (an alpha value of 1 is opaque) and at the 1.5.1 the default has changed to A_ZERO (an alpha value of 0 is opaque)?
    The default is A_ONE for both versions according to the specifications. See <fx_common_transparent_type> in the schema.
    Quote Originally Posted by rogerjames99
    2. YOU CAN IGNORE THIS QUESTION FOR THE TIME BEING, I NEED TO REPHRASE IT!!!! I was assuming that the colour referred to in the specification of the transparent element was the colour supplied by that element.
    Please read specification chapter 7 section "Rendering: Determining Transparency" for details. That should help you frame your question.
    Quote Originally Posted by rogerjames99
    3. Other posts in this forum say that in a situation where both a diffuse texture and a transparent texture are present some sort of multitexturing should be performed. But taking the phong technique as an example no specification of how this should be performed is given. The phong equation given in the specification does not have a term for the refracted colour. Can any one give me any hints how this should be done in OpenGL terms.
    It's possible that OpenGL fix-function pipeline can only approximate some content that utilizes all the elements. You're right that the phong (and blinn) equations in the spec don't include the additional reflective term that may be present. I'll submit a bug for that into bugzilla. Stay tuned.

  3. #3
    Junior Member
    Join Date
    Nov 2008
    Location
    Lancaster - UK
    Posts
    24
    Marcus,

    Thank you for your reply. I aplogoise for not having worked out how to qoute the original message in replies yet!

    My question about the default value for opaque was prompted by the following text in the 1.5.0 release notes.

    Resolves report K-622 (Spec: K-311.
    The <transparent> elementís opaque attribute now allows, in addition to A_ONE and RGB_ZERO, the
    following values:
    ē A_ZERO (the default): Takes the transparency information from the colorís alpha channel, where the
    value 0.0 is opaque.

    I went on to check the 1.5.0 specification and both the A_ values are shown as default in there!

    However as you say it is A_ONE in 1.5.0 schema document, thank goodness. I thought I was going to have to make all my code for setting up the transparent/transparency defaults version dependent. I wonder if Google have fixed their transparency code in the latest version of Sketchup? They still write dae documents with a default for opaque (A_ONE) and a value in transparency of 0 for opaque in version 6.

    I will watch out for you Bugzilla entry regarding the phong equations, thanks.

    If I still have your attention, maybe I can prevail on you to answer this question. If I draw a simple surface in Sketchup and attach a texture map to it that has an alpha channel (e.g. a png image). Then in Sketchup this is displayed as expected with the zero alpha portions of the image shown as transparent. If I ask Sketchup to export this to dae it writes a technique looking like this.
    Code :
                <technique sid="COMMON">
                   <phong>
                      <emission>
                         <color>0.000000 0.000000 0.000000 1</color>
                      </emission>
                      <ambient>
                         <color>0.000000 0.000000 0.000000 1</color>
                      </ambient>
                      <diffuse>
                         <texture texture="material1-image-sampler" texcoord="UVSET0"/>
                      </diffuse>
                      <specular>
                         <color>0.330000 0.330000 0.330000 1</color>
                      </specular>
                      <shininess>
                         <float>20.000000</float>
                      </shininess>
                      <reflectivity>
                         <float>0.100000</float>
                      </reflectivity>
                      <transparent>
                         <color>1 1 1 1</color>
                      </transparent>
                      <transparency>
                         <float>0.000000</float>
                      </transparency>
                   </phong>
                </technique>

    I think this will result in a totally transparent material which ignores any alpha information from the texture. Firstly am I correct, and secondly how should the technique be written so that it renders using the alpha map from the material. My guess is something like this
    Code :
                <technique sid="COMMON">
                   <phong>
                      <emission>
                         <color>0.000000 0.000000 0.000000 1</color>
                      </emission>
                      <ambient>
                         <color>0.000000 0.000000 0.000000 1</color>
                      </ambient>
                      <diffuse>
                         <color>0.000000 0.000000 0.000000 1</color>
                      </diffuse>
                      <specular>
                         <color>0.330000 0.330000 0.330000 1</color>
                      </specular>
                      <shininess>
                         <float>20.000000</float>
                      </shininess>
                      <reflectivity>
                         <float>0.100000</float>
                      </reflectivity>
                      <transparent>
                          <texture texture="material1-image-sampler" texcoord="UVSET0"/>
                      </transparent>
                      <transparency>
                         <float>1.000000</float>
                      </transparency>
                   </phong>
                </technique>

    Roger

  4. #4
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771
    Quote Originally Posted by rogerjames99
    I aplogoise for not having worked out how to qoute the original message in replies yet!
    Just press the QUOTE button and start writing.
    Quote Originally Posted by rogerjames99
    My question about the default value for opaque was prompted by the following text in the 1.5.0 release notes.

    Resolves report K-622 (Spec: K-311.
    The <transparent> elementís opaque attribute now allows, in addition to A_ONE and RGB_ZERO, the
    following values:
    ē A_ZERO (the default): Takes the transparency information from the colorís alpha channel, where the
    value 0.0 is opaque.

    I went on to check the 1.5.0 specification and both the A_ values are shown as default in there!
    Definitely a bug in the spec and release notes then. I'm guessing a copy&paste error. Thanks.
    Quote Originally Posted by rogerjames99
    However as you say it is A_ONE in 1.5.0 schema document, thank goodness.
    The schema is authoritative too.
    Quote Originally Posted by rogerjames99
    I wonder if Google have fixed their transparency code in the latest version of Sketchup? They still write dae documents with a default for opaque (A_ONE) and a value in transparency of 0 for opaque in version 6.
    I will let Google know of the issue you've brought up.
    Quote Originally Posted by rogerjames99
    If I still have your attention, maybe I can prevail on you to answer this question. If I draw a simple surface in Sketchup and attach a texture map to it that has an alpha channel (e.g. a png image). Then in Sketchup this is displayed as expected with the zero alpha portions of the image shown as transparent.
    Right that would be A_ONE mode in COLLADA.
    Quote Originally Posted by rogerjames99
    If I ask Sketchup to export this to dae it writes a technique looking like this.
    Code :
    <diffuse>
      <texture texture="material1-image-sampler" texcoord="UVSET0"/>
    </diffuse>
    <transparent>
      <color>1 1 1 1</color>
    </transparent>
    <transparency>
      <float>0.000000</float>
    </transparency>
    I think this will result in a totally transparent material which ignores any alpha information from the texture. Firstly am I correct,
    Yes I agree since the transparency factor is 0 then the material's contribution is fully transparent.
    Quote Originally Posted by rogerjames99
    and secondly how should the technique be written so that it renders using the alpha map from the material.
    Using the <phong> shader, calculate the material color (mat) using the terms (elements) given (emission, ambient, diffuse, specular, reflective). that produces the "mat" color (e.g. RGBA) used in the transparency calculation in chapter 7 of the spec.

    In this case the <diffuse> is a (presumably) RGBA texture and so the only change needed to fix the SketchUp export is to change <transparency> to 1.0.

    Note that <transparent> and <transparency> (and <reflective> and <reflectivity>) are post operations (i.e. layers on top) in the rendering calculations (again Chapter 7 for transparent).

  5. #5
    Junior Member
    Join Date
    Nov 2008
    Location
    Lancaster - UK
    Posts
    24
    Quote Originally Posted by marcus
    Quote Originally Posted by rogerjames99
    and secondly how should the technique be written so that it renders using the alpha map from the material.
    Using the <phong> shader, calculate the material color (mat) using the terms (elements) given (emission, ambient, diffuse, specular, reflective). that produces the "mat" color (e.g. RGBA) used in the transparency calculation in chapter 7 of the spec.

    In this case the <diffuse> is a (presumably) RGBA texture and so the only change needed to fix the SketchUp export is to change <transparency> to 1.0.

    Note that <transparent> and <transparency> (and <reflective> and <reflectivity>) are post operations (i.e. layers on top) in the rendering calculations (again Chapter 7 for transparent).
    I think I have the hang of this quoting thing now!

    Once again thanks for the reply, I think it takes us to the heart of the problem I am facing in implementing this in the OpenSceneGraph importer.

    The OSG format is essential a 'thin' abstraction of OpenGL. For performance reasons I try wherever possible not to introduce programmable shaders into the imported scenegraph. The spec says that I should use the values from <transparency> and <transparent>.a for the rgb blending equations. It does not mention the use of a mat.a term anywhere in the rgb blending process. In OpenGL terms I interpret this as using a source blend factor of ONE_MINUS_CONSTANT_ALPHA and I copy the <transparency> * <transparent>.a value into the alpha value of glBlendColor (the constant colour). This will of course ignore any alpha value from the material and with default values produce an opaque result (which is what people have been complaining about!). So as far as I can see I either have to have some way of determining from the <technique> which of the following two versions of the Collada transparency equations to use:

    i. The one from the spec.
    ii. One modified as follows:-
    result.r = fb.r * (1.0f - mat.a) + mat.r * mat.a

    both of which can be achieved without using shaders. Or use a much more complex version of the equations which incorporates the mat.a factor into the rgb blending along the with the transparent.a and tranparency factors.

    This all seems so complex that I think I must have made a stupid mistake somewhere.

    I cannot help feeling that the ability to specify a texture in the transparent field instead of a color plays into this somewhere. If the same RGBA material were specified for both <diffuse> and <transparent> then in A_ONE opaque mode and provided that <transparency> was 1 the equations from the spec would produce the desired result. However this would mean that Google (and others) would be seriously broken.

    Any further guidance will be gratefully received. I feel like I am going daft (Northern English slang for insane) over this.

    Roger

  6. #6
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771
    Quote Originally Posted by rogerjames99
    The OSG format is essential a 'thin' abstraction of OpenGL. For performance reasons I try wherever possible not to introduce programmable shaders into the imported scenegraph.
    Yep I'm well familiar with Robert and Don's work and was part of the R&D team at Sony Computer Entertainment that contributed the COLLADA plug-in to OSG.
    Quote Originally Posted by rogerjames99
    The spec says that I should use the values from <transparency> and <transparent>.a for the rgb blending equations. It does not mention the use of a mat.a term anywhere in the rgb blending process.
    Sure it does and you talk as-if having seen it (page 249) in your reply lol. OpenGL fixed-function pipeline can only approximate a transparent layer on top of a (transparent) phong surface. Use the equations in Chapter 7 Rendering as a guide to your approximation.
    Quote Originally Posted by rogerjames99
    In OpenGL terms I interpret this as using a source blend factor of ONE_MINUS_CONSTANT_ALPHA and I copy the <transparency> * <transparent>.a value into the alpha value of glBlendColor (the constant colour). This will of course ignore any alpha value from the material and with default values produce an opaque result (which is what people have been complaining about!).
    Simplify things to what I described previously (again page 249). You have a framebuffer of color, possibly a vertex color (w/ alpha), a COLLADA material (e.g. <phong>) that contributes a 'mat' (i.e. OpenGL material) color (w/ RGBA channels for emission, ambient, diffuse, specular), a transparent "layer" color (and scalar), and a reflective "layer" color (and scalar).
    Quote Originally Posted by rogerjames99
    I cannot help feeling that the ability to specify a texture in the transparent field instead of a color plays into this somewhere. If the same RGBA material were specified for both <diffuse> and <transparent> then in A_ONE opaque mode and provided that <transparency> was 1 the equations from the spec would produce the desired result. However this would mean that Google (and others) would be seriously broken.
    I have not seen SketchUp export content as you just described. They export a texture in the <diffuse> channel only. Google has confirmed to me in email that they are aware of this bug in their exporter and they characterize it as follows:
    Quote Originally Posted by Google
    It WAS fixed, but the fix was rolled back prior to SketchUp 7 release, so the defect is still there. Ideally the fix would look something like this:
    Code :
    <transparent opaque=A_ONE><color>1 1 1 1</color></transparency>
    <transparency><float>a</float></transparency>
    where the defect is we are writing this:
    Code :
    <transparency>1 - a</transparency>
    Hope that helps.

  7. #7
    Junior Member
    Join Date
    Nov 2008
    Location
    Lancaster - UK
    Posts
    24
    Quote Originally Posted by marcus
    Quote Originally Posted by rogerjames99
    The OSG format is essentially a 'thin' abstraction of OpenGL. For performance reasons I try wherever possible not to introduce programmable shaders into the imported scenegraph.
    Yep I'm well familiar with Robert and Don's work and was part of the R&D team at Sony Computer Entertainment that contributed the COLLADA plug-in to OSG.
    I am well aware of that. I was just putting the background in for anyone who was not. I am just someone who has spent some time supplying patches .
    Quote Originally Posted by marcus
    Quote Originally Posted by rogerjames99
    The spec says that I should use the values from <transparency> and <transparent>.a for the rgb blending equations. It does not mention the use of a mat.a term anywhere in the rgb blending process.
    Sure it does and you talk as-if having seen it (page 249) in your reply lol. OpenGL fixed-function pipeline can only approximate a transparent layer on top of a (transparent) phong surface. Use the equations in Chapter 7 Rendering as a guide to your approximation.
    I realise that you are being very patient with your replies to my questions and that that patience may be wearing thin lol. However I do not understand your reply. I have read page 249 and its antecedents going back to revision B of the 1.4.1 release notes many times. I probably need to make it clear that I use the phrase "rgb blending process" to refer to the three equations which provide the red, green, and blue values to the result variable, not to the the fourth equation that provides the alpha value. The mat.a term does not appear anywhere in those first three equations. If I use them as guidance as you suggest, then whenever transparency processing has been activated by the presence of either transparent or transparency in the technique, I should ignore the materials alpha value when calculating the red green and blue values of the resulting colour, whether or not I am doing this for OpenGL or any other renderer. Or have I once again totally misread what you are saying.

    Thanks,

    Roger

  8. #8
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771
    Quote Originally Posted by rogerjames99
    I realise that you are being very patient with your replies to my questions and that that patience may be wearing thin lol. However I do not understand your reply. I have read page 249 and its antecedents going back to revision B of the 1.4.1 release notes many times. I probably need to make it clear that I use the phrase "rgb blending process" to refer to the three equations which provide the red, green, and blue values to the result variable, not to the the fourth equation that provides the alpha value. The mat.a term does not appear anywhere in those first three equations.
    No worries Roger, I have lots of patience! Although you have managed to confused me wrt what's on page 249 so I conclude we must be looking at different versions of the document or something.

    From the 1.5.0 spec, on page 249 there is the equation for A_ONE mode with the "mat.a" term (highlighted in red):
    In A_ONE opaque mode:

    result.r = fb.r * (1.0f - transparent.a * transparency) + mat.r *
    (transparent.a * transparency)
    result.g = fb.g * (1.0f - transparent.a * transparency) + mat.g *
    (transparent.a * transparency)
    result.b = fb.b * (1.0f - transparent.a * transparency) + mat.b *
    (transparent.a * transparency)
    result.a = fb.a * (1.0f - transparent.a * transparency) + mat.a *
    (transparent.a * transparency)
    That is the material alpha that I'm talking about that is the result of the surface material color, e.g. <phong> surface color layer excluding reflective and transparent layers.

    For "mat" plug in the values from e.g. <phong><diffuse> etc. and for "transparent" plug in the values from <phong><transparent> etc..

    Does that help?

  9. #9
    Junior Member
    Join Date
    Nov 2008
    Location
    Lancaster - UK
    Posts
    24
    Quote Originally Posted by marcus
    No worries Roger, I have lots of patience! Although you have managed to confused me wrt what's on page 249 so I conclude we must be looking at different versions of the document or something.

    From the 1.5.0 spec, on page 249 there is the equation for A_ONE mode with the "mat.a" term (highlighted in red):
    In A_ONE opaque mode:

    result.r = fb.r * (1.0f - transparent.a * transparency) + mat.r *
    (transparent.a * transparency)
    result.g = fb.g * (1.0f - transparent.a * transparency) + mat.g *
    (transparent.a * transparency)
    result.b = fb.b * (1.0f - transparent.a * transparency) + mat.b *
    (transparent.a * transparency)
    result.a = fb.a * (1.0f - transparent.a * transparency) + mat.a *
    (transparent.a * transparency)
    That is the material alpha that I'm talking about that is the result of the surface material color, e.g. <phong> surface color layer excluding reflective and transparent layers.

    For "mat" plug in the values from e.g. <phong><diffuse> etc. and for "transparent" plug in the values from <phong><transparent> etc..

    Does that help?
    Mark,

    You have highlighted my problem exactly! Let's say that I have an image with an alpha channel which denotes areas of the image that should be transparent and I want this image to be used in a material to be rendered with alpha blending. To turn on alpha blending the spec says I have to include a transparent or a transparency term in the technique. So lets say I include both with default values as follows

    <transparent> <color> 1.0 1.0 1.0 1.0 </color> </transparent>
    <transparency> <float> 1.0 </float> </transparency>

    and I put a sampler for my image in the <diffuse> term.

    The equations then work out like this

    result.rgb = fb.rgb * (1.0f - 1.0f * 1.0f) + mat.rgb *
    (1.0f * 1.0f)
    result.a = fb.a * (1.0f - 1.0f * 1.0f) + mat.a *
    (1.0f * 1.0f)

    Which simplifies to

    result.rgb = mat.rgb
    result.a = mat.a

    i.e. The visible rgb rendering ignores any alpha value from the image which is rendered opaque.

    OK so lets try another approach. Say this time I put the image sampler in the transparent term and let the diffuse color default.

    result.rgb = fb.rgb * (1.0f - transparent.a * 1.0f) + mat.rgb *
    (transparent.a * 1.0f)
    result.a = fb.a * (1.0f - transparent.a * 1.0f) + mat.a *
    (transparent.a * 1.0f)

    which simplifies to

    result.rgb = fb.rgb * (1.0f - transparent.a) + mat.rgb * transparent.a
    result.a = fb.a * (1.0f - transparent.a) + mat.a * transparent.a

    This is a fairly standard alpha blending equation with alpha values taken from the image alpha channel. But the visible result will be output from the phong equation (diffuse ambient etc..) and none of the rgb information from the image will be visible. I cannot remember what the defaults are in this case but I suspect the result will be black modulated by the alpha map. The result alpha value will also be incorrect.

    The nearest I can get to the desired result would appear to be to specify the same image sampler in both the diffuse and transparent terms. This gives the following equations (same as before).

    result.rgb = fb.rgb * (1.0f - transparent.a) + mat.rgb * transparent.a
    result.a = fb.a * (1.0f - transparent.a) + mat.a * transparent.a

    Because transparent.a and mat.a are the same (phong notwithstanding) this simplifies to.

    result.rgb = fb.rgb * (1.0f - mat.a) + mat.rgb * mat.a
    result.a = fb.a * (1.0f - mat.a) + mat.a * mat.a

    Which is about what is needed apart from an erroneous alpha value in the result.

    I have looked at this time and again ever since I first put the transparency code into the OSG dae plugin last year and still cannot make sense of it.

    If I take as an example how images with an alpha channel used as a material are handled in Google Earth then it would appear that whenever a material is encountrered that has an image sampler in the diffuse term and that image has an alpha channel then blending is turned on using the image alpha channel as the source of the blending information.

    Also looking at the ColladaLoader example from the Collada sourceforge site, I find the following code

    // if diffuse texture has a alfa channel or opacity is less than 1, this will return true
    bool CCLMaterial::IsTransparent() {

    The image alpha channel is always used as the blending factor source.

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


    So it looks a number of implementations have adopted their own interpretations of this part of the spec.

    Help.

    Roger

  10. #10
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771
    Quote Originally Posted by rogerjames99
    To turn on alpha blending the spec says I have to include a transparent or a transparency term in the technique.
    Hmm... the spec says that "If either <transparent> or <transparency> exists then transparency rendering is activated". Probably "activated" is a bad choice of words since activation/deactivation of a run-time mode is not the point of that section, rather the blending equations are.
    Quote Originally Posted by rogerjames99
    The equations then work out like this

    result.rgb = fb.rgb * (1.0f - 1.0f * 1.0f) + mat.rgb *
    (1.0f * 1.0f)
    result.a = fb.a * (1.0f - 1.0f * 1.0f) + mat.a *
    (1.0f * 1.0f)

    Which simplifies to

    result.rgb = mat.rgb
    result.a = mat.a

    i.e. The visible rgb rendering ignores any alpha value from the image which is rendered opaque.
    Pardon me but mat.a includes the diffuse texture alpha from the <phong> shader. It's not ignored.

    Hope that clears things up (pun intended )

Page 1 of 4 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •