Improve lightmap/texture interpolation?

Get support for anything JK2 related, find tutorials for in-game and modding topics, and post any suggestions for the site here.
Post Reply
Tom Arrow
Posts: 92
Joined: 21 Sep 2016, 03:05

Improve lightmap/texture interpolation?

Post by Tom Arrow »

I have noticed that the lightmaps look kinda shitty at some points, see attached a rather clear example of this on ffa_bespin. For the screenshot, I used mono-color textures, to make it more apparent.

It seems like the current interpolation (from upsizing the tiny lightmaps) creates a weird tile-like structure, which is clearly faulty. I extracted the lightmaps from ffa_bespin and resized them with a few methods and I got similar shitty results with very simple resizing algorithms. But advanced algorithms like Lanczos 3 gave fine results and created exactly the circle-like gradients you would expect.

I also attached a screenshot where the same happens with saber glows, which is much more apparent and ugly even with normal textures.

Those things do not seem to be affected by r_textureMode, so I was wondering whether this was a limitation of OpenGL or of the engine itself, which may possibly be doing the upsizing. If the engine is doing it, it should be rather trivial to replace this code with some Gaussian (?) interpolation with a certain performance hit.

If it is an OpenGL thing, can it be hacked with not much effort?

I know I could crawl the code myself for this, but being the noob that I am, I suspect I would take ages to find the right place, so if some of you guys already know something about the process, I would appreciate input.
Attachments
tilelightsshot0103.jpg
tilelightsshot0103.jpg (141.45 KiB) Viewed 49295 times
tilelightsshot0105.jpg
tilelightsshot0105.jpg (148.03 KiB) Viewed 49295 times
User avatar
fau
Staff
Posts: 433
Joined: 16 Aug 2015, 01:01
Location: Warsaw / Poland
Contact:

Re: Improve lightmap/texture interpolation?

Post by fau »

r_texturemode is a bit broken atm, I had to modify engine to take this screenshot: viewtopic.php?f=23&t=136&p=4499&hilit=minecraft#p4499
I don't remember what was it exactly, maybe just my video driver.

Upsizing lightmaps is an interesting take, but you can't automatically make up for information that isn't there. Eg you pick a method that smooths-out blocky edges, but some lightmaps may represent actual sharp shadows. If anything recompiling a map with higher res lightmaps is the way to go.

Saber glows on the floor are something else, these are dynamic lights and they have their own limitations.

For your information: lightmaps are not picmiped and don't use mipmaps. Try r_lightmap values 1 and 2
Tom Arrow
Posts: 92
Joined: 21 Sep 2016, 03:05

Re: Improve lightmap/texture interpolation?

Post by Tom Arrow »

r_lightmap is cheat protected. But I tried it on my own offline server and it just made the lights ... overbright. Didnt take away the edges.

Yes, you have a point, in a way. Then again, I think you don't. This is clearly a bad upscaling algorithm at work. Look close. It looks like there are tile-like lines in the spot light. This indicates to me that when the renderer (or whatever) calculates a value for a pixel (or texel? whatever) that is not on a perfect line between two lower-resolution pixels, it loses brightness. Say we have four pixels with 100% brightness and want to interpolate a pixel that is perfectly centered between those. The correct equation would end up looking something like 0.25*100%+0.25*100%+0.25*100%+0.25*100%=100%.

So my guess is that there is some modification (gamma?) fucking it up by making the data nonlinear or something (?). This is my guess because I know a similar effect with other non-linear data, specifically audio. Audio data is not linear and when you do a linear blend between two audio pieces, you get a dip in the perceived 'power' of the sound. I don't know the exact algorithm, but Cubase offers a blending mode called 'constant power' for this, which does a kind of 'curved' blend. This works perfectly. [Edit. Discard this paragraph, it's probably bullshit]

I don't see why the current algorithm would be of any importance anyway. Those are not real edges even in the original lightmap. Those 'tiles', I think, are really the single pixels from the lightmap (they're really small, I attached one of them). There is no edge information in there. They are artifacts. The result, in my eyes, is just wrong. It's what I get with a bad upsizing algorithm. In video editing, I get a similar result when I take a small picture and upscale it without interpolation, then apply an effect called 'Box Blur'. This is a very fast blurring algorithm which creates exactly these kinds of artifacts, too. It is very inferior to other algorithms like Gaussian Blur, but it is a lot faster. Which leads me to assume that the same case is with JK2. They probably implemented the simple blur / interpolation algorithm, because it was faster. That's less relevant today, but back then, it probably made a huge difference.

See attached, the original lightmap (tiny). I also attached a resized version with IrfanViews 'triangle' algorithm (very simple) and one with the 'lanzcos' algorithm. You can clearly see the same type of artifacts in the Triangle version, but very clean circles of light in the Lanzcos version. In fact, even the edges look better in the Lanzcos version. :)

Nice screenshot btw. Was that a lot of modifications?
Attachments
lightmap_0003_resizeTriangle.jpg
lightmap_0003_resizeTriangle.jpg (810.62 KiB) Viewed 49291 times
lightmap_0003_resizeLanzcos.jpg
lightmap_0003_resizeLanzcos.jpg (886.82 KiB) Viewed 49291 times
lightmap_0003.jpg
lightmap_0003.jpg (3.31 KiB) Viewed 49291 times
Tom Arrow
Posts: 92
Joined: 21 Sep 2016, 03:05

Re: Improve lightmap/texture interpolation?

Post by Tom Arrow »

As for the dynamic lights, I think the same applies to them in some way. You can see if you look closely that interpolation is indeed being done. It's not completely blocky, more like 'blockish'. That is, the blocks are blurred. I bet this can be improved upon.
User avatar
fau
Staff
Posts: 433
Joined: 16 Aug 2015, 01:01
Location: Warsaw / Poland
Contact:

Re: Improve lightmap/texture interpolation?

Post by fau »

Well, linear magnifying filter supported by graphics cards is not the best algorithm out there, but anything better would be way too slow. Iirc it uses Taxicab metric for calculating texel weights so you get stronger intensity along perpendicular lines and "squarish" gradients when upscalling.

I'm not 100% sure what type of artifacts you're talking about.

Yes, gamma is fucking up blending in JK2 because textures are saved in gamma space rather than linear, but I don't think this is it. Lightmaps are probably in linear, didn't check.

Most JK2 either used old q3map2 or didn't make use of sharp shadow techniques, but you can have sharp edges that would get really broken by lanchos upscalling. In JKA they are used more often. Just try upscalling a rectangle with different algorithms. Lanczos will do the worst.

Anyway, what's the point of this upscalling when you can simply ask q3map2 to produce high res lightmaps with from the lighting infomation it has?

Modifications in screenshots: no, I only made gl_nearest texture mode work and the rest is a known combination of cvars among quake 3 players, I played on such settings for a good while (with smaller squares though) ;-)
Tom Arrow
Posts: 92
Joined: 21 Sep 2016, 03:05

Re: Improve lightmap/texture interpolation?

Post by Tom Arrow »

Ah, that seems accurate, yes. Taxicab ... what I meant with artifacts was this thing about perpendicular lines being stronger.

Anyhow, I still feel like I'd like to try. Is there any way to use another algorithm without extreme hassle?

As for q3map2, that would be great if it could store lightmaps at large enough scale in the BSP. Normal storage seems to be 128x128, although you probably could at least get it to use more separate lightmaps (that is, fewer vertexes in each lightmap). But from what I read, it's not possible to get it to separate one square face into multiple lightmaps, so the maximum resolution for any square face will always be 128x128. Unless one were to modify q3map2 and the jk2mv/jomme code, but I personally don't feel I have the time to be doing that right now. Meh.

Maybe I could ask the ca Bespin makers for the source file so that I can try recompile with a different, whats it called, lightmapscale?

Interesting bit about Lanczos. I'll try that if I get the chance.

May I ask what those known cvars are?
User avatar
fau
Staff
Posts: 433
Joined: 16 Aug 2015, 01:01
Location: Warsaw / Poland
Contact:

Re: Improve lightmap/texture interpolation?

Post by fau »

r_picmip around 8 - it controls size of squares. r_texturemode gl_nearest. Perhaps r_vertexlight 1

Can't say for sure, but I haven't heard of any other hardware accelerated filtering than nearest and linear in 3d applications.

Changing lightmaps size in q3map2 and jk2mv is certainly easier than trying to implement magnifying filter other than nearest/linear. literally 3 lines of code + ability to recompile them. Not saying it's not possible, I don't know, but certainly there is no easy/standard way exposed in OpenGL API
Tom Arrow
Posts: 92
Joined: 21 Sep 2016, 03:05

Re: Improve lightmap/texture interpolation?

Post by Tom Arrow »

Another possibility would be to upscale the lightmaps within JK2MV as soon as they are loaded. Thus you keep backwards compatibility. Meanwhile you could somehow allow for JK2MV to support variable lightmap sizes. Two problems solved with one go.
User avatar
ouned
Administrator
Posts: 596
Joined: 23 Feb 2015, 13:03
Location: Gliese581c

Re: Improve lightmap/texture interpolation?

Post by ouned »

I cant see how this is a problem. When looking at your screenshots it clearly is but in "normal" mode I never even noticed it.
Maybe I'm just too used to it though.
Tom Arrow
Posts: 92
Joined: 21 Sep 2016, 03:05

Re: Improve lightmap/texture interpolation?

Post by Tom Arrow »

Oh, it's not a big problem. Call it annoying perfectionism or something. It's why I asked if there was a quick fix. Clearly this isn't worth investing a month of work into. But if I had just missed some simple cvar, that would have been worth it.
Post Reply
Created by Matti from StylesFactory.pl and Warlords of Draenor (modified by jk2.info)
Powered by phpBB® Forum Software © phpBB Limited
 

 

cron