Skip to content

Commit

Permalink
Kill off custom matrix library
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Jan 3, 2025
1 parent a394d77 commit b18dc38
Show file tree
Hide file tree
Showing 30 changed files with 83 additions and 118 deletions.
4 changes: 2 additions & 2 deletions src/AShortHike/Scenes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TempMaterialProgram extends UnityShaderProgramBase {
public override both = `
${UnityShaderProgramBase.Common}
layout(std140) uniform ub_MaterialParams {
layout(std140, row_major) uniform ub_MaterialParams {
vec4 u_Color;
vec4 u_MainTexST;
vec4 u_Misc[1];
Expand Down Expand Up @@ -108,7 +108,7 @@ class TerrainMaterialProgram extends UnityShaderProgramBase {
public override both = `
${UnityShaderProgramBase.Common}
layout(std140) uniform ub_MaterialParams {
layout(std140, row_major) uniform ub_MaterialParams {
vec4 u_Color;
vec4 u_TexST[6];
vec4 u_Misc[1];
Expand Down
2 changes: 1 addition & 1 deletion src/BanjoKazooie/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ layout(std140, row_major) uniform ub_DrawParams {
mat4x2 u_TexMatrix[2];
};
layout(std140) uniform ub_CombineParameters {
layout(std140, row_major) uniform ub_CombineParameters {
vec4 u_PrimColor;
vec4 u_EnvColor;
#ifdef EXTRA_COMBINE
Expand Down
2 changes: 1 addition & 1 deletion src/DarkSouls/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ class MaterialProgram_Base extends DeviceProgram {
public static BindingDefinitions = `
// Expected to be constant across the entire scene.
layout(std140, row_major) uniform ub_SceneParams {
mat4x4 u_ProjectionView;
mat4 u_ProjectionView;
vec4 u_CameraPosWorld; // DebugMode is in w
};
Expand Down
2 changes: 1 addition & 1 deletion src/Fez/Sky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SkyBackgroundProgram extends DeviceProgram {
public static ub_Params = 0;

public override both: string = `
layout(std140) uniform ub_Params {
layout(std140, row_major) uniform ub_Params {
vec4 u_ScaleOffset;
vec4 u_Misc[1];
};
Expand Down
2 changes: 1 addition & 1 deletion src/GrandTheftAuto3/program.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ precision mediump float;
precision lowp sampler2DArray;

layout(std140, row_major) uniform ub_SceneParams {
mat4x4 u_Projection;
mat4 u_Projection;
mat4x3 u_ViewMatrix;
mat4x3 u_WorldMatrix;
vec4 u_Frustum;
Expand Down
12 changes: 6 additions & 6 deletions src/Halo1/scenes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void mainVS() {

class ShaderTransparencyGenericProgram extends BaseProgram {
public static BindingsDefinition = `
layout(std140) uniform ub_ShaderParams {
layout(std140, row_major) uniform ub_ShaderParams {
Mat4x2 u_MapTransform0;
Mat4x2 u_MapTransform1;
Mat4x2 u_MapTransform2;
Expand Down Expand Up @@ -616,7 +616,7 @@ class MaterialRender_TransparencyGeneric {

class ShaderTransparencyChicagoProgram extends BaseProgram {
public static BindingsDefinition = `
layout(std140) uniform ub_ShaderParams {
layout(std140, row_major) uniform ub_ShaderParams {
Mat4x2 u_MapTransform0;
Mat4x2 u_MapTransform1;
Mat4x2 u_MapTransform2;
Expand Down Expand Up @@ -773,7 +773,7 @@ void mainPS() {

class ShaderTransparencyWaterProgram extends BaseProgram {
public static BindingsDefinition = `
layout(std140) uniform ub_ShaderParams {
layout(std140, row_major) uniform ub_ShaderParams {
Mat4x2 u_RippleTransform;
vec4 u_PerpendicularTint;
vec4 u_ParallelTint;
Expand Down Expand Up @@ -858,7 +858,7 @@ class RippleAnimation {

class ShaderCompositeRippleProgram extends DeviceProgram {
public static BindingsDefinition = `
layout(std140) uniform ub_ShaderParams {
layout(std140, row_major) uniform ub_ShaderParams {
Mat4x2 u_MapTransform0;
Mat4x2 u_MapTransform1;
Mat4x2 u_MapTransform2;
Expand Down Expand Up @@ -1136,7 +1136,7 @@ interface TextureAnimationFunction {

class ShaderModelProgram extends BaseProgram {
public static BindingsDefinition = `
layout(std140) uniform ub_ShaderParams {
layout(std140, row_major) uniform ub_ShaderParams {
Mat4x2 u_BaseMapTransform;
};
`;
Expand Down Expand Up @@ -1232,7 +1232,7 @@ varying vec3 v_IncidentLight;
`;

public static BindingsDefinition = `
layout(std140) uniform ub_ShaderParams {
layout(std140, row_major) uniform ub_ShaderParams {
vec4 u_ReflectionPerpendicularColor;
vec4 u_ReflectionParallelColor;
};
Expand Down
29 changes: 16 additions & 13 deletions src/HeavyIron/rw/pipelines/AtomicAllInOne.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DeviceProgram } from "../../../Program.js";
import { makeStaticDataBuffer } from "../../../gfx/helpers/BufferHelpers.js";
import { filterDegenerateTriangleIndexBuffer, convertToTriangleIndexBuffer, GfxTopology } from "../../../gfx/helpers/TopologyHelpers.js";
import { fillColor, fillMatrix4x4, fillVec3v, fillVec4 } from "../../../gfx/helpers/UniformBufferHelpers.js";
import { fillColor, fillMatrix4x3, fillMatrix4x4, fillVec3v, fillVec4 } from "../../../gfx/helpers/UniformBufferHelpers.js";
import { GfxIndexBufferDescriptor, GfxBindingLayoutDescriptor, GfxVertexBufferDescriptor, GfxBufferUsage, GfxVertexAttributeDescriptor, GfxInputLayoutBufferDescriptor, GfxVertexBufferFrequency, GfxMegaStateDescriptor, GfxCompareMode, GfxBlendFactor, GfxCullMode } from "../../../gfx/platform/GfxPlatform.js";
import { GfxFormat } from "../../../gfx/platform/GfxPlatformFormat.js";
import { GfxBuffer, GfxProgram, GfxInputLayout } from "../../../gfx/platform/GfxPlatformImpl.js";
Expand Down Expand Up @@ -45,10 +45,10 @@ struct DirectionalLight {
vec4 color;
};
layout(std140) uniform ub_AtomicParams {
Mat4x4 u_Projection;
Mat4x4 u_ViewMatrix;
Mat4x4 u_ModelMatrix;
layout(std140, row_major) uniform ub_AtomicParams {
mat4 u_Projection;
mat4x3 u_ViewMatrix;
mat4x3 u_ModelMatrix;
DirectionalLight u_DirectionalLights[MAX_DIRECTIONAL_LIGHTS];
vec4 u_AmbientColor;
vec4 u_FogColor;
Expand All @@ -63,7 +63,7 @@ layout(std140) uniform ub_AtomicParams {
#define u_EnablePrelit ((u_AtomicFlags & 0x1) != 0)
#define u_EnableLight ((u_AtomicFlags & 0x2) != 0)
layout(std140) uniform ub_MeshParams {
layout(std140, row_major) uniform ub_MeshParams {
vec4 u_MaterialColor;
vec4 u_MeshMisc;
};
Expand All @@ -82,18 +82,21 @@ varying float v_FogAmount;
`;

public override vert = `
${GfxShaderLibrary.invlerp}
${GfxShaderLibrary.saturate}
layout(location = ${AtomicProgram.a_Position}) in vec3 a_Position;
layout(location = ${AtomicProgram.a_Normal}) in vec3 a_Normal;
layout(location = ${AtomicProgram.a_Color}) in vec4 a_Color;
layout(location = ${AtomicProgram.a_TexCoord}) in vec2 a_TexCoord;
${GfxShaderLibrary.invlerp}
${GfxShaderLibrary.saturate}
${GfxShaderLibrary.MulNormalMatrix}
void main() {
gl_Position = Mul(u_Projection, Mul(u_ViewMatrix, Mul(u_ModelMatrix, vec4(a_Position, 1.0))));
vec3 t_PositionWorld = u_ModelMatrix * vec4(a_Position, 1.0);
vec3 t_PositionView = u_ViewMatrix * vec4(t_PositionWorld, 1.0);
gl_Position = u_Projection * vec4(t_PositionView, 1.0);
vec3 t_Normal = normalize(Mul(u_ModelMatrix, vec4(a_Normal, 0.0)).xyz);
vec3 t_Normal = MulNormalMatrix(u_ModelMatrix, a_Normal);
vec4 t_Color = u_EnablePrelit ? a_Color : (u_EnableLight ? vec4(0, 0, 0, 1) : vec4(1.0));
Expand Down Expand Up @@ -271,8 +274,8 @@ class InstanceData {
const mapped = template.mapUniformBufferF32(AtomicProgram.ub_AtomicParams);

offs += fillMatrix4x4(mapped, offs, rw.viewerInput.camera.projectionMatrix);
offs += fillMatrix4x4(mapped, offs, rw.camera.viewMatrix);
offs += fillMatrix4x4(mapped, offs, atomic.frame.matrix);
offs += fillMatrix4x3(mapped, offs, rw.camera.viewMatrix);
offs += fillMatrix4x3(mapped, offs, atomic.frame.matrix);

if (geom.flags & RpGeometryFlag.LIGHT) {
const ambientColor = scratchColor1;
Expand Down
2 changes: 1 addition & 1 deletion src/InteractiveExamples/FoxFur.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class FurProgram extends DeviceProgram {

public override both = `
layout(std140, row_major) uniform ub_ShapeParams {
mat4x4 u_Projection;
mat4 u_Projection;
mat4x3 u_BoneMatrix[1];
vec4 u_Misc[3];
vec4 u_TintColor;
Expand Down
2 changes: 1 addition & 1 deletion src/JetSetRadio/Render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class JSRProgram extends DeviceProgram {
precision mediump float;
// Expected to be constant across the entire scene.
layout(std140, row_major) uniform ub_SceneParams {
mat4x4 u_Projection;
mat4 u_Projection;
mat4x3 u_LightDirection;
};
layout(std140, row_major) uniform ub_ModelParams {
Expand Down
2 changes: 1 addition & 1 deletion src/KatamariDamacy/Gallery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GalleryCircleProgram extends DeviceProgram {
public static ub_Params = 0;

public override both: string = `
layout(std140) uniform ub_Params {
layout(std140, row_major) uniform ub_Params {
vec4 u_ColorInner;
vec4 u_ColorOuter;
vec4 u_ScaleOffset;
Expand Down
4 changes: 2 additions & 2 deletions src/MarioKartWii/PostEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class EggBloomBaseProgram extends DeviceProgram {
uniform sampler2D u_Texture;
uniform sampler2D u_Texture2;
layout(std140) uniform ub_Params {
layout(std140, row_major) uniform ub_Params {
vec4 u_ThresholdColor;
vec4 u_CompositeColor;
vec4 u_CompositeColorScale;
Expand Down Expand Up @@ -423,7 +423,7 @@ class EggDOFBaseProgram extends DeviceProgram {
uniform sampler2D u_Texture;
uniform sampler2D u_Texture2;
layout(std140) uniform ub_Params {
layout(std140, row_major) uniform ub_Params {
Mat4x2 u_IndTexMat;
vec4 u_Misc0;
};
Expand Down
2 changes: 1 addition & 1 deletion src/NeedForSpeedMostWanted/postprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void main() {

class NfsVisualTreatmentProgram extends DeviceProgram {
public override both = `
layout(std140) uniform ub_PostProcParams {
layout(std140, row_major) uniform ub_PostProcParams {
float ub_TintIntensity;
};
Expand Down
2 changes: 1 addition & 1 deletion src/NeonWhite/Scenes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TempMaterialProgram extends UnityShaderProgramBase {
public override both = `
${UnityShaderProgramBase.Common}
layout(std140) uniform ub_MaterialParams {
layout(std140, row_major) uniform ub_MaterialParams {
vec4 u_Color;
vec4 u_MainTexST;
vec4 u_Misc[1];
Expand Down
2 changes: 1 addition & 1 deletion src/PaperMario64/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class BackgroundBillboardProgram extends DeviceProgram {
public static ub_Params = 0;

public override both: string = `
layout(std140) uniform ub_Params {
layout(std140, row_major) uniform ub_Params {
vec4 u_ScaleOffset;
};
Expand Down
2 changes: 1 addition & 1 deletion src/PaperMarioTTYD/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BackgroundBillboardProgram extends DeviceProgram {
public static ub_Params = 0;

public override both: string = `
layout(std140) uniform ub_Params {
layout(std140, row_major) uniform ub_Params {
vec4 u_ScaleOffset;
};
Expand Down
2 changes: 1 addition & 1 deletion src/SourceEngine/LuminanceHistogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const scratchVec4 = vec4.create();

class LuminanceThreshProgram extends DeviceProgram {
public override both = `
layout(std140) uniform ub_Params {
layout(std140, row_major) uniform ub_Params {
vec4 u_Misc[2];
};
Expand Down
4 changes: 2 additions & 2 deletions src/SourceEngine/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ const bindingLayoutsBloom: GfxBindingLayoutDescriptor[] = [

class BloomDownsampleProgram extends DeviceProgram {
public override both = `
layout(std140) uniform ub_Params {
layout(std140, row_major) uniform ub_Params {
vec4 u_Misc[2];
};
Expand Down Expand Up @@ -1585,7 +1585,7 @@ void main() {

class BloomBlurProgram extends DeviceProgram {
public override both = `
layout(std140) uniform ub_Params {
layout(std140, row_major) uniform ub_Params {
vec4 u_Misc[2];
};
Expand Down
2 changes: 1 addition & 1 deletion src/SourceEngine/Materials/Material_Refract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ precision mediump float;
${MaterialShaderTemplateBase.Common}
layout(std140) uniform ub_ObjectParams {
layout(std140, row_major) uniform ub_ObjectParams {
vec4 u_BumpScaleBias;
vec4 u_RefractTint;
vec4 u_Misc[1];
Expand Down
2 changes: 1 addition & 1 deletion src/SourceEngine/Materials/Material_Sky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ precision mediump float;
${MaterialShaderTemplateBase.Common}
layout(std140) uniform ub_ObjectParams {
layout(std140, row_major) uniform ub_ObjectParams {
Mat4x2 u_BaseTextureTransform;
vec4 u_ColorScale;
};
Expand Down
2 changes: 1 addition & 1 deletion src/SourceEngine/Materials/Material_SpriteCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ precision mediump float;
${MaterialShaderTemplateBase.Common}
// In the future, we should use vertex data for some of this...
layout(std140) uniform ub_ObjectParams {
layout(std140, row_major) uniform ub_ObjectParams {
vec4 u_BaseTextureScaleBias[5]; // Two animation frames, dual
vec4 u_Color;
vec4 u_Misc[1];
Expand Down
33 changes: 18 additions & 15 deletions src/SpongebobRevengeOfTheFlyingDutchman/program.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ struct OmniLight {
};

struct HFog {
Mat4x4 transform;
mat4 transform;
vec4 color;
};

#define NUM_OMNI_LIGHTS 4

layout(std140) uniform ub_SceneParams {
Mat4x4 u_Projection;
layout(std140, row_major) uniform ub_SceneParams {
mat4 u_Projection;
};

layout(std140) uniform ub_MaterialParams {
Mat4x3 u_ModelView;
Mat4x3 u_View;
layout(std140, row_major) uniform ub_MaterialParams {
mat4x3 u_Model;
mat4x3 u_ModelView;
vec4 u_Color;
vec4 u_Emit;
Mat4x2 u_TexTransform;
mat4x2 u_TexTransform;
};

layout(std140) uniform ub_InstanceParams {
layout(std140, row_major) uniform ub_InstanceParams {
DirectionalLight u_light;
HFog u_hFog;
OmniLight u_omni[NUM_OMNI_LIGHTS];
Expand All @@ -39,7 +39,7 @@ uniform sampler2D u_Texture;
uniform sampler2D u_TextureReflection;

varying vec2 v_TexCoord;
varying vec4 v_WorldPosition;
varying vec3 v_WorldPosition;
varying vec3 v_LightColor;
varying vec3 v_ClipNormal;

Expand All @@ -49,11 +49,14 @@ layout(location = 1) in vec2 a_TexCoord;
layout(location = 2) in vec3 a_Normal;

void main() {
v_WorldPosition = Mul(_Mat4x4(u_ModelView), vec4(a_Position, 1.0));
gl_Position = Mul(u_Projection, Mul(_Mat4x4(u_View), vec4(a_Position, 1.0)));
v_TexCoord = Mul(_Mat4x4(u_TexTransform), vec4(a_TexCoord.xy, 1.0, 1.0)).xy;
vec3 worldNormal = normalize(Mul(_Mat4x4(u_ModelView), vec4(a_Normal, 0.0)).xyz);
v_ClipNormal = normalize(Mul(_Mat4x4(u_View), vec4(worldNormal, 0.0)).xyz);
v_WorldPosition = u_Model * vec4(a_Position, 1.0);
vec3 t_PositionView = u_ModelView * vec4(a_Position, 1.0);
gl_Position = u_Projection * vec4(t_PositionView, 1.0);

v_TexCoord = u_TexTransform * vec4(a_TexCoord.xy, 1.0, 1.0);
vec3 worldNormal = normalize(u_Model * vec4(a_Normal, 0.0));
v_ClipNormal = u_ModelView * vec4(a_Normal, 0.0);

// AMBIENT
v_LightColor = u_light.ambient;
// DIFFUSE
Expand Down Expand Up @@ -88,7 +91,7 @@ void main() {
gl_FragColor = vec4(surfacecol * v_LightColor + reflectionColor.rgb, alpha);
// FOG
if (u_hFog.color.a > 0.0) {
vec4 fogPos = Mul(u_hFog.transform, v_WorldPosition);
vec4 fogPos = u_hFog.transform * vec4(v_WorldPosition, 1.0);
float fogAmount = clamp(1.0 - fogPos.y, 0.0, 1.0);
gl_FragColor.rgb = mix(gl_FragColor.rgb, u_hFog.color.rgb, fogAmount * u_hFog.color.a);
}
Expand Down
2 changes: 1 addition & 1 deletion src/StarFoxAdventures/blur.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { fillVec4 } from "../gfx/helpers/UniformBufferHelpers.js";
const BindingsDefinition = `
uniform sampler2D u_Texture;
layout(std140) uniform ub_Params {
layout(std140, row_major) uniform ub_Params {
vec4 u_Misc[1];
};
#define u_HalfTexel (u_Misc[0].xy)
Expand Down
Loading

0 comments on commit b18dc38

Please sign in to comment.