mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 07:45:39 +00:00
multiview linker-method
This commit is contained in:
parent
dd5901d351
commit
606a795a54
33 changed files with 112 additions and 169 deletions
|
@ -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(','))
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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<osg::Shader> castingVertexShader = shaderManager.getShader("shadowcasting_vertex.glsl", { {"GLSLVersion", "120"} }, osg::Shader::VERTEX);
|
||||
osg::ref_ptr<osg::Shader> castingVertexShader = shaderManager.getShader("shadowcasting_vertex.glsl", { }, osg::Shader::VERTEX);
|
||||
osg::ref_ptr<osg::GLExtensions> 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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,7 +182,6 @@ namespace Stereo
|
|||
{
|
||||
if (getMultiview())
|
||||
{
|
||||
defines["GLSLVersion"] = "330 compatibility";
|
||||
defines["useOVR_multiview"] = "1";
|
||||
defines["numViews"] = "2";
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#version @GLSLVersion
|
||||
#version 120
|
||||
|
||||
#include "vertexcolors.glsl"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#version @GLSLVersion
|
||||
#version 120
|
||||
|
||||
#include "openmw_vertex.h.glsl"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#version @GLSLVersion
|
||||
#version 120
|
||||
|
||||
#if @useUBO
|
||||
#extension GL_ARB_uniform_buffer_object : require
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#version @GLSLVersion
|
||||
#version 120
|
||||
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#version @GLSLVersion
|
||||
#version 120
|
||||
|
||||
varying vec2 diffuseMapUV;
|
||||
varying vec4 passColor;
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -1,4 +1,4 @@
|
|||
#version @GLSLVersion
|
||||
#version 120
|
||||
#pragma import_defines(FORCE_OPAQUE)
|
||||
|
||||
#if @useUBO
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#version @GLSLVersion
|
||||
#version 120
|
||||
#pragma import_defines(FORCE_OPAQUE)
|
||||
|
||||
#if @useGPUShader4
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#version @GLSLVersion
|
||||
#version 120
|
||||
|
||||
#include "openmw_vertex.h.glsl"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#version @GLSLVersion
|
||||
#version 120
|
||||
#pragma import_defines(FORCE_OPAQUE)
|
||||
|
||||
#if @useUBO
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
31
files/shaders/openmw_fragment_multiview.glsl
Normal file
31
files/shaders/openmw_fragment_multiview.glsl
Normal file
|
@ -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
|
|
@ -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);
|
||||
|
|
41
files/shaders/openmw_vertex_multiview.glsl
Normal file
41
files/shaders/openmw_vertex_multiview.glsl
Normal file
|
@ -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];
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
#version @GLSLVersion
|
||||
#version 120
|
||||
|
||||
varying vec2 uv;
|
||||
uniform samplerCube cubeMap;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#version @GLSLVersion
|
||||
#version 120
|
||||
|
||||
varying vec2 uv;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#version @GLSLVersion
|
||||
#version 120
|
||||
|
||||
#if @useGPUShader4
|
||||
#extension GL_EXT_gpu_shader4: require
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#version @GLSLVersion
|
||||
#version 120
|
||||
|
||||
varying vec2 diffuseMapUV;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#version @GLSLVersion
|
||||
#version 120
|
||||
|
||||
#include "skypasses.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)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#version @GLSLVersion
|
||||
#version 120
|
||||
|
||||
#if @useUBO
|
||||
#extension GL_ARB_uniform_buffer_object : require
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#version @GLSLVersion
|
||||
#version 120
|
||||
|
||||
#include "openmw_vertex.h.glsl"
|
||||
|
||||
|
|
Loading…
Reference in a new issue