Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revamp cubemap code and fix quake3 skybox with small bottom face, fix #142 #179

Merged
merged 3 commits into from
Mar 10, 2019

Conversation

illwieckz
Copy link
Member

@illwieckz illwieckz commented Mar 5, 2019

Skybox code revamp

The skybox code was very ugly with 10 gotos and buggy behavior, for example it would not attempt to load any multifile skybox if a single-file skybox was successfully loaded but had invalid content.

Also, the code was inefficient, for example it was doing the image rotation operation for every face even if the rotation has an angle of 0°, hence allocating a new image, copying all the pixels in the new image et. for nothing.

Irregular skybox fixing

Some quake3 skyboxes were shipped with a smaller bottom face, for example a 16×16 bottom face while other faces were 512×512 that was probably a trick to save file size when textures were stored losslessly in a tga and bandwith was low as voice modems.

To fix this, a new R_Resize function is added to tr_image.cpp that is just a wrapper to ResampleTexture that makes in-place resizing easier.

The faces are resized to the size of a square that has for width and height the greater width and height found in any face. This way it would not only fix the quake3 skyboxes with smaller bottom faces, but also non-square skyboxes.

A warning is displayed so the user is encouraged to fix the skybox because 1. we workaround something that is broken, 2. user may is likely to have access to tools with resize algorithms that produce better looking results.

In any way, those kind of small bottom faces were likely to not be seen, that's also why they were downscaled at first.

@illwieckz
Copy link
Member Author

illwieckz commented Mar 5, 2019

Example of such skybox (alamo, from the Smokin' Guns game):

smaller face in alamo skybox

Before:

broken alamo skybox

After:

fixed alamo skybox

fixed alamo skybox

@illwieckz
Copy link
Member Author

illwieckz commented Mar 5, 2019

Note that this issue was first faced with Tremulous maps so the issue is very likely to occur because that was a supported feature of Tremulous, hence the regression label.

@g-bougard
Copy link

Hi @illwieckz
the fix seems fine to me.
Btw you should not mix tab/space indentation in your patch.

@megatog615
Copy link

Why not examine the sizes of all sides and scale them all to the biggest just in case there exists a skybox with this trick done on another side than the bottom? You could even have the algorithm skip sides that already equal the detected size.

@illwieckz
Copy link
Member Author

oh right, there was some boring spaces, fixed!

@illwieckz
Copy link
Member Author

@megatog615 I thought about it but it would require some extra code for an occurrence that will probably never happen… probably not worth it.

@illwieckz
Copy link
Member Author

I just thought about a way to check on all faces while not being so much intrusive so I added a commit trying that instead.

By the way even if it may look possible to do this for all kind of supported cubemap, I really doubt this kind of feature exists outside of quake3.

@illwieckz
Copy link
Member Author

illwieckz commented Mar 6, 2019

I was bored by the skybox code so I revamped it entirely. The skybox code was very ugly with 10 gotos and buggy behavior, for example it would not attempt to load any multi-file skybox if a single-file skybox was successfully loaded but had invalid content.

Also, the code was inefficient, for example it was doing the image rotation operation for every face even if the rotation had an angle of 0, hence allocating a new image, copying all the pixels in the new image etc. for nothing.

The skybox faces are now resized to the size of a square that has for width and height the greater width and height found among the six faces of the cube. This way it would not only fix the quake3 skyboxes with smaller bottom faces, but also non-square skyboxes.

@illwieckz illwieckz changed the title fix quake3 skybox with small bottom face, fix #142 revamp cubemap code and fix quake3 skybox with small bottom face, fix #142 Mar 6, 2019
Copy link
Member

@slipher slipher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer have to live in fear: the goto's are vanquished!

src/engine/renderer/tr_image.cpp Outdated Show resolved Hide resolved
src/engine/renderer/tr_image.cpp Outdated Show resolved Hide resolved
@@ -1937,23 +1937,53 @@ static void R_Rotate( byte *in, int width, int height, int degrees )
ri.Hunk_FreeTempMemory( tmp );
}

byte *R_Resize( byte *in, int width, int height, int width2, int height2 )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use a comment or a different name to indicate that it's specifically for upsampling, not any resize.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think that algorithm does not work for downscaling?
we only use it to upscale, but isn't it generic enough to downscale too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well maybe, if not with the best quality. But there's already a downsampling function ResampleTexture in the same file.

@illwieckz illwieckz force-pushed the fixskybox branch 2 times, most recently from 55afc66 to 6e3792d Compare March 9, 2019 19:09
@illwieckz illwieckz force-pushed the fixskybox branch 2 times, most recently from b114737 to 1d45c0c Compare March 9, 2019 22:58
@illwieckz illwieckz merged commit 58342ad into DaemonEngine:master Mar 10, 2019
@illwieckz illwieckz deleted the fixskybox branch January 18, 2020 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants