Skip to content

Commit 57f1e63

Browse files
committed
Modify shader handling to be simpler and more invisible.
Updating prefabs and sample scenes to match. No longer persist an OsvrDistortion component all over - we just temporarily make one to add if we need one. Also not storing things we don't need in the shader, etc.
1 parent 4365ef5 commit 57f1e63

16 files changed

Lines changed: 362 additions & 532 deletions

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: 24 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,59 @@
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>
2525
Shader "Osvr/OsvrDistortion" {
2626
Properties
2727
{
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)
28+
_K1_Red ("K1 Red", Range (0.00,1.00)) = 0.0 // sliders
29+
_K1_Green ("K1 Green", Range (0.00,1.00)) = 0.0
30+
_K1_Blue ("K1 Blue", Range (0.00,1.00)) = 0.0
31+
_Center ("Center of Projection", Vector) = (.5,.5,0,0)
3432
_MainTex ("Base (RGB)", 2D) = "" {}
3533
}
36-
CGINCLUDE
34+
CGINCLUDE
3735
#include "UnityCG.cginc"
38-
36+
3937
struct v2f {
4038
float4 pos : SV_POSITION;
4139
float2 uv : TEXCOORD0;
4240
};
43-
41+
4442
float _K1_Red;
4543
float _K1_Green;
4644
float _K1_Blue;
47-
float4 _Full_Center;
48-
float4 _Left_Center;
49-
float4 _Right_Center;
45+
float4 _Center;
5046
sampler2D _MainTex;
5147

52-
v2f vert( appdata_img v )
48+
v2f vert( appdata_img v )
5349
{
5450
v2f o;
5551
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
5652
o.uv = v.texcoord.xy;
5753
return o;
58-
}
54+
}
5955
float2 Distort(float2 p, float k1)
6056
{
61-
62-
6357
float r2 = p.x * p.x + p.y * p.y;
64-
float r = sqrt(r2);
6558

66-
float newRadius = (1 + k1*r*r);
59+
float newRadius = (1 + k1*r2);
6760
p.x = p.x * newRadius;
6861
p.y = p.y * newRadius;
6962

7063
return p;
7164
}
72-
73-
half4 frag(v2f i) : SV_Target
65+
66+
half4 frag(v2f i) : SV_Target
7467
{
7568
float2 uv_red, uv_green, uv_blue;
7669
float4 color_red, color_green, color_blue;
7770
float2 sectorOrigin;
7871
float4 color;
7972

80-
sectorOrigin = _Full_Center.xy;
73+
sectorOrigin = _Center.xy;
8174

8275
uv_red = Distort(i.uv-sectorOrigin, _K1_Red) + sectorOrigin;
8376
uv_green = Distort(i.uv-sectorOrigin, _K1_Green) + sectorOrigin;
@@ -101,13 +94,13 @@ Properties
10194

10295
Subshader {
10396
Pass {
104-
ZTest Always Cull Off ZWrite Off
97+
ZTest Always Cull Off ZWrite Off
98+
99+
CGPROGRAM
100+
#pragma vertex vert
101+
#pragma fragment frag
102+
ENDCG
103+
}
105104

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

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)