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

PixelShaderGen: Use LOD bias when sampling texture on Metal and OpenGL ES #10292

Merged
merged 4 commits into from
Dec 28, 2021

Conversation

OatmealDome
Copy link
Member

#9998, take two.

In Twilight Princess, the iris of Midna's eyes disappears as the camera moves further away from her model. This is done by using two mipmaps: one with her iris, and one with just the pale yellow of her sclera. The game sets the distance at which the transition between the two mipmaps occurs by setting the LOD bias value to a large negative value.

To emulate LOD bias in the Vulkan backend, mipLodBias in the VkSamplerCreateInfo for the texture's sampler is set. Unfortunately, Metal does not support setting LOD bias in a sampler, so mipLodBias is ignored by MoltenVK. On OpenGL ES, the sampler parameter for setting LOD bias (GL_TEXTURE_LOD_BIAS) is unsupported, unlike desktop OpenGL.

This causes Midna's iris to only appear when the camera is very close to her.

While manual texture sampling does solve this issue, it can be less performant at higher resolutions and on low-power platforms (i.e. Android). As a separate workaround, we can pass through a bias value in the texture() call in the fragment shader, which both OpenGL ES and Metal support.

Fixes https://bugs.dolphin-emu.org/issues/11568 and https://bugs.dolphin-emu.org/issues/11993..

Screenshots (macOS)

Broken:

image

Fixed:

image

@pizuz
Copy link

pizuz commented Dec 26, 2021

Works as intended (nVidia GeForce GT 750M on macOS 10.15.7).

Comment on lines +516 to +518
// GL_TEXTURE_LOD_BIAS is not supported on GLES.
g_Config.backend_info.bSupportsLodBiasInSampler = false;

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you're only ever setting it to false for GLES; you're never setting it to true for regular OpenGL. That's probably the cause of the fifoci differences on ogl-lin-mesa.

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe I set it to true by default in OGLMain.cpp?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yes, I missed that. And FifoCI does seem to be using regular OpenGL (see the build log, which says Dolphin [refs/pull/10292/head] 5.0-15686 | FifoPlayer SC | OpenGL | HLE | FPS: 1 - VPS: 1 - 0% instead of OpenGL ES).

@JMC47 JMC47 merged commit 01e8e95 into dolphin-emu:master Dec 28, 2021
@brujo5
Copy link

brujo5 commented Dec 28, 2021

someone posted this in forum

Version 5.0-15676 fixed the problem of lack of shadows in Rayman 3 in OpenGL ES, but in version 5.0-15706, which is part 2 of this fix in this API, games break when using OpenGL ES and this message appears as this image capture:

image https://forums.dolphin-emu.org/attachment.php?aid=19950

https://forums.dolphin-emu.org/Thread-games-crashes-on-opengl-es-from-5-0-15706?pid=523231#pid523231

@OatmealDome
Copy link
Member Author

#10314 should fix this crash. Sorry about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants