Skip to content

Commit 1541f03

Browse files
author
Camacho
committed
Updated to a new version of unity, 2018.1.4f1. Also fixed a bug, where divison by zero would cause the screen to go black
1 parent fd25ac0 commit 1541f03

File tree

5 files changed

+26
-19
lines changed

5 files changed

+26
-19
lines changed

Assets/OpenRelativity/Shaders/desaturateShader.shader

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
2+
13
Shader "Colors/Desaturate" {
24
Properties {
35
_MainTex ("Base (RGB)", 2D) = "" {}
@@ -78,7 +80,7 @@ Shader "Colors/Desaturate" {
7880
v2f vert( appdata_img v ) {
7981
v2f o;
8082

81-
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
83+
o.pos = UnityObjectToClipPos(v.vertex);
8284
o.uv1.xy = v.texcoord;
8385

8486
//You need this otherwise the screen flips and weird stuff happens

Assets/OpenRelativity/Shaders/relativity.shader

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
2+
// Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
3+
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
4+
15
Shader "Relativity/ColorShift"
26
{
37
Properties
@@ -80,7 +84,7 @@ Shader "Relativity/ColorShift"
8084
{
8185
v2f o;
8286

83-
o.pos = mul(_Object2World, v.vertex); //get position in world frame
87+
o.pos = mul(unity_ObjectToWorld, v.vertex); //get position in world frame
8488
o.pos -= _playerOffset; //Shift such that we use a coordinate system where the player is at 0,0,0
8589

8690

@@ -91,17 +95,10 @@ Shader "Relativity/ColorShift"
9195

9296

9397
float vuDot = (_vpc.x*_viw.x + _vpc.y*_viw.y + _vpc.z*_viw.z); //Get player velocity dotted with velocity of the object.
94-
float4 uparra;
95-
//IF our speed is zero, this parallel velocity component will be NaN, so we have a check here just to be safe
96-
if ( speed != 0 )
97-
{
98-
uparra = (vuDot/(speed*speed)) * _vpc; //Get the parallel component of the object's velocity
99-
}
100-
//If our speed is zero, set parallel velocity to zero
101-
else
102-
{
103-
uparra = 0;
104-
}
98+
99+
float4 uparra = (vuDot / (speed * speed)) * _vpc;
100+
uparra = !(isnan(uparra) || isinf(uparra)) ? uparra : 0;
101+
105102
//Get the perpendicular component of our velocity, just by subtraction
106103
float4 uperp = _viw - uparra;
107104
//relative velocity calculation
@@ -229,13 +226,13 @@ Shader "Relativity/ColorShift"
229226
riw += _playerOffset;
230227

231228
//Transform the vertex back into local space for the mesh to use it
232-
o.pos = mul(_World2Object*1.0,riw);
229+
o.pos = mul(unity_WorldToObject*1.0,riw);
233230

234-
o.pos2 = mul(_Object2World, o.pos );
231+
o.pos2 = mul(unity_ObjectToWorld, o.pos );
235232
o.pos2 -= _playerOffset;
236233

237234

238-
o.pos = mul(UNITY_MATRIX_MVP, o.pos);
235+
o.pos = UnityObjectToClipPos(o.pos);
239236

240237

241238
return o;

Assets/OpenRelativity/Shaders/skybox.shader

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
2+
// Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
3+
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
4+
15
Shader "Relativity/SkyboxShift" {
26
Properties {
37
_MainTex ("Base (RGB)", 2D) = "" {}
@@ -72,8 +76,8 @@ Shader "Relativity/SkyboxShift" {
7276
v2f o;
7377

7478

75-
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
76-
o.pos2 = mul(_Object2World, v.vertex);
79+
o.pos = UnityObjectToClipPos(v.vertex);
80+
o.pos2 = mul(unity_ObjectToWorld, v.vertex);
7781

7882
o.pos2 -= _playerOffset;
7983

@@ -220,7 +224,7 @@ Shader "Relativity/SkyboxShift" {
220224
float3 rgbFinal = XYZToRGBC(xf,yf,zf);
221225
//rgbFinal = constrainRGB(rgbFinal.x,rgbFinal.y, rgbFinal.z);
222226

223-
float4x4 temp = mul(1.0*_Object2World, _World2Object);
227+
float4x4 temp = mul(1.0*unity_ObjectToWorld, unity_WorldToObject);
224228
float4 temp2 = mul( temp,float4( (float)rgbFinal.x,(float)rgbFinal.y,(float)rgbFinal.z,1));
225229
//float4 temp2 =float4( (float)rgbFinal.x,(float)rgbFinal.y,(float)rgbFinal.z,1);
226230
return temp2;

Packages/manifest.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"dependencies": {
3+
}
4+
}
Binary file not shown.

0 commit comments

Comments
 (0)