# Texture atlas question

## Recommended Posts

So I've been trying to get a texture atlas to display correctly on my chunks but some of the textures are displayed sideways. I'm stumped trying to figure out how to rotate the textures. I've had some success using SetVertexNormal but I don't know how to flip them 90 degrees. Here's the shader I'm using, I converted it from this article. https://0fps.net/2013/07/09/texture-atlases-wrapping-and-mip-mapping/

```    //Initialize accumulators
vec4 color = vec4(0.0, 0.0, 0.0, 0.0);
float totalWeight = 0;

vec2 tileUV = vec2(dot(ex_normal.zxy, ex_position),
dot(ex_normal.yzx, ex_position));

tileOffset = vec2(0.20, 0);
vec2 tileSize = vec2(0.025,0.025);

for(int dx=0; dx<2; ++dx)
for(int dy=0; dy<2; ++dy)
{
//Compute coordinate in 2x2 tile patch
vec2 tileCoord = 2.0 * fract(1 * (tileUV + vec2(dx,dy)));

//Weight sample based on distance to center
float w = pow(1.0 - max(abs(tileCoord.x - 1.0), abs(tileCoord.y - 1.0)), 8.0);

//Compute atlas coord
vec2 atlasUV = tileOffset + tileSize * tileCoord;

//Sample and accumulate
color += w * texture(texture0, atlasUV);
totalWeight += w;
}
//Return weighted color
fragData0 = (color / totalWeight);```

I'm completely new to shader programming, so I'm sure there's some stupid mistake I've overlooked. Alternately I've tried using a texture array instead but have had little success. I was trying to follow this code but I couldn't get it to work.

I guess texturing with algorithms is a bit more complicated than I thought it was going to be. I was planning on rendering multiple chunks and cave generation but got stuck trying to figure out how to properly texture a single chunk.

Its been a while since I was tackling texture arrays & atlases.  I did manage to get the arrays working in a way, but not exactly how I wanted them too work.  As far as getting your texture to rotate, have you tried swapping dx and dy?  Is that what you mean by getting them to flip 90°?  I'm away from my PC at the moment so I'm unable to test it and I'm just going off memory.  😉

1 hour ago, Lethal Raptor Games said:

Its been a while since I was tackling texture arrays & atlases.  I did manage to get the arrays working in a way, but not exactly how I wanted them too work.  As far as getting your texture to rotate, have you tried swapping dx and dy?  Is that what you mean by getting them to flip 90°?  I'm away from my PC at the moment so I'm unable to test it and I'm just going off memory.  😉

That worked! I feel so stupid for not thinking of that before. I had to make a conditional statement in the shader to swap the UV based on the normal position.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
• ### Recent Topics

• #### changing state of post-process shader by code

By Christian Clavet, in Programming

• 10 replies
• 366 views
• #### How to use the underwater shader?

By havenphillip, in Programming

• 14 replies
• 490 views
• #### Question: Texture tiling on decals.

By reepblue, in Technical Assistance

• #### how make "Moving Platforms" Face direction of motion

By Russell, in Programming

• 8 replies
• 166 views
• #### Camera don't render on texture in STANDALONE version

By Russell, in Bug Reports

• 9 replies
• 146 views
×

• Pages

• Back
• Store

• #### Support

• Projects
×
• Create New...