diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fdfbdac13b..696e8113c5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -378,7 +378,7 @@ variables: &tests-targets - $env:CCACHE_BASEDIR = Get-Location - $env:CCACHE_DIR = "$(Get-Location)\ccache" - New-Item -Type Directory -Force -Path $env:CCACHE_DIR - - sh CI/before_script.msvc.sh -c $config -p Win64 -v 2019 -k -V -N -b -t -C + - sh CI/before_script.msvc.sh -c $config -p Win64 -v 2019 -k -V -N -b -t -C $multiview - cd MSVC2019_64_Ninja - .\ActivateMSVC.ps1 - cmake --build . --config $config --target ($targets.Split(',')) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 15d690534a..20e69450d1 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -412,7 +412,6 @@ namespace MWRender globalDefines["preLightEnv"] = Settings::Manager::getBool("apply lighting to environment maps", "Shaders") ? "1" : "0"; globalDefines["radialFog"] = Settings::Manager::getBool("radial fog", "Shaders") ? "1" : "0"; globalDefines["useGPUShader4"] = "0"; - globalDefines["GLSLVersion"] = "120"; globalDefines["useOVR_multiview"] = "0"; globalDefines["numViews"] = "1"; diff --git a/components/sceneutil/mwshadowtechnique.cpp b/components/sceneutil/mwshadowtechnique.cpp index 60dd613df5..3210bf4a4e 100644 --- a/components/sceneutil/mwshadowtechnique.cpp +++ b/components/sceneutil/mwshadowtechnique.cpp @@ -921,7 +921,7 @@ void SceneUtil::MWShadowTechnique::setupCastingShader(Shader::ShaderManager & sh { // This can't be part of the constructor as OSG mandates that there be a trivial constructor available - osg::ref_ptr castingVertexShader = shaderManager.getShader("shadowcasting_vertex.glsl", { {"GLSLVersion", "120"} }, osg::Shader::VERTEX); + osg::ref_ptr castingVertexShader = shaderManager.getShader("shadowcasting_vertex.glsl", { }, osg::Shader::VERTEX); osg::ref_ptr exts = osg::GLExtensions::Get(0, false); std::string useGPUShader4 = exts && exts->isGpuShader4Supported ? "1" : "0"; for (int alphaFunc = GL_NEVER; alphaFunc <= GL_ALWAYS; ++alphaFunc) @@ -932,8 +932,7 @@ void SceneUtil::MWShadowTechnique::setupCastingShader(Shader::ShaderManager & sh program->addShader(shaderManager.getShader("shadowcasting_fragment.glsl", { {"alphaFunc", std::to_string(alphaFunc)}, {"alphaToCoverage", "0"}, {"adjustCoverage", "1"}, - {"useGPUShader4", useGPUShader4}, - {"GLSLVersion", "120"} + {"useGPUShader4", useGPUShader4} }, osg::Shader::FRAGMENT)); } } diff --git a/components/stereo/stereomanager.cpp b/components/stereo/stereomanager.cpp index 7214fe0031..bbbdc6e934 100644 --- a/components/stereo/stereomanager.cpp +++ b/components/stereo/stereomanager.cpp @@ -182,7 +182,6 @@ namespace Stereo { if (getMultiview()) { - defines["GLSLVersion"] = "330 compatibility"; defines["useOVR_multiview"] = "1"; defines["numViews"] = "2"; } diff --git a/files/shaders/CMakeLists.txt b/files/shaders/CMakeLists.txt index 30909d4311..97f32ad979 100644 --- a/files/shaders/CMakeLists.txt +++ b/files/shaders/CMakeLists.txt @@ -18,8 +18,10 @@ set(SHADER_FILES objects_fragment.glsl openmw_fragment.glsl openmw_fragment.h.glsl + openmw_fragment_multiview.glsl openmw_vertex.glsl openmw_vertex.h.glsl + openmw_vertex_multiview.glsl terrain_vertex.glsl terrain_fragment.glsl lighting.glsl @@ -40,8 +42,6 @@ set(SHADER_FILES gui_fragment.glsl debug_vertex.glsl debug_fragment.glsl - multiview_fragment.glsl - multiview_vertex.glsl sky_vertex.glsl sky_fragment.glsl skypasses.glsl diff --git a/files/shaders/debug_fragment.glsl b/files/shaders/debug_fragment.glsl index ab6ad813ee..1b25510d66 100644 --- a/files/shaders/debug_fragment.glsl +++ b/files/shaders/debug_fragment.glsl @@ -1,4 +1,4 @@ -#version @GLSLVersion +#version 120 #include "vertexcolors.glsl" diff --git a/files/shaders/debug_vertex.glsl b/files/shaders/debug_vertex.glsl index 5331859122..fd41a6ff48 100644 --- a/files/shaders/debug_vertex.glsl +++ b/files/shaders/debug_vertex.glsl @@ -1,4 +1,4 @@ -#version @GLSLVersion +#version 120 #include "openmw_vertex.h.glsl" diff --git a/files/shaders/groundcover_fragment.glsl b/files/shaders/groundcover_fragment.glsl index c7e6ec36aa..d669634190 100644 --- a/files/shaders/groundcover_fragment.glsl +++ b/files/shaders/groundcover_fragment.glsl @@ -1,4 +1,4 @@ -#version @GLSLVersion +#version 120 #if @useUBO #extension GL_ARB_uniform_buffer_object : require diff --git a/files/shaders/groundcover_vertex.glsl b/files/shaders/groundcover_vertex.glsl index 660a4624f0..ff3dacdd99 100644 --- a/files/shaders/groundcover_vertex.glsl +++ b/files/shaders/groundcover_vertex.glsl @@ -1,6 +1,6 @@ -#version @GLSLVersion +#version 120 -#include "multiview_vertex.glsl" +#include "openmw_vertex.h.glsl" #if @useUBO #extension GL_ARB_uniform_buffer_object : require diff --git a/files/shaders/gui_fragment.glsl b/files/shaders/gui_fragment.glsl index 7c0a3b4811..a8c9434711 100644 --- a/files/shaders/gui_fragment.glsl +++ b/files/shaders/gui_fragment.glsl @@ -1,4 +1,4 @@ -#version @GLSLVersion +#version 120 uniform sampler2D diffuseMap; diff --git a/files/shaders/gui_vertex.glsl b/files/shaders/gui_vertex.glsl index 670de5b6e3..b378b097bd 100644 --- a/files/shaders/gui_vertex.glsl +++ b/files/shaders/gui_vertex.glsl @@ -1,4 +1,4 @@ -#version @GLSLVersion +#version 120 varying vec2 diffuseMapUV; varying vec4 passColor; diff --git a/files/shaders/multiview_fragment.glsl b/files/shaders/multiview_fragment.glsl deleted file mode 100644 index 662dbe5f55..0000000000 --- a/files/shaders/multiview_fragment.glsl +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef MULTIVIEW_FRAGMENT -#define MULTIVIEW_FRAGMENT - -// This file either enables or disables GL_OVR_multiview2 related code. -// For use in fragment shaders - -// REQUIREMENT: -// GLSL version: 330 or greater -// GLSL profile: compatibility -// NOTE: If stereo is enabled using Misc::StereoView::shaderStereoDefines, version 330 compatibility (or greater) will be set. -// -// This file provides symbols for sampling stereo-aware textures. Without multiview, these texture uniforms are sampler2D, -// while in stereo the same uniforms are sampler2DArray instead. The symbols defined in this file mask this difference, allowing -// the same code to work in both cases. Use mw_stereoAwareSampler2D and mw_stereoAwareTexture2D, where you otherwise would use -// sampler2D and texture2D() -// -// USAGE: -// For stereo-aware textures, such as reflections, use the mw_stereoAwareSampler2D sampler and mw_stereoAwareTexture2D method -// instead of the usual sampler2D and texture2D. -// -// Using water reflection as an example, the old code for these textures changes from -// uniform sampler2D reflectionMap; -// ... -// vec3 reflection = texture2D(reflectionMap, screenCoords + screenCoordsOffset).rgb; -// -// to -// uniform mw_stereoAwareSampler2D reflectionMap; -// ... -// vec3 reflection = mw_stereoAwareTexture2D(reflectionMap, screenCoords + screenCoordsOffset).rgb; -// - -#if @useOVR_multiview - -#extension GL_OVR_multiview : require -#extension GL_OVR_multiview2 : require -#extension GL_EXT_texture_array : require - -#define mw_stereoAwareSampler2D sampler2DArray -#define mw_stereoAwareTexture2D(texture, uv) texture2DArray(texture, vec3((uv), gl_ViewID_OVR)) - -#else // useOVR_multiview - -#define mw_stereoAwareSampler2D sampler2D -#define mw_stereoAwareTexture2D(texture, uv) texture2D(texture, uv) - -#endif // useOVR_multiview - -#endif // MULTIVIEW_FRAGMENT \ No newline at end of file diff --git a/files/shaders/multiview_vertex.glsl b/files/shaders/multiview_vertex.glsl deleted file mode 100644 index 0cabeb84a2..0000000000 --- a/files/shaders/multiview_vertex.glsl +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef MULTIVIEW_VERTEX -#define MULTIVIEW_VERTEX - -// This file either enables or disables GL_OVR_multiview related code. -// For use in vertex shaders - -// REQUIREMENT: -// GLSL version: 330 or greater -// GLSL profile: compatibility -// NOTE: If stereo is enabled using Misc::StereoView::shaderStereoDefines, version 330 compatibility (or greater) will be set. - -// USAGE: -// To create a stereo-aware vertex shader, use the matrix accessor functions defined in this .glsl file to compute gl_Position. -// For the vertex stage, usually only gl_Position needs to be computed with stereo awareness, while other variables such as viewPos -// should be computed in the center camera's view space and take no stereo awareness. -// -// A typical gl_Position line will look like the following: -// gl_Position = mw_stereoAwareProjectionMatrix() * (mw_stereoAwareModelViewMatrix() * gl_Vertex); -// -// If you need to perform intermediate computations before determining the final values of gl_Position and viewPos, -// your code might look more like the following: -// vec4 intermediateViewPos = gl_ModelViewMatrix * gl_Vertex; -// vec4 viewPos = myWhateverCode(intermediateViewPos); -// gl_Position = mw_stereoAwareProjectionMatrix() * mw_stereoAwareViewPosition(viewPos); -// - -#if @useOVR_multiview - -#extension GL_OVR_multiview : require - -#ifndef MULTIVIEW_FRAGMENT -// Layout cannot be used in the fragment shader -layout(num_views = @numViews) in; -#endif - -uniform mat4 projectionMatrixMultiView[@numViews]; -uniform mat4 viewMatrixMultiView[@numViews]; - -// NOTE: -// stereo-aware inverse view matrices and normal matrices have not been implemented. -// Some effects like specular highlights would need stereo aware normal matrices to be 100% correct. -// But the difference is not likely to be noticeable unless you're actively looking for it. - -mat4 mw_stereoAwareProjectionMatrix() -{ - return projectionMatrixMultiView[gl_ViewID_OVR]; -} - -mat4 mw_stereoAwareModelViewMatrix() -{ - return viewMatrixMultiView[gl_ViewID_OVR] * gl_ModelViewMatrix; -} - -vec4 mw_stereoAwareViewPosition(vec4 viewPos) -{ - return viewMatrixMultiView[gl_ViewID_OVR] * viewPos; -} - -#else // useOVR_multiview - -uniform mat4 projectionMatrix; - -mat4 mw_stereoAwareProjectionMatrix() -{ - return projectionMatrix; -} - -mat4 mw_stereoAwareModelViewMatrix() -{ - return gl_ModelViewMatrix; -} - -vec4 mw_stereoAwareViewPosition(vec4 viewPos) -{ - return viewPos; -} - -#endif // useOVR_multiview - -#endif // MULTIVIEW_VERTEX \ No newline at end of file diff --git a/files/shaders/nv_default_fragment.glsl b/files/shaders/nv_default_fragment.glsl index e4d8046662..ff81a2b94d 100644 --- a/files/shaders/nv_default_fragment.glsl +++ b/files/shaders/nv_default_fragment.glsl @@ -1,4 +1,4 @@ -#version @GLSLVersion +#version 120 #pragma import_defines(FORCE_OPAQUE) #if @useUBO diff --git a/files/shaders/nv_default_vertex.glsl b/files/shaders/nv_default_vertex.glsl index 2554677018..f182bbe8be 100644 --- a/files/shaders/nv_default_vertex.glsl +++ b/files/shaders/nv_default_vertex.glsl @@ -1,6 +1,6 @@ -#version @GLSLVersion +#version 120 -#include "multiview_vertex.glsl" +#include "openmw_vertex.h.glsl" #if @useUBO #extension GL_ARB_uniform_buffer_object : require diff --git a/files/shaders/nv_nolighting_fragment.glsl b/files/shaders/nv_nolighting_fragment.glsl index 116677318a..7c4f4737e0 100644 --- a/files/shaders/nv_nolighting_fragment.glsl +++ b/files/shaders/nv_nolighting_fragment.glsl @@ -1,4 +1,4 @@ -#version @GLSLVersion +#version 120 #pragma import_defines(FORCE_OPAQUE) #if @useGPUShader4 diff --git a/files/shaders/nv_nolighting_vertex.glsl b/files/shaders/nv_nolighting_vertex.glsl index a3d884d026..7b1f6961b4 100644 --- a/files/shaders/nv_nolighting_vertex.glsl +++ b/files/shaders/nv_nolighting_vertex.glsl @@ -1,4 +1,4 @@ -#version @GLSLVersion +#version 120 #include "openmw_vertex.h.glsl" diff --git a/files/shaders/objects_fragment.glsl b/files/shaders/objects_fragment.glsl index 7e7ef647cc..85950c7468 100644 --- a/files/shaders/objects_fragment.glsl +++ b/files/shaders/objects_fragment.glsl @@ -1,4 +1,4 @@ -#version @GLSLVersion +#version 120 #pragma import_defines(FORCE_OPAQUE) #if @useUBO diff --git a/files/shaders/objects_vertex.glsl b/files/shaders/objects_vertex.glsl index 4764e63ce4..10543f767a 100644 --- a/files/shaders/objects_vertex.glsl +++ b/files/shaders/objects_vertex.glsl @@ -1,6 +1,6 @@ -#version @GLSLVersion +#version 120 -#include "multiview_vertex.glsl" +#include "openmw_vertex.h.glsl" #if @useUBO #extension GL_ARB_uniform_buffer_object : require diff --git a/files/shaders/openmw_fragment.h.glsl b/files/shaders/openmw_fragment.h.glsl index c5bcf21c9d..ae1a131b42 100644 --- a/files/shaders/openmw_fragment.h.glsl +++ b/files/shaders/openmw_fragment.h.glsl @@ -1,4 +1,5 @@ -@link "openmw_fragment.glsl" +@link "openmw_fragment.glsl" if !@useOVR_multiview +@link "openmw_fragment_multiview.glsl" if @useOVR_multiview vec4 mw_sampleReflectionMap(vec2 uv); diff --git a/files/shaders/openmw_fragment_multiview.glsl b/files/shaders/openmw_fragment_multiview.glsl new file mode 100644 index 0000000000..1a2c0d991b --- /dev/null +++ b/files/shaders/openmw_fragment_multiview.glsl @@ -0,0 +1,31 @@ +#version 330 compatibility + +#extension GL_OVR_multiview : require +#extension GL_OVR_multiview2 : require +#extension GL_EXT_texture_array : require + +#include "openmw_fragment.h.glsl" + +uniform sampler2DArray reflectionMap; + +vec4 mw_sampleReflectionMap(vec2 uv) +{ + return texture2DArray(reflectionMap, vec3((uv), gl_ViewID_OVR)); +} + +#if @refraction_enabled + +uniform sampler2DArray refractionMap; +uniform sampler2DArray refractionDepthMap; + +vec4 mw_sampleRefractionMap(vec2 uv) +{ + return texture2DArray(refractionMap, vec3((uv), gl_ViewID_OVR)); +} + +float mw_sampleRefractionDepthMap(vec2 uv) +{ + return texture2DArray(refractionDepthMap, vec3((uv), gl_ViewID_OVR)).x; +} + +#endif \ No newline at end of file diff --git a/files/shaders/openmw_vertex.h.glsl b/files/shaders/openmw_vertex.h.glsl index 00feb9310e..5f591e4311 100644 --- a/files/shaders/openmw_vertex.h.glsl +++ b/files/shaders/openmw_vertex.h.glsl @@ -1,4 +1,5 @@ -@link "openmw_vertex.glsl" +@link "openmw_vertex.glsl" if !@useOVR_multiview +@link "openmw_vertex_multiview.glsl" if @useOVR_multiview vec4 mw_modelToClip(vec4 pos); vec4 mw_modelToView(vec4 pos); diff --git a/files/shaders/openmw_vertex_multiview.glsl b/files/shaders/openmw_vertex_multiview.glsl new file mode 100644 index 0000000000..f65d9f0da0 --- /dev/null +++ b/files/shaders/openmw_vertex_multiview.glsl @@ -0,0 +1,41 @@ +#version 330 compatibility + +#extension GL_OVR_multiview : require +#extension GL_OVR_multiview2 : require + +layout(num_views = @numViews) in; + +#include "openmw_vertex.h.glsl" + +uniform mat4 projectionMatrixMultiView[@numViews]; +uniform mat4 viewMatrixMultiView[@numViews]; + +vec4 mw_modelToClip(vec4 pos) +{ + return projectionMatrixMultiView[gl_ViewID_OVR] * mw_modelToView(pos); +} + +vec4 mw_modelToView(vec4 pos) +{ + return viewMatrixMultiView[gl_ViewID_OVR] * gl_ModelViewMatrix * pos; +} + +vec4 mw_viewToClip(vec4 pos) +{ + return projectionMatrixMultiView[gl_ViewID_OVR] * pos; +} + +vec4 mw_viewStereoAdjust(vec4 pos) +{ + return viewMatrixMultiView[gl_ViewID_OVR] * pos; +} + +mat4 mw_viewMatrix() +{ + return viewMatrixMultiView[gl_ViewID_OVR] * gl_ModelViewMatrix; +} + +mat4 mw_projectionMatrix() +{ + return projectionMatrixMultiView[gl_ViewID_OVR]; +} diff --git a/files/shaders/s360_fragment.glsl b/files/shaders/s360_fragment.glsl index f5f623c828..f52e1478ee 100644 --- a/files/shaders/s360_fragment.glsl +++ b/files/shaders/s360_fragment.glsl @@ -1,4 +1,4 @@ -#version @GLSLVersion +#version 120 varying vec2 uv; uniform samplerCube cubeMap; diff --git a/files/shaders/s360_vertex.glsl b/files/shaders/s360_vertex.glsl index 375dcda0ba..ad96620c3f 100644 --- a/files/shaders/s360_vertex.glsl +++ b/files/shaders/s360_vertex.glsl @@ -1,4 +1,4 @@ -#version @GLSLVersion +#version 120 varying vec2 uv; diff --git a/files/shaders/shadowcasting_fragment.glsl b/files/shaders/shadowcasting_fragment.glsl index 186934fec2..07fad047e1 100644 --- a/files/shaders/shadowcasting_fragment.glsl +++ b/files/shaders/shadowcasting_fragment.glsl @@ -1,4 +1,4 @@ -#version @GLSLVersion +#version 120 #if @useGPUShader4 #extension GL_EXT_gpu_shader4: require diff --git a/files/shaders/shadowcasting_vertex.glsl b/files/shaders/shadowcasting_vertex.glsl index 25d5c402d7..e36f21a4de 100644 --- a/files/shaders/shadowcasting_vertex.glsl +++ b/files/shaders/shadowcasting_vertex.glsl @@ -1,4 +1,4 @@ -#version @GLSLVersion +#version 120 varying vec2 diffuseMapUV; diff --git a/files/shaders/sky_fragment.glsl b/files/shaders/sky_fragment.glsl index 0f2ff938c2..cfa3650c02 100644 --- a/files/shaders/sky_fragment.glsl +++ b/files/shaders/sky_fragment.glsl @@ -1,4 +1,4 @@ -#version @GLSLVersion +#version 120 #include "skypasses.glsl" diff --git a/files/shaders/sky_vertex.glsl b/files/shaders/sky_vertex.glsl index 5b6a99be01..6d9ef7a073 100644 --- a/files/shaders/sky_vertex.glsl +++ b/files/shaders/sky_vertex.glsl @@ -1,6 +1,6 @@ -#version @GLSLVersion +#version 120 -#include "multiview_vertex.glsl" +#include "openmw_vertex.h.glsl" #include "openmw_vertex.h.glsl" @@ -14,12 +14,12 @@ varying vec2 diffuseMapUV; mat4 selectModelViewMatrix() { #if @useOVR_multiview - mat4 viewOffsetMatrix = viewMatrixMultiView[gl_ViewID_OVR]; + mat4 viewOffsetMatrix = mw_viewMatrix(); // Sky geometries aren't actually all that distant. So delete view translation to keep them looking distant. viewOffsetMatrix[3][0] = 0; viewOffsetMatrix[3][1] = 0; viewOffsetMatrix[3][2] = 0; - return viewOffsetMatrix * gl_ModelViewMatrix; + return viewOffsetMatrix; #else return gl_ModelViewMatrix; #endif @@ -27,7 +27,7 @@ mat4 selectModelViewMatrix() void main() { - gl_Position = mw_modelToClip(gl_Vertex); + gl_Position = mw_viewToClip(selectModelViewMatrix() * gl_Vertex); passColor = gl_Color; if (pass == PASS_CLOUDS) diff --git a/files/shaders/terrain_fragment.glsl b/files/shaders/terrain_fragment.glsl index e5532f9bce..d9d4a6dc30 100644 --- a/files/shaders/terrain_fragment.glsl +++ b/files/shaders/terrain_fragment.glsl @@ -1,4 +1,4 @@ -#version @GLSLVersion +#version 120 #if @useUBO #extension GL_ARB_uniform_buffer_object : require diff --git a/files/shaders/terrain_vertex.glsl b/files/shaders/terrain_vertex.glsl index abceb019b7..07ffeee202 100644 --- a/files/shaders/terrain_vertex.glsl +++ b/files/shaders/terrain_vertex.glsl @@ -1,6 +1,6 @@ -#version @GLSLVersion +#version 120 -#include "multiview_vertex.glsl" +#include "openmw_vertex.h.glsl" #if @useUBO #extension GL_ARB_uniform_buffer_object : require diff --git a/files/shaders/water_fragment.glsl b/files/shaders/water_fragment.glsl index 87645f2135..8db92a2984 100644 --- a/files/shaders/water_fragment.glsl +++ b/files/shaders/water_fragment.glsl @@ -1,6 +1,6 @@ -#version @GLSLVersion +#version 120 -#include "multiview_fragment.glsl" +#include "openmw_fragment.h.glsl" #if @useUBO #extension GL_ARB_uniform_buffer_object : require diff --git a/files/shaders/water_vertex.glsl b/files/shaders/water_vertex.glsl index e3dd29d2a0..b09d3b54ae 100644 --- a/files/shaders/water_vertex.glsl +++ b/files/shaders/water_vertex.glsl @@ -1,4 +1,4 @@ -#version @GLSLVersion +#version 120 #include "openmw_vertex.h.glsl"