Skip to content

Commit

Permalink
World of Warcraft: Remove legacy matrix library usage
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Jan 3, 2025
1 parent cd0f3ed commit 3b074bb
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 165 deletions.
20 changes: 11 additions & 9 deletions src/BanjoKazooie/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class F3DEX_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;
#ifdef LIGHTING
#ifdef TEXTURE_GEN
vec4 u_LookAtVectors[2];
Expand All @@ -47,9 +47,9 @@ layout(std140) uniform ub_SceneParams {
#endif
};
layout(std140) uniform ub_DrawParams {
Mat4x3 u_BoneMatrix[BONE_MATRIX_COUNT];
Mat4x2 u_TexMatrix[2];
layout(std140, row_major) uniform ub_DrawParams {
mat4x3 u_BoneMatrix[BONE_MATRIX_COUNT];
mat4x2 u_TexMatrix[2];
};
layout(std140) uniform ub_CombineParameters {
Expand Down Expand Up @@ -93,7 +93,8 @@ vec3 ConvertToSignedInt(vec3 t_Input) {
void main() {
int t_BoneIndex = int(a_Position.w);
gl_Position = Mul(u_Projection, Mul(_Mat4x4(u_BoneMatrix[t_BoneIndex]), vec4(a_Position.xyz, 1.0)));
vec3 t_PositionView = u_BoneMatrix[t_BoneIndex] * vec4(a_Position.xyz, 1.0);
gl_Position = u_Projection * vec4(t_PositionView, 1.0);
v_Color = t_One;
#ifdef USE_VERTEX_COLOR
Expand All @@ -104,15 +105,16 @@ void main() {
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);
${this.generateClamp()}
#ifdef LIGHTING
// convert (unsigned) colors to normal vector components
vec4 t_Normal = vec4(ConvertToSignedInt(a_Color.rgb), 0.0);
t_Normal = normalize(Mul(_Mat4x4(u_BoneMatrix[t_BoneIndex]), t_Normal));
vec3 t_NormalView = u_BoneMatrix[t_BoneIndex] * vec4(t_Normal.xyz, 0.0);
t_Normal = normalize(vec4(t_NormalView, 0.0));
#ifdef PARAMETERIZED_LIGHTING
v_Color = ${this.generateLightingExpression()};
Expand Down
30 changes: 14 additions & 16 deletions src/SuperMarioGalaxy/ImageEffect.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@

import { SceneObjHolder, SceneObj } from "./Main.js";
import { NameObj, CalcAnimType, MovementType } from "./NameObj.js";
import { getMatrixTranslation } from "../MathHelpers.js";
import { vec3 } from "gl-matrix";
import { AreaObj, AreaObjMgr, AreaFormType } from "./AreaObj.js";
import { JMapInfoIter, getJMapInfoArg7, getJMapInfoArg0, getJMapInfoArg1, getJMapInfoArg2, getJMapInfoArg3 } from "./JMapInfo.js";
import { ZoneAndLayer } from "./LiveActor.js";
import { fallback } from "../util.js";
import { connectToScene, getAreaObj } from "./ActorUtil.js";
import { DeviceProgram } from "../Program.js";
import { TextureMapping } from "../TextureHolder.js";
import { nArray, assert } from "../util.js";
import { GfxWrapMode, GfxTexFilterMode, GfxBindingLayoutDescriptor, GfxMipFilterMode, GfxBlendMode, GfxBlendFactor, GfxMegaStateDescriptor, GfxFormat, GfxProgram, GfxTextureDimension, GfxSamplerFormatKind } from "../gfx/platform/GfxPlatform.js";
import { fillVec4 } from "../gfx/helpers/UniformBufferHelpers.js";
import { GfxRenderInst, GfxRenderInstManager } from "../gfx/render/GfxRenderInstManager.js";
import { fullscreenMegaState, makeMegaState, setAttachmentStateSimple } from "../gfx/helpers/GfxMegaStateDescriptorHelpers.js";
import { MathConstants } from "../MathHelpers.js";
import { GfxrAttachmentSlot, GfxrRenderTargetDescription, GfxrGraphBuilder, GfxrRenderTargetID } from "../gfx/render/GfxRenderGraph.js";
import { GfxShaderLibrary, glslGenerateFloat } from "../gfx/helpers/GfxShaderLibrary.js";
import { IsDepthReversed } from "../gfx/helpers/ReversedDepthHelpers.js";
import { fillVec4 } from "../gfx/helpers/UniformBufferHelpers.js";
import { GfxBindingLayoutDescriptor, GfxBlendFactor, GfxBlendMode, GfxFormat, GfxMegaStateDescriptor, GfxMipFilterMode, GfxProgram, GfxSamplerFormatKind, GfxTexFilterMode, GfxTextureDimension, GfxWrapMode } from "../gfx/platform/GfxPlatform.js";
import { GfxrAttachmentSlot, GfxrGraphBuilder, GfxrRenderTargetDescription, GfxrRenderTargetID } from "../gfx/render/GfxRenderGraph.js";
import { GfxRenderInst, GfxRenderInstManager } from "../gfx/render/GfxRenderInstManager.js";
import { GXShaderLibrary } from "../gx/gx_material.js";
import { getMatrixTranslation } from "../MathHelpers.js";
import { DeviceProgram } from "../Program.js";
import { TextureMapping } from "../TextureHolder.js";
import { assert, fallback, nArray } from "../util.js";
import { connectToScene, getAreaObj } from "./ActorUtil.js";
import { AreaFormType, AreaObj, AreaObjMgr } from "./AreaObj.js";
import { JMapInfoIter, getJMapInfoArg0, getJMapInfoArg1, getJMapInfoArg2, getJMapInfoArg3, getJMapInfoArg7 } from "./JMapInfo.js";
import { ZoneAndLayer } from "./LiveActor.js";
import { SceneObj, SceneObjHolder } from "./Main.js";
import { CalcAnimType, MovementType, NameObj } from "./NameObj.js";

const scratchVec3 = vec3.create();

Expand Down
14 changes: 6 additions & 8 deletions src/WorldOfWarcraft/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { getDerivativeBezier, getPointBezier } from "../Spline.js";
import { makeStaticDataBuffer } from "../gfx/helpers/BufferHelpers.js";
import { reverseDepthForCompareMode } from "../gfx/helpers/ReversedDepthHelpers.js";
import {
fillMatrix4x2,
fillMatrix4x4,
fillVec3v,
fillVec4,
Expand Down Expand Up @@ -1043,11 +1044,9 @@ export class ModelBatch {
}

public setModelParams(renderInst: GfxRenderInst) {
const numVec4s = 4;
const numMat4s = 3;
let offset = renderInst.allocateUniformBuffer(
ModelProgram.ub_MaterialParams,
numVec4s * 4 + numMat4s * 16,
4 * 4 + 8 * 4,
);
const uniformBuf = renderInst.mapUniformBufferF32(
ModelProgram.ub_MaterialParams,
Expand Down Expand Up @@ -1076,23 +1075,22 @@ export class ModelBatch {
color[2],
this.getVertexColorAlpha(),
);
offset += fillMatrix4x4(
offset += fillMatrix4x2(
uniformBuf,
offset,
this.getTextureTransform(0),
);
offset += fillMatrix4x4(
offset += fillMatrix4x2(
uniformBuf,
offset,
this.getTextureTransform(1),
);
const textureWeight: vec4 = [
offset += fillVec4(uniformBuf, offset,
this.getTextureWeight(0),
this.getTextureWeight(1),
this.getTextureWeight(2),
this.getTextureWeight(3),
];
offset += fillVec4v(uniformBuf, offset, textureWeight);
);
}
}

Expand Down
Loading

0 comments on commit 3b074bb

Please sign in to comment.