diff --git a/src/SourceEngine/Materials/MaterialBase.ts b/src/SourceEngine/Materials/MaterialBase.ts index a53e8420c..f62df4c97 100644 --- a/src/SourceEngine/Materials/MaterialBase.ts +++ b/src/SourceEngine/Materials/MaterialBase.ts @@ -122,16 +122,16 @@ export class MaterialShaderTemplateBase extends UberShaderTemplateBasic { // #define DEBUG_DIFFUSEONLY 1 // #define DEBUG_FULLBRIGHT 1 -layout(std140) uniform ub_SceneParams { - Mat4x4 u_ProjectionView; +layout(std140, row_major) uniform ub_SceneParams { + mat4 u_ProjectionView; vec4 u_SceneMisc[3]; }; -layout(std140) uniform ub_SkinningParams { +layout(std140, row_major) uniform ub_SkinningParams { #if SKINNING_MODE == ${SkinningMode.Smooth} - Mat4x3 u_BoneMatrix[${MaterialShaderTemplateBase.MaxSkinningParamsBoneMatrix}]; + mat4x3 u_BoneMatrix[${MaterialShaderTemplateBase.MaxSkinningParamsBoneMatrix}]; #else - Mat4x3 u_ModelMatrix; + mat4x3 u_ModelMatrix; #endif }; @@ -247,15 +247,15 @@ layout(location = ${MaterialShaderTemplateBase.a_BoneWeights}) in vec4 a_BoneWei layout(location = ${MaterialShaderTemplateBase.a_BoneIDs}) in vec4 a_BoneIndices; #endif -Mat4x3 CalcWorldFromLocalMatrix() { +mat4x3 CalcWorldFromLocalMatrix() { #if SKINNING_MODE == ${SkinningMode.Smooth} // Calculate our per-vertex position. - Mat4x3 t_WorldFromLocalMatrix = _Mat4x3(0.0); + mat4x3 t_WorldFromLocalMatrix = mat4x3(0.0); - Fma(t_WorldFromLocalMatrix, u_BoneMatrix[int(a_BoneIndices.x)], a_BoneWeights.x); - Fma(t_WorldFromLocalMatrix, u_BoneMatrix[int(a_BoneIndices.y)], a_BoneWeights.y); - Fma(t_WorldFromLocalMatrix, u_BoneMatrix[int(a_BoneIndices.z)], a_BoneWeights.z); - Fma(t_WorldFromLocalMatrix, u_BoneMatrix[int(a_BoneIndices.w)], a_BoneWeights.w); + t_WorldFromLocalMatrix += u_BoneMatrix[int(a_BoneIndices.x)] * a_BoneWeights.x; + t_WorldFromLocalMatrix += u_BoneMatrix[int(a_BoneIndices.y)] * a_BoneWeights.y; + t_WorldFromLocalMatrix += u_BoneMatrix[int(a_BoneIndices.z)] * a_BoneWeights.z; + t_WorldFromLocalMatrix += u_BoneMatrix[int(a_BoneIndices.w)] * a_BoneWeights.w; return t_WorldFromLocalMatrix; #else diff --git a/src/SourceEngine/Materials/Material_Eyes.ts b/src/SourceEngine/Materials/Material_Eyes.ts index ea579a22d..d036849ff 100644 --- a/src/SourceEngine/Materials/Material_Eyes.ts +++ b/src/SourceEngine/Materials/Material_Eyes.ts @@ -19,9 +19,9 @@ precision mediump float; ${MaterialShaderTemplateBase.Common} -layout(std140) uniform ub_ObjectParams { - Mat4x2 u_BaseTransform; - Mat4x2 u_IrisTransform; +layout(std140, row_major) uniform ub_ObjectParams { + mat4x2 u_BaseTransform; + mat4x2 u_IrisTransform; }; varying vec3 v_PositionWorld; @@ -34,13 +34,13 @@ uniform sampler2D u_TextureIris; #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); v_PositionWorld.xyz = t_PositionWorld; - gl_Position = Mul(u_ProjectionView, vec4(t_PositionWorld, 1.0)); + gl_Position = u_ProjectionView * vec4(t_PositionWorld, 1.0); - v_TexCoord0.xy = Mul(u_BaseTransform, vec4(a_TexCoord01.xy, 1.0, 1.0)); - v_TexCoord0.zw = Mul(u_IrisTransform, vec4(t_PositionWorld, 1.0)); + v_TexCoord0.xy = u_BaseTransform * vec4(a_TexCoord01.xy, 1.0, 1.0); + v_TexCoord0.zw = u_IrisTransform * vec4(t_PositionWorld, 1.0); // XXX(jstpierre): Move lighting into common helpers v_Lighting.rgb = vec3(1.0); diff --git a/src/SourceEngine/Materials/Material_Generic.ts b/src/SourceEngine/Materials/Material_Generic.ts index ee696b4bf..6448befe2 100644 --- a/src/SourceEngine/Materials/Material_Generic.ts +++ b/src/SourceEngine/Materials/Material_Generic.ts @@ -42,7 +42,7 @@ struct WorldLight { vec4 Direction; }; -layout(std140) uniform ub_ObjectParams { +layout(std140, row_major) uniform ub_ObjectParams { #if defined USE_AMBIENT_CUBE // TODO(jstpierre): Pack this more efficiently? vec4 u_AmbientCube[6]; @@ -51,15 +51,15 @@ layout(std140) uniform ub_ObjectParams { // We support up to N lights. WorldLight u_WorldLights[${ShaderTemplate_Generic.MaxDynamicWorldLights}]; #endif - Mat4x2 u_BaseTextureTransform; + mat4x2 u_BaseTextureTransform; #if defined USE_BUMPMAP - Mat4x2 u_BumpmapTransform; + mat4x2 u_BumpmapTransform; #endif #if defined USE_BUMPMAP2 - Mat4x2 u_Bumpmap2Transform; + mat4x2 u_Bumpmap2Transform; #endif #if defined USE_DETAIL - Mat4x2 u_DetailTextureTransform; + mat4x2 u_DetailTextureTransform; #endif #if defined USE_ENVMAP_MASK vec4 u_EnvmapMaskScaleBias; @@ -82,7 +82,7 @@ layout(std140) uniform ub_ObjectParams { vec4 u_SpecTintBoost; #endif #if defined USE_PROJECTED_LIGHT - Mat4x4 u_ProjectedLightFromWorldMatrix; + mat4 u_ProjectedLightFromWorldMatrix; vec4 u_ProjectedLightColor; vec4 u_ProjectedLightOrigin; #endif @@ -274,13 +274,13 @@ vec3 AmbientLight(in vec3 t_NormalWorld) { void CalcTreeSway(inout vec3 t_PositionLocal) { #if defined VERT && defined USE_TREE_SWAY - Mat4x3 t_WorldFromLocalMatrix = CalcWorldFromLocalMatrix(); + mat4x3 t_WorldFromLocalMatrix = CalcWorldFromLocalMatrix(); float t_WindIntensity = length(u_TreeSwayWindDir); - vec3 t_WindDirLocal = Mul(vec3(u_TreeSwayWindDir, 0.0), t_WorldFromLocalMatrix).xyz; + vec3 t_WindDirLocal = (vec3(u_TreeSwayWindDir, 0.0) * t_WorldFromLocalMatrix).xyz; vec3 t_PosOffs = vec3(0.0); - vec3 t_OriginWorld = Mul(t_WorldFromLocalMatrix, vec4(0.0, 0.0, 0.0, 1.0)); + vec3 t_OriginWorld = t_WorldFromLocalMatrix * vec4(0.0, 0.0, 0.0, 1.0); float t_TimeOffset = dot(t_OriginWorld, vec3(1.0)) * 19.0; float t_SwayTime = (u_TreeSwayTime + t_TimeOffset) * u_TreeSwaySpeed; @@ -314,12 +314,12 @@ void mainVS() { vec3 t_PositionLocal = a_Position; CalcTreeSway(t_PositionLocal); - Mat4x3 t_WorldFromLocalMatrix = CalcWorldFromLocalMatrix(); - vec3 t_PositionWorld = Mul(t_WorldFromLocalMatrix, vec4(t_PositionLocal, 1.0)); + mat4x3 t_WorldFromLocalMatrix = CalcWorldFromLocalMatrix(); + vec3 t_PositionWorld = t_WorldFromLocalMatrix * vec4(t_PositionLocal, 1.0); v_PositionWorld.xyz = t_PositionWorld; - gl_Position = Mul(u_ProjectionView, vec4(t_PositionWorld, 1.0)); + gl_Position = u_ProjectionView * vec4(t_PositionWorld, 1.0); - vec3 t_NormalWorld = normalize(Mul(t_WorldFromLocalMatrix, vec4(a_Normal.xyz, 0.0))); + vec3 t_NormalWorld = normalize(t_WorldFromLocalMatrix * vec4(a_Normal.xyz, 0.0)); #if defined USE_VERTEX_COLOR v_Color = a_Color; @@ -382,7 +382,7 @@ void mainVS() { #endif #if defined HAS_FULL_TANGENTSPACE - vec3 t_TangentSWorld = normalize(Mul(t_WorldFromLocalMatrix, vec4(a_TangentS.xyz, 0.0))); + vec3 t_TangentSWorld = normalize(t_WorldFromLocalMatrix * vec4(a_TangentS.xyz, 0.0)); vec3 t_TangentTWorld = cross(t_TangentSWorld, t_NormalWorld); v_TangentSpaceBasis0 = t_TangentSWorld * a_TangentS.w; @@ -390,7 +390,7 @@ void mainVS() { #endif v_TangentSpaceBasis2 = t_NormalWorld; - v_TexCoord0.xy = Mul(u_BaseTextureTransform, vec4(a_TexCoord01.xy, 1.0, 1.0)); + v_TexCoord0.xy = u_BaseTextureTransform * vec4(a_TexCoord01.xy, 1.0, 1.0); v_TexCoord0.zw = a_TexCoord01.xy; #if defined USE_LIGHTMAP || defined USE_DECAL v_TexCoord1.xy = a_TexCoord01.zw; @@ -656,10 +656,10 @@ void mainPS() { #if defined USE_DETAIL bool use_seamless_detail = ${MaterialUtil.getDefineBool(m, `USE_SEAMLESS_DETAIL`)}; if (use_seamless_detail) { - float t_SeamlessDetailScale = u_DetailTextureTransform.mx.x; + float t_SeamlessDetailScale = u_DetailTextureTransform[0][0]; t_DetailTexture = DebugColorTexture(SeamlessSampleTex(PP_SAMPLER_2D(u_TextureDetail), t_SeamlessDetailScale)); } else { - vec2 t_DetailTexCoord = Mul(u_DetailTextureTransform, vec4(v_TexCoord0.zw, 1.0, 1.0)); + vec2 t_DetailTexCoord = u_DetailTextureTransform * vec4(v_TexCoord0.zw, 1.0, 1.0); t_DetailTexture = DebugColorTexture(texture(SAMPLER_2D(u_TextureDetail), t_DetailTexCoord)); } t_Albedo = CalcDetail(t_Albedo, t_DetailTexture); @@ -674,7 +674,7 @@ void mainPS() { bool use_ssbump = ${MaterialUtil.getDefineBool(m, `USE_SSBUMP`)}; // TODO(jstpierre): It seems like $bumptransform might not even be respected in lightmappedgeneric shaders? - vec2 t_BumpmapTexCoord = ${MaterialUtil.ifDefineBool(m, `USE_BUMPMAP`, `Mul(u_BumpmapTransform, vec4(v_TexCoord0.zw, 1.0, 1.0))`, `vec2(0.0)`)}; + vec2 t_BumpmapTexCoord = ${MaterialUtil.ifDefineBool(m, `USE_BUMPMAP`, `u_BumpmapTransform * vec4(v_TexCoord0.zw, 1.0, 1.0)`, `vec2(0.0)`)}; vec4 t_BumpmapSample = vec4(0.0); vec3 t_BumpmapNormal; @@ -683,7 +683,7 @@ void mainPS() { bool use_bumpmap2 = ${MaterialUtil.getDefineBool(m, `USE_BUMPMAP2`)}; if (use_bumpmap2) { - vec2 t_Bumpmap2TexCoord = ${MaterialUtil.ifDefineBool(m, `USE_BUMPMAP2`, `Mul(u_Bumpmap2Transform, vec4(v_TexCoord0.zw, 1.0, 1.0))`, `vec2(0.0)`)}; + vec2 t_Bumpmap2TexCoord = ${MaterialUtil.ifDefineBool(m, `USE_BUMPMAP2`, `u_Bumpmap2Transform * vec4(v_TexCoord0.zw, 1.0, 1.0)`, `vec2(0.0)`)}; vec4 t_Bumpmap2Sample = UnpackNormalMap(texture(SAMPLER_2D(u_TextureBumpmap2), t_Bumpmap2TexCoord)); bool use_bumpmask = ${MaterialUtil.getDefineBool(m, `USE_BUMPMASK`)}; @@ -901,7 +901,7 @@ void mainPS() { #if defined USE_PROJECTED_LIGHT // Projected Light (Flashlight, env_projected_texture) - vec4 t_ProjectedLightCoord = Mul(u_ProjectedLightFromWorldMatrix, vec4(v_PositionWorld.xyz, 1.0)); + vec4 t_ProjectedLightCoord = u_ProjectedLightFromWorldMatrix * vec4(v_PositionWorld.xyz, 1.0); t_ProjectedLightCoord.xyz /= t_ProjectedLightCoord.www; // Clip space is between -1 and 1. Move it into 0...1 space. diff --git a/src/SourceEngine/Materials/Material_Modulate.ts b/src/SourceEngine/Materials/Material_Modulate.ts index d7b973baa..1a9cee46b 100644 --- a/src/SourceEngine/Materials/Material_Modulate.ts +++ b/src/SourceEngine/Materials/Material_Modulate.ts @@ -19,8 +19,8 @@ precision mediump float; ${MaterialShaderTemplateBase.Common} -layout(std140) uniform ub_ObjectParams { - Mat4x2 u_BaseTextureTransform; +layout(std140, row_major) uniform ub_ObjectParams { + mat4x2 u_BaseTextureTransform; }; varying vec3 v_PositionWorld; @@ -32,12 +32,12 @@ uniform sampler2D u_BaseTexture; #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); v_PositionWorld.xyz = t_PositionWorld; - gl_Position = Mul(u_ProjectionView, vec4(t_PositionWorld, 1.0)); + gl_Position = u_ProjectionView * vec4(t_PositionWorld, 1.0); - v_TexCoord0.xy = Mul(u_BaseTextureTransform, vec4(a_TexCoord01.xy, 1.0, 1.0)); + v_TexCoord0.xy = u_BaseTextureTransform * vec4(a_TexCoord01.xy, 1.0, 1.0); } #endif diff --git a/src/SourceEngine/Materials/Material_Refract.ts b/src/SourceEngine/Materials/Material_Refract.ts index 9814383a2..007f2bf9b 100644 --- a/src/SourceEngine/Materials/Material_Refract.ts +++ b/src/SourceEngine/Materials/Material_Refract.ts @@ -63,14 +63,14 @@ layout(binding = 11) uniform samplerCube u_TextureEnvmap; #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); v_PositionWorld.xyz = t_PositionWorld; - gl_Position = Mul(u_ProjectionView, vec4(t_PositionWorld, 1.0)); + gl_Position = u_ProjectionView * vec4(t_PositionWorld, 1.0); - vec3 t_NormalWorld = normalize(Mul(t_WorldFromLocalMatrix, vec4(a_Normal.xyz, 0.0))); + vec3 t_NormalWorld = normalize(t_WorldFromLocalMatrix * vec4(a_Normal.xyz, 0.0)); - vec3 t_TangentSWorld = normalize(Mul(t_WorldFromLocalMatrix, vec4(a_TangentS.xyz, 0.0))); + vec3 t_TangentSWorld = normalize(t_WorldFromLocalMatrix * vec4(a_TangentS.xyz, 0.0)); vec3 t_TangentTWorld = cross(t_TangentSWorld, t_NormalWorld); v_TangentSpaceBasis0 = t_TangentSWorld * a_TangentS.w; diff --git a/src/SourceEngine/Materials/Material_Sky.ts b/src/SourceEngine/Materials/Material_Sky.ts index b94eb93c6..59a6e0a21 100644 --- a/src/SourceEngine/Materials/Material_Sky.ts +++ b/src/SourceEngine/Materials/Material_Sky.ts @@ -33,10 +33,10 @@ layout(binding = 0) uniform sampler2D u_Texture; #if defined VERT void mainVS() { - Mat4x3 t_WorldFromLocalMatrix = CalcWorldFromLocalMatrix(); - vec3 t_PositionWorld = Mul(t_WorldFromLocalMatrix, vec4(a_Position, 1.0)); - gl_Position = Mul(u_ProjectionView, vec4(t_PositionWorld, 1.0)); - v_TexCoord0.xy = Mul(u_BaseTextureTransform, vec4(a_TexCoord01.xy, 0.0, 1.0)); + mat4x3 t_WorldFromLocalMatrix = CalcWorldFromLocalMatrix(); + vec3 t_PositionWorld = t_WorldFromLocalMatrix * vec4(a_Position, 1.0); + gl_Position = u_ProjectionView * vec4(t_PositionWorld, 1.0); + v_TexCoord0.xy = u_BaseTextureTransform * vec4(a_TexCoord01.xy, 0.0, 1.0); } #endif @@ -58,8 +58,8 @@ precision mediump float; ${MaterialShaderTemplateBase.Common} -layout(std140) uniform ub_ObjectParams { - Mat4x2 u_BaseTextureTransform; +layout(std140, row_major) uniform ub_ObjectParams { + mat4x2 u_BaseTextureTransform; vec4 u_TextureSizeInfo; vec4 u_ColorScale; }; @@ -77,11 +77,11 @@ layout(binding = 0) uniform sampler2D u_TextureHdrCompressed; #if defined VERT void mainVS() { - Mat4x3 t_WorldFromLocalMatrix = CalcWorldFromLocalMatrix(); - vec3 t_PositionWorld = Mul(t_WorldFromLocalMatrix, vec4(a_Position, 1.0)); - gl_Position = Mul(u_ProjectionView, vec4(t_PositionWorld, 1.0)); + mat4x3 t_WorldFromLocalMatrix = CalcWorldFromLocalMatrix(); + vec3 t_PositionWorld = t_WorldFromLocalMatrix * vec4(a_Position, 1.0); + gl_Position = u_ProjectionView * vec4(t_PositionWorld, 1.0); - vec2 t_TexCoord = Mul(u_BaseTextureTransform, vec4(a_TexCoord01.xy, 0.0, 1.0)); + vec2 t_TexCoord = u_BaseTextureTransform * vec4(a_TexCoord01.xy, 0.0, 1.0); v_TexCoord0.xy = t_TexCoord + vec2(-u_TexelXIncr, -u_TexelYIncr); v_TexCoord0.zw = t_TexCoord + vec2( u_TexelXIncr, -u_TexelYIncr); diff --git a/src/SourceEngine/Materials/Material_SolidEnergy.ts b/src/SourceEngine/Materials/Material_SolidEnergy.ts index 8ca6168f9..66fd95a4f 100644 --- a/src/SourceEngine/Materials/Material_SolidEnergy.ts +++ b/src/SourceEngine/Materials/Material_SolidEnergy.ts @@ -21,11 +21,11 @@ precision mediump float; ${MaterialShaderTemplateBase.Common} -layout(std140) uniform ub_ObjectParams { - Mat4x2 u_BaseTextureTransform; +layout(std140, row_major) uniform ub_ObjectParams { + mat4x2 u_BaseTextureTransform; #if defined USE_DETAIL - Mat4x2 u_Detail1TextureTransform; - Mat4x2 u_Detail2TextureTransform; + mat4x2 u_Detail1TextureTransform; + mat4x2 u_Detail2TextureTransform; #endif #if defined USE_FLOWMAP vec4 u_Misc[3]; @@ -57,28 +57,28 @@ layout(binding = 5) uniform sampler2D u_TextureFlowBounds; #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); v_PositionWorld.xyz = t_PositionWorld; - gl_Position = Mul(u_ProjectionView, vec4(t_PositionWorld, 1.0)); + gl_Position = u_ProjectionView * vec4(t_PositionWorld, 1.0); v_PositionWorld.w = -gl_Position.z; #if !GFX_CLIPSPACE_NEAR_ZERO() v_PositionWorld.w = v_PositionWorld.w * 0.5 + 0.5; #endif - vec3 t_NormalWorld = normalize(Mul(t_WorldFromLocalMatrix, vec4(a_Normal.xyz, 0.0))); + vec3 t_NormalWorld = normalize(t_WorldFromLocalMatrix * vec4(a_Normal.xyz, 0.0)); - vec3 t_TangentSWorld = normalize(Mul(t_WorldFromLocalMatrix, vec4(a_TangentS.xyz, 0.0))); + vec3 t_TangentSWorld = normalize(t_WorldFromLocalMatrix * vec4(a_TangentS.xyz, 0.0)); vec3 t_TangentTWorld = cross(t_TangentSWorld, t_NormalWorld); - v_TexCoord0.xy = Mul(u_BaseTextureTransform, vec4(a_TexCoord01.xy, 1.0, 1.0)); + v_TexCoord0.xy = u_BaseTextureTransform * vec4(a_TexCoord01.xy, 1.0, 1.0); v_TexCoord0.zw = vec2(0.0); v_TexCoord1.xyzw = vec4(0.0); #if defined USE_DETAIL - v_TexCoord1.xy = Mul(u_Detail1TextureTransform, vec4(a_TexCoord01.xy, 1.0, 1.0)); - v_TexCoord1.zw = Mul(u_Detail2TextureTransform, vec4(a_TexCoord01.xy, 1.0, 1.0)); + v_TexCoord1.xy = u_Detail1TextureTransform * vec4(a_TexCoord01.xy, 1.0, 1.0); + v_TexCoord1.zw = u_Detail2TextureTransform * vec4(a_TexCoord01.xy, 1.0, 1.0); #endif #if defined USE_FLOWMAP diff --git a/src/SourceEngine/Materials/Material_SpriteCard.ts b/src/SourceEngine/Materials/Material_SpriteCard.ts index 2a937a325..7f38dd00f 100644 --- a/src/SourceEngine/Materials/Material_SpriteCard.ts +++ b/src/SourceEngine/Materials/Material_SpriteCard.ts @@ -41,9 +41,9 @@ layout(binding = 0) uniform sampler2D u_Texture; #if defined VERT void mainVS() { - Mat4x3 t_WorldFromLocalMatrix = CalcWorldFromLocalMatrix(); - vec3 t_PositionWorld = Mul(t_WorldFromLocalMatrix, vec4(a_Position, 1.0)); - gl_Position = Mul(u_ProjectionView, vec4(t_PositionWorld, 1.0)); + mat4x3 t_WorldFromLocalMatrix = CalcWorldFromLocalMatrix(); + vec3 t_PositionWorld = t_WorldFromLocalMatrix * vec4(a_Position, 1.0)); + gl_Position = u_ProjectionView * vec4(t_PositionWorld, 1.0)); v_TexCoord0.xy = CalcScaleBias(a_TexCoord01.xy, u_BaseTextureScaleBias[0]); v_TexCoord0.zw = CalcScaleBias(a_TexCoord01.xy, u_BaseTextureScaleBias[1]); v_TexCoord1.xy = CalcScaleBias(a_TexCoord01.xy, u_BaseTextureScaleBias[2]); diff --git a/src/SourceEngine/Materials/Material_UnlitTwoTexture.ts b/src/SourceEngine/Materials/Material_UnlitTwoTexture.ts index 7837f5ced..e869b76d2 100644 --- a/src/SourceEngine/Materials/Material_UnlitTwoTexture.ts +++ b/src/SourceEngine/Materials/Material_UnlitTwoTexture.ts @@ -19,9 +19,9 @@ precision mediump float; ${MaterialShaderTemplateBase.Common} -layout(std140) uniform ub_ObjectParams { - Mat4x2 u_Texture1Transform; - Mat4x2 u_Texture2Transform; +layout(std140, row_major) uniform ub_ObjectParams { + mat4x2 u_Texture1Transform; + mat4x2 u_Texture2Transform; vec4 u_ModulationColor; }; @@ -35,13 +35,13 @@ uniform sampler2D u_Texture2; #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); v_PositionWorld.xyz = t_PositionWorld; - gl_Position = Mul(u_ProjectionView, vec4(t_PositionWorld, 1.0)); + gl_Position = u_ProjectionView * vec4(t_PositionWorld, 1.0); - v_TexCoord0.xy = Mul(u_Texture1Transform, vec4(a_TexCoord01.xy, 1.0, 1.0)); - v_TexCoord0.zw = Mul(u_Texture2Transform, vec4(a_TexCoord01.xy, 1.0, 1.0)); + v_TexCoord0.xy = u_Texture1Transform * vec4(a_TexCoord01.xy, 1.0, 1.0); + v_TexCoord0.zw = u_Texture2Transform * vec4(a_TexCoord01.xy, 1.0, 1.0); } #endif diff --git a/src/SourceEngine/Materials/Material_Water.ts b/src/SourceEngine/Materials/Material_Water.ts index 7a9977855..9bda3177c 100644 --- a/src/SourceEngine/Materials/Material_Water.ts +++ b/src/SourceEngine/Materials/Material_Water.ts @@ -47,7 +47,7 @@ precision mediump sampler2DArray; ${MaterialShaderTemplateBase.Common} -layout(std140) uniform ub_ObjectParams { +layout(std140, row_major) uniform ub_ObjectParams { vec4 u_BumpScaleBias; #if defined USE_TEXSCROLL vec4 u_TexScroll0ScaleBias; @@ -56,7 +56,7 @@ layout(std140) uniform ub_ObjectParams { vec4 u_RefractTint; vec4 u_ReflectTint; vec4 u_WaterFogColor; - Mat4x4 u_ProjectedDepthToWorld; + mat4 u_ProjectedDepthToWorld; #if defined USE_FLOWMAP vec4 u_BaseTextureScaleBias; @@ -114,10 +114,10 @@ layout(binding = 14) uniform sampler2D u_TextureFramebufferDepth; #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); v_PositionWorld.xyz = t_PositionWorld; - gl_Position = Mul(u_ProjectionView, vec4(t_PositionWorld, 1.0)); + gl_Position = u_ProjectionView * vec4(t_PositionWorld, 1.0); // Convert from projected position to texture space. // TODO(jstpierre): This could probably be done easier with gl_FragCoord @@ -159,7 +159,7 @@ vec3 CalcPosWorldFromScreen(vec2 t_ProjTexCoord, float t_DepthSample) { // Reconstruct world-space position for the sample. vec3 t_PosViewport = vec3(t_ProjTexCoord.x, t_ProjTexCoord.y, t_DepthSample); vec4 t_PosClip = CalcPosClipFromViewport(t_PosViewport); - vec4 t_PosWorld = Mul(u_ProjectedDepthToWorld, t_PosClip); + vec4 t_PosWorld = u_ProjectedDepthToWorld * t_PosClip; // Divide by W. t_PosWorld.xyz /= t_PosWorld.www; return t_PosWorld.xyz;