Jump to content

How to use nearest neighbor texture filtering for pixel art?


photo

Recommended Posts

I am currently working on a game which will make heavy use of unlit bill boarded planes with pixel art on them, however i can't find a way to disable texture filtering on the texture I'm using. Below you can see a terrible image which should be nice and crisp.

image.png.9ad41cfe927ce4bdbfb8dd9bdb98141f.png

i would like it to look nice an crisp like

 image.png.f9caf680445fd2c95816fa1d63736073.png
that image was achieve by using a higher resolution texture. but that is wasteful
 

Link to comment

What I want is some material which has no lighting, transparency is either fully transparent (discard) or fully opaque. and has no texture filtering so that low res textures would still look nice. The idea is we would like to use unigine's full potential for visual fidelity for our environments,  but would have sprites similar to early 3D games that always face the camera with low res but sharp looking textures.

Link to comment

Write a shader or own material?

Love the PixelArt Look btw.. ;)

Edited by werner.poetzelberger
  • Like 1
Link to comment

Yes i was thinking this may be the direction I have to go but I don't have much experience with this. I was under the impression that texture filtering was an aspect of the texture it's self when sent to the GPU and that unigine would be setting the filter mode on the texture when it is sent to the gpu

Link to comment

Okay so I went and made a shader to try and remove texture filtering and so far it has not worked

// Include the UUSL language header
#include <core/shaders/common/fragment.h>

// Adds a texture sampler  (slot 0)
INIT_TEXTURE(0, TEX_COLOR)

STRUCT(FRAGMENT_IN)
    INIT_POSITION                // Projected position
    INIT_IN(float4,0)            // Texcoord (uv)
    INIT_IN(float3,1)            // Vertex TBN (X)
    INIT_IN(float3,2)            // Vertex TBN (Y)
    INIT_IN(float3,3)            // Vertex TBN (Z)
END

MAIN_BEGIN_DEFERRED(FRAGMENT_IN)
    
    // Get the UV coords
    float4 texcoord = IN_DATA(0);

    // Get the texture data
    float4 texture_data = TEXTURE(TEX_COLOR, (floor(texcoord.xy*textureResolution(TEX_COLOR))+0.5)/textureResolution(TEX_COLOR) );
    texture_data = texture_data;
    // Define the normal of a fragment in tangent-space
    STATICVAR float3 tangentspace_normal = float3(0.0f,0.0f,1.0f);
    
    // Calculate the view-space normal
    float3 viewspace_normal;
    viewspace_normal.x = dot(IN_DATA(1),tangentspace_normal);
    viewspace_normal.y = dot(IN_DATA(2),tangentspace_normal);
    viewspace_normal.z = dot(IN_DATA(3),tangentspace_normal);
    viewspace_normal = normalize(viewspace_normal);

    // Fill G-Buffer: set the calculated normal and albedo color of the texture
    GBuffer gbuffer = GBufferDefault();
    gbuffer.albedo = texture_data.rgb;
    gbuffer.normal = viewspace_normal;

    setGBuffer(gbuffer);
    
MAIN_END

// end

this should quantize the texture resolution so it falls on a grid but it doesn't quite work, below is the result i get from the low res texture
image.png.42b59869d54b4fa5fbf8b73ca8a0c80c.png
and below is the expected result 

image.png.9bd7643d8f35e8ade75fc2e52b03726d.png

as you can see there are some pretty heavy artifacts, it would be nice if there was a nearest neighbor filtering option

Link to comment
×
×
  • Create New...