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. 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
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");