Skip to content

Commit aaac662

Browse files
committed
Separate settings and display index
1 parent 07d837c commit aaac662

18 files changed

+524
-76
lines changed

.idea/.idea.ipw-firmware/.idea/.gitignore

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.ipw-firmware/.idea/indexLayout.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.ipw-firmware/.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Materials/ProjectorMaterial.mat

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Material:
116116
- _Overlap2: 0.0576
117117
- _Parallax: 0.005
118118
- _Power: 2
119-
- _Power2: 2.058
119+
- _Power2: 2
120120
- _QueueOffset: 0
121121
- _ReceiveShadows: 1
122122
- _Smoothness: 0.5

Assets/Rendering/MeshUtils.cs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using UnityEngine;
2+
3+
public static class MeshUtils
4+
{
5+
public static Mesh CreateTransform(Vector3[] v)
6+
{
7+
var mesh = new Mesh
8+
{
9+
vertices = v,
10+
triangles = new int[] { 0, 1, 2, 0, 2, 3 }
11+
};
12+
13+
var shiftedPositions = new Vector2[] { Vector2.zero, new Vector2(0, v[1].y - v[0].y), new Vector2(v[2].x - v[1].x, v[2].y - v[3].y), new Vector2(v[3].x - v[0].x, 0) };
14+
mesh.uv = shiftedPositions;
15+
16+
var widthsHeights = new Vector2[4];
17+
widthsHeights[0].x = widthsHeights[3].x = shiftedPositions[3].x;
18+
widthsHeights[1].x = widthsHeights[2].x = shiftedPositions[2].x;
19+
widthsHeights[0].y = widthsHeights[1].y = shiftedPositions[1].y;
20+
widthsHeights[2].y = widthsHeights[3].y = shiftedPositions[2].y;
21+
mesh.uv2 = widthsHeights;
22+
23+
mesh.UploadMeshData(false);
24+
return mesh;
25+
}
26+
}

Assets/Rendering/MeshUtils.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class ProjectorTransformationData
6+
{
7+
public Mesh ScreenMesh = MeshUtils.CreateTransform(new Vector3[] { new Vector3(-1, -1, 0), new Vector3(-1, 1, 0), new Vector3(1, 1, 0), new Vector3(1, -1, 0) });
8+
public float Saturation = 1f;
9+
public float Brightness = 0f;
10+
public float Contrast = 1f;
11+
12+
/// <summary>
13+
/// Flips all transformations for use on mirrored screen
14+
/// </summary>
15+
public bool FlipCurve = false;
16+
17+
/// <summary>
18+
/// Determines the amount of darkened crossover space in the middle of the IPW
19+
/// </summary>
20+
public float CrossOver = 0.05f;
21+
22+
/// <summary>
23+
/// Enables dimming and anti-distortion ransformations
24+
/// </summary>
25+
public bool EnableCurve = true;
26+
}

Assets/Rendering/ProjectorTransformationData.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Rendering/ProjectorTransformationPass.cs

+5-39
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,21 @@ public class ProjectorTransformationPass : ScriptableRenderPass
99
private RenderTargetHandle _tempTexture;
1010

1111
public const int MAX_DISPLAYS = 8; // Unity limit
12-
public static Mesh[] ScreenMeshes = new Mesh[MAX_DISPLAYS];
12+
public static ProjectorTransformationData[] ScreenData = new ProjectorTransformationData[MAX_DISPLAYS];
1313
public static float[] Saturation = new float[MAX_DISPLAYS];
1414
public static float[] Brightness = new float[MAX_DISPLAYS];
1515
public static float[] Contrast = new float[MAX_DISPLAYS];
1616
public static bool[] FlipCurve = new bool[MAX_DISPLAYS];
1717
public static float[] CrossOver = new float[MAX_DISPLAYS];
1818
public static bool EnableCurve = true;
1919

20-
public static Mesh CreateTransform(Vector3[] v)
21-
{
22-
var mesh = new Mesh
23-
{
24-
vertices = v,
25-
triangles = new int[] { 0, 1, 2, 0, 2, 3 }
26-
};
27-
28-
var shiftedPositions = new Vector2[] { Vector2.zero, new Vector2(0, v[1].y - v[0].y), new Vector2(v[2].x - v[1].x, v[2].y - v[3].y), new Vector2(v[3].x - v[0].x, 0) };
29-
mesh.uv = shiftedPositions;
30-
31-
var widthsHeights = new Vector2[4];
32-
widthsHeights[0].x = widthsHeights[3].x = shiftedPositions[3].x;
33-
widthsHeights[1].x = widthsHeights[2].x = shiftedPositions[2].x;
34-
widthsHeights[0].y = widthsHeights[1].y = shiftedPositions[1].y;
35-
widthsHeights[2].y = widthsHeights[3].y = shiftedPositions[2].y;
36-
mesh.uv2 = widthsHeights;
37-
38-
mesh.UploadMeshData(false);
39-
return mesh;
40-
}
41-
4220
public ProjectorTransformationPass(string profilerTag, RenderPassEvent renderPassEvent, Material materialToBlit)
4321
{
4422
this.renderPassEvent = renderPassEvent;
4523
_profilerTag = profilerTag;
4624
_materialToBlit = materialToBlit;
4725

48-
ScreenMeshes[0] = CreateTransform(new Vector3[] { new Vector3(-1, -1, 0), new Vector3(-1, 1, 0), new Vector3(1, 1, 0), new Vector3(1, -1, 0) });
49-
Saturation[0] = 1f;
50-
Brightness[0] = 0f;
51-
Contrast[0] = 1f;
52-
CrossOver[0] = 0.05f;
53-
54-
for (int i = 1; i < MAX_DISPLAYS; i++)
55-
{
56-
ScreenMeshes[i] = Object.Instantiate(ScreenMeshes[0]);
57-
Saturation[i] = Saturation[0];
58-
Brightness[i] = Brightness[0];
59-
Contrast[i] = Contrast[0];
60-
}
26+
for (int i = 0; i < MAX_DISPLAYS; i++) ScreenData[i] = new ProjectorTransformationData();
6127
}
6228

6329
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
@@ -82,11 +48,11 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
8248
cmd.SetGlobalFloat(Shader.PropertyToID("crossOver"), CrossOver[displayNumber]);
8349
cmd.ClearRenderTarget(false, true, Color.black);
8450

85-
var mesh = ScreenMeshes[displayNumber];
51+
var mesh = ScreenData[displayNumber].ScreenMesh;
8652
if (mesh == null) // Editor doesn't always call the constructor
8753
{
88-
mesh = CreateTransform(new Vector3[] { new Vector3(-1, -1, 0), new Vector3(-1, 1, 0), new Vector3(1, 1, 0), new Vector3(1, -1, 0) });
89-
ScreenMeshes[displayNumber] = mesh;
54+
mesh = MeshUtils.CreateTransform(new Vector3[] { new Vector3(-1, -1, 0), new Vector3(-1, 1, 0), new Vector3(1, 1, 0), new Vector3(1, -1, 0) });
55+
ScreenData[displayNumber].ScreenMesh = mesh;
9056
}
9157

9258
cmd.DrawMesh(mesh, Matrix4x4.identity, _materialToBlit, 0, 0);

0 commit comments

Comments
 (0)