Restauring the pixels


sebt3

homebrew player (P. & C.)
Joined
Sep 9, 2008
Messages
4,885
Age
42
Location
France
Website
sebt3.openpandora.org
Hi there,


When scalling a texture up, the SGX tend to do a blurry job, so I wanted to get a "pixel restaurer" shader.


In my test, I'm using a quad with coordinate for fullscreen ((-1,-1) to (1,1)


Here is the shaders :


test.vert :



Code:
attribute vec4 a_position;

attribute vec2 a_texCoord0;

varying vec2 v_texCoord0;

uniform vec4 u_param;

void main()

{

    	vec2 dotPos;

    	dotPos.x = (floor(a_texCoord0.x/u_param.x))*u_param.x;

    	dotPos.y = (floor(a_texCoord0.y/u_param.y))*u_param.y;

    	gl_Position =  a_position;

    	v_texCoord0 = dotPos;

}

test.frag :



Code:
precision mediump float;

varying vec2 v_texCoord0;

uniform sampler2D s_texture0;

void main()

{

    	gl_FragColor = texture2D(s_texture0, v_texCoord0);

}


I'm pushing the size of a pixel in u_param.xy (aka 2/texture width for x and 2/texture height for y).


But it still doing that ugly blurry mess.


Could someone explain me what I'm missing ?
 

Exophase

Nothing good will ever come of Exophase.
Joined
Sep 21, 2006
Messages
10,308
Age
39
Location
Cleveland OH
Texture filtering is done by the TMU in hardware, it happens outside of the fragment shader. What you're describing is probably due to having bilinear filtering enabled. This page should help you:


http://gregs-blog.co...ters-explained/


You'll want to set the mag filter to nearest - instead of getting something blurry it'll look unevenly blocky. That is, if it's not an integer scale ratio. Since it's magnification you don't have to worry about mipmapping (unless you use an LOD bias). And due to only having one MIP level there won't be a difference between bilinear and trilinear filtering.


If you're only scaling by an integer ratio you might be wondering why it matters if bilinear filtering is on, since the fractional part of the texture coordinates should be zero. This is because OpenGL samples at the center of a texel. If you offset the texture coordinates by 0.5 integer scaling should be sharp regardless of the filter.


You should be able to handle all of these things in OpenGL ES 1.x, w/o needing shaders.
 
Last edited by a moderator:

sebt3

homebrew player (P. & C.)
Joined
Sep 9, 2008
Messages
4,885
Age
42
Location
France
Website
sebt3.openpandora.org
goosh, now I feel stupid :wacko:



Code:
    	//GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));

    	//GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));

    	GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));

    	GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));


Thanks Exophase, much better now
 
Top