Skip to content

Commit f25043b

Browse files
committed
Merge pull request #70 from OSVR/shader-cleanup
Shader cleanup
2 parents a609be8 + 7b63b22 commit f25043b

17 files changed

+359
-533
lines changed

OSVR-Unity/Assets/OSVRUnity/Prefabs/VRDisplayTracked.prefab

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ GameObject:
4747
- 114: {fileID: 11431734}
4848
- 114: {fileID: 11431736}
4949
- 114: {fileID: 11400556}
50-
- 114: {fileID: 11417594}
5150
m_Layer: 0
5251
m_Name: VRDisplayTracked
5352
m_TagString: Untagged
@@ -207,25 +206,6 @@ MonoBehaviour:
207206
m_Script: {fileID: 11500000, guid: a288e4aec9950634b83d232abc73d1bb, type: 3}
208207
m_Name:
209208
m_EditorClassIdentifier:
210-
JsonDescriptorFile: {fileID: 4900000, guid: 903a53a7997a82c42b329c472b623a4e, type: 3}
211-
--- !u!114 &11417594
212-
MonoBehaviour:
213-
m_ObjectHideFlags: 1
214-
m_PrefabParentObject: {fileID: 0}
215-
m_PrefabInternal: {fileID: 100100000}
216-
m_GameObject: {fileID: 131736}
217-
m_Enabled: 1
218-
m_EditorHideFlags: 0
219-
m_Script: {fileID: 11500000, guid: db80e57e78593b64384f21c9a3022b68, type: 3}
220-
m_Name:
221-
m_EditorClassIdentifier:
222-
k1Red: 0
223-
k1Green: 0
224-
k1Blue: 0
225-
fullCenter: {x: .5, y: .5}
226-
leftCenter: {x: .5, y: .5}
227-
rightCenter: {x: .5, y: .5}
228-
distortionShader: {fileID: 4800000, guid: 1dffc394b375bda49bb119de26c0bb35, type: 3}
229209
--- !u!114 &11431730
230210
MonoBehaviour:
231211
m_ObjectHideFlags: 1

OSVR-Unity/Assets/OSVRUnity/Prefabs/VRDisplayUntracked.prefab

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ GameObject:
1111
- 20: {fileID: 2000000}
1212
- 81: {fileID: 8100000}
1313
- 114: {fileID: 11400000}
14+
- 114: {fileID: 11452958}
1415
m_Layer: 0
1516
m_Name: VRDisplayUntracked
1617
m_TagString: Untagged
@@ -167,6 +168,17 @@ MonoBehaviour:
167168
m_EditorClassIdentifier:
168169
eye: 1
169170
cachedTransform: {fileID: 0}
171+
--- !u!114 &11452958
172+
MonoBehaviour:
173+
m_ObjectHideFlags: 1
174+
m_PrefabParentObject: {fileID: 0}
175+
m_PrefabInternal: {fileID: 100100000}
176+
m_GameObject: {fileID: 100000}
177+
m_Enabled: 1
178+
m_EditorHideFlags: 0
179+
m_Script: {fileID: 11500000, guid: a288e4aec9950634b83d232abc73d1bb, type: 3}
180+
m_Name:
181+
m_EditorClassIdentifier:
170182
--- !u!1001 &100100000
171183
Prefab:
172184
m_ObjectHideFlags: 1
File renamed without changes.

OSVR-Unity/Assets/OSVRUnity/Shaders/OsvrDistortion.shader renamed to OSVR-Unity/Assets/OSVRUnity/Resources/OsvrDistortion.shader

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/// you may not use this file except in compliance with the License.
1010
/// You may obtain a copy of the License at
1111
///
12-
/// http://www.apache.org/licenses/LICENSE-2.0
12+
/// http://www.apache.org/licenses/LICENSE-2.0
1313
///
1414
/// Unless required by applicable law or agreed to in writing, software
1515
/// distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,66 +18,63 @@
1818
/// limitations under the License.
1919
/// </copyright>
2020
/// <summary>
21-
/// Based on Unity's (Pro Only) Image Effect: Fisheye.shader
21+
/// Long ago, based on Unity's (Pro Only) Image Effect: Fisheye.shader
2222
/// Author: Greg Aring
2323
/// Email: greg@sensics.com
2424
/// </summary>
25+
26+
/// Syntax reference: see http://docs.unity3d.com/Manual/SL-Shader.html
27+
2528
Shader "Osvr/OsvrDistortion" {
2629
Properties
2730
{
28-
_K1_Red ("K1 Red", Range (0.00,1.00)) = 0.5 // sliders
29-
_K1_Green ("Reflection distort", Range (0.00,1.00)) = 0.5
30-
_K1_Blue ("Reflection distort", Range (0.00,1.00)) = 0.5
31-
_Full_Center ("FullCenter", Vector) = (.5,.5,0,0)
32-
_Left_Center ("LeftCenter", Vector) = (.5,.5,0,0)
33-
_Right_Center ("RightCenter", Vector) = (.5,.5,0,0)
31+
_K1_Red ("K1 Red", Range (0.00,1.00)) = 0.0 // sliders
32+
_K1_Green ("K1 Green", Range (0.00,1.00)) = 0.0
33+
_K1_Blue ("K1 Blue", Range (0.00,1.00)) = 0.0
34+
_Center ("Center of Projection", Vector) = (.5,.5,0,0)
3435
_MainTex ("Base (RGB)", 2D) = "" {}
3536
}
36-
CGINCLUDE
37+
CGINCLUDE
3738
#include "UnityCG.cginc"
38-
39+
3940
struct v2f {
4041
float4 pos : SV_POSITION;
4142
float2 uv : TEXCOORD0;
4243
};
43-
44+
4445
float _K1_Red;
4546
float _K1_Green;
4647
float _K1_Blue;
47-
float4 _Full_Center;
48-
float4 _Left_Center;
49-
float4 _Right_Center;
48+
float4 _Center;
5049
sampler2D _MainTex;
5150

52-
v2f vert( appdata_img v )
51+
v2f vert( appdata_img v )
5352
{
5453
v2f o;
5554
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
5655
o.uv = v.texcoord.xy;
5756
return o;
58-
}
57+
}
5958
float2 Distort(float2 p, float k1)
6059
{
61-
62-
60+
/// @todo would pow improve performance here? (by using SFU if available?)
6361
float r2 = p.x * p.x + p.y * p.y;
64-
float r = sqrt(r2);
6562

66-
float newRadius = (1 + k1*r*r);
63+
float newRadius = (1 + k1*r2);
6764
p.x = p.x * newRadius;
6865
p.y = p.y * newRadius;
6966

7067
return p;
7168
}
72-
73-
half4 frag(v2f i) : SV_Target
69+
70+
half4 frag(v2f i) : SV_Target
7471
{
7572
float2 uv_red, uv_green, uv_blue;
7673
float4 color_red, color_green, color_blue;
7774
float2 sectorOrigin;
7875
float4 color;
7976

80-
sectorOrigin = _Full_Center.xy;
77+
sectorOrigin = _Center.xy;
8178

8279
uv_red = Distort(i.uv-sectorOrigin, _K1_Red) + sectorOrigin;
8380
uv_green = Distort(i.uv-sectorOrigin, _K1_Green) + sectorOrigin;
@@ -101,13 +98,13 @@ Properties
10198

10299
Subshader {
103100
Pass {
104-
ZTest Always Cull Off ZWrite Off
101+
ZTest Always Cull Off ZWrite Off
102+
103+
CGPROGRAM
104+
#pragma vertex vert
105+
#pragma fragment frag
106+
ENDCG
107+
}
105108

106-
CGPROGRAM
107-
#pragma vertex vert
108-
#pragma fragment frag
109-
ENDCG
110-
}
111-
112109
}
113-
}
110+
}

OSVR-Unity/Assets/OSVRUnity/Shaders/OsvrDistortion.shader.meta renamed to OSVR-Unity/Assets/OSVRUnity/Resources/OsvrDistortion.shader.meta

File renamed without changes.

0 commit comments

Comments
 (0)