From a2f5e1c07545e21825770044c86ba5bf37b11d01 Mon Sep 17 00:00:00 2001 From: Mads Buvik Sandvei Date: Sun, 26 Jan 2025 16:23:56 +0100 Subject: [PATCH] Fix multiview use in techniques --- components/fx/pass.cpp | 21 +++++++++++++++---- components/fx/technique.cpp | 2 +- files/data/shaders/internal_distortion.omwfx | 4 ++-- .../compatibility/multiview_resolve.frag | 2 +- .../shaders/lib/core/fragment_multiview.glsl | 2 +- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/components/fx/pass.cpp b/components/fx/pass.cpp index cf50d20fe2..c55bee76e3 100644 --- a/components/fx/pass.cpp +++ b/components/fx/pass.cpp @@ -81,6 +81,7 @@ namespace fx #define omw_Position @position #define omw_Texture1D @texture1D #define omw_Texture2D @texture2D +#define omw_Texture2DArray @texture2DArray #define omw_Texture3D @texture3D #define omw_Vertex @vertex #define omw_FragColor @fragColor @@ -154,7 +155,7 @@ mat4 omw_InvProjectionMatrix() float omw_GetDepth(vec2 uv) { #if OMW_MULTIVIEW - float depth = omw_Texture2D(omw_SamplerDepth, vec3(uv, gl_ViewID_OVR)).r; + float depth = omw_Texture2DArray(omw_SamplerDepth, vec3(uv, gl_ViewID_OVR)).r; #else float depth = omw_Texture2D(omw_SamplerDepth, uv).r; #endif @@ -165,10 +166,19 @@ mat4 omw_InvProjectionMatrix() #endif } + vec4 omw_GetDistortion(vec2 uv) + { +#if OMW_MULTIVIEW + return omw_Texture2DArray(omw_SamplerDistortion, vec3(uv, gl_ViewID_OVR)); +#else + return omw_Texture2D(omw_SamplerDistortion, uv); +#endif + } + vec4 omw_GetLastShader(vec2 uv) { #if OMW_MULTIVIEW - return omw_Texture2D(omw_SamplerLastShader, vec3(uv, gl_ViewID_OVR)); + return omw_Texture2DArray(omw_SamplerLastShader, vec3(uv, gl_ViewID_OVR)); #else return omw_Texture2D(omw_SamplerLastShader, uv); #endif @@ -177,7 +187,7 @@ mat4 omw_InvProjectionMatrix() vec4 omw_GetLastPass(vec2 uv) { #if OMW_MULTIVIEW - return omw_Texture2D(omw_SamplerLastPass, vec3(uv, gl_ViewID_OVR)); + return omw_Texture2DArray(omw_SamplerLastPass, vec3(uv, gl_ViewID_OVR)); #else return omw_Texture2D(omw_SamplerLastPass, uv); #endif @@ -186,7 +196,7 @@ mat4 omw_InvProjectionMatrix() vec3 omw_GetNormals(vec2 uv) { #if OMW_MULTIVIEW - return omw_Texture2D(omw_SamplerNormals, vec3(uv, gl_ViewID_OVR)).rgb * 2.0 - 1.0; + return omw_Texture2DArray(omw_SamplerNormals, vec3(uv, gl_ViewID_OVR)).rgb * 2.0 - 1.0; #else return omw_Texture2D(omw_SamplerNormals, uv).rgb * 2.0 - 1.0; #endif @@ -275,6 +285,9 @@ float omw_EstimateFogCoverageFromUV(vec2 uv) { "@hdr", technique.getHDR() ? "1" : "0" }, { "@in", mLegacyGLSL ? "varying" : "in" }, { "@out", mLegacyGLSL ? "varying" : "out" }, { "@position", "gl_Position" }, { "@texture1D", mLegacyGLSL ? "texture1D" : "texture" }, + // Note, @texture2DArray must be defined before @texture2D since @texture2D is a perfect prefix of + // texture2DArray + { "@texture2DArray", mLegacyGLSL ? "texture2DArray" : "texture" }, { "@texture2D", mLegacyGLSL ? "texture2D" : "texture" }, { "@texture3D", mLegacyGLSL ? "texture3D" : "texture" }, { "@vertex", mLegacyGLSL ? "gl_Vertex" : "_omw_Vertex" }, diff --git a/components/fx/technique.cpp b/components/fx/technique.cpp index f56e0d498e..5963e274ec 100644 --- a/components/fx/technique.cpp +++ b/components/fx/technique.cpp @@ -85,7 +85,7 @@ namespace fx mDescription = {}; mVersion = {}; mGLSLExtensions.clear(); - mGLSLVersion = mUBO ? 330 : 120; + mGLSLVersion = (mUBO || Stereo::getMultiview()) ? 330 : 120; mGLSLProfile.clear(); mDynamic = false; } diff --git a/files/data/shaders/internal_distortion.omwfx b/files/data/shaders/internal_distortion.omwfx index b641bb6711..b8e62ff229 100644 --- a/files/data/shaders/internal_distortion.omwfx +++ b/files/data/shaders/internal_distortion.omwfx @@ -6,11 +6,11 @@ fragment main { { const float multiplier = 0.14; - vec2 offset = omw_Texture2D(omw_SamplerDistortion, omw_TexCoord).rg; + vec2 offset = omw_GetDistortion(omw_TexCoord).rg; offset *= multiplier; offset = clamp(offset, vec2(-1.0), vec2(1.0)); - float occlusionFactor = omw_Texture2D(omw_SamplerDistortion, omw_TexCoord+offset).b; + float occlusionFactor = omw_GetDistortion(omw_TexCoord+offset).b; omw_FragColor = mix(omw_GetLastShader(omw_TexCoord + offset), omw_GetLastShader(omw_TexCoord), occlusionFactor); } diff --git a/files/shaders/compatibility/multiview_resolve.frag b/files/shaders/compatibility/multiview_resolve.frag index a77a3b35d1..9aeb54314b 100644 --- a/files/shaders/compatibility/multiview_resolve.frag +++ b/files/shaders/compatibility/multiview_resolve.frag @@ -1,4 +1,4 @@ -#version 120 +#version 330 #extension GL_EXT_texture_array : require varying vec2 uv; diff --git a/files/shaders/lib/core/fragment_multiview.glsl b/files/shaders/lib/core/fragment_multiview.glsl index 767a3e04bd..e29c5afbc9 100644 --- a/files/shaders/lib/core/fragment_multiview.glsl +++ b/files/shaders/lib/core/fragment_multiview.glsl @@ -50,5 +50,5 @@ uniform sampler2DArray opaqueDepthTex; vec4 sampleOpaqueDepthTex(vec2 uv) { - return texture2DArray(opaqueDepthTex, vec3((uv), gl_ViewID_OVR)); + return texture(opaqueDepthTex, vec3((uv), gl_ViewID_OVR)); }