Updates from June, 2014 Toggle Comment Threads | Keyboard Shortcuts

  • Pablo 4:24 PM on 19 June 2014 Permalink | Reply  

    Alternativa3D two sided texture 

    It is so simple… you just basically have to set the culling property of the draw unit of your material to Context3DTriangleFace.NONE

    that will draw both sides of each polygon. In  my case, to do this, i got a copy of the TextureMaterial class into my proyect source directory and changed the visibiity of the method getDrawUnit to protected. Then, you just override it in your own material’s class and set the culling protperty of the return value of the super.getDrawUnit then return the same value:

    override protected function getDrawUnit(program:TextureMaterialProgram, camera:Camera3D, surface:Surface, geometry:Geometry, opacityMap:TextureResource):DrawUnit {
    var du:DrawUnit = super.getDrawUnit(program,camera,surface,geometry,opacityMap);
    du.culling = Context3DTriangleFace.NONE; // <-- THIS MAKES THE MATERIAL TWO SIDED!
    return du;

    Source: http://forum.alternativaplatform.com/index.php?showtopic=3986&p=22123

  • Pablo 9:04 PM on 18 June 2014 Permalink | Reply  

    AGAL, PNG blending & Transparency (bug)? 

    So, to make this short, i was trying to find out how to make a fragment shader to be able to put several PNGs one on top of the other and have them mix togheder, i achieved that by using this code:

    • t3 = temporal variable.
    • t0 = transparentPNG with just lines and shading. It is a “tex”… a png that has just shading information.
    • t2 = base color “skin color”.  Just a color, no alpha. 
    • c1.w = 1 the number one.


    "sub t3.xyz, t0.xyz, t2.xyz", // shading color - base color.
    "mul t3.xyz, t3.xyz, t0.w", // multiply the above value by the alpha value of the shading layer.
    "add t2.xyz, t2.xyz, t3.xyz", // add the above value to the base color.

    That works fine, BUT it has an issue. If you draw a semi transparent white line for example, since colors in PNG are premultiplied by their alpha values, you will get a greyish color on top of the base color. So white %50 alpha will make the color below to look darker. To solve that, you have to remove the premultiplication ( idk if there’s a more optimal way to solve this, this is how i did it with the knowledge i have right now…). The color components of a PNG are multiplyed by their alpha component. If you divide them by their alpha you will inverse the operation, obtaining the original color without alpha.

     "div t0.xyz, t0.xyz, t3.w" , //Remove premultiplication by dividing by the alpha.
    "sub t3.xyz, t0.xyz, t2.xyz", 
    "mul t3.xyz, t3.xyz, t0.w",
    "add t2.xyz, t2.xyz, t3.xyz"

    Now there’s another issue. In SOME computers, it will work fine. but in some others, the new line added will turn fully transparent pixels into black pixels. Any pixel that has an alpha values greater than cero will look fine…. to solve that, you have to remove the premultiplication using a new number, that will be equal to the alpha value of the shading layer BUT it will be 1 (fully opaque) if the alpha value is equal to CERO. Final code…

     "sub t3.w, c1.w, t0.w", // t3.w = 1 - alpha value of shading layer. ( c1.w = 1 )
    "sge t3.w, t3.w, c1.w", // t3.w = 1 if the value above was CERO, else ONE
    "add t3.w, t3.w, t0.w", // now we ADD the alpha value. CERO will turn into ONE, the rest will remain the same.

    "div t0.xyz, t0.xyz, t3.w" ,
    "sub t3.xyz, t0.xyz, t2.xyz",
    "mul t3.xyz, t3.xyz, t0.w",
    "add t2.xyz, t2.xyz, t3.xyz"

    now it should work fine and the PNG will blend correctly with the base color just like in photoshop.

    If you (the reader) know a better solution, please post it as a comment below, because i want to know how to do this properly. I’m just starting to learn this, so mabe i just made a complete mess and i dont know it. 

  • Pablo 11:42 AM on 1 June 2014 Permalink | Reply  

    “Stack underflow” error only in Release mode. 

    Today i came across a very weird error, that showed, only in release mode:

    VerifyError: Error #1024: Stack underflow occurred.

    Apparently, after googling the web, it happens (one of the many reasons…) when the compiler compiles by error a trace statement. 

    In general, trace() calls get ignored in release mode, but if they appear in the code in non conventional ways, they can enter the swf file and trigger that error.

    In my case, i was tracing something if some condition was true, but i wrote it this way: 

    some_variable && trace(“variable is true”);

    apparently that was the error making the trace enter the published swf bytecode. 

    My solution was to remove that line and i wont be using that type of tracing anymore. 

    More usefull info about this subject here: 



Compose new post
Next post/Next comment
Previous post/Previous comment
Show/Hide comments
Go to top
Go to login
Show/Hide help
shift + esc