mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
improve:uniform xr splash screen display effect (#14416)
This commit is contained in:
+23
-19
@@ -24,7 +24,7 @@
|
||||
|
||||
import { EDITOR, TAOBAO, TAOBAO_MINIGAME } from 'internal:constants';
|
||||
import { Material } from '../asset/assets/material';
|
||||
import { clamp01, Mat4, Vec2, Settings, settings, sys, cclegacy, easing } from '../core';
|
||||
import { clamp01, Mat4, Vec2, Settings, settings, sys, cclegacy, easing, preTransforms } from '../core';
|
||||
import {
|
||||
Sampler, SamplerInfo, Shader, Texture, TextureInfo, Device, InputAssembler, InputAssemblerInfo, Attribute, Buffer,
|
||||
BufferInfo, Rect, Color, BufferTextureCopy, CommandBuffer, BufferUsageBit, Format,
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
import { PipelineStateManager } from '../rendering';
|
||||
import { SetIndex } from '../rendering/define';
|
||||
import { ccwindow } from '../core/global-exports';
|
||||
import { XREye } from '../xr/xr-enums';
|
||||
|
||||
const v2_0 = new Vec2();
|
||||
type SplashEffectType = 'default' | 'custom' | 'off';
|
||||
@@ -429,24 +430,27 @@ export class SplashScreen {
|
||||
for (let xrEye = 0; xrEye < renderSize; xrEye++) {
|
||||
if (sys.isXR) {
|
||||
xr.entry.renderLoopStart(xrEye);
|
||||
const xrConfigDeviceVendor = 13;
|
||||
const compatibleDevice = 4;
|
||||
if (xr.entry.getXRIntConfig(xrConfigDeviceVendor) !== compatibleDevice) {
|
||||
const xrFov = xr.entry.getEyeFov(xrEye);
|
||||
const left = Math.tan(xrFov[0]);
|
||||
const right = Math.tan(xrFov[1]);
|
||||
const bottom = Math.tan(xrFov[2]);
|
||||
const top = Math.tan(xrFov[3]);
|
||||
Mat4.ortho(this.projection, left, right, bottom, top, -1, 1, device.capabilities.clipSpaceMinZ,
|
||||
device.capabilities.clipSpaceSignY, swapchain.surfaceTransform);
|
||||
this.bgMat.setProperty('u_projection', this.projection);
|
||||
this.bgMat.passes[0].update();
|
||||
this.logoMat.setProperty('u_projection', this.projection);
|
||||
this.logoMat.passes[0].update();
|
||||
if (this.watermarkMat) {
|
||||
this.watermarkMat.setProperty('u_projection', this.projection);
|
||||
this.watermarkMat.passes[0].update();
|
||||
}
|
||||
const xrFov = xr.entry.getEyeFov(xrEye);
|
||||
// device's fov may be asymmetry
|
||||
let radioLeft = 1.0;
|
||||
let radioRight = 1.0;
|
||||
if (xrEye === XREye.LEFT) {
|
||||
radioLeft = Math.abs(Math.tan(xrFov[0])) / Math.abs(Math.tan(xrFov[1]));
|
||||
} else if (xrEye === XREye.RIGHT) {
|
||||
radioRight = Math.abs(Math.tan(xrFov[1])) / Math.abs(Math.tan(xrFov[0]));
|
||||
}
|
||||
Mat4.ortho(this.projection, -radioLeft, radioRight, -1, 1, -1, 1, device.capabilities.clipSpaceMinZ,
|
||||
device.capabilities.clipSpaceSignY, swapchain.surfaceTransform);
|
||||
// keep scale to [-1, 1] only use offset
|
||||
this.projection.m00 = preTransforms[swapchain.surfaceTransform][0];
|
||||
this.projection.m05 = preTransforms[swapchain.surfaceTransform][3] * device.capabilities.clipSpaceSignY;
|
||||
this.bgMat.setProperty('u_projection', this.projection);
|
||||
this.bgMat.passes[0].update();
|
||||
this.logoMat.setProperty('u_projection', this.projection);
|
||||
this.logoMat.passes[0].update();
|
||||
if (this.watermarkMat) {
|
||||
this.watermarkMat.setProperty('u_projection', this.projection);
|
||||
this.watermarkMat.passes[0].update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
Copyright (c) 2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @en XR Eye Enum.
|
||||
* @zh XR视窗枚举。
|
||||
*/
|
||||
export enum XREye {
|
||||
/**
|
||||
* @en None.
|
||||
* @zh 无。
|
||||
*/
|
||||
NONE = -1,
|
||||
/**
|
||||
* @en Left eye.
|
||||
* @zh 左眼。
|
||||
*/
|
||||
LEFT = 0,
|
||||
/**
|
||||
* @en Right eye.
|
||||
* @zh 右眼。
|
||||
*/
|
||||
RIGHT = 1
|
||||
}
|
||||
|
||||
/**
|
||||
* @en XR Config Key Enum.
|
||||
* @zh XR配置键值枚举。
|
||||
*/
|
||||
export enum XRConfigKey {
|
||||
/**
|
||||
* @en Session running.
|
||||
* @zh 会话运行中。
|
||||
*/
|
||||
SESSION_RUNNING = 2,
|
||||
/**
|
||||
* @en View count.
|
||||
* @zh 视窗数量。
|
||||
*/
|
||||
VIEW_COUNT = 6,
|
||||
/**
|
||||
* @en Swapchain width.
|
||||
* @zh 交换链宽度。
|
||||
*/
|
||||
SWAPCHAIN_WIDTH = 7,
|
||||
/**
|
||||
* @en Swapchain height.
|
||||
* @zh 交换链高度。
|
||||
*/
|
||||
SWAPCHAIN_HEIGHT = 8,
|
||||
/**
|
||||
* @en Device IPD.
|
||||
* @zh 设备瞳距。
|
||||
*/
|
||||
DEVICE_IPD = 37,
|
||||
/**
|
||||
* @en Split AR Glasses.
|
||||
* @zh 分体式AR眼镜。
|
||||
*/
|
||||
SPLIT_AR_GLASSES = 42
|
||||
}
|
||||
Reference in New Issue
Block a user