khanat-opennel-code/code/snowballs2/bin/pp_oculus_vr.cg

55 lines
1.8 KiB
Text
Raw Normal View History

2014-04-19 19:53:29 +00:00
/************************************************************************************
Filename : pp_oculus_vr.cg
Content : Barrel fragment program ported from Oculus SDK Samples to Cg
Created : July 01, 2013
Modified by : Jan Boon (Kaetemi)
Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
************************************************************************************/
void pp_oculus_vr(
// Per fragment parameters
float2 texCoord : TEXCOORD0,
// Fragment program constants
uniform float2 cLensCenter,
uniform float2 cScreenCenter,
uniform float2 cScale,
uniform float2 cScaleIn,
uniform float4 cHmdWarpParam,
uniform sampler2D nlTex0 : TEX0,
// Output color
out float4 oCol : COLOR)
{
float2 theta = (texCoord - cLensCenter) * cScaleIn; // Scales to [-1, 1]
float rSq = theta.x * theta.x + theta.y * theta.y;
float2 theta1 = theta * (cHmdWarpParam.x + cHmdWarpParam.y * rSq +
cHmdWarpParam.z * rSq * rSq + cHmdWarpParam.w * rSq * rSq * rSq);
float2 tc = cLensCenter + cScale * theta1;
if (!all(equal(clamp(tc, cScreenCenter-float2(0.25,0.5), cScreenCenter+float2(0.25,0.5)), tc)))
{
oCol = float4(0, 0, 0, 0);
}
else
{
oCol = tex2D(nlTex0, tc);
}
}