fix: 光照缩放问题

This commit is contained in:
unanmed 2024-04-30 23:38:08 +08:00
parent 763ff0f3e7
commit 518f5a5815
2 changed files with 20 additions and 8 deletions

View File

@ -32,7 +32,7 @@ main.floors.MT50=
], ],
"9,13": [ "9,13": [
"在你刚进入苍蓝之殿时,你只能先前往左下角部分(本地图的左面),右下角暂时不能前往。注意往上走往左依然可以进入左下角,不要只盯着这个地图的左边不放。", "在你刚进入苍蓝之殿时,你只能先前往左下角部分(本地图的左面),右下角暂时不能前往。注意往上走往左依然可以进入左下角,不要只盯着这个地图的左边不放。",
"注意火炬可通行,而且跳跃时会跳过火炬,不会跳到火炬上" "注意火炬可通行,而且跳跃时会跳过火炬,不会跳到火炬上。以及由于不可抗力,修改游戏缩放后需要刷新页面才能使光照正常。"
], ],
"9,1": [ "9,1": [
"建议优先点出学习技能,对于特定场景将会非常有帮助", "建议优先点出学习技能,对于特定场景将会非常有帮助",

View File

@ -15,7 +15,7 @@ const MAX_LIGHT_NUM = 5;
/** 阴影层的Z值 */ /** 阴影层的Z值 */
const Z_INDEX = 55; const Z_INDEX = 55;
// 我也不知道这个数怎么来的,试出来是这个,别动就行 // 我也不知道这个数怎么来的,试出来是这个,别动就行
const FOVY = Math.PI / 1.86; const FOVY = Math.PI / 2;
const ignore: Set<AllNumbers> = new Set([660]); const ignore: Set<AllNumbers> = new Set([660]);
interface LightConfig { interface LightConfig {
@ -70,7 +70,7 @@ function addLightFromBlock(floors: FloorIds[], block: number, config: LightConfi
}) })
} }
Mota.require('var', 'loading').once('coreInit', () => { Mota.require('var', 'hook').once('reset', () => {
Shadow.init(); Shadow.init();
addLightFromBlock( addLightFromBlock(
core.floorIds.slice(61), core.floorIds.slice(61),
@ -412,7 +412,7 @@ export class Shadow {
const polygons = calMapPolygons(this.floorId, this.immerse, nocache); const polygons = calMapPolygons(this.floorId, this.immerse, nocache);
const res: number[] = []; const res: number[] = [];
const ratio = core.domStyle.scale * devicePixelRatio; const ratio = devicePixelRatio * core.domStyle.scale;
const m = core._PX_ * ratio * 2; const m = core._PX_ * ratio * 2;
polygons.forEach(v => { polygons.forEach(v => {
@ -768,7 +768,7 @@ export class Shadow {
const gl = Shadow.gl; const gl = Shadow.gl;
const ratio = core.domStyle.scale * devicePixelRatio; const ratio = core.domStyle.scale * devicePixelRatio;
const cameraMatrix = mat4.create(); const cameraMatrix = mat4.create();
mat4.lookAt(cameraMatrix, [light.x * ratio, light.y * ratio, core._PX_ * 2], [light.x * ratio, light.y * ratio, 0], [0, 1, 0]); mat4.lookAt(cameraMatrix, [light.x * ratio, light.y * ratio, core._PX_ * 2 * ratio], [light.x * ratio, light.y * ratio, 0], [0, 1, 0]);
const size = core._PX_ * ratio * 2; const size = core._PX_ * ratio * 2;
gl.viewport(0, 0, size, size); gl.viewport(0, 0, size, size);
@ -887,6 +887,7 @@ export class Shadow {
const gl = this.gl; const gl = this.gl;
if (!isWebGL2Supported()) return; if (!isWebGL2Supported()) return;
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true); gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
const ratio = core.domStyle.scale * devicePixelRatio;
// program // program
const depth = createProgram(gl, depthVertex, depthFragment); const depth = createProgram(gl, depthVertex, depthFragment);
@ -938,7 +939,7 @@ export class Shadow {
// Matrix // Matrix
const lightProjection = mat4.create(); const lightProjection = mat4.create();
mat4.perspective(lightProjection, FOVY, 1, 1, core._PX_ * 2); mat4.perspective(lightProjection, FOVY, 1, 1, core._PX_ * ratio);
this.martix = { this.martix = {
projection: lightProjection projection: lightProjection
} }
@ -978,6 +979,17 @@ export class Shadow {
} }
} }
static resize() {
if (this.martix) {
const ratio = core.domStyle.scale * devicePixelRatio;
const lightProjection = mat4.create();
mat4.perspective(lightProjection, FOVY, 1, 1, core._PX_ * ratio);
this.martix = {
projection: lightProjection
}
}
}
/** /**
* *
*/ */