This tutorial will show how u can make ur texture rendering look much nicer with little to no effort.
This applies to OSRS, 317 and probably < 500 revs, when i use the term "rs renderer" i am referring to the renderer used in the 317/osrs client
So, the rs renderer clamps/stretches texture coordinates when rendering a textured triangle, which means that if the coordinate is out of bounds(0-1 or if it's easier to think of, 0-4095 for a 64x64 texture) it'll simply be given the edge color
If you looked at the rasterizer in the client, you may have seen something like this:
Code:
if (u < 0) {
u = 0;
} else if (u > 4032) {
u = 4032;
}
which clamps the u(x) coordinate, now instead of clamping u would ideally want to repeat the texture, which means that once it goes out of bounds, it starts from 0, for example if you have the following texture coordinates
u = 1.2
v = 1.45
they become 0.2 and 0.45 when you repeat the texture.
This is very simple to implement, also lets make it toggleable
1) Open the Graphics3D/Rasterizer class(whatever it's called in ur client) and create a new variable called repeatTexture
2) Open the Model class, create a new boolean array called repeatTexture and make sure to initialize it properly in the model constructors, merge method
3) find the method that calls the triangle drawing methods(could be called rasterize or something) and add the following lines(put them after the triangle alpha check for example, just has to be before the draw calls):
Code:
if (repeatTexture == null) {
Rasterizer.repeatTexture = false;
} else {
Rasterizer.repeatTexture = repeatTexture[face];
}
4) Open the Graphics3D/Rasterizer class and find the textured scanline drawing method could be called something like drawTexturedScanline, find the parts that clamp the coordinate
Code:
if (u < 0) {
u = 0;
} else if (u > 4032) {
u = 4032;
}
and replace it with
Code:
if (!repeatTexture) {
if (u < 0) {
u = 0;
} else if (u > 4032) {
u = 4032;
}
}
the same for 128x128 textures, instead of 4032 it's 16256, and now the final part, just before you store the pixel, repeat it by AND'ing it with 4095, 16383
Example:
Code:
if (repeatTexture) {
raster[offset] = texels[(vA & 0x3f80) + (uA >> 7) & 16383] >>> lightness;
} else {
raster[offset] = texels[(vA & 0x3f80) + (uA >> 7)] >>> lightness;
}
this was extremely simple, wasn't it(NOTE: this makes the textures a little brighter, so u need to account for that if u don't want it to be this way, however imo it looks better)? now let me show some before vs after images/gifs
those are just a few examples, the main benefit of this is that u don't have to worry about the coordinates going out of bounds when u define the texture coordinates, this has saved me a lot of time(from spending 15-30mins or sometimes even longer for a nice textured model, it now takes 1-2mins and looks really good)
NOTE: this does not decrease the performance at all