mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 15:44:36 +00:00
Oculus VR (Rift) support
Input device and shaders for supporting the Oculus Rift.
This commit is contained in:
parent
2123365d4d
commit
de7a72d82a
24 changed files with 3214 additions and 0 deletions
|
|
@ -54,6 +54,9 @@ function initializeCore()
|
|||
exec( "./audioStates.cs" );
|
||||
exec( "./audioAmbiences.cs" );
|
||||
|
||||
// Input devices
|
||||
exec("~/scripts/client/oculusVR.cs");
|
||||
|
||||
// Seed the random number generator.
|
||||
setRandomSeed();
|
||||
|
||||
|
|
|
|||
125
Templates/Empty/game/core/scripts/client/oculusVR.cs
Normal file
125
Templates/Empty/game/core/scripts/client/oculusVR.cs
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Only load these functions if an Oculus VR device is present
|
||||
if(!isFunction(isOculusVRDeviceActive))
|
||||
return;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function oculusSensorMetricsCallback()
|
||||
{
|
||||
return " | OVR Sensor 0 |" @
|
||||
" rot: " @ getOVRSensorEulerRotation(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Call this function from createCanvas() to have the Canvas attach itself
|
||||
// to the Rift's display. The Canvas' window will still open on the primary
|
||||
// display if that is different from the Rift, but it will move to the Rift
|
||||
// when it goes full screen. If the Rift is not connected then nothing
|
||||
// will happen.
|
||||
function pointCanvasToOculusVRDisplay()
|
||||
{
|
||||
$pref::Video::displayOutputDevice = getOVRHMDDisplayDeviceName(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Call this function from GameConnection::initialControlSet() just before
|
||||
// your "Canvas.setContent(PlayGui);" call, or at any time you wish to switch
|
||||
// to a side-by-side rendering and the appropriate barrel distortion. This
|
||||
// will turn on side-by-side rendering and tell the GameConnection to use the
|
||||
// Rift as its display device.
|
||||
// Parameters:
|
||||
// %gameConnection - The client GameConnection instance
|
||||
// %trueStereoRendering - If true will enable stereo rendering with an eye
|
||||
// offset for each viewport. This will render each frame twice. If false
|
||||
// then a pseudo stereo rendering is done with only a single render per frame.
|
||||
function enableOculusVRDisplay(%gameConnection, %trueStereoRendering)
|
||||
{
|
||||
setOVRHMDAsGameConnectionDisplayDevice(%gameConnection);
|
||||
PlayGui.renderStyle = "stereo side by side";
|
||||
|
||||
if(%trueStereoRendering)
|
||||
{
|
||||
OVRBarrelDistortionPostFX.isEnabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
OVRBarrelDistortionMonoPostFX.isEnabled = true;
|
||||
}
|
||||
|
||||
// Reset all sensors
|
||||
ovrResetAllSensors();
|
||||
}
|
||||
|
||||
// Call this function when ever you wish to turn off the stereo rendering
|
||||
// and barrel distortion for the Rift.
|
||||
function disableOculusVRDisplay(%gameConnection)
|
||||
{
|
||||
%gameConnection.clearDisplayDevice();
|
||||
PlayGui.renderStyle = "standard";
|
||||
OVRBarrelDistortionPostFX.isEnabled = false;
|
||||
OVRBarrelDistortionMonoPostFX.isEnabled = false;
|
||||
}
|
||||
|
||||
// Helper function to set the standard Rift control scheme. You could place
|
||||
// this function in GameConnection::initialControlSet() at the same time
|
||||
// you call enableOculusVRDisplay().
|
||||
function setStandardOculusVRControlScheme(%gameConnection)
|
||||
{
|
||||
if(isOVRHMDSimulated(0))
|
||||
{
|
||||
// We are simulating a HMD so allow the mouse and gamepad to control
|
||||
// both yaw and pitch.
|
||||
%gameConnection.setControlSchemeParameters(true, true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// A HMD is connected so have the mouse and gamepad only add to yaw
|
||||
%gameConnection.setControlSchemeParameters(true, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Helper function to set the resolution for the Rift.
|
||||
// Parameters:
|
||||
// %fullscreen - If true then the display will be forced to full screen. If
|
||||
// pointCanvasToOculusVRDisplay() was called before the Canvas was created, then
|
||||
// the full screen display will appear on the Rift.
|
||||
function setVideoModeForOculusVRDisplay(%fullscreen)
|
||||
{
|
||||
%res = getOVRHMDResolution(0);
|
||||
Canvas.setVideoMode(%res.x, %res.y, %fullscreen, 32, 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Reset all Oculus Rift sensors. This will make the Rift's current heading
|
||||
// be considered the origin.
|
||||
function resetOculusVRSensors()
|
||||
{
|
||||
ovrResetAllSensors();
|
||||
}
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Only load these shaders if an Oculus VR device is present
|
||||
if(!isFunction(isOculusVRDeviceActive))
|
||||
return;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Shader data
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
singleton ShaderData( OVRMonoToStereoShader )
|
||||
{
|
||||
DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl";
|
||||
DXPixelShaderFile = "shaders/common/postFx/oculusvr/monoToStereoP.hlsl";
|
||||
|
||||
pixVersion = 2.0;
|
||||
};
|
||||
|
||||
singleton ShaderData( OVRBarrelDistortionShader )
|
||||
{
|
||||
DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl";
|
||||
DXPixelShaderFile = "shaders/common/postFx/oculusvr/barrelDistortionP.hlsl";
|
||||
|
||||
pixVersion = 2.0;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// GFX state blocks
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
singleton GFXStateBlockData( OVRBarrelDistortionStateBlock : PFX_DefaultStateBlock )
|
||||
{
|
||||
samplersDefined = true;
|
||||
samplerStates[0] = SamplerClampLinear;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Barrel Distortion PostFx
|
||||
//
|
||||
// To be used with the Oculus Rift.
|
||||
// Expects a stereo pair to exist on the back buffer and then applies the
|
||||
// appropriate barrel distortion.
|
||||
//-----------------------------------------------------------------------------
|
||||
singleton BarrelDistortionPostEffect( OVRBarrelDistortionPostFX )
|
||||
{
|
||||
isEnabled = false;
|
||||
allowReflectPass = false;
|
||||
|
||||
renderTime = "PFXAfterDiffuse";
|
||||
renderPriority = 100;
|
||||
|
||||
// The barrel distortion
|
||||
shader = OVRBarrelDistortionShader;
|
||||
stateBlock = OVRBarrelDistortionStateBlock;
|
||||
|
||||
texture[0] = "$backBuffer";
|
||||
|
||||
scaleOutput = 1.25;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Barrel Distortion Mono PostFx
|
||||
//
|
||||
// To be used with the Oculus Rift.
|
||||
// Takes a non-stereo image and turns it into a stereo pair with barrel
|
||||
// distortion applied. Only a vertical slice around the center of the back
|
||||
// buffer is used to generate the pseudo stereo pair.
|
||||
//-----------------------------------------------------------------------------
|
||||
singleton PostEffect( OVRBarrelDistortionMonoPostFX )
|
||||
{
|
||||
isEnabled = false;
|
||||
allowReflectPass = false;
|
||||
|
||||
renderTime = "PFXAfterDiffuse";
|
||||
renderPriority = 100;
|
||||
|
||||
// Converts the mono display to a stereo one
|
||||
shader = OVRMonoToStereoShader;
|
||||
stateBlock = OVRBarrelDistortionStateBlock;
|
||||
|
||||
texture[0] = "$backBuffer";
|
||||
target = "$outTex";
|
||||
|
||||
// The actual barrel distortion
|
||||
new BarrelDistortionPostEffect(OVRBarrelDistortionMonoStage2PostFX)
|
||||
{
|
||||
shader = OVRBarrelDistortionShader;
|
||||
stateBlock = OVRBarrelDistortionStateBlock;
|
||||
texture[0] = "$inTex";
|
||||
target = "$backBuffer";
|
||||
|
||||
scaleOutput = 1.25;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
function OVRBarrelDistortionMonoPostFX::setShaderConsts( %this )
|
||||
{
|
||||
%HMDIndex = 0;
|
||||
|
||||
%xOffsets = getOVRHMDEyeXOffsets(%HMDIndex);
|
||||
%this.setShaderConst( "$LensXOffsets", %xOffsets );
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
#include "../postFx.hlsl"
|
||||
#include "../../torque.hlsl"
|
||||
|
||||
uniform sampler2D backBuffer : register(S0);
|
||||
|
||||
uniform float3 LensCenter; // x=Left X, y=Right X, z=Y
|
||||
uniform float2 ScreenCenter;
|
||||
uniform float2 Scale;
|
||||
uniform float2 ScaleIn;
|
||||
uniform float4 HmdWarpParam;
|
||||
|
||||
// Scales input texture coordinates for distortion.
|
||||
// ScaleIn maps texture coordinates to Scales to ([-1, 1]), although top/bottom will be
|
||||
// larger due to aspect ratio.
|
||||
float2 HmdWarp(float2 in01, float2 lensCenter)
|
||||
{
|
||||
float2 theta = (in01 - lensCenter) * ScaleIn; // Scales to [-1, 1]
|
||||
float rSq = theta.x * theta.x + theta.y * theta.y;
|
||||
float2 theta1 = theta * (HmdWarpParam.x + HmdWarpParam.y * rSq + HmdWarpParam.z * rSq * rSq + HmdWarpParam.w * rSq * rSq * rSq);
|
||||
return lensCenter + Scale * theta1;
|
||||
}
|
||||
|
||||
float4 main( PFXVertToPix IN ) : COLOR0
|
||||
{
|
||||
float2 texCoord;
|
||||
float xOffset;
|
||||
float2 lensCenter;
|
||||
lensCenter.y = LensCenter.z;
|
||||
if(IN.uv0.x < 0.5)
|
||||
{
|
||||
texCoord.x = IN.uv0.x;
|
||||
texCoord.y = IN.uv0.y;
|
||||
xOffset = 0.0;
|
||||
lensCenter.x = LensCenter.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
texCoord.x = IN.uv0.x - 0.5;
|
||||
texCoord.y = IN.uv0.y;
|
||||
xOffset = 0.5;
|
||||
lensCenter.x = LensCenter.y;
|
||||
}
|
||||
|
||||
float2 tc = HmdWarp(texCoord, lensCenter);
|
||||
|
||||
float4 color;
|
||||
if (any(clamp(tc, ScreenCenter-float2(0.25,0.5), ScreenCenter+float2(0.25, 0.5)) - tc))
|
||||
{
|
||||
color = float4(0,0,0,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
tc.x += xOffset;
|
||||
color = tex2D(backBuffer, tc);
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
#include "../postFx.hlsl"
|
||||
#include "../../torque.hlsl"
|
||||
|
||||
uniform sampler2D backBuffer : register(S0);
|
||||
|
||||
uniform float2 LensXOffsets;
|
||||
|
||||
float4 main( PFXVertToPix IN ) : COLOR0
|
||||
{
|
||||
float2 texCoord;
|
||||
float xOffset;
|
||||
float2 lensCenter;
|
||||
lensCenter.y = 0.5;
|
||||
if(IN.uv0.x < 0.5)
|
||||
{
|
||||
texCoord.x = IN.uv0.x;
|
||||
texCoord.y = IN.uv0.y;
|
||||
xOffset = 0.0;
|
||||
lensCenter.x = LensXOffsets.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
texCoord.x = IN.uv0.x - 0.5;
|
||||
texCoord.y = IN.uv0.y;
|
||||
xOffset = 0.5;
|
||||
lensCenter.x = LensXOffsets.y;
|
||||
}
|
||||
|
||||
texCoord.x *= 2.0;
|
||||
texCoord.x += lensCenter.x;
|
||||
texCoord.x *= 0.5;
|
||||
texCoord.x += 0.25;
|
||||
|
||||
float4 color = tex2D(backBuffer, texCoord);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
|
@ -54,6 +54,9 @@ function initializeCore()
|
|||
exec( "./audioStates.cs" );
|
||||
exec( "./audioAmbiences.cs" );
|
||||
|
||||
// Input devices
|
||||
exec("~/scripts/client/oculusVR.cs");
|
||||
|
||||
// Seed the random number generator.
|
||||
setRandomSeed();
|
||||
|
||||
|
|
|
|||
125
Templates/Full/game/core/scripts/client/oculusVR.cs
Normal file
125
Templates/Full/game/core/scripts/client/oculusVR.cs
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Only load these functions if an Oculus VR device is present
|
||||
if(!isFunction(isOculusVRDeviceActive))
|
||||
return;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function oculusSensorMetricsCallback()
|
||||
{
|
||||
return " | OVR Sensor 0 |" @
|
||||
" rot: " @ getOVRSensorEulerRotation(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Call this function from createCanvas() to have the Canvas attach itself
|
||||
// to the Rift's display. The Canvas' window will still open on the primary
|
||||
// display if that is different from the Rift, but it will move to the Rift
|
||||
// when it goes full screen. If the Rift is not connected then nothing
|
||||
// will happen.
|
||||
function pointCanvasToOculusVRDisplay()
|
||||
{
|
||||
$pref::Video::displayOutputDevice = getOVRHMDDisplayDeviceName(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Call this function from GameConnection::initialControlSet() just before
|
||||
// your "Canvas.setContent(PlayGui);" call, or at any time you wish to switch
|
||||
// to a side-by-side rendering and the appropriate barrel distortion. This
|
||||
// will turn on side-by-side rendering and tell the GameConnection to use the
|
||||
// Rift as its display device.
|
||||
// Parameters:
|
||||
// %gameConnection - The client GameConnection instance
|
||||
// %trueStereoRendering - If true will enable stereo rendering with an eye
|
||||
// offset for each viewport. This will render each frame twice. If false
|
||||
// then a pseudo stereo rendering is done with only a single render per frame.
|
||||
function enableOculusVRDisplay(%gameConnection, %trueStereoRendering)
|
||||
{
|
||||
setOVRHMDAsGameConnectionDisplayDevice(%gameConnection);
|
||||
PlayGui.renderStyle = "stereo side by side";
|
||||
|
||||
if(%trueStereoRendering)
|
||||
{
|
||||
OVRBarrelDistortionPostFX.isEnabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
OVRBarrelDistortionMonoPostFX.isEnabled = true;
|
||||
}
|
||||
|
||||
// Reset all sensors
|
||||
ovrResetAllSensors();
|
||||
}
|
||||
|
||||
// Call this function when ever you wish to turn off the stereo rendering
|
||||
// and barrel distortion for the Rift.
|
||||
function disableOculusVRDisplay(%gameConnection)
|
||||
{
|
||||
%gameConnection.clearDisplayDevice();
|
||||
PlayGui.renderStyle = "standard";
|
||||
OVRBarrelDistortionPostFX.isEnabled = false;
|
||||
OVRBarrelDistortionMonoPostFX.isEnabled = false;
|
||||
}
|
||||
|
||||
// Helper function to set the standard Rift control scheme. You could place
|
||||
// this function in GameConnection::initialControlSet() at the same time
|
||||
// you call enableOculusVRDisplay().
|
||||
function setStandardOculusVRControlScheme(%gameConnection)
|
||||
{
|
||||
if(isOVRHMDSimulated(0))
|
||||
{
|
||||
// We are simulating a HMD so allow the mouse and gamepad to control
|
||||
// both yaw and pitch.
|
||||
%gameConnection.setControlSchemeParameters(true, true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// A HMD is connected so have the mouse and gamepad only add to yaw
|
||||
%gameConnection.setControlSchemeParameters(true, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Helper function to set the resolution for the Rift.
|
||||
// Parameters:
|
||||
// %fullscreen - If true then the display will be forced to full screen. If
|
||||
// pointCanvasToOculusVRDisplay() was called before the Canvas was created, then
|
||||
// the full screen display will appear on the Rift.
|
||||
function setVideoModeForOculusVRDisplay(%fullscreen)
|
||||
{
|
||||
%res = getOVRHMDResolution(0);
|
||||
Canvas.setVideoMode(%res.x, %res.y, %fullscreen, 32, 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Reset all Oculus Rift sensors. This will make the Rift's current heading
|
||||
// be considered the origin.
|
||||
function resetOculusVRSensors()
|
||||
{
|
||||
ovrResetAllSensors();
|
||||
}
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Only load these shaders if an Oculus VR device is present
|
||||
if(!isFunction(isOculusVRDeviceActive))
|
||||
return;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Shader data
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
singleton ShaderData( OVRMonoToStereoShader )
|
||||
{
|
||||
DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl";
|
||||
DXPixelShaderFile = "shaders/common/postFx/oculusvr/monoToStereoP.hlsl";
|
||||
|
||||
pixVersion = 2.0;
|
||||
};
|
||||
|
||||
singleton ShaderData( OVRBarrelDistortionShader )
|
||||
{
|
||||
DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl";
|
||||
DXPixelShaderFile = "shaders/common/postFx/oculusvr/barrelDistortionP.hlsl";
|
||||
|
||||
pixVersion = 2.0;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// GFX state blocks
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
singleton GFXStateBlockData( OVRBarrelDistortionStateBlock : PFX_DefaultStateBlock )
|
||||
{
|
||||
samplersDefined = true;
|
||||
samplerStates[0] = SamplerClampLinear;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Barrel Distortion PostFx
|
||||
//
|
||||
// To be used with the Oculus Rift.
|
||||
// Expects a stereo pair to exist on the back buffer and then applies the
|
||||
// appropriate barrel distortion.
|
||||
//-----------------------------------------------------------------------------
|
||||
singleton BarrelDistortionPostEffect( OVRBarrelDistortionPostFX )
|
||||
{
|
||||
isEnabled = false;
|
||||
allowReflectPass = false;
|
||||
|
||||
renderTime = "PFXAfterDiffuse";
|
||||
renderPriority = 100;
|
||||
|
||||
// The barrel distortion
|
||||
shader = OVRBarrelDistortionShader;
|
||||
stateBlock = OVRBarrelDistortionStateBlock;
|
||||
|
||||
texture[0] = "$backBuffer";
|
||||
|
||||
scaleOutput = 1.25;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Barrel Distortion Mono PostFx
|
||||
//
|
||||
// To be used with the Oculus Rift.
|
||||
// Takes a non-stereo image and turns it into a stereo pair with barrel
|
||||
// distortion applied. Only a vertical slice around the center of the back
|
||||
// buffer is used to generate the pseudo stereo pair.
|
||||
//-----------------------------------------------------------------------------
|
||||
singleton PostEffect( OVRBarrelDistortionMonoPostFX )
|
||||
{
|
||||
isEnabled = false;
|
||||
allowReflectPass = false;
|
||||
|
||||
renderTime = "PFXAfterDiffuse";
|
||||
renderPriority = 100;
|
||||
|
||||
// Converts the mono display to a stereo one
|
||||
shader = OVRMonoToStereoShader;
|
||||
stateBlock = OVRBarrelDistortionStateBlock;
|
||||
|
||||
texture[0] = "$backBuffer";
|
||||
target = "$outTex";
|
||||
|
||||
// The actual barrel distortion
|
||||
new BarrelDistortionPostEffect(OVRBarrelDistortionMonoStage2PostFX)
|
||||
{
|
||||
shader = OVRBarrelDistortionShader;
|
||||
stateBlock = OVRBarrelDistortionStateBlock;
|
||||
texture[0] = "$inTex";
|
||||
target = "$backBuffer";
|
||||
|
||||
scaleOutput = 1.25;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
function OVRBarrelDistortionMonoPostFX::setShaderConsts( %this )
|
||||
{
|
||||
%HMDIndex = 0;
|
||||
|
||||
%xOffsets = getOVRHMDEyeXOffsets(%HMDIndex);
|
||||
%this.setShaderConst( "$LensXOffsets", %xOffsets );
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
#include "../postFx.hlsl"
|
||||
#include "../../torque.hlsl"
|
||||
|
||||
uniform sampler2D backBuffer : register(S0);
|
||||
|
||||
uniform float3 LensCenter; // x=Left X, y=Right X, z=Y
|
||||
uniform float2 ScreenCenter;
|
||||
uniform float2 Scale;
|
||||
uniform float2 ScaleIn;
|
||||
uniform float4 HmdWarpParam;
|
||||
|
||||
// Scales input texture coordinates for distortion.
|
||||
// ScaleIn maps texture coordinates to Scales to ([-1, 1]), although top/bottom will be
|
||||
// larger due to aspect ratio.
|
||||
float2 HmdWarp(float2 in01, float2 lensCenter)
|
||||
{
|
||||
float2 theta = (in01 - lensCenter) * ScaleIn; // Scales to [-1, 1]
|
||||
float rSq = theta.x * theta.x + theta.y * theta.y;
|
||||
float2 theta1 = theta * (HmdWarpParam.x + HmdWarpParam.y * rSq + HmdWarpParam.z * rSq * rSq + HmdWarpParam.w * rSq * rSq * rSq);
|
||||
return lensCenter + Scale * theta1;
|
||||
}
|
||||
|
||||
float4 main( PFXVertToPix IN ) : COLOR0
|
||||
{
|
||||
float2 texCoord;
|
||||
float xOffset;
|
||||
float2 lensCenter;
|
||||
lensCenter.y = LensCenter.z;
|
||||
if(IN.uv0.x < 0.5)
|
||||
{
|
||||
texCoord.x = IN.uv0.x;
|
||||
texCoord.y = IN.uv0.y;
|
||||
xOffset = 0.0;
|
||||
lensCenter.x = LensCenter.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
texCoord.x = IN.uv0.x - 0.5;
|
||||
texCoord.y = IN.uv0.y;
|
||||
xOffset = 0.5;
|
||||
lensCenter.x = LensCenter.y;
|
||||
}
|
||||
|
||||
float2 tc = HmdWarp(texCoord, lensCenter);
|
||||
|
||||
float4 color;
|
||||
if (any(clamp(tc, ScreenCenter-float2(0.25,0.5), ScreenCenter+float2(0.25, 0.5)) - tc))
|
||||
{
|
||||
color = float4(0,0,0,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
tc.x += xOffset;
|
||||
color = tex2D(backBuffer, tc);
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
#include "../postFx.hlsl"
|
||||
#include "../../torque.hlsl"
|
||||
|
||||
uniform sampler2D backBuffer : register(S0);
|
||||
|
||||
uniform float2 LensXOffsets;
|
||||
|
||||
float4 main( PFXVertToPix IN ) : COLOR0
|
||||
{
|
||||
float2 texCoord;
|
||||
float xOffset;
|
||||
float2 lensCenter;
|
||||
lensCenter.y = 0.5;
|
||||
if(IN.uv0.x < 0.5)
|
||||
{
|
||||
texCoord.x = IN.uv0.x;
|
||||
texCoord.y = IN.uv0.y;
|
||||
xOffset = 0.0;
|
||||
lensCenter.x = LensXOffsets.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
texCoord.x = IN.uv0.x - 0.5;
|
||||
texCoord.y = IN.uv0.y;
|
||||
xOffset = 0.5;
|
||||
lensCenter.x = LensXOffsets.y;
|
||||
}
|
||||
|
||||
texCoord.x *= 2.0;
|
||||
texCoord.x += lensCenter.x;
|
||||
texCoord.x *= 0.5;
|
||||
texCoord.x += 0.25;
|
||||
|
||||
float4 color = tex2D(backBuffer, texCoord);
|
||||
|
||||
return color;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue