Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Strange shader problem.  (Read 205 times)
0 Members and 1 Guest are viewing this topic.
Offline LiquidNitrogen
« Posted 2018-12-07 04:47:08 »

I'm trying to make a shader which can do texture edge wrapping for arbitrary texture regions within an atlas. Generally it works quite well, although there is a strange jittering artifact which I cant figure out how to correct.

These 4 triangles are each drawn with a different sized region of the same texture.


Looking closely, the pixels are misplaced, it is easiest to see on the yellow lines, which should be straight lines.
(there are also some artifacts from edge bleeding, and nearest-neighbour filtering, which dont seem relevant to the problem)



*The problem seems to be only visible when using nearest texture filtering, linear filtering probably hides it enough to be invisible.
*The problem appears and dissappears depending on camera zoom. Specially noticeable when zoom = 1.
*If I offset the texture coords, some values make the problem dissappear. eg: + 0.01 or, + 100.0
*Avoiding using negative texture coord values doesnt help.
*changing precision qualifiers in the shader doesnt seem to make any difference.

Im assuming it is some sort of floating point precision error, which the vertex shaders interpolation naturally accounts for, but my fragment shader code cant account for?

The issue might not be a problem for linear filtered textures, but the intention is to use it for low resolution pixel art with nearest texture filtering, and currently it is ugly.

fragment shader code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
uniform sampler2D u_texture;
varying vec4 v_atlasRegion; // {u1, v1, u2, v2}
varying vec2 v_texCoord;
const float TILE_SIZE = 2048.0 / 32.0; //this should be called howManySingleWorldUnitTilesFitOnTheTexture!

void main(){
   vec2 start = v_atlasRegion.xy;
   vec2 end = v_atlasRegion.zw;
   vec2 size = end - start;

   vec2 sampleCoord = mod(v_texCoord , size * TILE_SIZE) / TILE_SIZE + start;

   gl_FragColor = texture2D(u_texture, sampleCoord);

}

The texCoord attribute values in the mesh have the same values as the position attribute, so they should line up nicely.
Offline LiquidNitrogen
« Reply #1 - Posted 2018-12-07 05:36:47 »

Another part of the mystery! There doesnt appear to be any standard egde bleeding present..
I've circled the source tile, added a red rectangle around the exterior of the tiles region, but what is drawn to the screen appears to be some weird sampling from the pink/green area around that (as if its sampling from a different mipmap level there).

perhaps im doing something wrong with the mod function?

Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (333 views)
2018-11-16 13:46:03

hadezbladez (175 views)
2018-11-16 13:41:33

hadezbladez (333 views)
2018-11-16 13:35:35

hadezbladez (80 views)
2018-11-16 13:32:03

EgonOlsen (2173 views)
2018-06-10 19:43:48

EgonOlsen (2201 views)
2018-06-10 19:43:44

EgonOlsen (1375 views)
2018-06-10 19:43:20

DesertCoockie (2007 views)
2018-05-13 18:23:11

nelsongames (1644 views)
2018-04-24 18:15:36

nelsongames (2294 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!