Add getEyeFromViewMatrix() for vertex shader (#9175)

This new method, intended for the vertex shader, returns a matrix that
transforms vertices from view space (also known as head space) to the
current eye space.

BUGS=[441127971]
This commit is contained in:
Sungun Park
2025-09-03 11:05:34 -07:00
committed by GitHub
parent 3bd6412780
commit b0f8e1be7a
5 changed files with 14 additions and 3 deletions

View File

@@ -7,3 +7,5 @@ We are chaning the way Vulkan buffers are handled. We need to switch over to a m
appropriate header in [RELEASE_NOTES.md](./RELEASE_NOTES.md).
## Release notes for next branch cut
- materials: added `getEyeFromViewMatrix()` for vertex shader [⚠️ **Recompile Materials**]

View File

@@ -63,6 +63,7 @@ void PerViewDescriptorSetUtils::prepareCamera(PerViewUib& s,
for (int i = 0; i < config.stereoscopicEyeCount; i++) {
mat4f const& eyeFromHead = camera.eyeFromView[i]; // identity for monoscopic rendering
mat4f const& clipFromEye = camera.eyeProjection[i];
s.eyeFromViewMatrix[i] = eyeFromHead;
// clipFromEye * eyeFromHead * headFromWorld
s.clipFromWorldMatrix[i] = highPrecisionMultiply(
clipFromEye, highPrecisionMultiply(eyeFromHead, headFromWorld));

View File

@@ -76,7 +76,8 @@ struct PerViewUib { // NOLINT(cppcoreguidelines-pro-type-member-init)
math::mat4f worldFromViewMatrix; // clip view -> world : model matrix
math::mat4f clipFromViewMatrix; // clip <- view world : projection matrix
math::mat4f viewFromClipMatrix; // clip -> view world : inverse projection matrix
math::mat4f clipFromWorldMatrix[CONFIG_MAX_STEREOSCOPIC_EYES]; // clip <- view <- world
math::mat4f eyeFromViewMatrix[CONFIG_MAX_STEREOSCOPIC_EYES]; // clip eye <- view world
math::mat4f clipFromWorldMatrix[CONFIG_MAX_STEREOSCOPIC_EYES]; // clip <- eye <- view <- world
math::mat4f worldFromClipMatrix; // clip -> view -> world
math::mat4f userWorldFromWorldMatrix; // userWorld <- world
math::float4 clipTransform; // [sx, sy, tx, ty] only used by VERTEX_DOMAIN_DEVICE
@@ -212,8 +213,8 @@ struct PerViewUib { // NOLINT(cppcoreguidelines-pro-type-member-init)
};
// 2 KiB == 128 float4s
static_assert(sizeof(PerViewUib) == sizeof(math::float4) * 128,
"PerViewUib should be exactly 2KiB");
static_assert(sizeof(PerViewUib) == sizeof(math::float4) * 144,
"PerViewUib should be 16 x 144 bytes");
// ------------------------------------------------------------------------------------------------
// MARK: -

View File

@@ -99,6 +99,8 @@ BufferInterfaceBlock const& UibGenerator::getPerViewUib() noexcept {
{ "worldFromViewMatrix", 0, Type::MAT4, Precision::HIGH, FeatureLevel::FEATURE_LEVEL_0 },
{ "clipFromViewMatrix", 0, Type::MAT4, Precision::HIGH, FeatureLevel::FEATURE_LEVEL_0 },
{ "viewFromClipMatrix", 0, Type::MAT4, Precision::HIGH, FeatureLevel::FEATURE_LEVEL_0 },
{ "eyeFromViewMatrix", CONFIG_MAX_STEREOSCOPIC_EYES,
Type::MAT4, Precision::HIGH, FeatureLevel::FEATURE_LEVEL_0 },
{ "clipFromWorldMatrix", CONFIG_MAX_STEREOSCOPIC_EYES,
Type::MAT4, Precision::HIGH, FeatureLevel::FEATURE_LEVEL_0 },
{ "worldFromClipMatrix", 0, Type::MAT4, Precision::HIGH, FeatureLevel::FEATURE_LEVEL_0 },

View File

@@ -46,6 +46,11 @@ highp mat4 getViewFromClipMatrix() {
return frameUniforms.viewFromClipMatrix;
}
/** @public-api */
highp mat4 getEyeFromViewMatrix() {
return frameUniforms.eyeFromViewMatrix[getEyeIndex()];
}
/** @public-api */
highp mat4 getClipFromWorldMatrix() {
return frameUniforms.clipFromWorldMatrix[getEyeIndex()];