aboutsummaryrefslogtreecommitdiffstats
path: root/LibOVR/Src/CAPI/D3D1X/Shaders/DistortionChroma_ps.psh
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-03-21 23:01:12 +0100
committerSven Gothel <[email protected]>2015-03-21 23:01:12 +0100
commit0c5c4be020c2d55540058a49b2a879f46d5a1e13 (patch)
tree00f84c2ca18cc233b826014094b9cad0769a3ea5 /LibOVR/Src/CAPI/D3D1X/Shaders/DistortionChroma_ps.psh
parentcbbd775b6c754927632c333ff01424a0d2048c7c (diff)
parente490c3c7f7bb5461cfa78a214827aa534fb43a3e (diff)
Merge branch 'vanilla_0.4.4' and resolve conflicts
TODO: Validate for removed patches due to relocation Resolved Conflicts: LibOVR/Src/Kernel/OVR_ThreadsWinAPI.cpp LibOVR/Src/OVR_Linux_HMDDevice.cpp LibOVR/Src/OVR_OSX_HMDDevice.cpp LibOVR/Src/OVR_Profile.cpp LibOVR/Src/OVR_Sensor2Impl.cpp LibOVR/Src/OVR_SensorFusion.cpp LibOVR/Src/OVR_SensorImpl.cpp LibOVR/Src/OVR_Win32_DeviceStatus.cpp LibOVR/Src/OVR_Win32_HIDDevice.cpp LibOVR/Src/OVR_Win32_HIDDevice.h LibOVR/Src/OVR_Win32_HMDDevice.cpp
Diffstat (limited to 'LibOVR/Src/CAPI/D3D1X/Shaders/DistortionChroma_ps.psh')
-rw-r--r--LibOVR/Src/CAPI/D3D1X/Shaders/DistortionChroma_ps.psh135
1 files changed, 135 insertions, 0 deletions
diff --git a/LibOVR/Src/CAPI/D3D1X/Shaders/DistortionChroma_ps.psh b/LibOVR/Src/CAPI/D3D1X/Shaders/DistortionChroma_ps.psh
new file mode 100644
index 0000000..c69fce0
--- /dev/null
+++ b/LibOVR/Src/CAPI/D3D1X/Shaders/DistortionChroma_ps.psh
@@ -0,0 +1,135 @@
+/************************************************************************************
+
+Filename : DistortionChroma_ps.psh
+
+Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
+
+Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
+you may not use the Oculus VR Rift SDK except in compliance with the License,
+which is provided at the time of installation or download, or which
+otherwise accompanies this software in either electronic or hard copy form.
+
+You may obtain a copy of the License at
+
+http://www.oculusvr.com/licenses/LICENSE-3.2
+
+Unless required by applicable law or agreed to in writing, the Oculus VR SDK
+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.
+
+************************************************************************************/
+
+Texture2D Texture : register(t0);
+Texture2D LastTexture : register(t1);
+SamplerState Linear : register(s0);
+
+float2 OverdriveScales;
+float AaDerivativeMult;
+
+// Fast approximate gamma to linear conversion when averaging colors
+float3 ToLinear(float3 inColor) { return inColor * inColor; }
+float3 ToGamma(float3 inColor) { return sqrt(inColor); }
+
+void SampleStep(float2 oTexCoord0, float2 oTexCoord1, float2 oTexCoord2, float colorWeight, float2 texOffset,
+ inout float3 totalColor, inout float totalWeight)
+{
+ float3 newColor = 0;
+ newColor.r += Texture.Sample(Linear, oTexCoord0 + texOffset).r;
+ newColor.g += Texture.Sample(Linear, oTexCoord1 + texOffset).g;
+ newColor.b += Texture.Sample(Linear, oTexCoord2 + texOffset).b;
+ newColor = ToLinear(newColor);
+
+ totalColor += newColor * colorWeight;
+ totalWeight += colorWeight;
+}
+
+float3 ApplyHqAa(float2 oTexCoord0, float2 oTexCoord1, float2 oTexCoord2)
+{
+ float2 texWidth = fwidth(oTexCoord1);
+ float2 texStep = texWidth * AaDerivativeMult;
+
+ float totalWeight = 0;
+ float3 totalColor = 0;
+
+ // center sample
+ SampleStep(oTexCoord0, oTexCoord1, oTexCoord2, 4, 0, totalColor, totalWeight);
+
+ float3 smplExp = 1.0 / 3.0;
+ float3 smplWgt = 1.0;
+
+ SampleStep(oTexCoord0, oTexCoord1, oTexCoord2, smplWgt.x, -1.000 * smplExp.x * texStep, totalColor, totalWeight);
+ //SampleStep(oTexCoord0, oTexCoord1, oTexCoord2, smplWgt.y, -1.250 * smplExp.y * texStep, totalColor, totalWeight);
+ SampleStep(oTexCoord0, oTexCoord1, oTexCoord2, smplWgt.z, -1.875 * smplExp.z * texStep, totalColor, totalWeight);
+ SampleStep(oTexCoord0, oTexCoord1, oTexCoord2, smplWgt.z, 1.875 * smplExp.z * texStep, totalColor, totalWeight);
+ //SampleStep(oTexCoord0, oTexCoord1, oTexCoord2, smplWgt.y, 1.250 * smplExp.y * texStep, totalColor, totalWeight);
+ SampleStep(oTexCoord0, oTexCoord1, oTexCoord2, smplWgt.x, 1.000 * smplExp.x * texStep, totalColor, totalWeight);
+
+ return ToGamma(totalColor.rgb / totalWeight);
+}
+
+void main(in float4 oPosition : SV_Position,
+ in float oColor : COLOR,
+ in float2 oTexCoord0 : TEXCOORD0,
+ in float2 oTexCoord1 : TEXCOORD1,
+ in float2 oTexCoord2 : TEXCOORD2,
+ out float4 outColor0 : SV_Target0,
+ out float4 outColor1 : SV_Target1)
+{
+#define USE_ANISO 0
+
+#if USE_ANISO // enable "SampleMode hqFilter = (distortionCaps ... " in code
+ // Using anisotropic sampling - requires sRGB sampling
+
+ #if 1 // feeding in proper ddx & ddy does not yield better visuals
+ float2 uvDeriv = float2(ddx(oTexCoord1.x), ddy(oTexCoord1.y));
+ float ResultR = Texture.SampleGrad(Linear, oTexCoord0, uvDeriv.x, uvDeriv.y).r;
+ float ResultG = Texture.SampleGrad(Linear, oTexCoord1, uvDeriv.x, uvDeriv.y).g;
+ float ResultB = Texture.SampleGrad(Linear, oTexCoord2, uvDeriv.x, uvDeriv.y).b;
+ float3 newColor = float3(ResultR, ResultG, ResultB);
+ #else
+ float2 uvDerivX = ddx(oTexCoord1);
+ float2 uvDerivY = ddy(oTexCoord1);
+ float ResultR = Texture.SampleGrad(Linear, oTexCoord0, uvDerivX, uvDerivY).r;
+ float ResultG = Texture.SampleGrad(Linear, oTexCoord1, uvDerivX, uvDerivY).g;
+ float ResultB = Texture.SampleGrad(Linear, oTexCoord2, uvDerivX, uvDerivY).b;
+ float3 newColor = float3(ResultR, ResultG, ResultB);
+ #endif
+
+#else
+
+ float3 newColor;
+ // High quality anti-aliasing in distortion
+ if(AaDerivativeMult > 0)
+ {
+ newColor = ApplyHqAa(oTexCoord0, oTexCoord1, oTexCoord2);
+ }
+ else
+ {
+ float ResultR = Texture.Sample(Linear, oTexCoord0).r;
+ float ResultG = Texture.Sample(Linear, oTexCoord1).g;
+ float ResultB = Texture.Sample(Linear, oTexCoord2).b;
+ newColor = float3(ResultR, ResultG, ResultB);
+ }
+
+#endif
+
+ newColor = newColor * oColor.xxx;
+ outColor0 = float4(newColor, 1.0);
+ outColor1 = outColor0;
+
+ // pixel luminance overdrive
+ if(OverdriveScales.x > 0)
+ {
+ float3 oldColor = LastTexture.Load(int3(oPosition.xy, 0)).rgb;
+
+ float3 adjustedScales;
+ adjustedScales.x = newColor.x > oldColor.x ? OverdriveScales.x : OverdriveScales.y;
+ adjustedScales.y = newColor.y > oldColor.y ? OverdriveScales.x : OverdriveScales.y;
+ adjustedScales.z = newColor.z > oldColor.z ? OverdriveScales.x : OverdriveScales.y;
+
+ float3 overdriveColor = saturate(newColor + (newColor - oldColor) * adjustedScales);
+ outColor1 = float4(overdriveColor, 1.0);
+ }
+}