mirror of https://github.com/OpenMW/openmw.git
multiview linker-method
parent
dd5901d351
commit
606a795a54
@ -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
|
@ -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
|
@ -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];
|
||||
}
|
Loading…
Reference in New Issue