turning off texture smoothing alternativa3d 8

Now that alternativa3d has been released as opensource and is available online at github, this opens up the opportunities for developers to try some great things with the technology and hopefully contribute to its development. The first thing that bugged me with version 8 is that I couldn’t turn off the smoothing of images. In version 7 you could easily do this by setting material.smooth to false and get that pixelated look. So I thought now the source is released I’d put together a little example of how to get this same effect. minecraft head To create this I duplicated the TextureMaterial class from the alternativa source code and made my own PixelTextureMaterial. In this class there are 2 constants that contain AGAL code that is for the diffuse and diffuse with alpha rendering. If you aren’t familar with AGAL, I guess it can be described as sort of gpu assembly code. Anyway there is a line in the AGAL code that begins with “tex” and then has some various registers and flag options. Here is an example of code

tex t0, v0, s0 <2d, linear,linear,miplinear>

The flag options between the arrows are what we are interested in, these options represent this data

<dimension,mipmapping,filtering,repeat>

The texture dimension can be : 2d, cube The texture mipmapping can be : nomip, mipnone, mipnearest, miplinear The texture filtering can be : nearest, linear The texture repeat can be : repeat, wrap, clamp The texture filtering is responsible for the way our image is sampled and the current TextureMaterial is set to use linear filtering, if we change this to say nearest we can get that pixelated look we want. Here is what my changed code looks like, you can of course alter the other flag options to remove mipmapping or change the repeat etc if you desire. The full source code is available here or see the demo here.

static alternativa3d const getDiffuseProcedure:Procedure = new Procedure([
    	"#v0=vUV",
    	"#s0=sDiffuse",
    	"#c0=cThresholdAlpha",
    	"tex t0, v0, s0 <2d, linear,nearest, miplinear>",
    	"mul t0.w, t0.w, c0.w",
    	"mov o0, t0"
], "getDiffuseProcedure");
    
static alternativa3d const getDiffuseOpacityProcedure:Procedure = new Procedure([
    	"#v0=vUV",
    	"#s0=sDiffuse",
    	"#s1=sOpacity",
    	"#c0=cThresholdAlpha",
    	"tex t0, v0, s0 <2d, linear,nearest, miplinear>",
    	"tex t1, v0, s1 <2d, linear,nearest, miplinear>",
    	"mul t0.w, t1.x, c0.w",
    	"mov o0, t0"
], "getDiffuseOpacityProcedure");

Downloads

Comments

  • avatar-terry
    # Terry
    Found this via google, thank you! Incredible useful little class :)
  • avatar-p48l0
    # P48l0
    Why it draws more triangles withouth smoothing on?
  • avatar-davidejones
    # davidejones

    Hmm I hadn’t noticed that but you are right. Its doing 2 draw calls when showing pixelated. It might be the way I wrote the material, at the time i used some outProcedure.compileFromArray method to change things depending on the smoothing option. Perhaps its causing it to call the agal twice?

    Basically if you take the texturematerial source code from github and replace 2d, linear,nearest, miplinear with 2d,nearest,clip,mipnone it should do the same and perhaps without doubling the faces.

    Maybe i can post an updated version, i’ve learnt alot since i first made this minor change

    • avatar-p48l0
      # P48l0

      @davidejones yeah, you’re right, i did that replacement and it removes the smoothness without redrawing triangles. Hey, you know what would be cool? A “Fog” tutorial. I’m trying to create fog and so far, the only solution i could find (i dont know almost anything about coding shaders…) is to create several semi-transparent planes in front of the camera in layers… like an old Playstation game.

      Im guessing that a shader could do that much better?

  • avatar-davidejones
    # davidejones

    Ah glad that worked.

    I’ve tried out the built in fog system, I can write up how to at least do that.

    • avatar-p48l0
      # P48l0
      @davidejones a fog tutorial would be cool, i have been searching for info but without much success. And i think it would be really cool to have one because fog is a feature that adds a lot of volume to a scene.
      • avatar-davidejones
        # davidejones
        I’ve added a quick fog post if you wanna check it out :)
  • avatar-franklin
    # Franklin
    Hi, I’m just getting started with flash and using alternativa3d for iOS games. How did you get you lines/edges in the box to be so smooth? Mine are really jagged and drawing primitives from alternative for dummies part 1
    • avatar-davidejones
      # davidejones
      do you mean the edges of the box? the primitive box? It just works like that for me. It could be some of your settings like the flash player you are targeting and maybe the stage quality setting
      • avatar-franklin
        # Franklin
        How do I change the quality setting? Sorry, I’m a total mood.
        • avatar-davidejones
          # davidejones

          see if that helps

          stage.quality = StageQuality.HIGH;

          • avatar-franklin
            # Franklin
            didn’t work, tried several different ways.
          • avatar-franklin
            # Franklin

            Ok, I had to import the package StageQuality and it ran, but the quality didn’t change at all. Have you seen away 3d, the quality is 100x better, it just seems alternativa3d is easier because it has better documentation.

            maybe something with smooth?

  • avatar-davidejones
    # davidejones
    Not really sure what you mean the quality works great for me and as good as away3d. Email me your code you are working with and i’ll see if i can see anything wrong with it.
  • avatar-noktai
    # Noktai
    I get an incompatable override error on both canDrawInShadowMap and collectDraws in PixelTextureMaterial.as. I am using the exact sources you provided and used them in a flashdevelop project. Very frustrating, any idea what could be the problem? The override on fillResources seems to work fine for some reason, very strange.
  • avatar-uv-scrolling-material-for-alternativa3d
    # UV Scrolling Material for Alternativa3D |
    […] Turning off texture smoothing alternativa3d 8 […]

Comments are currently closed