Professional Web Applications Themes

Alpha transparency borders on dynamically loaded imagesfor use with textures - Macromedia Director 3D

Hi there folks. Well, I have been beating my head over this and am hoping one of you can help me out. Essentially I have 16bit images that are loaded into my shockwave application at run-time. These images are user defined which means that I will not know their size ahead of time. Once the images are loaded I then create textures and apply them to various shaders. Ok, all of this works just fine. What I need to do though is create an alpha transparent border around the images, so when I apply them to their surfaces I only ...

  1. #1

    Default Alpha transparency borders on dynamically loaded imagesfor use with textures

    Hi there folks. Well, I have been beating my head over this and am hoping one
    of you can help me out.
    Essentially I have 16bit images that are loaded into my shockwave application
    at run-time. These images are user defined which means that I will not know
    their size ahead of time. Once the images are loaded I then create textures
    and apply them to various shaders. Ok, all of this works just fine. What I
    need to do though is create an alpha transparent border around the images, so
    when I apply them to their surfaces I only see the image and nothing around it.
    I am doing this because these images will only appear at specific parts on a
    surface, textureRepeat will be false, and many models will be stacked in the
    same exact location using the same model resource. I have everything working,
    but I cannot figure out the alpha part for the life of me. Also, when I test
    the alpha based image by itself it works just fine. It is not until I try and
    combine the 16bit (converted to 32bit at run-time) image that I run into
    problems.
    I have tried:
    - Creating a 32bit alpha image in Fireworks with a transparent border and a
    black rect for the inside. I then copy the dynamic image over the alpha image
    (only after going from 16bit to 32bit in imaging Lingo) and leave a little room
    at the edges for the transparency. Well, I get a crazy amount of streaks here
    even when I try to up the trans border by around 24 pixels on each side.
    - Using another similiar alpha based image as a mask with copyPixels and
    extractAlpha/setAlpha like this... (code is a little rough here)
    newImage = new(#bitmap)
    newImage.name = "place_Test"
    newImage.image = member("place").image

    newAlpha = new(#bitmap)
    newAlpha.name = "AHH"
    newAlpha.image = image(newImage.image.width + 24,
    newImage.image.height + 24, 32)
    newAlpha.image.useAlpha = true
    newAlpha.image.copyPixels(member("vase").image, newAlpha.image.rect,
    member("vase").image.rect)
    newAlphaInfo = newAlpha.image.extractAlpha()
    newAlpha.image.useAlpha = false

    --reverse dark to light
    iAlphaReverse = image(newAlpha.image.width, newAlpha.image.height, 8,
    #grayscale)

    iAlphaReverse.fill(iAlphaReverse.rect, rgb(0,0,0))
    iAlphaReverse.copyPixels(newAlphaInfo, iAlphaReverse.rect,
    newAlphaInfo.rect, [#ink : #reverse])

    --newAlphaInfo.copyPixels(iAlphaReverse, newAlphaInfo.rect,
    iAlphaReverse.rect, [#ink:#subtractpin])
    newAlphaMask = iAlphaReverse.createMask()

    rescaleAbs(newImage, newImage.image.width, newImage.image.height,
    "place_Test", 32)

    destImage = member("place_Test").image.duplicate()
    destImage.fill(destImage.rect, rgb(0,0,0))

    newAlpha.image.useAlpha = false

    destImage.copyPixels(newImage.image, newImage.image.rect,
    newImage.image.rect, [#maskImage:newAlphaMask, #ink:#add])

    destImage.setAlpha(iAlphaReverse)
    destImage.useAlpha = true
    member("place_Test").image = destImage

    I apologize for the messy code. I have cut and pasted from all over the place
    and am getting confused. In any case, I think I am making this harder then it
    needs to be and hope someone can help.

    Thank you in advance,
    Dave

    Sonic2004 Guest

  2. #2

    Default Re: Alpha transparency borders on dynamically loadedimages for use with textures

    Not totally sure to be honest, but have you had a look here...

    http://www.adobe.com/devnet/director/articles/director_alpha.html
    Nickname Guest

  3. #3

    Default Re: Alpha transparency borders on dynamically loadedimages for use with textures

    Hey there Nickname, thank you for the reply. I have, in fact, read that very
    article a couple of times to ensure that I did not miss anything. While it did
    help me with creating alpha textures within tools like Fireworks or Photoshop
    it does not explain how to create the alpha transparency at run-time using only
    Lingo. Better yet, how to combine a 16bit image with a 32bit alpha. The
    interesting thing is that I already do this in another part of my code with
    different image objects, but for some reason the same methodology does not work
    at all in this particular application. I did, however, test one of the images
    that I am referring to and as a sprite it works just fine. As a texture I get
    streaking.

    Is there something interesting that needs to be done to ensure that one does
    not get streaking when working with alpha transparency in textures as compared
    to sprites???

    Thank you,
    Dave

    Sonic2004 Guest

  4. #4

    Default Re: Alpha transparency borders on dynamically loadedimages for use with textures

    Have a look at: .renderFormat (a property of textures), and
    getRenderServices().textureRenderFormat (which sets the default texture render
    format.

    You may find that setting your texture's renderformat property to #rgba8888
    gets rid of the streaking.

    - Ben



    duckets Guest

  5. #5

    Default Re: Alpha transparency borders on dynamically loadedimages for use with textures

    Hey there duckets thank you for the reply as well. I guess I should do a
    better job of providing more upfront information in the description of my
    problem. I have tried using #rgba8888, #rgba4444, and #rgba5551 all with the
    same result. I have also used both OpenGL and Direct3D in my hunt to get rid
    of the streaking to no avail. Here is what is different when I do not get
    streaking. I can create an image in Fireworks with the correct masking
    technique and just load that image as a texture with no streaking. I, however,
    cannot seem to do the same only using imaging Lingo which is what I need to do.
    So, the issue I am having seems to be using the correct technique in imaging
    Lingo to convert a 16bit image to a 32bit one with alpha trans at the borders.
    Thank you again for your assistance.

    Sonic2004 Guest

  6. #6

    Default Re: Alpha transparency borders on dynamically loadedimages for use with textures

    Hi again folks. Ok, has anyone any knowledge of an xTra called GLEX? I was
    able to find a beta online and it literally solved my problems right out of the
    box. The issue with alpha transparency and Z ordering as I have described
    immediately disappeard after about 5 mins of configuration. I would really
    like to purchase this xTra if it is possible and I am working on a time crunch.
    Any information would be very helpful.

    Thank you,
    Dave

    Sonic2004 Guest

  7. #7

    Default Re: Alpha transparency borders on dynamically loaded images foruse with textures

    It was created by Lucas Meijer and Noisecrime. I'm not sure if they ever
    got it to the point of a commercial release.
    If you search the dir3d-l and/or dirgames-l list archives you'll find
    contact addresses and threads relating to this xtra.
    Sean Guest

  8. #8

    Default Re: Alpha transparency borders on dynamically loadedimages for use with textures

    So, were you having an alpha transparency z ordering problem? From you initial
    post it sounded like your problem was to do with the visual appearance of the
    textures ('streaking', maybe bit-depth related) rather than z-sorting. Did you
    solve the streaking?

    - Ben


    duckets Guest

  9. #9

    Default Re: Alpha transparency borders on dynamically loadedimages for use with textures

    Is your texture width and height a power of two?(16,32,64,128,256,512,1024,etc)
    If not then your texture will look lousy and streaking may still occur due to
    the renderer forcing the image to scale to a power of two. I have been able to
    work around this problem on occasion by using the #rgba5551 textureformat under
    DX_7. Also, if I remember correctly, when you are creating the mask in an image
    object the mask has to be 8bit and of the same dimensions as the 32 bit host
    image (the mask function in imaging lingo does not add alpha transparency to
    the host image/base layer, but merely composites transparent layers onto the 32
    bit host image, i.e. the 32 bit host image should contain the alpha
    transparency before compositing). In addition, trying to up-sample from 16 bit
    to 32 bit may alias your image boundaries significantly and could be an issue.
    On the other hand, the problem could lie with your UV mapping, but we can't
    tell for sure unless you post the actual code used or at least a screen capture
    of the problem.

    _eyesonly Guest

  10. #10

    Default Re: Alpha transparency borders on dynamically loadedimages for use with textures

    Hi, you can try using other texture layer as mask on the same shader. As
    usually you create the texture from a dynamic loaded image, then apply this
    texture to the shader on the texture list index 1 (textureList[1]). Next part
    does the job, create other texture from a 32 bits image with the alpha
    information and fill all pixels with white color, this is very important
    because the second texture layer will be multiply with the first texture layer.
    This texture set its render format to rgba8888. Apply the mask texture to the
    same shader at texture list index 2, verify that the blendFunctionList index 2
    is #multiply.

    I include the code of a project that use this masking approach:

    property pMember
    property pEarthSphere
    property pNightSphere
    property pLastTransform

    on beginSprite me
    pMember = sprite(me.spriteNum).member
    me.setupWorld()
    end

    on setupWorld(me)
    pMember.resetWorld()

    repeat with i = pMember.light.count down to 1
    pMember.deletelight(i)
    end repeat

    vEarthModelResource = pMember.newModelResource("EARTH MODEL RESOURCE",
    #sphere)
    vEarthModelResource.radius = 50.000
    vEarthModelResource.resolution = 20

    vEarthTexture = pMember.newTexture("EARTH TEXTURE", #fromCastMember,
    member(3,1))

    vEarthShader = pMember.newShader("EARTH SHADER", #standard)
    vEarthShader.emissive = color(255,255,255)
    vEarthShader.flat = TRUE
    vEarthShader.transparent = FALSE
    vEarthShader.textureList[1] = vEarthTexture

    pEarthSphere = pMember.newModel("EARTH MODEL", vEarthModelResource)
    pEarthSphere.shaderList = vEarthShader

    vNightModelResource = pMember.newModelResource("NIGHT MODEL RESOURCE",
    #sphere)
    vNightModelResource.radius = 50.2000
    vNightModelResource.resolution = 20

    vNightTexture = pMember.newTexture("NIGHT TEXTURE", #fromCastMember,
    member(4,1))
    vNightTexture.quality = #lowFiltered
    vNightTexture.nearFiltering = FALSE
    vNightTexture.renderFormat = #rgba8880

    vNightShader = pMember.newShader("NIGHT SHADER", #standard)
    vNightShader.emissive = color(255,255,255)
    vNightShader.flat = TRUE
    vNightShader.transparent = TRUE
    vNightShader.textureList[1] = vNightTexture

    vMaskNightTexture = pMember.newTexture("MASK NIGHT TEXTURE",
    #fromCastMember, member(6,1))
    vMaskNightTexture.renderFormat = #rgba8888

    vNightShader.textureList[2] = vMaskNightTexture
    vNightShader.textureModeList[2] = #wrapPlanar

    pNightSphere = pMember.newModel("NIGHT MODEL", vNightModelResource)
    pNightSphere.shaderList[1] = vNightShader

    pNightSphere.parent = pEarthSphere


    end


    on exitFrame(me)
    pEarthSphere.rotate(0.0,0.1,0.0)
    me.moveMaskNightTexture()
    end


    on moveMaskNightTexture(me)
    vRotationVector = - pEarthSphere.transform.rotation
    pNightSphere.shaderList[1].wrapTransformList[2].rotation = vRotationVector
    end


    DAVID Guest

Similar Threads

  1. Alpha in Targa, not transparency
    By Ken Warren in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 6
    Last Post: November 27th, 06:48 AM
  2. Alpha channels on textures
    By guy.bowden@gmail.com in forum Macromedia Director 3D
    Replies: 3
    Last Post: August 10th, 05:12 PM
  3. staggered performance as textures are loaded
    By macromedia in forum Macromedia Director 3D
    Replies: 5
    Last Post: October 15th, 12:59 AM
  4. textures with alpha showing BEHIND objects which are BEHIND them...
    By Gianpiero Colagiacomo in forum Macromedia Director 3D
    Replies: 0
    Last Post: September 27th, 07:58 PM
  5. Textures with Alpha Channels
    By randallr webforumsuser@macromedia.com in forum Macromedia Director 3D
    Replies: 2
    Last Post: August 9th, 10:52 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139