Skip to content

Commit b8b88f7

Browse files
committed
Bug fixes
Worst of the bugs should be fixed. Apparently camera transform positions weren't being updated...
1 parent a4c76cf commit b8b88f7

7 files changed

Lines changed: 281 additions & 98 deletions

AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
1818
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
1919

20-
[assembly: AssemblyVersion("1.0.*")]
20+
[assembly: AssemblyVersion("1.3.*")]
2121

2222
// The following attributes are used to specify the signing key for the assembly,
2323
// if desired. See the Mono documentation for more information about signing.
240 KB
Binary file not shown.

Layer_Names.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Layer 0: Default
2+
Layer 1: TransparentFX
3+
Layer 2: Ignore Raycast
4+
Layer 3:
5+
Layer 4: Water
6+
Layer 5: UI
7+
Layer 6:
8+
Layer 7:
9+
Layer 8: PartsList_Icons
10+
Layer 9: Atmosphere
11+
Layer 10: Scaled Scenery
12+
Layer 11: UI_Culled
13+
Layer 12: UI_Main
14+
Layer 13: UI_Mask
15+
Layer 14: Screens
16+
Layer 15: Local Scenery
17+
Layer 16: kerbals
18+
Layer 17: Editor_UI
19+
Layer 18: SkySphere
20+
Layer 19: Disconnected Parts
21+
Layer 20: Internal Space
22+
Layer 21: Part Triggers
23+
Layer 22: KerbalInstructors
24+
Layer 23: ScaledSpaceSun
25+
Layer 24: MapFX
26+
Layer 25: EzGUI_UI
27+
Layer 26: WheelCollidersIgnore
28+
Layer 27: WheelColliders
29+
Layer 28: TerrainColliders
30+
Layer 29: DragRender
31+
Layer 30: SurfaceFX

Reflection-Plugin-Continued.userprefs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Properties>
2-
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release" PreferredExecutionTarget="MonoDevelop.Default" />
3-
<MonoDevelop.Ide.Workbench ActiveDocument="ReflectiveShaderModule.cs">
2+
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release" />
3+
<MonoDevelop.Ide.Workbench ActiveDocument="ReflectiveScript.cs">
44
<Files>
55
<File FileName="Resources\Reflective.Bumped_Diffuse.shader" Line="1" Column="1" />
66
<File FileName="Resources\Reflective.Bumped_Unlit.shader" Line="1" Column="1" />
@@ -11,16 +11,15 @@
1111
<File FileName="Resources\Reflective.Parallax_Diffuse.shader" Line="1" Column="1" />
1212
<File FileName="Resources\Reflective.Parallax_Specular.shader" Line="1" Column="1" />
1313
<File FileName="Resources\Reflective.VertexLit.shader" Line="1" Column="1" />
14-
<File FileName="ReflectiveShaderModule.cs" Line="190" Column="58" />
15-
<File FileName="ReflectiveScript.cs" Line="30" Column="3" />
14+
<File FileName="ReflectiveShaderModule.cs" Line="1" Column="1" />
15+
<File FileName="ReflectiveScript.cs" Line="145" Column="29" />
1616
</Files>
1717
<Pads>
1818
<Pad Id="ProjectPad">
1919
<State expanded="True">
2020
<Node name="ReflectionPlugin" expanded="True">
2121
<Node name="References" expanded="True" />
22-
<Node name="Resources" expanded="True" />
23-
<Node name="ReflectiveShaderModule.cs" selected="True" />
22+
<Node name="ReflectiveScript.cs" selected="True" />
2423
</Node>
2524
</State>
2625
</Pad>

ReflectionPlugin.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
<Reference Include="System" />
3535
<Reference Include="System.Core" />
3636
<Reference Include="Assembly-CSharp">
37-
<HintPath>..\..\..\..\..\Games\KSP_win_0.24.2_Ioncross_Development\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
37+
<HintPath>..\..\..\..\..\Games\KSP_win_1.0.4\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
3838
</Reference>
3939
<Reference Include="UnityEngine">
40-
<HintPath>..\..\..\..\..\Games\KSP_win_1.0\KSP_Data\Managed\UnityEngine.dll</HintPath>
40+
<HintPath>..\..\..\..\..\Games\KSP_win_1.0.4\KSP_Data\Managed\UnityEngine.dll</HintPath>
4141
</Reference>
4242
</ItemGroup>
4343
<ItemGroup>

ReflectiveScript.cs

Lines changed: 155 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22

33
namespace ReflectionPlugin
44
{
5+
public class ProcCubeMap : ProceduralCubemap
6+
{
7+
ProcCubeMap()
8+
{
9+
}
10+
}
11+
512
public class ReflectiveScript : MonoBehaviour
613
{
14+
public static int i = 0;
715
public int CubemapSize = 128;
8-
public float FarClipPlane = 100f;
16+
public Material currentMaterial;
17+
public float FarClipPlane = float.MaxValue;
918
public float NearClipPlane = -1f;
1019
public Renderer MatRenderer;
1120
public bool OneFacePerFrame;
@@ -16,6 +25,7 @@ public class ReflectiveScript : MonoBehaviour
1625

1726
private Camera _cam;
1827
private RenderTexture _rtex;
28+
private GameObject _go;
1929
public string status = "";
2030
private string renderResult = "PRE-INITIALIZATION";
2131
//private int maskBit = 12;
@@ -25,18 +35,22 @@ public class ReflectiveScript : MonoBehaviour
2535

2636
private void Start()
2737
{
28-
this.UpdateCubemap(63);
38+
//currentMaterial = renderer.material;
39+
for(int i = 0; i < 31; i++)
40+
Debug.Log (" Layer " + i.ToString () + ": " + LayerMask.LayerToName(i));
41+
UpdateCubemap(63);
42+
dirty = 7;
2943
}
3044

3145
private bool ShouldUpdate()
3246
{
33-
if (realTimeReflection || this.dirty > 0)
47+
if (realTimeReflection || dirty > 0)
3448
{
3549
return true;
3650
}
37-
else if ( Planetarium.GetUniversalTime() >= this.lastUpdate + this.updateRate && (Time.time > this.lastRealUpdate + 5f))
51+
else if ( Planetarium.GetUniversalTime() >= lastUpdate + updateRate && (Time.time > lastRealUpdate + 5f))
3852
{
39-
this.dirty = 6;
53+
dirty = 6;
4054
return true;
4155
}
4256
else
@@ -48,97 +62,191 @@ private bool ShouldUpdate()
4862
{
4963
scene = FlightGlobals.currentMainBody.name;
5064
}
51-
if (scene != this.lastScene)
65+
if (scene != lastScene)
5266
{
53-
this.dirty = 7;
54-
this.lastScene = scene;
67+
dirty = 7;
68+
lastScene = scene;
5569
return true;
5670
}
5771
}
5872
return false;
5973
}
74+
75+
protected void FixedUpdate()
76+
{
77+
_cam.transform.position = _go.transform.position = transform.position;
78+
}
6079

61-
62-
63-
private void OnPostRender()
80+
protected void LateUpdate()
6481
{
6582
if (ShouldUpdate())
6683
{
67-
if (OneFacePerFrame && this.dirty < 7)
84+
if (OneFacePerFrame && dirty < 7)
6885
{
69-
//this._cam.cullingMask = maskBit;
70-
this.UpdateCubemap(1 << Time.frameCount % 6);
86+
//_cam.cullingMask = maskBit;
87+
UpdateCubemap(1 << Time.frameCount % 6);
7188
}
7289
else
7390
{
74-
//this._cam.cullingMask = maskBit;
75-
this.UpdateCubemap(63);
91+
//_cam.cullingMask = maskBit;
92+
UpdateCubemap(63);
7693
}
7794
}
7895
else
79-
status = renderResult + ((lastUpdate + this.updateRate) - Planetarium.GetUniversalTime()).ToString();
96+
status = renderResult + ((lastUpdate + updateRate) - Planetarium.GetUniversalTime()).ToString();
8097
}
8198

82-
private void UpdateCubemap(int faceMask)
99+
/*
100+
Layer 0: Default
101+
Layer 1: TransparentFX
102+
Layer 2: Ignore Raycast
103+
Layer 3:
104+
Layer 4: Water
105+
Layer 5: UI
106+
Layer 6:
107+
Layer 7:
108+
Layer 8: PartsList_Icons
109+
Layer 9: Atmosphere
110+
Layer 10: Scaled Scenery
111+
Layer 11: UI_Culled
112+
Layer 12: UI_Main
113+
Layer 13: UI_Mask
114+
Layer 14: Screens
115+
Layer 15: Local Scenery
116+
Layer 16: kerbals
117+
Layer 17: Editor_UI
118+
Layer 18: SkySphere
119+
Layer 19: Disconnected Parts
120+
Layer 20: Internal Space
121+
Layer 21: Part Triggers
122+
Layer 22: KerbalInstructors
123+
Layer 23: ScaledSpaceSun
124+
Layer 24: MapFX
125+
Layer 25: EzGUI_UI
126+
Layer 26: WheelCollidersIgnore
127+
Layer 27: WheelColliders
128+
Layer 28: TerrainColliders
129+
Layer 29: DragRender
130+
Layer 30: SurfaceFX
131+
*/
132+
133+
protected void UpdateCubemap(int faceMask)
83134
{
84-
if (!(bool)((UnityEngine.Object)this._cam))
135+
136+
if ((object)_cam == null)
137+
{
138+
_go = new GameObject("CubemapCamera" + i.ToString ());
139+
_go.AddComponent(typeof(Camera));
140+
_go.hideFlags = HideFlags.HideAndDontSave;
141+
_go.transform.position = transform.position;
142+
_go.transform.rotation = Quaternion.identity;
143+
_go.camera.clearFlags = CameraClearFlags.Skybox;
144+
_go.camera.renderingPath = RenderingPath.UsePlayerSettings;
145+
_go.camera.depth = Camera.main.depth + 1;
146+
_go.camera.aspect = 1;
147+
float[] distances = new float[32];
148+
149+
distances[10] = 3.0E+07F;
150+
distances[15] = 3.0E+07F;
151+
152+
_go.camera.layerCullDistances = distances;
153+
154+
//_go.camera.cullingMask = LayerMask. //(1 << 0) | (1 << 4) | (1 << 9) | (1 << 10) | (1 << 15) | (1 << 18) | (1 << 23);
155+
_cam = _go.camera;
156+
_cam.nearClipPlane = NearClipPlane;
157+
_cam.farClipPlane = FarClipPlane;
158+
_cam.enabled = false;
159+
i += 1;
160+
}
161+
162+
163+
/*
164+
if (!(bool)((UnityEngine.Object)_cam))
85165
{
86-
GameObject gameObject1 = new GameObject("ReflectionCamera", new System.Type[1] { typeof(Camera) });
166+
GameObject gameObject1 = new GameObject("CubemapCamera", new System.Type[1] { typeof(Camera) });
87167
gameObject1.hideFlags = HideFlags.HideAndDontSave;
88168
GameObject gameObject2 = gameObject1;
89-
gameObject2.transform.position = this.transform.position;
169+
gameObject2.transform.position = transform.position;
90170
gameObject2.transform.rotation = Quaternion.identity;
91-
this._cam = gameObject2.camera;
92-
this._cam.hdr = true;
93-
this._cam.depth = Camera.main.depth + 1;
94-
this._cam.farClipPlane = this.FarClipPlane;
95-
this._cam.enabled = false;
96-
this._cam.cullingMask = (1 << 0) | (1 << 4) | (1 << 9) | (1 << 10) | (1 << 15) | (1 << 18) | (1 << 23);
97-
//this._cam.cullingMask = (1 << maskBit);
98-
this._cam.layerCullSpherical = true;
99-
if (this.NearClipPlane > 0f)
100-
this._cam.nearClipPlane = this.NearClipPlane;
171+
_cam = gameObject2.camera;
172+
//_cam.hdr = true;
173+
_cam.depth = Camera.main.depth + 1;//Camera.main.depth + 1;
174+
_cam.farClipPlane = FarClipPlane;
175+
_cam.enabled = false;
176+
_cam.cullingMask = (1 << 0) | (1 << 4) | (1 << 9) | (1 << 10) | (1 << 15) | (1 << 18) | (1 << 23);
177+
//_cam.cullingMask = (1 << maskBit);
178+
//_cam.layerCullSpherical = true;
179+
if (NearClipPlane > 0f)
180+
_cam.nearClipPlane = NearClipPlane;
101181
for (int i = 0; i < 32; i++)
102182
{
103-
this._cam.layerCullDistances[i] = int.MaxValue;
183+
_cam.layerCullDistances[i] = int.MaxValue;
104184
}
105-
// -1 -False True
106-
//this.status = this._cam.cullingMask.ToString();
107-
//this._cam.cullingMask = 32771;
185+
status = _cam.cullingMask.ToString();
108186
}
109-
if (!(bool)((UnityEngine.Object)this._rtex))
187+
*/
188+
if ((object)_rtex == null)
110189
{
111190
ReflectiveScript reflectiveScript = this;
112-
RenderTexture renderTexture1 = new RenderTexture(this.CubemapSize, this.CubemapSize, 16);
191+
RenderTexture renderTexture1 = new RenderTexture(CubemapSize, CubemapSize, 16);
113192
renderTexture1.isCubemap = true;
193+
renderTexture1.isPowerOfTwo = true;
114194
renderTexture1.hideFlags = HideFlags.HideAndDontSave;
195+
renderTexture1.useMipMap = true;
196+
renderTexture1.wrapMode = TextureWrapMode.Clamp;
115197
RenderTexture renderTexture2 = renderTexture1;
198+
_cam.backgroundColor = Color.black;
199+
116200
reflectiveScript._rtex = renderTexture2;
117-
this.MatRenderer.sharedMaterial.SetTexture("_Cube", (Texture)this._rtex);
201+
//MatRenderer.sharedMaterial.SetTexture("_Cube", (Texture)_rtex);
202+
foreach (Renderer r in GetComponentsInChildren<Renderer>())
203+
{
204+
foreach (Material m in r.sharedMaterials)
205+
{
206+
if (m.HasProperty("_Cube"))
207+
{
208+
m.SetTexture("_Cube", _rtex);
209+
}
210+
}
211+
}
118212
}
119-
this._cam.transform.position = this.transform.position;
120-
if (this._cam.RenderToCubemap(this._rtex, faceMask))
213+
if ((object)_cam == null)
214+
Debug.Log ("_cam null");
215+
if ((object)_rtex == null)
216+
Debug.Log ("_rtex null");
217+
if ((object)_go == null)
218+
Debug.Log ("_go null");
219+
220+
221+
_cam.transform.position = transform.position;
222+
if (_cam.RenderToCubemap(_rtex, faceMask))
121223
{
122-
this.lastUpdate = Planetarium.GetUniversalTime();
123-
this.lastRealUpdate = Time.time;
224+
//Debug.Log ("Checking time");
225+
lastUpdate = Planetarium.GetUniversalTime();
226+
lastRealUpdate = Time.time;
227+
//Debug.Log ("Setting material");
228+
//currentMaterial.SetTexture ("_Cube", _rtex);
229+
//renderer.material = currentMaterial;
124230
renderResult = "Success: (next)";
125-
if (this.dirty > 0)
231+
if (dirty > 0)
126232
{
127233
if (faceMask == 63)
128-
this.dirty = 0;
234+
dirty = 0;
129235
else
130236
{
131-
this.dirty -= 1;
237+
dirty -= 1;
132238
}
133239
}
134240
}
135241
else
136242
renderResult = "Failure: (next)";
243+
//Debug.Log ("Result = " + renderResult);
137244
}
138245
private void OnDisable()
139246
{
140-
UnityEngine.Object.DestroyImmediate((UnityEngine.Object)this._cam);
141-
UnityEngine.Object.DestroyImmediate((UnityEngine.Object)this._rtex);
247+
UnityEngine.Object.DestroyImmediate((UnityEngine.Object)_cam);
248+
UnityEngine.Object.DestroyImmediate((UnityEngine.Object)_rtex);
249+
UnityEngine.Object.DestroyImmediate((UnityEngine.Object)_go);
142250
}
143251
}
144252
}

0 commit comments

Comments
 (0)