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
<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");
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
@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?
Ah glad that worked.
I’ve tried out the built in fog system, I can write up how to at least do that.
see if that helps
stage.quality = StageQuality.HIGH;
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?
Depending on which version you are using and which material is why the incompatible override will appear. I’d recommend grabbing the latest version from github and checking the files there to see what the right override should be. They added more to arguments.
https://github.com/AlternativaPlatform/Alternativa3D/blob/master/src/alternativa/engine3d/materials/Material.as#L87