Skip to content

Commit ea19124

Browse files
committed
[fptl] first pass at code cleanup and coding conventions compliance
1 parent e3d6e6b commit ea19124

13 files changed

Lines changed: 1004 additions & 984 deletions

Assets/ScriptableRenderLoop/ForwardRenderLoop/ForwardRenderLoop.cs

Lines changed: 91 additions & 91 deletions
Large diffs are not rendered by default.

Assets/ScriptableRenderLoop/common/SkyboxHelper.cs

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,41 @@ public SkyboxHelper()
99
{
1010
}
1111

12-
const int NumFullSubdivisions = 3; // 3 subdivs == 2048 triangles
13-
const int NumHorizonSubdivisions = 2;
12+
const int k_NumFullSubdivisions = 3; // 3 subdivs == 2048 triangles
13+
const int k_NumHorizonSubdivisions = 2;
1414

1515
public void CreateMesh()
1616
{
17-
Vector3[] vertData = new Vector3[8 * 3];
18-
for (int i = 0; i < 8 * 3; i++)
17+
var vertData = new Vector3[8 * 3];
18+
for (var i = 0; i < 8 * 3; i++)
1919
{
20-
vertData[i] = octaVerts[i];
20+
vertData[i] = m_OctaVerts[i];
2121
}
2222

2323
// Regular subdivisions
24-
for (int i = 0; i < NumFullSubdivisions; i++)
24+
for (var i = 0; i < k_NumFullSubdivisions; i++)
2525
{
26-
Vector3[] srcData = vertData.Clone() as Vector3[];
27-
List<Vector3> verts = new List<Vector3>();
26+
var srcData = vertData.Clone() as Vector3[];
27+
var verts = new List<Vector3>();
2828

29-
for (int k = 0; k < srcData.Length; k += 3)
29+
for (var k = 0; k < srcData.Length; k += 3)
3030
{
3131
Subdivide(verts, srcData[k], srcData[k + 1], srcData[k + 2]);
3232
}
3333
vertData = verts.ToArray();
3434
}
3535

3636
// Horizon subdivisions
37-
float horizonLimit = 1.0f;
38-
for (int i = 0; i < NumHorizonSubdivisions; i++)
37+
var horizonLimit = 1.0f;
38+
for (var i = 0; i < k_NumHorizonSubdivisions; i++)
3939
{
40-
Vector3[] srcData = vertData.Clone() as Vector3[];
41-
List<Vector3> verts = new List<Vector3>();
40+
var srcData = vertData.Clone() as Vector3[];
41+
var verts = new List<Vector3>();
4242

4343
horizonLimit *= 0.5f; // First iteration limit to y < +-0.5, next one 0.25 etc.
44-
for (int k = 0; k < srcData.Length; k += 3)
44+
for (var k = 0; k < srcData.Length; k += 3)
4545
{
46-
float maxAbsY = Mathf.Max(Mathf.Abs(srcData[k].y), Mathf.Abs(srcData[k + 1].y), Mathf.Abs(srcData[k + 2].y));
46+
var maxAbsY = Mathf.Max(Mathf.Abs(srcData[k].y), Mathf.Abs(srcData[k + 1].y), Mathf.Abs(srcData[k + 2].y));
4747
if (maxAbsY > horizonLimit)
4848
{
4949
// Pass through existing triangle
@@ -60,21 +60,23 @@ public void CreateMesh()
6060
}
6161

6262
// Write out the mesh
63-
int vertexCount = vertData.Length;
63+
var vertexCount = vertData.Length;
6464
var triangles = new int[vertexCount];
65-
for (int i = 0; i < vertexCount; i++)
65+
for (var i = 0; i < vertexCount; i++)
6666
{
6767
triangles[i] = i;
6868
}
6969

70-
_mesh = new Mesh();
71-
_mesh.vertices = vertData;
72-
_mesh.triangles = triangles;
70+
m_Mesh = new Mesh
71+
{
72+
vertices = vertData,
73+
triangles = triangles
74+
};
7375
}
7476

7577
public UnityEngine.Mesh mesh
7678
{
77-
get { return _mesh; }
79+
get { return m_Mesh; }
7880
}
7981

8082
public void Draw(RenderLoop loop, Camera camera)
@@ -84,17 +86,16 @@ public void Draw(RenderLoop loop, Camera camera)
8486
return;
8587
}
8688

87-
Material mat = RenderSettings.skybox;
89+
var mat = RenderSettings.skybox;
8890

8991
if (mat == null)
9092
{
9193
return;
9294
}
9395

94-
CommandBuffer cmd = new CommandBuffer();
95-
cmd.name = "Skybox";
96+
var cmd = new CommandBuffer { name = "Skybox" };
9697

97-
bool looksLikeSixSidedShader = true;
98+
var looksLikeSixSidedShader = true;
9899
looksLikeSixSidedShader &= (mat.passCount == 6); // should have six passes
99100
//looksLikeSixSidedShader &= !mat.GetShader()->GetShaderLabShader()->HasLightingPasses();
100101

@@ -109,11 +110,11 @@ public void Draw(RenderLoop loop, Camera camera)
109110
CreateMesh();
110111
}
111112

112-
float dist = camera.farClipPlane * 10.0f;
113+
var dist = camera.farClipPlane * 10.0f;
113114

114-
Matrix4x4 world = Matrix4x4.TRS(camera.transform.position, Quaternion.identity, new Vector3(dist, dist, dist));
115+
var world = Matrix4x4.TRS(camera.transform.position, Quaternion.identity, new Vector3(dist, dist, dist));
115116

116-
Matrix4x4 skyboxProj = SkyboxHelper.GetProjectionMatrix(camera);
117+
var skyboxProj = SkyboxHelper.GetProjectionMatrix(camera);
117118
cmd.SetProjectionAndViewMatrices(skyboxProj, camera.worldToCameraMatrix);
118119
cmd.DrawMesh(mesh, world, mat);
119120

@@ -124,11 +125,11 @@ public void Draw(RenderLoop loop, Camera camera)
124125
cmd.Dispose();
125126
}
126127

127-
static public Matrix4x4 GetProjectionMatrix(Camera camera)
128+
public static Matrix4x4 GetProjectionMatrix(Camera camera)
128129
{
129-
Matrix4x4 skyboxProj = Matrix4x4.Perspective(camera.fieldOfView, camera.aspect, camera.nearClipPlane, camera.farClipPlane);
130+
var skyboxProj = Matrix4x4.Perspective(camera.fieldOfView, camera.aspect, camera.nearClipPlane, camera.farClipPlane);
130131

131-
float nearPlane = camera.nearClipPlane * 0.01f;
132+
var nearPlane = camera.nearClipPlane * 0.01f;
132133
skyboxProj = AdjustDepthRange(skyboxProj, camera.nearClipPlane, nearPlane, camera.farClipPlane);
133134
return MakeProjectionInfinite(skyboxProj, nearPlane);
134135
}
@@ -137,7 +138,7 @@ static Matrix4x4 MakeProjectionInfinite(Matrix4x4 m, float nearPlane)
137138
{
138139
const float epsilon = 1e-6f;
139140

140-
Matrix4x4 r = m;
141+
var r = m;
141142
r[2, 2] = -1.0f + epsilon;
142143
r[2, 3] = (-2.0f + epsilon) * nearPlane;
143144
r[3, 2] = -1.0f;
@@ -146,24 +147,24 @@ static Matrix4x4 MakeProjectionInfinite(Matrix4x4 m, float nearPlane)
146147

147148
static Matrix4x4 AdjustDepthRange(Matrix4x4 mat, float origNear, float newNear, float newFar)
148149
{
149-
float x = mat[0, 0];
150-
float y = mat[1, 1];
151-
float w = mat[0, 2];
152-
float z = mat[1, 2];
150+
var x = mat[0, 0];
151+
var y = mat[1, 1];
152+
var w = mat[0, 2];
153+
var z = mat[1, 2];
153154

154-
float r = ((2.0f * origNear) / x) * ((w + 1) * 0.5f);
155-
float t = ((2.0f * origNear) / y) * ((z + 1) * 0.5f);
156-
float l = ((2.0f * origNear) / x) * (((w + 1) * 0.5f) - 1);
157-
float b = ((2.0f * origNear) / y) * (((z + 1) * 0.5f) - 1);
155+
var r = ((2.0f * origNear) / x) * ((w + 1) * 0.5f);
156+
var t = ((2.0f * origNear) / y) * ((z + 1) * 0.5f);
157+
var l = ((2.0f * origNear) / x) * (((w + 1) * 0.5f) - 1);
158+
var b = ((2.0f * origNear) / y) * (((z + 1) * 0.5f) - 1);
158159

159-
float ratio = (newNear / origNear);
160+
var ratio = (newNear / origNear);
160161

161162
r *= ratio;
162163
t *= ratio;
163164
l *= ratio;
164165
b *= ratio;
165166

166-
Matrix4x4 ret = new Matrix4x4();
167+
var ret = new Matrix4x4();
167168

168169
ret[0, 0] = (2.0f * newNear) / (r - l); ret[0, 1] = 0; ret[0, 2] = (r + l) / (r - l); ret[0, 3] = 0;
169170
ret[1, 0] = 0; ret[1, 1] = (2.0f * newNear) / (t - b); ret[1, 2] = (t + b) / (t - b); ret[1, 3] = 0;
@@ -174,7 +175,7 @@ static Matrix4x4 AdjustDepthRange(Matrix4x4 mat, float origNear, float newNear,
174175
}
175176

176177
// Octahedron vertices
177-
Vector3[] octaVerts =
178+
readonly Vector3[] m_OctaVerts =
178179
{
179180
new Vector3(0.0f, 1.0f, 0.0f), new Vector3(0.0f, 0.0f, -1.0f), new Vector3(1.0f, 0.0f, 0.0f),
180181
new Vector3(0.0f, 1.0f, 0.0f), new Vector3(1.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f),
@@ -191,11 +192,11 @@ Vector3 SubDivVert(Vector3 v1, Vector3 v2)
191192
return Vector3.Normalize(v1 + v2);
192193
}
193194

194-
void Subdivide(List<Vector3> dest, Vector3 v1, Vector3 v2, Vector3 v3)
195+
void Subdivide(ICollection<Vector3> dest, Vector3 v1, Vector3 v2, Vector3 v3)
195196
{
196-
Vector3 v12 = SubDivVert(v1, v2);
197-
Vector3 v23 = SubDivVert(v2, v3);
198-
Vector3 v13 = SubDivVert(v1, v3);
197+
var v12 = SubDivVert(v1, v2);
198+
var v23 = SubDivVert(v2, v3);
199+
var v13 = SubDivVert(v1, v3);
199200

200201
dest.Add(v1);
201202
dest.Add(v12);
@@ -211,13 +212,13 @@ void Subdivide(List<Vector3> dest, Vector3 v1, Vector3 v2, Vector3 v3)
211212
dest.Add(v23);
212213
}
213214

214-
void SubdivideYOnly(List<Vector3> dest, Vector3 v1, Vector3 v2, Vector3 v3)
215+
void SubdivideYOnly(ICollection<Vector3> dest, Vector3 v1, Vector3 v2, Vector3 v3)
215216
{
216217
// Find out which vertex is furthest out from the others on the y axis
217218

218-
float d12 = Mathf.Abs(v2.y - v1.y);
219-
float d23 = Mathf.Abs(v2.y - v3.y);
220-
float d31 = Mathf.Abs(v3.y - v1.y);
219+
var d12 = Mathf.Abs(v2.y - v1.y);
220+
var d23 = Mathf.Abs(v2.y - v3.y);
221+
var d31 = Mathf.Abs(v3.y - v1.y);
221222

222223
Vector3 top, va, vb;
223224

@@ -240,8 +241,8 @@ void SubdivideYOnly(List<Vector3> dest, Vector3 v1, Vector3 v2, Vector3 v3)
240241
vb = v1;
241242
}
242243

243-
Vector3 v12 = SubDivVert(top, va);
244-
Vector3 v13 = SubDivVert(top, vb);
244+
var v12 = SubDivVert(top, va);
245+
var v13 = SubDivVert(top, vb);
245246

246247
dest.Add(top);
247248
dest.Add(v12);
@@ -268,5 +269,5 @@ void SubdivideYOnly(List<Vector3> dest, Vector3 v1, Vector3 v2, Vector3 v3)
268269
}
269270
}
270271

271-
Mesh _mesh;
272+
Mesh m_Mesh;
272273
}

0 commit comments

Comments
 (0)