diff --git a/src/AShortHike/Scenes.ts b/src/AShortHike/Scenes.ts index d249d12b0..c5baa0760 100644 --- a/src/AShortHike/Scenes.ts +++ b/src/AShortHike/Scenes.ts @@ -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]; @@ -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]; diff --git a/src/BanjoKazooie/render.ts b/src/BanjoKazooie/render.ts index 2550fbc38..d56b90891 100644 --- a/src/BanjoKazooie/render.ts +++ b/src/BanjoKazooie/render.ts @@ -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 diff --git a/src/DarkSouls/render.ts b/src/DarkSouls/render.ts index 0966ff2a3..c7a08a713 100644 --- a/src/DarkSouls/render.ts +++ b/src/DarkSouls/render.ts @@ -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 }; diff --git a/src/Fez/Sky.ts b/src/Fez/Sky.ts index e0424d18f..24315bd19 100644 --- a/src/Fez/Sky.ts +++ b/src/Fez/Sky.ts @@ -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]; }; diff --git a/src/GrandTheftAuto3/program.glsl b/src/GrandTheftAuto3/program.glsl index bcd3b3197..61333429c 100644 --- a/src/GrandTheftAuto3/program.glsl +++ b/src/GrandTheftAuto3/program.glsl @@ -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; diff --git a/src/Halo1/scenes.ts b/src/Halo1/scenes.ts index 91594b18b..6de9c9a82 100644 --- a/src/Halo1/scenes.ts +++ b/src/Halo1/scenes.ts @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; }; `; @@ -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; }; diff --git a/src/HeavyIron/rw/pipelines/AtomicAllInOne.ts b/src/HeavyIron/rw/pipelines/AtomicAllInOne.ts index 8515d876e..502431518 100644 --- a/src/HeavyIron/rw/pipelines/AtomicAllInOne.ts +++ b/src/HeavyIron/rw/pipelines/AtomicAllInOne.ts @@ -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"; @@ -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; @@ -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; }; @@ -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)); @@ -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; diff --git a/src/InteractiveExamples/FoxFur.ts b/src/InteractiveExamples/FoxFur.ts index c40dbeafb..14e4700be 100644 --- a/src/InteractiveExamples/FoxFur.ts +++ b/src/InteractiveExamples/FoxFur.ts @@ -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; diff --git a/src/JetSetRadio/Render.ts b/src/JetSetRadio/Render.ts index 7876f05d3..7e1438580 100644 --- a/src/JetSetRadio/Render.ts +++ b/src/JetSetRadio/Render.ts @@ -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 { diff --git a/src/KatamariDamacy/Gallery.ts b/src/KatamariDamacy/Gallery.ts index 6b855bac0..7a1aa9e24 100644 --- a/src/KatamariDamacy/Gallery.ts +++ b/src/KatamariDamacy/Gallery.ts @@ -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; diff --git a/src/MarioKartWii/PostEffect.ts b/src/MarioKartWii/PostEffect.ts index 3c5819ce4..00d0a634d 100644 --- a/src/MarioKartWii/PostEffect.ts +++ b/src/MarioKartWii/PostEffect.ts @@ -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; @@ -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; }; diff --git a/src/NeedForSpeedMostWanted/postprocess.ts b/src/NeedForSpeedMostWanted/postprocess.ts index ddd13cb8c..b03b21863 100644 --- a/src/NeedForSpeedMostWanted/postprocess.ts +++ b/src/NeedForSpeedMostWanted/postprocess.ts @@ -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; }; diff --git a/src/NeonWhite/Scenes.ts b/src/NeonWhite/Scenes.ts index 990ea2258..43134b83b 100644 --- a/src/NeonWhite/Scenes.ts +++ b/src/NeonWhite/Scenes.ts @@ -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]; diff --git a/src/PaperMario64/render.ts b/src/PaperMario64/render.ts index 611fd802f..d16912b03 100644 --- a/src/PaperMario64/render.ts +++ b/src/PaperMario64/render.ts @@ -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; }; diff --git a/src/PaperMarioTTYD/render.ts b/src/PaperMarioTTYD/render.ts index 7fd86919c..c201fb9d2 100644 --- a/src/PaperMarioTTYD/render.ts +++ b/src/PaperMarioTTYD/render.ts @@ -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; }; diff --git a/src/SourceEngine/LuminanceHistogram.ts b/src/SourceEngine/LuminanceHistogram.ts index 02f9ba5c1..43515dc58 100644 --- a/src/SourceEngine/LuminanceHistogram.ts +++ b/src/SourceEngine/LuminanceHistogram.ts @@ -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]; }; diff --git a/src/SourceEngine/Main.ts b/src/SourceEngine/Main.ts index facc0bc5f..63b2ec6a2 100644 --- a/src/SourceEngine/Main.ts +++ b/src/SourceEngine/Main.ts @@ -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]; }; @@ -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]; }; diff --git a/src/SourceEngine/Materials/Material_Refract.ts b/src/SourceEngine/Materials/Material_Refract.ts index 007f2bf9b..061c3de1d 100644 --- a/src/SourceEngine/Materials/Material_Refract.ts +++ b/src/SourceEngine/Materials/Material_Refract.ts @@ -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]; diff --git a/src/SourceEngine/Materials/Material_Sky.ts b/src/SourceEngine/Materials/Material_Sky.ts index 59a6e0a21..d7116315f 100644 --- a/src/SourceEngine/Materials/Material_Sky.ts +++ b/src/SourceEngine/Materials/Material_Sky.ts @@ -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; }; diff --git a/src/SourceEngine/Materials/Material_SpriteCard.ts b/src/SourceEngine/Materials/Material_SpriteCard.ts index 7f38dd00f..2e390b924 100644 --- a/src/SourceEngine/Materials/Material_SpriteCard.ts +++ b/src/SourceEngine/Materials/Material_SpriteCard.ts @@ -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]; diff --git a/src/SpongebobRevengeOfTheFlyingDutchman/program.glsl b/src/SpongebobRevengeOfTheFlyingDutchman/program.glsl index 3ac9b9bba..1ca604842 100644 --- a/src/SpongebobRevengeOfTheFlyingDutchman/program.glsl +++ b/src/SpongebobRevengeOfTheFlyingDutchman/program.glsl @@ -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]; @@ -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; @@ -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 @@ -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); } diff --git a/src/StarFoxAdventures/blur.ts b/src/StarFoxAdventures/blur.ts index fd7feab35..956a04b2f 100644 --- a/src/StarFoxAdventures/blur.ts +++ b/src/StarFoxAdventures/blur.ts @@ -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) diff --git a/src/SuperMarioGalaxy/ClipArea.ts b/src/SuperMarioGalaxy/ClipArea.ts index e254d75f9..7f5083df3 100644 --- a/src/SuperMarioGalaxy/ClipArea.ts +++ b/src/SuperMarioGalaxy/ClipArea.ts @@ -518,7 +518,7 @@ class FullscreenBlitProgram extends DeviceProgram { const bindingLayouts: GfxBindingLayoutDescriptor[] = [{ numUniformBuffers: 1, numSamplers: 1 }]; const fallOutFieldDrawCommon = ` -layout(std140) uniform ub_Params { +layout(std140, row_major) uniform ub_Params { vec4 u_EdgeColor; vec4 u_Misc[1]; }; diff --git a/src/SuperMarioGalaxy/ImageEffect.ts b/src/SuperMarioGalaxy/ImageEffect.ts index 857dc7bec..9ab3d5d81 100644 --- a/src/SuperMarioGalaxy/ImageEffect.ts +++ b/src/SuperMarioGalaxy/ImageEffect.ts @@ -104,7 +104,7 @@ class BloomPassBaseProgram extends DeviceProgram { uniform sampler2D u_Texture; uniform sampler2D u_Texture2; -layout(std140) uniform ub_Params { +layout(std140, row_major) uniform ub_Params { vec4 u_Misc[1]; }; #define u_BloomIntensity (u_Misc[0].x) @@ -389,7 +389,7 @@ uniform sampler2D u_Texture; uniform sampler2D u_Texture2; in vec2 v_TexCoord; -layout(std140) uniform ub_Params { +layout(std140, row_major) uniform ub_Params { vec4 u_Misc[1]; }; #define u_MaskFilter (u_Misc[0].x) @@ -556,7 +556,7 @@ class DepthOfFieldProgram extends DeviceProgram { uniform sampler2D u_TextureColor; uniform sampler2D u_TextureFramebufferDepth; -layout(std140) uniform ub_Params { +layout(std140, row_major) uniform ub_Params { vec4 u_Misc[1]; }; #define u_Intensity (u_Misc[0].x) diff --git a/src/TheWitness/Render.ts b/src/TheWitness/Render.ts index d80f8c70e..7845224e6 100644 --- a/src/TheWitness/Render.ts +++ b/src/TheWitness/Render.ts @@ -77,8 +77,8 @@ class TheWitnessShaderTemplate extends UberShaderTemplate { return ` precision mediump float; -layout(std140) uniform ub_SceneParams { - Mat4x4 u_ViewProjection; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_ViewProjection; vec4 u_CameraPosWorld; vec4 u_KeyLightDir; vec4 u_KeyLightColor; @@ -91,8 +91,8 @@ layout(std140) uniform ub_SceneParams { #define u_WindDirection (vec3(u_CameraPosWorld.w, u_KeyLightDir.w, 0.0)) #define u_SceneTime (u_KeyLightColor.w) -layout(std140) uniform ub_ObjectParams { - Mat4x3 u_ModelMatrix; +layout(std140, row_major) uniform ub_ObjectParams { + mat4x3 u_ModelMatrix; vec4 u_MaterialColorAndEmission; vec4 u_FoliageParams; vec4 u_SpecularParams; @@ -128,6 +128,7 @@ uniform sampler2D u_TerrainColor; ${GfxShaderLibrary.saturate} ${GfxShaderLibrary.CalcScaleBias} +${GfxShaderLibrary.MulNormalMatrix} vec3 UnpackNormalMap(in vec4 t_NormalMapSample) { vec3 t_Normal; @@ -224,9 +225,9 @@ void mainVS() { t_PositionLocal += (t_NormalLocal * t_ShellExtrude); } - v_PositionWorld = Mul(_Mat4x4(u_ModelMatrix), vec4(t_PositionLocal, 1.0)).xyz; + v_PositionWorld = u_ModelMatrix * vec4(t_PositionLocal, 1.0); - vec3 t_NormalWorld = Mul(_Mat4x4(u_ModelMatrix), vec4(t_NormalLocal, 0.0)).xyz; + vec3 t_NormalWorld = MulNormalMatrix(u_ModelMatrix, t_NormalLocal); vec3 t_TangentSWorld = a_TangentS.xyz; vec3 t_TangentTWorld = cross(t_NormalWorld, t_TangentSWorld); @@ -237,7 +238,7 @@ void mainVS() { CalcTrunkWind(v_PositionWorld, a_Color0, t_ObjectPos); } - gl_Position = Mul(u_ViewProjection, vec4(v_PositionWorld, 1.0)); + gl_Position = u_ViewProjection * vec4(v_PositionWorld, 1.0); v_TexCoord0 = a_TexCoord0.xy; bool use_scroll_speed = ${this.is_type(m, Material_Type.Refract) || this.is_type(m, Material_Type.Decal)}; diff --git a/src/WorldOfWarcraft/program.ts b/src/WorldOfWarcraft/program.ts index 464607d8e..6ea6565de 100644 --- a/src/WorldOfWarcraft/program.ts +++ b/src/WorldOfWarcraft/program.ts @@ -304,7 +304,7 @@ layout(std140, row_major) uniform ub_ModelParams { mat4x3 u_Transform; }; -layout(std140) uniform ub_BatchParams { +layout(std140, row_major) uniform ub_BatchParams { vec4 shaderParams; // vertexShader, pixelShader, numColorBufs, _ vec4 materialParams; // blendMode, applyInteriorLight, applyExteriorLight, unlit vec4 moreMaterialParams; // unfogged, exterior_light, sidn, window @@ -1304,7 +1304,7 @@ struct DoodadInstance { mat4x3 transform; }; -layout(std140) uniform ub_EmitterParams { +layout(std140, row_major) uniform ub_EmitterParams { vec4 params; // alphaTest, fragShaderType, blendMode vec4 ub_texScale; // x, y, _, _ }; diff --git a/src/ZeldaTwilightPrincess/d_kankyo_wether.ts b/src/ZeldaTwilightPrincess/d_kankyo_wether.ts index 311f8339e..8dea5f8a7 100644 --- a/src/ZeldaTwilightPrincess/d_kankyo_wether.ts +++ b/src/ZeldaTwilightPrincess/d_kankyo_wether.ts @@ -2236,7 +2236,7 @@ class BloomPassBaseProgram extends DeviceProgram { public static BindingsDefinition = ` uniform sampler2D u_Texture; -layout(std140) uniform ub_Params { +layout(std140, row_major) uniform ub_Params { vec4 u_MonoColor; vec4 u_BlendColor; vec4 u_Misc[1]; diff --git a/src/fres_nx/render.ts b/src/fres_nx/render.ts index d8b623ba2..237aebc75 100644 --- a/src/fres_nx/render.ts +++ b/src/fres_nx/render.ts @@ -147,9 +147,9 @@ class AglProgram extends DeviceProgram { public static globalDefinitions = ` precision mediump float; -layout(std140) uniform ub_ShapeParams { - Mat4x4 u_Projection; - Mat4x3 u_ModelView; +layout(std140, row_major) uniform ub_ShapeParams { + mat4 u_Projection; + mat4x3 u_ModelView; }; uniform sampler2D u_Samplers[8]; @@ -289,7 +289,8 @@ out vec4 v_NormalWorld; out vec4 v_TangentWorld; void main() { - gl_Position = Mul(u_Projection, Mul(_Mat4x4(u_ModelView), vec4(_p0, 1.0))); + vec3 t_PositionView = u_ModelView * vec4(_p0, 1.0); + gl_Position = u_Projection * vec4(t_PositionView, 1.0); v_PositionWorld = _p0.xyz; v_TexCoord0 = _u0; v_VtxColor = _c0; diff --git a/src/gfx/helpers/GfxShaderLibrary.ts b/src/gfx/helpers/GfxShaderLibrary.ts index 04f1bd6ef..88c10f852 100644 --- a/src/gfx/helpers/GfxShaderLibrary.ts +++ b/src/gfx/helpers/GfxShaderLibrary.ts @@ -3,40 +3,6 @@ export namespace GfxShaderLibrary { -// Matrix library. Automatically included into every shader by default for convenience reasons. -export const mat4 = ` -struct Mat4x4 { vec4 mx; vec4 my; vec4 mz; vec4 mw; }; -struct Mat4x3 { vec4 mx; vec4 my; vec4 mz; }; -struct Mat4x2 { vec4 mx; vec4 my; }; - -vec3 Mat4x3GetCol0(Mat4x3 m) { return vec3(m.mx.x, m.my.x, m.mz.x); } -vec3 Mat4x3GetCol1(Mat4x3 m) { return vec3(m.mx.y, m.my.y, m.mz.y); } -vec3 Mat4x3GetCol2(Mat4x3 m) { return vec3(m.mx.z, m.my.z, m.mz.z); } -vec3 Mat4x3GetCol3(Mat4x3 m) { return vec3(m.mx.w, m.my.w, m.mz.w); } - -vec4 Mul(Mat4x4 m, vec4 v) { return vec4(dot(m.mx, v), dot(m.my, v), dot(m.mz, v), dot(m.mw, v)); } -vec3 Mul(Mat4x3 m, vec4 v) { return vec3(dot(m.mx, v), dot(m.my, v), dot(m.mz, v)); } -vec2 Mul(Mat4x2 m, vec4 v) { return vec2(dot(m.mx, v), dot(m.my, v)); } - -vec4 Mul(vec3 v, Mat4x3 m) { -return vec4( - dot(Mat4x3GetCol0(m), v), - dot(Mat4x3GetCol1(m), v), - dot(Mat4x3GetCol2(m), v), - dot(Mat4x3GetCol3(m), v) -); -} - -void Fma(inout Mat4x3 d, Mat4x3 m, float s) { d.mx += m.mx * s; d.my += m.my * s; d.mz += m.mz * s; } - -Mat4x4 _Mat4x4(float n) { Mat4x4 o; o.mx = vec4(n, 0.0, 0.0, 0.0); o.my = vec4(0.0, n, 0.0, 0.0); o.mz = vec4(0.0, 0.0, n, 0.0); o.mw = vec4(0.0, 0.0, 0.0, n); return o; } -Mat4x4 _Mat4x4(Mat4x3 m) { Mat4x4 o = _Mat4x4(1.0); o.mx = m.mx; o.my = m.my; o.mz = m.mz; return o; } -Mat4x4 _Mat4x4(Mat4x2 m) { Mat4x4 o = _Mat4x4(1.0); o.mx = m.mx; o.my = m.my; return o; } - -Mat4x3 _Mat4x3(float n) { Mat4x3 o; o.mx = vec4(n, 0.0, 0.0, 0.0); o.my = vec4(0.0, n, 0.0, 0.0); o.mz = vec4(0.0, 0.0, n, 0.0); return o; } -Mat4x3 _Mat4x3(Mat4x4 m) { Mat4x3 o; o.mx = m.mx; o.my = m.my; o.mz = m.mz; return o; } -`; - // Helper math utility export const saturate: string = ` float saturate(float v) { return clamp(v, 0.0, 1.0); } @@ -50,16 +16,8 @@ float invlerp(float a, float b, float v) { return (v - a) / (b - a); } `; export const MulNormalMatrix: string = ` -vec3 MulNormalMatrix(Mat4x3 t_Matrix, vec3 t_Value) { - // Pull out the squared scaling. - vec3 t_Col0 = Mat4x3GetCol0(t_Matrix); - vec3 t_Col1 = Mat4x3GetCol1(t_Matrix); - vec3 t_Col2 = Mat4x3GetCol2(t_Matrix); - vec3 t_SqScale = vec3(dot(t_Col0, t_Col0), dot(t_Col1, t_Col1), dot(t_Col2, t_Col2)); - return normalize(Mul(t_Matrix, vec4(t_Value / t_SqScale, 0.0))); -} - vec3 MulNormalMatrix(mat4x3 t_Matrix, vec3 t_Value) { + // Pull out the squared scaling. vec3 t_SqScale = vec3(dot(t_Matrix[0], t_Matrix[0]), dot(t_Matrix[1], t_Matrix[1]), dot(t_Matrix[2], t_Matrix[2])); return normalize(t_Matrix * vec4(t_Value / t_SqScale, 0.0)); } diff --git a/src/gfx/shaderc/GfxShaderCompiler.ts b/src/gfx/shaderc/GfxShaderCompiler.ts index 328909422..15ba76a16 100644 --- a/src/gfx/shaderc/GfxShaderCompiler.ts +++ b/src/gfx/shaderc/GfxShaderCompiler.ts @@ -161,7 +161,6 @@ ${hasFragColor ? ` #define gl_FragColor o_color ${type === 'frag' ? `layout(location = 0) out vec4 o_color;` : ''} ` : ``} -${GfxShaderLibrary.mat4} ${definesString} ${rest} `.trim();