From b3c8c8eb56227128dce4c905048c17bfa3bf91ec Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Sat, 9 Jul 2022 22:21:48 +0200 Subject: [PATCH] Support sky blending in multiview mode --- files/shaders/fog.glsl | 8 ++++---- files/shaders/openmw_fragment.glsl | 9 +++++++++ files/shaders/openmw_fragment.h.glsl | 11 ++++++++++- files/shaders/openmw_fragment_multiview.glsl | 11 ++++++++++- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/files/shaders/fog.glsl b/files/shaders/fog.glsl index 9bf93079f3..d9d0548aa9 100644 --- a/files/shaders/fog.glsl +++ b/files/shaders/fog.glsl @@ -1,7 +1,8 @@ uniform float far; #if @skyBlending -uniform sampler2D sky; +#include "openmw_fragment.h.glsl" + uniform float skyBlendingStart; #endif @@ -23,14 +24,13 @@ vec4 applyFogAtDist(vec4 color, float euclideanDist, float linearDist) color.xyz = mix(color.xyz, gl_Fog.color.xyz, fogValue); #endif -#if @skyBlending && !@useOVR_multiview +#if @skyBlending float fadeValue = clamp((far - dist) / (far - skyBlendingStart), 0.0, 1.0); fadeValue *= fadeValue; #ifdef ADDITIVE_BLENDING color.xyz *= fadeValue; #else - vec3 skyColor = texture2D(sky, gl_FragCoord.xy / screenRes).xyz; - color.xyz = mix(skyColor, color.xyz, fadeValue); + color.xyz = mix(mw_sampleSkyColor(gl_FragCoord.xy / screenRes), color.xyz, fadeValue); #endif #endif diff --git a/files/shaders/openmw_fragment.glsl b/files/shaders/openmw_fragment.glsl index 151f8fdb13..8c8302f3ae 100644 --- a/files/shaders/openmw_fragment.glsl +++ b/files/shaders/openmw_fragment.glsl @@ -31,3 +31,12 @@ vec4 mw_samplerLastShader(vec2 uv) { return texture2D(omw_SamplerLastShader, uv); } + +#if @skyBlending +uniform sampler2D sky; + +vec3 mw_sampleSkyColor(vec2 uv) +{ + return texture2D(sky, uv).xyz; +} +#endif diff --git a/files/shaders/openmw_fragment.h.glsl b/files/shaders/openmw_fragment.h.glsl index c96912ead6..f7c1e2f21e 100644 --- a/files/shaders/openmw_fragment.h.glsl +++ b/files/shaders/openmw_fragment.h.glsl @@ -1,3 +1,6 @@ +#ifndef OPENMW_FRAGMENT_H_GLSL +#define OPENMW_FRAGMENT_H_GLSL + @link "openmw_fragment.glsl" if !@useOVR_multiview @link "openmw_fragment_multiview.glsl" if @useOVR_multiview @@ -8,4 +11,10 @@ vec4 mw_sampleRefractionMap(vec2 uv); float mw_sampleRefractionDepthMap(vec2 uv); #endif -vec4 mw_samplerLastShader(vec2 uv); \ No newline at end of file +vec4 mw_samplerLastShader(vec2 uv); + +#if @skyBlending +vec3 mw_sampleSkyColor(vec2 uv); +#endif + +#endif // OPENMW_FRAGMENT_H_GLSL diff --git a/files/shaders/openmw_fragment_multiview.glsl b/files/shaders/openmw_fragment_multiview.glsl index 0ec9a3e12b..61f69cc2d9 100644 --- a/files/shaders/openmw_fragment_multiview.glsl +++ b/files/shaders/openmw_fragment_multiview.glsl @@ -35,4 +35,13 @@ uniform sampler2DArray omw_SamplerLastShader; vec4 mw_samplerLastShader(vec2 uv) { return texture2DArray(omw_SamplerLastShader, vec3((uv), gl_ViewID_OVR)); -} \ No newline at end of file +} + +#if @skyBlending +uniform sampler2DArray sky; + +vec3 mw_sampleSkyColor(vec2 uv) +{ + return texture2DArray(sky, vec3((uv), gl_ViewID_OVR)).xyz; +} +#endif