From a394d77a9e9ffdbdce58da1992e3d874315c76cc Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 3 Jan 2025 10:29:42 -0800 Subject: [PATCH] More legacy matrix library removals Also fixes GTA3 in local mode. --- rsbuild.config.ts | 3 +- src/AShortHike/Scenes.ts | 12 +- src/Common/Unity/GameObject.ts | 10 +- src/DiddyKongRacing/DkrDrawCall.ts | 16 +- src/DiddyKongRacing/DkrSprites.ts | 16 +- src/DiddyKongRacing/F3DDKR_Program.ts | 24 +-- src/DiddyKongRacing/F3DDKR_Sprite_Program.ts | 14 +- src/DragonQuest8/render.ts | 47 +++--- src/FinalFantasyX/render.ts | 37 +++-- src/FinalFantasyX/scenes.ts | 30 ++-- src/GoldSrc/Render.ts | 6 +- src/GrandTheftAuto3/program.glsl | 20 ++- src/InteractiveExamples/FoxFur.ts | 11 +- src/InteractiveExamples/GridPlane.ts | 10 +- src/InteractiveExamples/Tess.ts | 30 ++-- src/JetSetRadio/Render.ts | 26 +-- src/KingdomHearts/program.glsl | 12 +- src/KingdomHearts/render.ts | 7 +- src/KingdomHearts2FinalMix/program.glsl | 13 +- src/KingdomHearts2FinalMix/render.ts | 7 +- src/MarioKart8Deluxe/Render.ts | 24 +-- src/Morrowind/NIFBase.ts | 29 ++-- src/Morrowind/Render.ts | 12 +- src/NeedForSpeedMostWanted/particles.ts | 11 +- src/NeedForSpeedMostWanted/render.ts | 14 +- src/NeonWhite/Scenes.ts | 6 +- src/PaperMario64/program.glsl | 17 +- src/Pilotwings64/Scenes.ts | 20 +-- src/PokemonSnap/particles.ts | 11 +- src/Subnautica/scenes.ts | 165 ------------------- src/main.ts | 2 - src/psychonauts/render.ts | 11 +- 32 files changed, 262 insertions(+), 411 deletions(-) delete mode 100644 src/Subnautica/scenes.ts diff --git a/rsbuild.config.ts b/rsbuild.config.ts index 3969a346f..cee9d2565 100644 --- a/rsbuild.config.ts +++ b/rsbuild.config.ts @@ -40,7 +40,8 @@ export default defineConfig({ // at the root. copy: [ { from: 'src/**/*.wasm', to: '[name][ext]' }, - { from: 'node_modules/librw/lib/librw.wasm' }, + { from: 'node_modules/librw/lib/librw.wasm', to: 'static/js/[name][ext]' }, + { from: 'src/vendor/basis_universal/basis_transcoder.wasm', to: 'static/js/[name][ext]' }, ], }, // Enable async TypeScript type checking. diff --git a/src/AShortHike/Scenes.ts b/src/AShortHike/Scenes.ts index b87b51a61..d249d12b0 100644 --- a/src/AShortHike/Scenes.ts +++ b/src/AShortHike/Scenes.ts @@ -32,14 +32,14 @@ varying vec2 v_TexCoord0; #if defined VERT void mainVS() { - Mat4x3 t_WorldFromLocalMatrix = CalcWorldFromLocalMatrix(); - vec3 t_PositionWorld = Mul(t_WorldFromLocalMatrix, vec4(a_Position, 1.0)); + mat4x3 t_WorldFromLocalMatrix = CalcWorldFromLocalMatrix(); + vec3 t_PositionWorld = t_WorldFromLocalMatrix * vec4(a_Position, 1.0); vec3 t_LightDirection = normalize(vec3(.2, -1, .5)); vec3 normal = MulNormalMatrix(t_WorldFromLocalMatrix, normalize(a_Normal)); float t_LightIntensityF = dot(-normal, t_LightDirection); float t_LightIntensityB = dot( normal, t_LightDirection); - gl_Position = Mul(u_ProjectionView, vec4(t_PositionWorld, 1.0)); + gl_Position = u_ProjectionView * vec4(t_PositionWorld, 1.0); v_LightIntensity = vec2(t_LightIntensityF, t_LightIntensityB); v_TexCoord0 = CalcScaleBias(a_TexCoord0, u_MainTexST); } @@ -126,14 +126,14 @@ uniform sampler2D u_Splat3; #ifdef VERT void mainVS() { - Mat4x3 t_WorldFromLocalMatrix = CalcWorldFromLocalMatrix(); - vec3 t_PositionWorld = Mul(t_WorldFromLocalMatrix, vec4(a_Position, 1.0)); + mat4x3 t_WorldFromLocalMatrix = CalcWorldFromLocalMatrix(); + vec3 t_PositionWorld = t_WorldFromLocalMatrix * vec4(a_Position, 1.0); vec3 t_LightDirection = normalize(vec3(.2, -1, .5)); vec3 normal = MulNormalMatrix(t_WorldFromLocalMatrix, normalize(a_Normal)); float t_LightIntensityF = dot(-normal, t_LightDirection); float t_LightIntensityB = dot( normal, t_LightDirection); - gl_Position = Mul(u_ProjectionView, vec4(t_PositionWorld, 1.0)); + gl_Position = u_ProjectionView * vec4(t_PositionWorld, 1.0); v_LightIntensity = vec2(t_LightIntensityF, t_LightIntensityB); for (int i = 0; i < 6; i++) diff --git a/src/Common/Unity/GameObject.ts b/src/Common/Unity/GameObject.ts index 16336b4be..1dcbe4dff 100644 --- a/src/Common/Unity/GameObject.ts +++ b/src/Common/Unity/GameObject.ts @@ -110,13 +110,13 @@ export class UnityShaderProgramBase extends DeviceProgram { public static Common = ` precision mediump float; -layout(std140) uniform ub_SceneParams { - Mat4x4 u_ProjectionView; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_ProjectionView; }; -layout(std140) uniform ub_ShapeParams { +layout(std140, row_major) uniform ub_ShapeParams { // TODO(jstpierre): Skinned mesh - Mat4x3 u_BoneMatrix[1]; + mat4x3 u_BoneMatrix[1]; }; #ifdef VERT @@ -137,7 +137,7 @@ layout(location = ${UnityChannel.BlendWeight}) attribute vec4 a_BlendWeight; ${GfxShaderLibrary.MulNormalMatrix} ${GfxShaderLibrary.CalcScaleBias} -Mat4x3 CalcWorldFromLocalMatrix() { +mat4x3 CalcWorldFromLocalMatrix() { return u_BoneMatrix[0]; } #endif diff --git a/src/DiddyKongRacing/DkrDrawCall.ts b/src/DiddyKongRacing/DkrDrawCall.ts index 6307bfa61..486351f59 100644 --- a/src/DiddyKongRacing/DkrDrawCall.ts +++ b/src/DiddyKongRacing/DkrDrawCall.ts @@ -21,8 +21,7 @@ const FLAG_IS_INVISIBLE_GEOMETRY = 0x00000100; const FLAG_IS_ENV_MAP_ENABLED = 0x00008000; // Spherical Environment Mapping const FLAG_IS_TEXTURE_ANIMATED = 0x00010000; -const viewMatrixScratch = mat4.create(); -const viewMatrixCalcScratch = mat4.create(); +const scratchMatrix = mat4.create(); const mirrorMatrix = mat4.fromValues( -1, 0, 0, 0, 0, 1, 0, 0, @@ -259,16 +258,15 @@ export class DkrDrawCall { offs += 16; } - computeViewMatrix(viewMatrixScratch, viewerInput.camera); - if(DkrControlGlobals.ADV2_MIRROR.on) { - mat4.mul(viewMatrixCalcScratch, mirrorMatrix, params.modelMatrix); - mat4.mul(viewMatrixCalcScratch, viewMatrixScratch, viewMatrixCalcScratch); + if (DkrControlGlobals.ADV2_MIRROR.on) { + mat4.mul(scratchMatrix, mirrorMatrix, params.modelMatrix); + mat4.mul(scratchMatrix, viewerInput.camera.viewMatrix, scratchMatrix); } else { - mat4.mul(viewMatrixCalcScratch, viewMatrixScratch, params.modelMatrix); + mat4.mul(scratchMatrix, viewerInput.camera.viewMatrix, params.modelMatrix); } - offs += fillMatrix4x3(d, offs, viewMatrixCalcScratch); + offs += fillMatrix4x3(d, offs, scratchMatrix); - if(!!params.objAnim) { + if (!!params.objAnim) { const currentFrameIndex = params.objAnim.getCurrentFrame(); this.vertexBufferDescriptors[0].byteOffset = this.objAnimPositionBufferByteOffset[params.objAnimIndex][currentFrameIndex]; const nextFrameIndex = (currentFrameIndex + 1) % params.objAnim.getKeyframes().length; diff --git a/src/DiddyKongRacing/DkrSprites.ts b/src/DiddyKongRacing/DkrSprites.ts index b068daae9..4ce172926 100644 --- a/src/DiddyKongRacing/DkrSprites.ts +++ b/src/DiddyKongRacing/DkrSprites.ts @@ -22,9 +22,7 @@ import { DkrControlGlobals } from './DkrControlGlobals.js'; import { DkrObject, MODEL_TYPE_2D_BILLBOARD } from './DkrObject.js'; import { F3DDKR_Sprite_Program, MAX_NUM_OF_SPRITE_FRAMES, MAX_NUM_OF_SPRITE_INSTANCES } from './F3DDKR_Sprite_Program.js'; -const viewMatrixScratch = mat4.create(); -const viewMatrixCalcScratch = mat4.create(); -const viewMatrixCalc2Scratch = mat4.create(); +const scratchMatrix = mat4.create(); const mirrorMatrix = mat4.fromValues( -1, 0, 0, 0, 0, 1, 0, 0, @@ -239,8 +237,6 @@ export class DkrSprites { this.bind(renderInst); renderInst.sortKey = setSortKeyDepth(renderInst.sortKey, 0); - computeViewMatrix(viewMatrixScratch, viewerInput.camera); - assert(layerInstances.length <= MAX_NUM_OF_SPRITE_INSTANCES); for (let i = 0; i < layerInstances.length; i++) { const instanceObject: DkrObject = layerInstances[i]; @@ -253,13 +249,13 @@ export class DkrSprites { const color = instanceObject.getSpriteColor(); offs += fillVec4v(d, offs, color); if (DkrControlGlobals.ADV2_MIRROR.on) { - mat4.mul(viewMatrixCalcScratch, mirrorMatrix, instanceObject.getModelMatrix()); - mat4.mul(viewMatrixCalcScratch, viewMatrixScratch, viewMatrixCalcScratch); + mat4.mul(scratchMatrix, mirrorMatrix, instanceObject.getModelMatrix()); + mat4.mul(scratchMatrix, viewerInput.camera.viewMatrix, scratchMatrix); } else { - mat4.mul(viewMatrixCalcScratch, viewMatrixScratch, instanceObject.getModelMatrix()); + mat4.mul(scratchMatrix, viewerInput.camera.viewMatrix, instanceObject.getModelMatrix()); } - calcBillboardMatrix(viewMatrixCalc2Scratch, viewMatrixCalcScratch, CalcBillboardFlags.UseRollLocal | CalcBillboardFlags.PriorityZ | CalcBillboardFlags.UseZPlane); - offs += fillMatrix4x3(d, offs, viewMatrixCalc2Scratch); + calcBillboardMatrix(scratchMatrix, scratchMatrix, CalcBillboardFlags.UseRollLocal | CalcBillboardFlags.PriorityZ | CalcBillboardFlags.UseZPlane); + offs += fillMatrix4x3(d, offs, scratchMatrix); } // Set tex parameters diff --git a/src/DiddyKongRacing/F3DDKR_Program.ts b/src/DiddyKongRacing/F3DDKR_Program.ts index 672d2539e..709875626 100644 --- a/src/DiddyKongRacing/F3DDKR_Program.ts +++ b/src/DiddyKongRacing/F3DDKR_Program.ts @@ -15,14 +15,14 @@ export class F3DDKR_Program extends DeviceProgram { public override both = ` precision mediump float; -layout(std140) uniform ub_SceneParams { - Mat4x4 u_Projection; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_Projection; }; -layout(std140) uniform ub_DrawParams { +layout(std140, row_major) uniform ub_DrawParams { vec4 u_Color; vec4 u_Misc[1]; - Mat4x3 u_ViewMatrix; + mat4x3 u_ModelViewMatrix; }; #define u_TexCoordOffset (u_Misc[0].xy) @@ -59,18 +59,21 @@ void main() { vec3 pos; bvec4 t_Options = DecodeOptions(); - if(t_Options.w) { // t_Options.w = Use object animation + if (t_Options.w) { // t_Options.w = Use object animation pos = mix(a_Position, a_Position_2, u_AnimProgress); // lerp between the keyframes. } else { pos = a_Position; // Just use the default position. } - gl_Position = Mul(u_Projection, Mul(_Mat4x4(u_ViewMatrix), vec4(pos, 1.0))); - if(t_Options.z) { + vec3 t_PositionView = u_ModelViewMatrix * vec4(pos, 1.0); + gl_Position = u_Projection * vec4(t_PositionView, 1.0); + + if (t_Options.z) { v_Color = vec4(1.0, 1.0, 1.0, 1.0); } else { v_Color = vec4(a_Color.xyz, a_Color.w * u_Color.w); } + v_TexCoord = a_TexCoord + u_TexCoordOffset.xy; } `; @@ -94,17 +97,18 @@ void main() { bvec4 t_Options = DecodeOptions(); - if(t_Options.x) { + if (t_Options.x) { textureColor = Texture2D_N64_Bilerp(PP_SAMPLER_2D(u_Texture), v_TexCoord); } - if(t_Options.y) { + if (t_Options.y) { vertexColor = v_Color; } gl_FragColor = vertexColor * textureColor; - if(gl_FragColor.a == 0.0) discard; + if (gl_FragColor.a == 0.0) + discard; } `; diff --git a/src/DiddyKongRacing/F3DDKR_Sprite_Program.ts b/src/DiddyKongRacing/F3DDKR_Sprite_Program.ts index e2f558ea8..c9c9ff0e4 100644 --- a/src/DiddyKongRacing/F3DDKR_Sprite_Program.ts +++ b/src/DiddyKongRacing/F3DDKR_Sprite_Program.ts @@ -14,22 +14,22 @@ export class F3DDKR_Sprite_Program extends DeviceProgram { public override both = ` precision mediump float; -layout(std140) uniform ub_SceneParams { - Mat4x4 u_Projection; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_Projection; }; struct SpriteInstance { vec4 info; // x = u_TexCoords index, y = Number of frames, z = alpha test, w = offset y vec4 color; - Mat4x3 viewMatrix; + mat4x3 modelViewMatrix; }; -layout(std140) uniform ub_DrawParams { +layout(std140, row_major) uniform ub_DrawParams { vec4 u_SpritesInfo; // x = Current frame. SpriteInstance u_Instances[${MAX_NUM_OF_SPRITE_INSTANCES}]; }; -layout(std140) uniform ub_TexParams { +layout(std140, row_major) uniform ub_TexParams { vec4 u_TexCoords[${MAX_NUM_OF_SPRITE_FRAMES}]; }; @@ -59,7 +59,9 @@ void main() { v_Color = instance.color; - gl_Position = Mul(u_Projection, Mul(_Mat4x4(instance.viewMatrix), vec4((a_Position+offset)*spriteSize, 1.0, 1.0))); + vec2 t_PositionLocal = (a_Position + offset) * spriteSize; + vec3 t_PositionView = instance.modelViewMatrix * vec4(t_PositionLocal, 1.0, 1.0); + gl_Position = u_Projection * vec4(t_PositionView, 1.0); if(gl_VertexID == 0) { v_TexCoord = vec2(x, y); diff --git a/src/DragonQuest8/render.ts b/src/DragonQuest8/render.ts index 45a1fbe5e..0d16e9cf4 100644 --- a/src/DragonQuest8/render.ts +++ b/src/DragonQuest8/render.ts @@ -40,14 +40,14 @@ export class DQ8Program extends DeviceProgram { #define SMOOTH_SKINNING() (SKINNING_MATRIX_COUNT > 0) precision mediump float; -layout(std140) uniform ub_SceneParams { - Mat4x4 u_Projection; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_Projection; }; -layout(std140) uniform ub_MDTSubmeshParams { - Mat4x4 u_ModelView; - Mat4x4 u_RigidTrans; +layout(std140, row_major) uniform ub_MDTSubmeshParams { + mat4x3 u_ModelView; + mat4x3 u_RigidTrans; #if SMOOTH_SKINNING() - Mat4x3 u_JointMatrix[SKINNING_MATRIX_COUNT]; + mat4x3 u_JointMatrix[SKINNING_MATRIX_COUNT]; #endif vec4 u_BGColor; vec4 u_BGColor2; @@ -76,28 +76,31 @@ out vec2 v_TexCoord; out vec4 v_col; void mainVS() { - vec4 pos = vec4(a_Position, 1.0); - #if SMOOTH_SKINNING() - Mat4x3 t_JointMatrix = _Mat4x3(0.0); - Fma(t_JointMatrix, u_JointMatrix[int(a_JointIndices.x)], a_JointWeights.x); - Fma(t_JointMatrix, u_JointMatrix[int(a_JointIndices.y)], a_JointWeights.y); - Fma(t_JointMatrix, u_JointMatrix[int(a_JointIndices.z)], a_JointWeights.z); - Fma(t_JointMatrix, u_JointMatrix[int(a_JointIndices.w)], a_JointWeights.w); - pos = Mul(_Mat4x4(t_JointMatrix), pos); + mat4x3 t_JointMatrix = mat4x3(0.0); + t_JointMatrix += u_JointMatrix[int(a_JointIndices.x)] * a_JointWeights.x; + t_JointMatrix += u_JointMatrix[int(a_JointIndices.y)] * a_JointWeights.y; + t_JointMatrix += u_JointMatrix[int(a_JointIndices.z)] * a_JointWeights.z; + t_JointMatrix += u_JointMatrix[int(a_JointIndices.w)] * a_JointWeights.w; #else - pos = Mul(u_RigidTrans,pos); + mat4x3 t_JointMatrix = u_RigidTrans; #endif + vec3 t_PositionLocal = t_JointMatrix * vec4(a_Position, 1.0); + if (u_bIsSkybox > 0.0) - pos = Mul(u_RigidTrans,pos); + t_PositionLocal = u_RigidTrans * vec4(t_PositionLocal, 1.0); // ??? + if (u_bIsSkybox > 0.0) v_col = u_BGColor; else v_col = a_vColor; - if (u_bIsSkybox > 0.0 && pos.y < 2000.0 && pos.y > -2000.0) + + if (u_bIsSkybox > 0.0 && t_PositionLocal.y < 2000.0 && t_PositionLocal.y > -2000.0) v_col = u_BGColor2; - gl_Position = Mul(u_Projection, Mul(u_ModelView,pos)); + + vec3 t_PositionView = u_ModelView * vec4(t_PositionLocal, 1.0); + gl_Position = u_Projection * vec4(t_PositionView, 1.0); v_TexCoord = a_TexCoord; } #endif @@ -305,17 +308,17 @@ export class MDTSubmeshInstance { let offs = renderInst.allocateUniformBuffer(DQ8Program.ub_MDTSubmeshParams, 16 * 2 + 12 + 16 * (this.mdtData.smoothSkinning ? MDS.MDS.maxJointCount : 0)); const d = renderInst.mapUniformBufferF32(DQ8Program.ub_MDTSubmeshParams); - offs += fillMatrix4x4(d, offs, viewMatrix); + offs += fillMatrix4x3(d, offs, viewMatrix); if (jointPerVertCount && !bIsSkybox) { mat4.invert(scratchMatrix, modelMatrix); mat4.mul(scratchMatrix, scratchMatrix, boneMatrices[this.rigidJointId]); - offs += fillMatrix4x4(d, offs, scratchMatrix); + offs += fillMatrix4x3(d, offs, scratchMatrix); } else { if (!bIsSkybox) - offs += fillMatrix4x4(d, offs, boneMatrices[this.rigidJointId]); + offs += fillMatrix4x3(d, offs, boneMatrices[this.rigidJointId]); else - offs += fillMatrix4x4(d, offs, modelMatrix); + offs += fillMatrix4x3(d, offs, modelMatrix); } if (this.mdtData.smoothSkinning) { diff --git a/src/FinalFantasyX/render.ts b/src/FinalFantasyX/render.ts index 39dd78b44..f05b3a7cb 100644 --- a/src/FinalFantasyX/render.ts +++ b/src/FinalFantasyX/render.ts @@ -31,15 +31,15 @@ export class FFXProgram extends DeviceProgram { precision mediump float; // Expected to be constant across the entire scene. -layout(std140) uniform ub_SceneParams { - Mat4x4 u_Projection; - Mat4x3 u_LightDirection; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_Projection; + mat4x3 u_LightDirection; float u_RenderHacks; }; -layout(std140) uniform ub_ModelParams { - Mat4x3 u_BoneMatrix; - Mat4x2 u_TextureMatrix; +layout(std140, row_major) uniform ub_ModelParams { + mat4x3 u_BoneMatrix; + mat4x2 u_TextureMatrix; vec4 u_Params; }; @@ -57,12 +57,14 @@ layout(location = 3) in vec4 a_Extra; void main() { int hackFlags = int(u_RenderHacks); + + vec3 t_PositionLocal = a_Position; #if EFFECT == 1 - gl_Position = vec4(mix(a_Position, a_Extra.xyz, u_Params.x), 1.0); -#else - gl_Position = vec4(a_Position, 1.0); + t_PositionLocal = mix(t_PositionLocal, a_Extra.xyz, u_Params.x); #endif - gl_Position = Mul(u_Projection, Mul(_Mat4x4(u_BoneMatrix), gl_Position)); + + vec3 t_PositionView = u_BoneMatrix * vec4(t_PositionLocal, 1.0); + gl_Position = u_Projection * vec4(t_PositionView, 1.0); #if EFFECT == 4 v_Color = mix(a_Color, a_Extra, u_Params.x); @@ -74,9 +76,9 @@ void main() { v_Color = vec4(1.); #if EFFECT == 6 - vec4 t_viewNormal = Mul(_Mat4x4(u_BoneMatrix), vec4(a_Extra.xyz, 0.0)); - t_viewNormal = Mul(_Mat4x4(u_LightDirection), vec4(t_viewNormal.xyz, 0.0)); - v_TexCoord = (t_viewNormal.xz/4.0) + 0.5; + vec4 t_ViewNormal = u_BoneMatrix * vec4(a_Extra.xyz, 0.0); + t_ViewNormal = u_LightDirection * vec4(t_ViewNormal.xyz, 0.0); + v_TexCoord = (t_ViewNormal.xz/4.0) + 0.5; #elif EFFECT == 3 v_TexCoord = mix(a_TexCoord, a_Extra.xy, u_Params.x); #elif EFFECT == 5 @@ -84,7 +86,8 @@ void main() { #else v_TexCoord = a_TexCoord; #endif - v_TexCoord = Mul(_Mat4x4(u_TextureMatrix), vec4(v_TexCoord, 0.0, 1.0)).xy; + + v_TexCoord = u_TextureMatrix * vec4(v_TexCoord, 0.0, 1.0); } `; @@ -353,7 +356,7 @@ const enum RenderLayer { const scratchMatrix = mat4.create(); const scratchAABB = new AABB(); -const posScrath = vec3.create(); +const scratchVec3 = vec3.create(); // LevelModelInstance is the basic unit of geometry export class LevelModelInstance { public drawCalls: DrawCallInstance[] = []; @@ -395,8 +398,8 @@ export class LevelModelInstance { template.setVertexInput(this.data.inputLayout, this.data.vertexBufferDescriptors, this.data.indexBufferDescriptor); template.sortKey = makeSortKey(this.layer); if (this.depthSort) { - transformVec3Mat4w1(posScrath, scratchMatrix, this.model.center); - template.sortKey = setSortKeyDepth(template.sortKey, -posScrath[2]); + transformVec3Mat4w1(scratchVec3, scratchMatrix, this.model.center); + template.sortKey = setSortKeyDepth(template.sortKey, -scratchVec3[2]); } for (let i = 0; i < this.drawCalls.length; i++) diff --git a/src/FinalFantasyX/scenes.ts b/src/FinalFantasyX/scenes.ts index f54bf6b80..1574f5368 100644 --- a/src/FinalFantasyX/scenes.ts +++ b/src/FinalFantasyX/scenes.ts @@ -1,25 +1,25 @@ -import * as BIN from "./bin.js"; -import * as Viewer from '../viewer.js'; -import * as UI from '../ui.js'; -import { makeBackbufferDescSimple, makeAttachmentClearDescriptor, standardFullClearRenderPassDescriptor } from '../gfx/helpers/RenderGraphHelpers.js'; -import { fillMatrix4x3, fillMatrix4x4, fillVec3v, fillVec4 } from '../gfx/helpers/UniformBufferHelpers.js'; +import { mat4, vec3 } from "gl-matrix"; +import AnimationController from "../AnimationController.js"; +import { CameraController } from "../Camera.js"; +import { Color, colorNewFromRGBA, Cyan, Magenta } from "../Color.js"; +import { NamedArrayBufferSlice } from "../DataFetcher.js"; +import { drawWorldSpaceText, getDebugOverlayCanvas2D } from "../DebugJunk.js"; +import { DebugDrawFlags } from "../gfx/helpers/DebugDraw.js"; +import { makeAttachmentClearDescriptor, makeBackbufferDescSimple, standardFullClearRenderPassDescriptor } from '../gfx/helpers/RenderGraphHelpers.js'; +import { fillMatrix4x3, fillMatrix4x4, fillVec4 } from '../gfx/helpers/UniformBufferHelpers.js'; import { GfxBindingLayoutDescriptor, GfxDevice, GfxTexture } from "../gfx/platform/GfxPlatform.js"; +import { GfxrAttachmentSlot } from "../gfx/render/GfxRenderGraph.js"; import { GfxRenderHelper } from '../gfx/render/GfxRenderHelper.js'; +import { GfxRenderInstList } from "../gfx/render/GfxRenderInstManager.js"; +import { Vec3UnitX, Vec3UnitZ } from "../MathHelpers.js"; import { SceneContext } from '../SceneBase.js'; import { FakeTextureHolder } from '../TextureHolder.js'; +import * as UI from '../ui.js'; import { hexzero, nArray } from '../util.js'; +import * as Viewer from '../viewer.js'; +import * as BIN from "./bin.js"; import { applyEffect, FFXProgram, findTextureIndex, LevelModelData, LevelPartInstance, TextureData } from "./render.js"; -import { CameraController } from "../Camera.js"; -import { mat4, vec3 } from "gl-matrix"; -import AnimationController from "../AnimationController.js"; -import { NamedArrayBufferSlice } from "../DataFetcher.js"; import { activateEffect, EventScript, LevelObjectHolder } from "./script.js"; -import { GfxrAttachmentSlot } from "../gfx/render/GfxRenderGraph.js"; -import { GfxRenderInstList } from "../gfx/render/GfxRenderInstManager.js"; -import { Color, Cyan, Magenta, colorNewFromRGBA } from "../Color.js"; -import { DebugDrawFlags } from "../gfx/helpers/DebugDraw.js"; -import { Vec3UnitX, Vec3UnitZ } from "../MathHelpers.js"; -import { drawWorldSpaceText, getDebugOverlayCanvas2D } from "../DebugJunk.js"; const pathBase = `FinalFantasyX`; diff --git a/src/GoldSrc/Render.ts b/src/GoldSrc/Render.ts index fe0f76af2..0c4b2d6b9 100644 --- a/src/GoldSrc/Render.ts +++ b/src/GoldSrc/Render.ts @@ -149,8 +149,8 @@ class GoldSrcProgram extends DeviceProgram { public static a_TexCoord = 1; public override both = ` -layout(std140) uniform ub_SceneParams { - Mat4x4 u_ViewProjection; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_ProjectionView; }; uniform sampler2D u_TextureDiffuse; @@ -164,7 +164,7 @@ layout(location = ${GoldSrcProgram.a_TexCoord}) in vec4 a_TexCoord; out vec4 v_TexCoord; void main() { - gl_Position = Mul(u_ViewProjection, vec4(a_Position, 1.0)); + gl_Position = u_ProjectionView * vec4(a_Position, 1.0); v_TexCoord = a_TexCoord; } `; diff --git a/src/GrandTheftAuto3/program.glsl b/src/GrandTheftAuto3/program.glsl index 3101690f4..bcd3b3197 100644 --- a/src/GrandTheftAuto3/program.glsl +++ b/src/GrandTheftAuto3/program.glsl @@ -2,10 +2,10 @@ precision mediump float; precision lowp sampler2DArray; -layout(std140) uniform ub_SceneParams { - Mat4x4 u_Projection; - Mat4x3 u_ViewMatrix; - Mat4x3 u_WorldMatrix; +layout(std140, row_major) uniform ub_SceneParams { + mat4x4 u_Projection; + mat4x3 u_ViewMatrix; + mat4x3 u_WorldMatrix; vec4 u_Frustum; vec4 u_AmbientColor; vec4 u_SkyTopColor; @@ -38,7 +38,8 @@ layout(location = 2) in vec3 a_TexCoord; layout(location = 3) in vec3 a_TexScroll; void main() { - gl_Position = Mul(u_Projection, Mul(_Mat4x4(u_ViewMatrix), vec4(a_Position, 1.0))); + vec3 t_PositionView = u_ViewMatrix * vec4(a_Position, 1.0); + gl_Position = u_Projection * vec4(t_PositionView, 1.0); v_Color = a_Color; v_TexCoord = a_TexCoord; v_TexScroll = a_TexScroll; @@ -53,8 +54,8 @@ void main() { // TODO: get this working again vec3 nearPlane = v_Position * u_Frustum.xyz; - vec3 cameraRay = Mul(u_WorldMatrix, vec4(nearPlane, 0.0)); - vec3 cameraPos = Mul(u_WorldMatrix, vec4(vec3(0.0), 1.0)); + vec3 cameraRay = u_WorldMatrix * vec4(nearPlane, 0.0); + vec3 cameraPos = u_WorldMatrix * vec4(vec3(0.0), 1.0); float elevation = atan(cameraRay.y, length(cameraRay.zx)); gl_FragColor = mix(u_SkyBotColor, u_SkyTopColor, clamp(abs(elevation / radians(45.0)), 0.0, 1.0)); gl_FragDepth = 0.0; @@ -72,8 +73,9 @@ void main() { gl_FragColor = mix(gl_FragColor, t_Color, t_Color.a); // slightly overlap water tiles to avoid seam - vec4 clipOffset = 0.01 * vec4(0, 0, 1, 0); - vec4 clipSpacePos = Mul(u_Projection, Mul(_Mat4x4(u_ViewMatrix), vec4(oceanPlane, 1.0)) + clipOffset); + vec3 clipOffset = 0.01 * vec3(0, 0, 1); + vec3 viewSpacePos = (u_ViewMatrix * vec4(oceanPlane, 1.0)) + clipOffset; + vec4 clipSpacePos = u_Projection * vec4(viewSpacePos, 1.0); float depthNDC = clipSpacePos.z / clipSpacePos.w; gl_FragDepth = 0.5 + 0.5 * depthNDC; } diff --git a/src/InteractiveExamples/FoxFur.ts b/src/InteractiveExamples/FoxFur.ts index a84323a12..c40dbeafb 100644 --- a/src/InteractiveExamples/FoxFur.ts +++ b/src/InteractiveExamples/FoxFur.ts @@ -126,9 +126,9 @@ class FurProgram extends DeviceProgram { public static ub_ShapeParams = 0; public override both = ` -layout(std140) uniform ub_ShapeParams { - Mat4x4 u_Projection; - Mat4x3 u_BoneMatrix[1]; +layout(std140, row_major) uniform ub_ShapeParams { + mat4x4 u_Projection; + mat4x3 u_BoneMatrix[1]; vec4 u_Misc[3]; vec4 u_TintColor; }; @@ -158,8 +158,9 @@ layout(location = 2) in vec2 a_TexCoord; out vec2 v_TexCoord; void main() { - vec3 t_Position = a_Position.xyz + (a_Normal.xyz * u_LayerMagnitude); - gl_Position = Mul(u_Projection, Mul(_Mat4x4(u_BoneMatrix[0]), vec4(t_Position, 1.0))); + vec3 t_PositionLocal = a_Position.xyz + (a_Normal.xyz * u_LayerMagnitude); + vec3 t_PositionView = u_BoneMatrix[0] * vec4(t_PositionLocal, 1.0); + gl_Position = u_Projection * vec4(t_PositionView, 1.0); v_TexCoord = a_TexCoord.xy; } `; diff --git a/src/InteractiveExamples/GridPlane.ts b/src/InteractiveExamples/GridPlane.ts index aa2e864ad..8f1312f07 100644 --- a/src/InteractiveExamples/GridPlane.ts +++ b/src/InteractiveExamples/GridPlane.ts @@ -16,9 +16,9 @@ class GridPlaneProgram extends DeviceProgram { public static ub_SceneParams = 0; public override both = ` -layout(std140) uniform ub_Params { - Mat4x4 u_WorldFromClip; - Mat4x4 u_ClipFromWorld; +layout(std140, row_major) uniform ub_Params { + mat4 u_WorldFromClip; + mat4 u_ClipFromWorld; vec4 u_GridColor; vec4 u_Misc[1]; }; @@ -53,7 +53,7 @@ ${GfxShaderLibrary.saturate} ${GfxShaderLibrary.invlerp} vec3 CalcWorldPos(in vec2 t_ClipXY, in float t_ClipZ) { - vec4 t_World = Mul(u_WorldFromClip, vec4(t_ClipXY, t_ClipZ, 1.0)); + vec4 t_World = u_WorldFromClip * vec4(t_ClipXY, t_ClipZ, 1.0); return t_World.xyz / t_World.www; } @@ -94,7 +94,7 @@ void main() { if (t_FragWorldFar.y > t_FragWorldNear.y) gl_FragColor.a *= 0.2; - vec4 t_PlaneClipPos = Mul(u_ClipFromWorld, vec4(t_FragWorldPos.xyz, 1.0)); + vec4 t_PlaneClipPos = u_ClipFromWorld * vec4(t_FragWorldPos.xyz, 1.0); t_PlaneClipPos.xyz /= t_PlaneClipPos.www; float t_PlaneClipZ = t_PlaneClipPos.z; diff --git a/src/InteractiveExamples/Tess.ts b/src/InteractiveExamples/Tess.ts index 65f52a45b..0e05a0efd 100644 --- a/src/InteractiveExamples/Tess.ts +++ b/src/InteractiveExamples/Tess.ts @@ -28,8 +28,8 @@ class PatchProgram extends DeviceProgram { public override both = ` ${GfxShaderLibrary.saturate} -layout(std140) uniform ub_SceneParams { - Mat4x4 u_ProjectionView; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_ProjectionView; vec4 u_CameraPosWorld; }; @@ -37,9 +37,9 @@ struct WaveParam { vec4 Param[1]; }; -layout(std140) uniform ub_ObjectParams { - Mat4x3 u_PatchToMeshMatrix; - Mat4x3 u_MeshToWorldMatrix; +layout(std140, row_major) uniform ub_ObjectParams { + mat4x3 u_PatchToMeshMatrix; + mat4x3 u_MeshToWorldMatrix; WaveParam u_Wave[2]; vec4 u_ColorAdd; }; @@ -72,6 +72,8 @@ out vec3 v_NormalWorld; out vec3 v_TangentWorld; out vec2 v_TexCoordLocal; +${GfxShaderLibrary.MulNormalMatrix} + vec3 SphereFromCube(vec3 t_Pos) { // http://mathproofs.blogspot.com/2005/07/mapping-cube-to-sphere.html vec3 t_Pos2 = t_Pos * t_Pos; @@ -87,8 +89,8 @@ void main() { vec3 t_PatchPos = vec3(t_PatchLoc.x, 0.0, t_PatchLoc.y); vec3 t_PatchNrm = vec3(0.0, 1.0, 0.0); - vec3 t_MeshPos = Mul(_Mat4x4(u_PatchToMeshMatrix), vec4(t_PatchPos, 1.0)).xyz; - vec3 t_MeshNrm = Mul(_Mat4x4(u_PatchToMeshMatrix), vec4(t_PatchNrm, 0.0)).xyz; + vec3 t_MeshPos = u_PatchToMeshMatrix * vec4(t_PatchPos, 1.0); + vec3 t_MeshNrm = u_PatchToMeshMatrix * vec4(t_PatchNrm, 0.0); vec3 t_MeshTng = vec3(1.0, 0.0, 0.0); vec2 t_TexCoordMesh; t_TexCoordMesh.xy = a_TexCoord.xy; @@ -102,17 +104,16 @@ void main() { t_TexCoordMesh.y = t_MeshNrm.y * 0.5 + 0.5; #endif - vec3 t_PosWorld = Mul(_Mat4x4(u_MeshToWorldMatrix), vec4(t_MeshPos, 1.0)).xyz; - v_NormalWorld = normalize(Mul(_Mat4x4(u_MeshToWorldMatrix), vec4(t_MeshNrm, 0.0)).xyz); - v_TangentWorld = normalize(Mul(_Mat4x4(u_MeshToWorldMatrix), vec4(t_MeshTng, 0.0)).xyz); + v_PositionWorld = u_MeshToWorldMatrix * vec4(t_MeshPos, 1.0); + v_NormalWorld = MulNormalMatrix(u_MeshToWorldMatrix, t_MeshNrm); + v_TangentWorld = normalize(u_MeshToWorldMatrix * vec4(t_MeshTng, 0.0)); #ifdef MODE_SPHERE - t_PosWorld.xyz += v_NormalWorld.xyz * CalcWaveHeight(0u, t_TexCoordMesh.xy); - t_PosWorld.xyz += v_NormalWorld.xyz * CalcWaveHeight(1u, t_TexCoordMesh.xy); + v_PositionWorld += v_NormalWorld * CalcWaveHeight(0u, t_TexCoordMesh.xy); + v_PositionWorld += v_NormalWorld * CalcWaveHeight(1u, t_TexCoordMesh.xy); #endif - v_PositionWorld.xyz = t_PosWorld.xyz; - gl_Position = Mul(u_ProjectionView, vec4(t_PosWorld, 1.0)); + gl_Position = u_ProjectionView * vec4(v_PositionWorld, 1.0); v_NormalMesh.xyz = t_MeshNrm.xyz; v_TexCoordLocal.xy = a_TexCoord.xy; @@ -263,7 +264,6 @@ class PatchLibrary { private patchVariation: { startIndex: number, indexCount: number }[] = []; constructor(cache: GfxRenderCache, public sideNumQuads: number = 32) { - const device = cache.device; const sideNumVerts = sideNumQuads + 1; let totalNumVerts = sideNumVerts ** 2.0; diff --git a/src/JetSetRadio/Render.ts b/src/JetSetRadio/Render.ts index 9a9516d04..7876f05d3 100644 --- a/src/JetSetRadio/Render.ts +++ b/src/JetSetRadio/Render.ts @@ -13,6 +13,7 @@ import { setAttachmentStateSimple } from "../gfx/helpers/GfxMegaStateDescriptorH import { lerpAngle } from "../MathHelpers.js"; import { PVRTextureHolder } from "./Scenes.js"; import { assert, nArray } from "../util.js"; +import { GfxShaderLibrary } from "../gfx/helpers/GfxShaderLibrary.js"; export class JSRProgram extends DeviceProgram { public static a_Position = 0; @@ -28,13 +29,13 @@ export class JSRProgram extends DeviceProgram { public override both = ` precision mediump float; // Expected to be constant across the entire scene. -layout(std140) uniform ub_SceneParams { - Mat4x4 u_Projection; - Mat4x3 u_LightDirection; +layout(std140, row_major) uniform ub_SceneParams { + mat4x4 u_Projection; + mat4x3 u_LightDirection; }; -layout(std140) uniform ub_ModelParams { - Mat4x3 u_BoneMatrix; - Mat4x2 u_TextureMatrix; +layout(std140, row_major) uniform ub_ModelParams { + mat4x3 u_BoneMatrix; + mat4x2 u_TextureMatrix; vec4 u_Diffuse; vec4 u_Ambient; vec4 u_Specular; @@ -68,12 +69,17 @@ layout(location = 3) in vec4 a_Diffuse; #ifdef SPECULAR layout(location = 4) in vec4 a_Specular; #endif + +${GfxShaderLibrary.MulNormalMatrix} + void main() { - gl_Position = vec4(a_Position, 1.0); - gl_Position = Mul(u_Projection, Mul(_Mat4x4(u_BoneMatrix), gl_Position)); + vec3 t_PositionView = u_BoneMatrix * vec4(a_Position, 1.0); + gl_Position = u_Projection * vec4(t_PositionView, 1.0); + #ifdef NORMAL - v_Normal = normalize(Mul(_Mat4x4(u_BoneMatrix), vec4(a_Normal, 0.0)).xyz); + v_Normal = MulNormalMatrix(u_BoneMatrix, a_Normal); #endif + #ifdef DIFFUSE v_Diffuse = a_Diffuse; #endif @@ -82,7 +88,7 @@ void main() { #endif #ifdef TEXTURE v_TexCoord = a_TexCoord; - v_TexCoord = Mul(_Mat4x4(u_TextureMatrix), vec4(v_TexCoord, 0.0, 1.0)).xy; + v_TexCoord = u_TextureMatrix * vec4(v_TexCoord, 0.0, 1.0); #endif } `; diff --git a/src/KingdomHearts/program.glsl b/src/KingdomHearts/program.glsl index 13a25c8ad..8c8e1c48c 100644 --- a/src/KingdomHearts/program.glsl +++ b/src/KingdomHearts/program.glsl @@ -2,14 +2,13 @@ precision mediump float; // Expected to be constant across the entire scene. -layout(std140) uniform ub_SceneParams { - Mat4x4 u_Projection; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_ProjectionView; float u_Time; }; -layout(std140) uniform ub_DrawParams { - Mat4x4 u_Model; - Mat4x3 u_View; +layout(std140, row_major) uniform ub_DrawParams { + mat4x3 u_Model; vec4 u_AnimOffset; }; @@ -32,7 +31,8 @@ layout(location = 5) in vec4 a_TexScaleOffset; layout(location = 6) in vec2 a_TexScroll; void main() { - gl_Position = Mul(u_Projection, Mul(_Mat4x4(u_View), Mul(u_Model, vec4(a_Position, 1.0)))); + vec3 t_PositionWorld = u_Model * vec4(a_Position, 1.0); + gl_Position = u_ProjectionView * vec4(t_PositionWorld, 1.0); v_Color = a_Color; v_TexCoord = a_TexCoord; v_TexClip = a_TexClip; diff --git a/src/KingdomHearts/render.ts b/src/KingdomHearts/render.ts index ca858364e..3b5306a87 100644 --- a/src/KingdomHearts/render.ts +++ b/src/KingdomHearts/render.ts @@ -427,10 +427,9 @@ class DrawCallInstance { mat4.rotateY(modelMatrixScratch, modelMatrixScratch, this.drawCall.rotYFactor * viewerInput.time / (Math.PI * 6)); } - let offs = renderInst.allocateUniformBuffer(KingdomHeartsProgram.ub_DrawParams, 32); + let offs = renderInst.allocateUniformBuffer(KingdomHeartsProgram.ub_DrawParams, 16); const mapped = renderInst.mapUniformBufferF32(KingdomHeartsProgram.ub_DrawParams); - offs += fillMatrix4x4(mapped, offs, modelMatrixScratch); - offs += fillMatrix4x3(mapped, offs, viewerInput.camera.viewMatrix); + offs += fillMatrix4x3(mapped, offs, modelMatrixScratch); if (this.drawCall.spriteAnim) { this.drawCall.spriteAnim.getUVOffset(viewerInput.time, uvAnimOffsetScratch); @@ -500,7 +499,7 @@ export class SceneRenderer { let offs = template.allocateUniformBuffer(KingdomHeartsProgram.ub_SceneParams, 20); const sceneParamsMapped = template.mapUniformBufferF32(KingdomHeartsProgram.ub_SceneParams); - offs += fillMatrix4x4(sceneParamsMapped, offs, viewerInput.camera.projectionMatrix); + offs += fillMatrix4x4(sceneParamsMapped, offs, viewerInput.camera.clipFromWorldMatrix); sceneParamsMapped[offs] = viewerInput.time; for (let i = 0; i < this.drawCallInstances.length; i++) diff --git a/src/KingdomHearts2FinalMix/program.glsl b/src/KingdomHearts2FinalMix/program.glsl index 54f13aaf0..72cc57ebf 100644 --- a/src/KingdomHearts2FinalMix/program.glsl +++ b/src/KingdomHearts2FinalMix/program.glsl @@ -1,14 +1,14 @@ + precision mediump float; // Expected to be constant across the entire scene. -layout(std140) uniform ub_SceneParams { - Mat4x4 u_Projection; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_ProjectionView; float u_Time; }; -layout(std140) uniform ub_DrawParams { - Mat4x4 u_Model; - Mat4x3 u_View; +layout(std140, row_major) uniform ub_DrawParams { + mat4x3 u_Model; vec4 u_AnimOffset; }; @@ -33,7 +33,8 @@ layout(location = 6) in vec2 a_TexScroll; layout(location = 7) in vec3 a_Normal; void main() { - gl_Position = Mul(u_Projection, Mul(_Mat4x4(u_View), Mul(u_Model, vec4(a_Position, 1.0)))); + vec3 t_PositionWorld = u_Model * vec4(a_Position, 1.0); + gl_Position = u_ProjectionView * vec4(t_PositionWorld, 1.0); v_Color = a_Color; v_TexCoord = a_TexCoord; v_TexClip = a_TexClip; diff --git a/src/KingdomHearts2FinalMix/render.ts b/src/KingdomHearts2FinalMix/render.ts index 418fe74e3..3d2b6bdda 100644 --- a/src/KingdomHearts2FinalMix/render.ts +++ b/src/KingdomHearts2FinalMix/render.ts @@ -511,10 +511,9 @@ class DrawCallInstance { renderInst.setSamplerBindingsFromTextureMappings(this.textureMappings); renderInst.setDrawCount(this.drawCall.indexCount, this.drawCall.firstIndex); - let offs = renderInst.allocateUniformBuffer(KingdomHeartsIIProgram.ub_DrawParams, 32); + let offs = renderInst.allocateUniformBuffer(KingdomHeartsIIProgram.ub_DrawParams, 16); const mapped = renderInst.mapUniformBufferF32(KingdomHeartsIIProgram.ub_DrawParams); - offs += fillMatrix4x4(mapped, offs, modelMatrix); - offs += fillMatrix4x3(mapped, offs, viewerInput.camera.viewMatrix); + offs += fillMatrix4x3(mapped, offs, modelMatrix); if (this.drawCall.textureAnim) { this.drawCall.textureAnim.fillUVOffset(uvAnimOffsetScratch); mapped[offs++] = uvAnimOffsetScratch[0]; @@ -585,7 +584,7 @@ class SceneRenderer { let offs = template.allocateUniformBuffer(KingdomHeartsIIProgram.ub_SceneParams, 20); const sceneParamsMapped = template.mapUniformBufferF32(KingdomHeartsIIProgram.ub_SceneParams); - offs += fillMatrix4x4(sceneParamsMapped, offs, viewerInput.camera.projectionMatrix); + offs += fillMatrix4x4(sceneParamsMapped, offs, viewerInput.camera.clipFromWorldMatrix); sceneParamsMapped[offs] = viewerInput.time; for (const instance of this.drawCallInstances) { diff --git a/src/MarioKart8Deluxe/Render.ts b/src/MarioKart8Deluxe/Render.ts index a13217274..9456393b6 100644 --- a/src/MarioKart8Deluxe/Render.ts +++ b/src/MarioKart8Deluxe/Render.ts @@ -139,8 +139,8 @@ class TurboUBER extends DeviceProgram { public static globalDefinitions = ` precision mediump float; -layout(std140) uniform ub_ShapeParams { - Mat4x4 u_ProjectionView; +layout(std140, row_major) uniform ub_ShapeParams { + mat4 u_ProjectionView; vec4 u_CameraPosWorld; }; @@ -150,13 +150,13 @@ struct EnvLightParam { vec4 Direction; }; -layout(std140) uniform ub_MaterialParams { - Mat4x3 u_Model; - Mat4x2 u_TexCoordSRT0; +layout(std140, row_major) uniform ub_MaterialParams { + mat4x3 u_Model; + mat4x2 u_TexCoordSRT0; vec4 u_TexCoordBake0ScaleBias; vec4 u_TexCoordBake1ScaleBias; - Mat4x2 u_TexCoordSRT2; - Mat4x2 u_TexCoordSRT3; + mat4x2 u_TexCoordSRT2; + mat4x2 u_TexCoordSRT3; vec4 u_AlbedoColorAndTransparency; vec4 u_EmissionColorAndNormalMapWeight; vec4 u_SpecularColorAndIntensity; @@ -225,8 +225,8 @@ out vec3 v_NormalWorld; out vec4 v_TangentWorld; void main() { - gl_Position = Mul(u_ProjectionView, Mul(_Mat4x4(u_Model), vec4(a_Position, 1.0))); - v_PositionWorld = a_Position.xyz; + v_PositionWorld = u_Model * vec4(a_Position, 1.0); + gl_Position = u_ProjectionView * vec4(v_PositionWorld, 1.0); bool gsys_invalidate_texture_srt = ${this.shaderOptionBool('gsys_invalidate_texture_srt')}; @@ -235,9 +235,9 @@ void main() { v_TexCoord23.xy = a_TexCoord2.xy; v_TexCoord23.zw = a_TexCoord3.xy; } else { - v_TexCoord0 = Mul(u_TexCoordSRT0, vec4(a_TexCoord0.xy, 1.0, 1.0)); - v_TexCoord23.xy = Mul(u_TexCoordSRT2, vec4(a_TexCoord2.xy, 1.0, 1.0)); - v_TexCoord23.zw = Mul(u_TexCoordSRT3, vec4(a_TexCoord3.xy, 1.0, 1.0)); + v_TexCoord0 = u_TexCoordSRT0 * vec4(a_TexCoord0.xy, 1.0, 1.0); + v_TexCoord23.xy = u_TexCoordSRT2 * vec4(a_TexCoord2.xy, 1.0, 1.0); + v_TexCoord23.zw = u_TexCoordSRT3 * vec4(a_TexCoord3.xy, 1.0, 1.0); } v_TexCoordBake.xy = CalcScaleBias(a_TexCoord1.xy, u_TexCoordBake0ScaleBias); diff --git a/src/Morrowind/NIFBase.ts b/src/Morrowind/NIFBase.ts index f6239b658..89d638589 100644 --- a/src/Morrowind/NIFBase.ts +++ b/src/Morrowind/NIFBase.ts @@ -276,15 +276,15 @@ class NifShader extends DeviceProgram { precision mediump float; precision mediump sampler2DArray; -layout(std140) uniform ub_SceneParams { - Mat4x4 u_ClipFromWorld; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_ClipFromWorld; vec4 u_SunDirection; vec4 u_SunDiffuse; vec4 u_SunAmbient; }; -layout(std140) uniform ub_ObjectParams { - Mat4x3 u_LocalFromNode; +layout(std140, row_major) uniform ub_ObjectParams { + mat4x3 u_LocalFromNode; vec4 u_Misc[1]; vec4 u_DiffuseColor; vec4 u_AmbientColor; @@ -292,8 +292,8 @@ layout(std140) uniform ub_ObjectParams { }; #if USE_INSTANCING() -layout(std140) uniform ub_InstanceParams { - Mat4x3 u_WorldFromLocal[${NifShader.MaxInstances}]; +layout(std140, row_major) uniform ub_InstanceParams { + mat4x3 u_WorldFromLocal[${NifShader.MaxInstances}]; }; #endif @@ -312,26 +312,25 @@ layout(location = ${NifShader.a_Color0}) in vec4 a_Color0; layout(location = ${NifShader.a_TexCoord0}) in vec2 a_TexCoord0; ${GfxShaderLibrary.saturate} +${GfxShaderLibrary.MulNormalMatrix} out vec4 v_Color0; out vec2 v_TexCoord0; void main() { - vec3 t_PositionLocal = Mul(u_LocalFromNode, vec4(a_Position, 1.0)); - vec3 t_NormalLocal = normalize(Mul(u_LocalFromNode, vec4(a_Normal, 0.0))); - vec3 t_PositionWorld; vec3 t_NormalWorld; + #if USE_INSTANCING() - Mat4x3 t_WorldFromLocal = u_WorldFromLocal[gl_InstanceID]; - t_PositionWorld = Mul(t_WorldFromLocal, vec4(t_PositionLocal, 1.0)); - t_NormalWorld = normalize(Mul(t_WorldFromLocal, vec4(t_NormalLocal, 0.0))); + mat4x3 t_WorldFromNode = mat4x3(mat4(u_WorldFromLocal[gl_InstanceID]) * mat4(u_LocalFromNode)); + t_PositionWorld = t_WorldFromNode * vec4(a_Position, 1.0); + t_NormalWorld = MulNormalMatrix(t_WorldFromNode, a_Normal); #else - t_PositionWorld = t_PositionLocal; - t_NormalWorld = normalize(t_NormalLocal); + t_PositionWorld = u_LocalFromNode * vec4(a_Position, 1.0); + t_NormalWorld = MulNormalMatrix(u_LocalFromNode, a_Normal); #endif - gl_Position = Mul(u_ClipFromWorld, vec4(t_PositionWorld, 1.0)); + gl_Position = u_ClipFromWorld * vec4(t_PositionWorld, 1.0); vec4 t_DiffuseColor = u_DiffuseColor; vec4 t_AmbientColor = u_AmbientColor; diff --git a/src/Morrowind/Render.ts b/src/Morrowind/Render.ts index b9be1ec38..0ec644778 100644 --- a/src/Morrowind/Render.ts +++ b/src/Morrowind/Render.ts @@ -512,15 +512,15 @@ class TerrainProgram extends DeviceProgram { precision mediump float; precision mediump sampler2DArray; -layout(std140) uniform ub_SceneParams { - Mat4x4 u_ClipFromWorld; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_ClipFromWorld; vec4 u_SunDirection; vec4 u_SunDiffuse; vec4 u_SunAmbient; }; -layout(std140) uniform ub_ObjectParams { - Mat4x3 u_WorldFromLocal; +layout(std140, row_major) uniform ub_ObjectParams { + mat4x3 u_WorldFromLocal; }; layout(location = 0) uniform sampler2DArray u_TextureTerrain; @@ -542,9 +542,9 @@ void main() { float x = (uv.x - 0.5) * 8192.0; float y = (uv.y - 0.5) * 8192.0; float z = a_Height; - vec3 t_PositionWorld = Mul(u_WorldFromLocal, vec4(x, y, z, 1.0)); + vec3 t_PositionWorld = u_WorldFromLocal * vec4(x, y, z, 1.0); - gl_Position = Mul(u_ClipFromWorld, vec4(t_PositionWorld, 1.0)); + gl_Position = u_ClipFromWorld * vec4(t_PositionWorld, 1.0); v_Color = a_Color; v_Color *= dot(a_Normal, u_SunDirection.xyz) * u_SunDiffuse.xyz + u_SunAmbient.xyz; } diff --git a/src/NeedForSpeedMostWanted/particles.ts b/src/NeedForSpeedMostWanted/particles.ts index b1cf734ca..e4ffc2c67 100644 --- a/src/NeedForSpeedMostWanted/particles.ts +++ b/src/NeedForSpeedMostWanted/particles.ts @@ -233,12 +233,12 @@ export class NfsParticleProgram extends DeviceProgram { public static ub_ObjectParams = 1; public override both = ` -layout(std140) uniform ub_SceneParams { - Mat4x4 u_ViewProjMat; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_ViewProjMat; }; -layout(std140) uniform ub_ObjectParams { - Mat4x3 u_ObjectViewMat; +layout(std140, row_major) uniform ub_ObjectParams { + mat4x3 u_ObjectViewMat; vec4 u_Color; float u_Frame; float u_Size; @@ -253,7 +253,8 @@ layout(location = ${NfsParticleProgram.a_Position}) in vec3 a_Position; out vec2 v_TexCoord; void main() { - gl_Position = Mul(u_ViewProjMat, vec4(Mul(u_ObjectViewMat, vec4(a_Position, 1.0)), 1.0)); + vec3 t_PositionWorld = u_ObjectViewMat * vec4(a_Position, 1.0); + gl_Position = u_ViewProjMat * vec4(t_PositionWorld, 1.0); float frame = mod(u_Frame, u_Size * u_Size); float constX = mod(frame, u_Size); diff --git a/src/NeedForSpeedMostWanted/render.ts b/src/NeedForSpeedMostWanted/render.ts index 7d062c6fe..1a5e2d88c 100644 --- a/src/NeedForSpeedMostWanted/render.ts +++ b/src/NeedForSpeedMostWanted/render.ts @@ -390,14 +390,14 @@ class NfsProgram extends DeviceProgram { public override both = ` precision mediump float; -layout(std140) uniform ub_SceneParams { - Mat4x4 u_WorldProjMat; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_WorldProjMat; vec4 u_CameraPos; vec2 u_ViewportSize; }; -layout(std140) uniform ub_ObjectParams { - Mat4x3 u_ObjectWorldMat; +layout(std140, row_major) uniform ub_ObjectParams { + mat4x3 u_ObjectWorldMat; vec2 u_uvOffset; float u_FogIntensity; }; @@ -471,15 +471,15 @@ out float v_Gloss; out float v_Alpha; void main() { - vec3 worldPos = Mul(u_ObjectWorldMat, vec4(a_Position, 1.0)); - gl_Position = Mul(u_WorldProjMat, vec4(worldPos, 1.0)); + vec3 worldPos = u_ObjectWorldMat * vec4(a_Position, 1.0); + gl_Position = u_WorldProjMat * vec4(worldPos, 1.0); vec3 worldPosGame = toGameWorldSpace(worldPos); vec3 cameraPosWorld = toGameWorldSpace(u_CameraPos.xyz); vec3 vecToEye = cameraPosWorld - worldPosGame; vec3 normal = toGameWorldSpace(MulNormalMatrix(u_ObjectWorldMat, a_Normal)); #ifdef NORMALMAP - vec3 tangent = toGameWorldSpace(MulNormalMatrix(u_ObjectWorldMat, a_Tangent)); + vec3 tangent = toGameWorldSpace(u_ObjectWorldMat * vec4(a_Tangent, 0.0)); vec3 bitangent = normalize(cross(normal, tangent)); vec3 tangentLightVec = toTangentSpace(-SunDirection, tangent, bitangent, normal); diff --git a/src/NeonWhite/Scenes.ts b/src/NeonWhite/Scenes.ts index 0ebbe2bd4..990ea2258 100644 --- a/src/NeonWhite/Scenes.ts +++ b/src/NeonWhite/Scenes.ts @@ -33,14 +33,14 @@ varying vec2 v_TexCoord0; #ifdef VERT void mainVS() { - Mat4x3 t_WorldFromLocalMatrix = CalcWorldFromLocalMatrix(); - vec3 t_PositionWorld = Mul(t_WorldFromLocalMatrix, vec4(a_Position, 1.0)); + mat4x3 t_WorldFromLocalMatrix = CalcWorldFromLocalMatrix(); + vec3 t_PositionWorld = t_WorldFromLocalMatrix * vec4(a_Position, 1.0); vec3 t_LightDirection = normalize(vec3(.2, -1, .5)); vec3 normal = MulNormalMatrix(t_WorldFromLocalMatrix, normalize(a_Normal)); float t_LightIntensityF = dot(-normal, t_LightDirection); float t_LightIntensityB = dot( normal, t_LightDirection); - gl_Position = Mul(u_ProjectionView, vec4(t_PositionWorld, 1.0)); + gl_Position = u_ProjectionView * vec4(t_PositionWorld, 1.0); v_LightIntensity = vec2(t_LightIntensityF, t_LightIntensityB); v_TexCoord0 = CalcScaleBias(a_TexCoord0, u_MainTexST); } diff --git a/src/PaperMario64/program.glsl b/src/PaperMario64/program.glsl index 69bd03d81..d6daa138f 100644 --- a/src/PaperMario64/program.glsl +++ b/src/PaperMario64/program.glsl @@ -2,17 +2,17 @@ precision mediump float; // Expected to be constant across the entire scene. -layout(std140) uniform ub_SceneParams { - Mat4x4 u_Projection; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_Projection; vec4 u_Misc0; }; #define u_ScreenSize (u_Misc0.xy) #define u_LodBias (u_Misc0.z) -layout(std140) uniform ub_DrawParams { - Mat4x3 u_BoneMatrix[1]; - Mat4x2 u_TexMatrix[2]; +layout(std140, row_major) uniform ub_DrawParams { + mat4x3 u_BoneMatrix[1]; + mat4x2 u_TexMatrix[2]; }; uniform sampler2D u_Texture0; @@ -32,15 +32,16 @@ vec3 Monochrome(vec3 t_Color) { } void main() { - gl_Position = Mul(u_Projection, Mul(_Mat4x4(u_BoneMatrix[0]), vec4(a_Position, 1.0))); + vec3 t_PositionView = u_BoneMatrix[0] * vec4(a_Position, 1.0); + gl_Position = u_Projection * vec4(t_PositionView, 1.0); v_Color = a_Color; #ifdef USE_MONOCHROME_VERTEX_COLOR v_Color.rgb = Monochrome(v_Color.rgb); #endif - v_TexCoord.xy = Mul(u_TexMatrix[0], vec4(a_TexCoord, 1.0, 1.0)); - v_TexCoord.zw = Mul(u_TexMatrix[1], vec4(a_TexCoord, 1.0, 1.0)); + v_TexCoord.xy = u_TexMatrix[0] * vec4(a_TexCoord, 1.0, 1.0); + v_TexCoord.zw = u_TexMatrix[1] * vec4(a_TexCoord, 1.0, 1.0); } #endif diff --git a/src/Pilotwings64/Scenes.ts b/src/Pilotwings64/Scenes.ts index 4ecf01bf0..6d32e94a4 100644 --- a/src/Pilotwings64/Scenes.ts +++ b/src/Pilotwings64/Scenes.ts @@ -2301,29 +2301,29 @@ class SnowProgram extends DeviceProgram { public static ub_DrawParams = 1; public override both = ` -layout(std140) uniform ub_SceneParams { - Mat4x4 u_Projection; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_Projection; }; -layout(std140) uniform ub_DrawParams { - Mat4x3 u_BoneMatrix; +layout(std140, row_major) uniform ub_DrawParams { + mat4x3 u_BoneMatrix; vec4 u_Shift; };` public override vert = ` layout(location = 0) in vec3 a_Position; void main() { - gl_Position = vec4(a_Position, 1.0) + vec4(u_Shift.xyz, 0.0); + vec3 t_PositionLocal = a_Position + u_Shift.xyz; // slightly clumsy, force into 0-10k cube, then shift center to origin // just easier than dealing with negative mod values float cubeSide = 5000.0; - gl_Position = mod(gl_Position, 2.0*vec4(cubeSide)) - vec4(vec3(cubeSide), 0.0); - gl_Position = Mul(_Mat4x4(u_BoneMatrix), gl_Position); + t_PositionLocal = mod(t_PositionLocal, 2.0 * vec3(cubeSide)) - vec3(cubeSide); + t_PositionLocal = u_BoneMatrix * vec4(t_PositionLocal, 1.0); // shift snow cube in front of camera - gl_Position.z -= cubeSide; + t_PositionLocal.z -= cubeSide; // add offset based on which corner this is, undoing perspective correction so every flake is the same size - gl_Position += (u_Shift.w * gl_Position.z) * vec4(float(gl_VertexID & 1) - 0.5, float((gl_VertexID >> 1) & 1) - 0.5, 0.0, 0.0); - gl_Position = Mul(u_Projection, gl_Position); + t_PositionLocal += (u_Shift.w * t_PositionLocal.z) * vec3(float(gl_VertexID & 1) - 0.5, float((gl_VertexID >> 1) & 1) - 0.5, 0.0); + gl_Position = u_Projection * vec4(t_PositionLocal, 1.0); // game writes snow directly to the frame buffer, with a very simple projection // this effectively leads to a slightly larger FOV, so apply the same multiplier here gl_Position = gl_Position * vec4(0.81778, 0.81778, 1.0, 1.0); diff --git a/src/PokemonSnap/particles.ts b/src/PokemonSnap/particles.ts index 0f04fe859..b32b55cc3 100644 --- a/src/PokemonSnap/particles.ts +++ b/src/PokemonSnap/particles.ts @@ -574,12 +574,12 @@ class ParticleProgram extends DeviceProgram { public override both = ` precision mediump float; -layout(std140) uniform ub_SceneParams { - Mat4x4 u_Projection; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_Projection; }; -layout(std140) uniform ub_DrawParams { - Mat4x3 u_Matrix; +layout(std140, row_major) uniform ub_DrawParams { + mat4x3 u_Matrix; vec4 u_PrimColor; vec4 u_EnvColor; }; @@ -592,7 +592,8 @@ varying vec2 v_TexCoord;`; layout(location = 0) in vec3 a_Position; void main() { - gl_Position = Mul(u_Projection, Mul(_Mat4x4(u_Matrix), vec4(a_Position, 1.0))); + vec3 t_PositionView = u_Matrix * vec4(a_Position, 1.0); + gl_Position = u_Projection * vec4(t_PositionView, 1.0); v_TexCoord = vec2(gl_VertexID & 1, (gl_VertexID >> 1) & 1); }`; public override frag = ` diff --git a/src/Subnautica/scenes.ts b/src/Subnautica/scenes.ts deleted file mode 100644 index f9adb8fdb..000000000 --- a/src/Subnautica/scenes.ts +++ /dev/null @@ -1,165 +0,0 @@ - -import { mat4, vec3 } from 'gl-matrix'; -import { UnityChannel } from '../Common/Unity/AssetManager.js'; -import { MeshRenderer as UnityMeshRenderer, UnityRuntime, createUnityRuntime } from '../Common/Unity/GameObject.js'; -import { AABB } from '../Geometry.js'; -import { SceneContext } from '../SceneBase.js'; -import { makeBackbufferDescSimple, standardFullClearRenderPassDescriptor } from '../gfx/helpers/RenderGraphHelpers.js'; -import { fillMatrix4x4 } from '../gfx/helpers/UniformBufferHelpers.js'; -import { GfxBindingLayoutDescriptor, GfxBuffer, GfxDevice, GfxProgram } from '../gfx/platform/GfxPlatform.js'; -import { GfxRenderCache } from '../gfx/render/GfxRenderCache.js'; -import { GfxrAttachmentSlot } from '../gfx/render/GfxRenderGraph.js'; -import { GfxRenderHelper } from '../gfx/render/GfxRenderHelper.js'; -import { GfxRenderInstList, GfxRenderInstManager } from '../gfx/render/GfxRenderInstManager.js'; -import * as Viewer from '../viewer.js'; -import { DeviceProgram } from '../Program.js'; -import { UnityVersion } from '../../rust/pkg/noclip_support.js'; - -class ChunkProgram extends DeviceProgram { - public static ub_SceneParams = 0; - public static ub_ShapeParams = 1; - - public override both = ` -precision mediump float; - -layout(std140) uniform ub_SceneParams { - Mat4x4 u_Projection; - Mat4x4 u_ModelView; -}; - -layout(std140) uniform ub_ShapeParams { - Mat4x4 u_ChunkModel; -}; - -varying vec2 v_LightIntensity; - -#ifdef VERT -layout(location = ${UnityChannel.Vertex}) attribute vec3 a_Position; -layout(location = ${UnityChannel.Normal}) attribute vec3 a_Normal; - -void mainVS() { - gl_Position = Mul(u_Projection, Mul(u_ModelView, Mul(u_ChunkModel, vec4(a_Position, 1.0)))); - vec3 t_LightDirection = normalize(vec3(.2, -1, .5)); - vec3 normal = normalize(a_Normal); - float t_LightIntensityF = dot(-normal, t_LightDirection); - float t_LightIntensityB = dot( normal, t_LightDirection); - v_LightIntensity = vec2(t_LightIntensityF, t_LightIntensityB); -} -#endif - -#ifdef FRAG -void mainPS() { - vec4 color = vec4(.4, .4, .4, 1.0); - float t_LightIntensity = gl_FrontFacing ? v_LightIntensity.x : v_LightIntensity.y; - float t_LightTint = 0.5 * t_LightIntensity; - gl_FragColor = sqrt(color + vec4(t_LightTint, t_LightTint, t_LightTint, 0.0)); -} -#endif -`; -} - -// big blocky scaley -const CHUNK_SCALE = 32; - -const bindingLayouts: GfxBindingLayoutDescriptor[] = [ - { numUniformBuffers: 2, numSamplers: 0 }, -]; - -class UnityRenderer implements Viewer.SceneGfx { - private renderHelper: GfxRenderHelper; - private renderInstListMain = new GfxRenderInstList(); - public program: GfxProgram; - - constructor(private runtime: UnityRuntime) { - this.renderHelper = new GfxRenderHelper(this.runtime.context.device, this.runtime.context); - } - - private prepareToRender(device: GfxDevice, viewerInput: Viewer.ViewerRenderInput): void { - this.runtime.update(); - - const template = this.renderHelper.pushTemplateRenderInst(); - template.setBindingLayouts(bindingLayouts); - - let offs = template.allocateUniformBuffer(0, 32); - const mapped = template.mapUniformBufferF32(0); - offs += fillMatrix4x4(mapped, offs, viewerInput.camera.projectionMatrix); - offs += fillMatrix4x4(mapped, offs, viewerInput.camera.viewMatrix); - - const meshRenderers = this.runtime.getComponents(UnityMeshRenderer); - this.renderHelper.renderInstManager.setCurrentList(this.renderInstListMain); - for (let i = 0; i < meshRenderers.length; i++) - meshRenderers[i].prepareToRender(this.renderHelper.renderInstManager, viewerInput); - - this.renderHelper.renderInstManager.popTemplate(); - this.renderHelper.prepareToRender(); - } - - public render(device: GfxDevice, viewerInput: Viewer.ViewerRenderInput) { - const renderInstManager = this.renderHelper.renderInstManager; - - const mainColorDesc = makeBackbufferDescSimple(GfxrAttachmentSlot.Color0, viewerInput, standardFullClearRenderPassDescriptor); - const mainDepthDesc = makeBackbufferDescSimple(GfxrAttachmentSlot.DepthStencil, viewerInput, standardFullClearRenderPassDescriptor); - - const builder = this.renderHelper.renderGraph.newGraphBuilder(); - - const mainColorTargetID = builder.createRenderTargetID(mainColorDesc, 'Main Color'); - const mainDepthTargetID = builder.createRenderTargetID(mainDepthDesc, 'Main Depth'); - builder.pushPass((pass) => { - pass.setDebugName('Main'); - pass.attachRenderTargetID(GfxrAttachmentSlot.Color0, mainColorTargetID); - pass.attachRenderTargetID(GfxrAttachmentSlot.DepthStencil, mainDepthTargetID); - pass.exec((passRenderer) => { - this.renderInstListMain.drawOnPassRenderer(this.renderHelper.renderCache, passRenderer); - }); - }); - this.renderHelper.antialiasingSupport.pushPasses(builder, viewerInput, mainColorTargetID); - builder.resolveRenderTargetToExternalTexture(mainColorTargetID, viewerInput.onscreenTexture); - - this.prepareToRender(device, viewerInput); - this.renderHelper.renderGraph.execute(builder); - this.renderInstListMain.reset(); - } - - public destroy(device: GfxDevice) { - this.runtime.destroy(device); - this.renderHelper.destroy(); - } -} - -class SubnauticaSceneDesc implements Viewer.SceneDesc { - constructor(public id: string, public name: string) { - } - - public async createScene(device: GfxDevice, context: SceneContext): Promise { - /*let assets = new UnityAssetManager('hike/level2', context, device); - await assets.loadAssetInfo(); - let tree = await assets.getGameObjectTree(); - for (let id in tree.nodes) { - let node = tree.nodes[id]; - if (!node.meshSet) { - continue; - } - if (!node.gameObjectSet) { - console.error(`invalid node! ${node.name}`) - continue; - } - renderer.addMesh(tree.meshes[node.meshPathID!], node); - }*/ - - const runtime = await createUnityRuntime(context, `AShortHike`, UnityVersion.V2021_3_27f1); - await runtime.loadLevel(`level2`); - - const renderer = new UnityRenderer(runtime); - return renderer; - } - -} - -const id = 'Subnautica'; -const name = 'Subnautica'; - -const sceneDescs = [ - new SubnauticaSceneDesc("Scanner Map", "Scanner Map"), -]; - -export const sceneGroup: Viewer.SceneGroup = { id, name, sceneDescs, hidden: true }; diff --git a/src/main.ts b/src/main.ts index 5379c3627..2b5a8d650 100644 --- a/src/main.ts +++ b/src/main.ts @@ -83,7 +83,6 @@ import * as Scenes_DiddyKongRacing from './DiddyKongRacing/scenes.js'; import * as Scenes_SpongebobRevengeOfTheFlyingDutchman from "./SpongebobRevengeOfTheFlyingDutchman/scenes.js"; import * as Scenes_MarioKart8Deluxe from './MarioKart8Deluxe/Scenes.js'; import * as Scenes_JetSetRadio from './JetSetRadio/Scenes.js'; -import * as Scenes_Subnautica from './Subnautica/scenes.js'; import * as Scenes_Halo1 from './Halo1/scenes.js'; import * as Scenes_WorldOfWarcraft from './WorldOfWarcraft/scenes.js'; import * as Scenes_Glover from './Glover/scenes.js'; @@ -215,7 +214,6 @@ const sceneGroups: (string | SceneGroup)[] = [ Scenes_TheStanleyParable.sceneGroup, Scenes_Infra.sceneGroup, Scenes_JetSetRadio.sceneGroup, - Scenes_Subnautica.sceneGroup, Scenes_WorldOfWarcraft.bcSceneGroup, Scenes_WorldOfWarcraft.wotlkSceneGroup, Scenes_HalfLife.sceneGroup, diff --git a/src/psychonauts/render.ts b/src/psychonauts/render.ts index 3917d832a..ba6a047fd 100644 --- a/src/psychonauts/render.ts +++ b/src/psychonauts/render.ts @@ -94,12 +94,12 @@ class PsychonautsProgram extends DeviceProgram { precision mediump float; // Expected to be constant across the entire scene. -layout(std140) uniform ub_SceneParams { - Mat4x4 u_Projection; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_Projection; }; -layout(std140) uniform ub_MeshFragParams { - Mat4x3 u_BoneMatrix[1]; +layout(std140, row_major) uniform ub_MeshFragParams { + mat4x3 u_BoneMatrix[1]; vec4 u_MaterialColor; vec4 u_TexCoordOffs; }; @@ -118,7 +118,8 @@ layout(location = ${PsychonautsProgram.a_TexCoord0}) in vec2 a_TexCoord0; layout(location = ${PsychonautsProgram.a_TexCoord1}) in vec2 a_TexCoord1; void main() { - gl_Position = Mul(u_Projection, Mul(_Mat4x4(u_BoneMatrix[0]), vec4(a_Position, 1.0))); + vec3 t_PositionView = u_BoneMatrix[0] * vec4(a_Position, 1.0); + gl_Position = u_Projection * vec4(t_PositionView, 1.0); v_Color = a_Color; v_TexCoord.xy = a_TexCoord0 + u_TexCoordOffs.xy; v_TexCoord.zw = a_TexCoord1;