Skip to content

Commit c1c43cf

Browse files
committed
Bug fixes + KSP 1.0.5 compilation
* Fixed long standing detached transform bug * Fixed rendering artifacts * Switched to multi-pass rendering (as done in Texture Replacer... MULTI-PAAAASSSS) * Compiled for KSP 1.0.5 * Included version file
1 parent 6df93e3 commit c1c43cf

8 files changed

Lines changed: 8828 additions & 36103 deletions
-1.06 MB
Binary file not shown.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"NAME":"Reflection Plugin Continued",
3+
"URL":"https://raw.githubusercontent.com/Starwaster/Reflection-Plugin-Continued/master/ReflectionPlugin.version",
4+
"DOWNLOAD":"https://github.com/Starwaster/Reflection-Plugin-Continued/releases",
5+
"GITHUB":
6+
{
7+
"USERNAME":"Starwaster",
8+
"REPOSITORY":"Reflection-Plugin-Continued",
9+
"ALLOW_PRE_RELEASE":false,
10+
},
11+
"VERSION":
12+
{
13+
"MAJOR":2,
14+
"MINOR":0,
15+
"PATCH":0,
16+
"BUILD":0
17+
},
18+
"KSP_VERSION":
19+
{
20+
"MAJOR":1,
21+
"MINOR":0,
22+
"PATCH":5
23+
},
24+
"KSP_VERSION_MIN":
25+
{
26+
"MAJOR":1,
27+
"MINOR":0,
28+
"PATCH":0
29+
},
30+
"KSP_VERSION_MAX":
31+
{
32+
"MAJOR":1,
33+
"MINOR":0,
34+
"PATCH":5
35+
}
36+
}
Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,13 @@
1-
<Properties>
2-
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release" />
3-
<MonoDevelop.Ide.Workbench ActiveDocument="ReflectiveScript.cs">
4-
<Files>
5-
<File FileName="Resources\Reflective.Bumped_Diffuse.shader" Line="1" Column="1" />
6-
<File FileName="Resources\Reflective.Bumped_Unlit.shader" Line="1" Column="1" />
7-
<File FileName="Resources\Reflective.Bumped_Specular.shader" Line="1" Column="1" />
8-
<File FileName="Resources\Reflective.Bumped_VertexLit.shader" Line="1" Column="1" />
9-
<File FileName="Resources\Reflective.Diffuse.shader" Line="1" Column="1" />
10-
<File FileName="Resources\Reflective.Specular.shader" Line="1" Column="1" />
11-
<File FileName="Resources\Reflective.Parallax_Diffuse.shader" Line="1" Column="1" />
12-
<File FileName="Resources\Reflective.Parallax_Specular.shader" Line="1" Column="1" />
13-
<File FileName="Resources\Reflective.VertexLit.shader" Line="1" Column="1" />
14-
<File FileName="ReflectiveShaderModule.cs" Line="1" Column="1" />
15-
<File FileName="ReflectiveScript.cs" Line="145" Column="29" />
16-
</Files>
17-
<Pads>
18-
<Pad Id="ProjectPad">
19-
<State expanded="True">
20-
<Node name="ReflectionPlugin" expanded="True">
21-
<Node name="References" expanded="True" />
22-
<Node name="ReflectiveScript.cs" selected="True" />
23-
</Node>
24-
</State>
25-
</Pad>
26-
</Pads>
27-
</MonoDevelop.Ide.Workbench>
28-
<MonoDevelop.Ide.DebuggingService.Breakpoints>
29-
<BreakpointStore />
30-
</MonoDevelop.Ide.DebuggingService.Breakpoints>
31-
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
1+
<Properties>
2+
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release" />
3+
<MonoDevelop.Ide.Workbench ActiveDocument="ReflectiveScript.cs">
4+
<Files>
5+
<File FileName="ReflectiveScript.cs" Line="140" Column="7" />
6+
<File FileName="ReflectiveShaderModule.cs" Line="66" Column="25" />
7+
</Files>
8+
</MonoDevelop.Ide.Workbench>
9+
<MonoDevelop.Ide.DebuggingService.Breakpoints>
10+
<BreakpointStore />
11+
</MonoDevelop.Ide.DebuggingService.Breakpoints>
12+
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
3213
</Properties>

ReflectionPlugin.csproj

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
55
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6-
<ProductVersion>10.0.0</ProductVersion>
6+
<ProductVersion>8.0.30703</ProductVersion>
77
<SchemaVersion>2.0</SchemaVersion>
88
<ProjectGuid>{729C879C-030C-4473-8B33-7DFBF3C4431A}</ProjectGuid>
99
<OutputType>Library</OutputType>
@@ -33,11 +33,8 @@
3333
<ItemGroup>
3434
<Reference Include="System" />
3535
<Reference Include="System.Core" />
36-
<Reference Include="Assembly-CSharp">
37-
<HintPath>..\..\..\..\..\Games\KSP_win_1.0.4\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
38-
</Reference>
3936
<Reference Include="UnityEngine">
40-
<HintPath>..\..\..\..\..\Games\KSP_win_1.0.4\KSP_Data\Managed\UnityEngine.dll</HintPath>
37+
<HintPath>..\..\..\..\..\Games\KSP_win_1.0.5\KSP_Data\Managed\UnityEngine.dll</HintPath>
4138
</Reference>
4239
</ItemGroup>
4340
<ItemGroup>
@@ -50,15 +47,9 @@
5047
<Folder Include="Resources\" />
5148
</ItemGroup>
5249
<ItemGroup>
53-
<EmbeddedResource Include="Resources\Reflective.Bumped_Diffuse.shader">
54-
<LogicalName>ReflectionPlugin.Resources.Reflective.Bumped_Diffuse.shader</LogicalName>
55-
</EmbeddedResource>
56-
<EmbeddedResource Include="Resources\Reflective.Bumped_Specular.shader">
57-
<LogicalName>ReflectionPlugin.Resources.Reflective.Bumped_Specular.shader</LogicalName>
58-
</EmbeddedResource>
59-
<EmbeddedResource Include="Resources\Reflective.Bumped_Unlit.shader">
60-
<LogicalName>ReflectionPlugin.Resources.Reflective.Bumped_Unlit.shader</LogicalName>
61-
</EmbeddedResource>
50+
<EmbeddedResource Include="Resources\Reflective.Bumped_Diffuse.shader" />
51+
<EmbeddedResource Include="Resources\Reflective.Bumped_Specular.shader" />
52+
<EmbeddedResource Include="Resources\Reflective.Bumped_Unlit.shader" />
6253
<EmbeddedResource Include="Resources\Reflective.VertexLit.shader" />
6354
<EmbeddedResource Include="Resources\Reflective.Specular.shader" />
6455
<EmbeddedResource Include="Resources\Reflective.Parallax_Specular.shader" />

ReflectionPlugin_2.0.zip

1.1 MB
Binary file not shown.

ReflectiveScript.cs

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ public class ReflectiveScript : MonoBehaviour
1515
public int CubemapSize = 128;
1616
public Material currentMaterial;
1717
public float FarClipPlane = float.MaxValue;
18-
public float NearClipPlane = -1f;
18+
public float NearClipPlane = 0.125f;
1919
public Renderer MatRenderer;
2020
public bool OneFacePerFrame;
21-
public bool realTimeReflection = true;
22-
public double updateRate = 0.0;
21+
public bool realTimeReflection = false;
22+
public double updateRate = 300.0f;
2323
public int dirty = 7;
24+
public float scaledFaderEnd = 70000;
2425
//private int maskBit;
2526

2627
private Camera _cam;
@@ -72,12 +73,12 @@ private bool ShouldUpdate()
7273
return false;
7374
}
7475

75-
protected void FixedUpdate()
76-
{
77-
_cam.transform.position = _go.transform.position = transform.position;
78-
}
76+
//protected void FixedUpdate()
77+
//{
78+
// _cam.transform.position = _go.transform.position = transform.position;
79+
//}
7980

80-
protected void LateUpdate()
81+
protected void Update()
8182
{
8283
if (ShouldUpdate())
8384
{
@@ -135,56 +136,30 @@ protected void UpdateCubemap(int faceMask)
135136

136137
if ((object)_cam == null)
137138
{
138-
_go = new GameObject("CubemapCamera" + i.ToString ());
139-
_go.AddComponent(typeof(Camera));
139+
_go = new GameObject("CubemapCamera");
140+
_go.AddComponent<Camera>();
140141
_go.hideFlags = HideFlags.HideAndDontSave;
141142
_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-
148-
_cam = _go.camera;
143+
//_go.transform.rotation = Quaternion.identity;
144+
_cam = _go.GetComponent<Camera>();
145+
_cam.clearFlags = CameraClearFlags.Depth;
146+
_cam.renderingPath = RenderingPath.UsePlayerSettings;
147+
//_cam.depth = Camera.main.depth + 1;
148+
_cam.aspect = 1;
149+
_cam.layerCullSpherical = true;
149150
_cam.nearClipPlane = NearClipPlane;
150151
_cam.farClipPlane = FarClipPlane;
151152
_cam.enabled = false;
152-
i += 1;
153153
}
154154

155155

156-
/*
157-
if (!(bool)((UnityEngine.Object)_cam))
158-
{
159-
GameObject gameObject1 = new GameObject("CubemapCamera", new System.Type[1] { typeof(Camera) });
160-
gameObject1.hideFlags = HideFlags.HideAndDontSave;
161-
GameObject gameObject2 = gameObject1;
162-
gameObject2.transform.position = transform.position;
163-
gameObject2.transform.rotation = Quaternion.identity;
164-
_cam = gameObject2.camera;
165-
//_cam.hdr = true;
166-
_cam.depth = Camera.main.depth + 1;//Camera.main.depth + 1;
167-
_cam.farClipPlane = FarClipPlane;
168-
_cam.enabled = false;
169-
_cam.cullingMask = (1 << 0) | (1 << 4) | (1 << 9) | (1 << 10) | (1 << 15) | (1 << 18) | (1 << 23);
170-
//_cam.cullingMask = (1 << maskBit);
171-
//_cam.layerCullSpherical = true;
172-
if (NearClipPlane > 0f)
173-
_cam.nearClipPlane = NearClipPlane;
174-
for (int i = 0; i < 32; i++)
175-
{
176-
_cam.layerCullDistances[i] = int.MaxValue;
177-
}
178-
status = _cam.cullingMask.ToString();
179-
}
180-
*/
181156
if ((object)_rtex == null)
182157
{
183158
ReflectiveScript reflectiveScript = this;
184159
RenderTexture renderTexture1 = new RenderTexture(CubemapSize, CubemapSize, 16);
185160
renderTexture1.isCubemap = true;
186161
renderTexture1.isPowerOfTwo = true;
187-
renderTexture1.hideFlags = HideFlags.HideAndDontSave;
162+
//renderTexture1.hideFlags = HideFlags.HideAndDontSave;
188163
renderTexture1.useMipMap = true;
189164
renderTexture1.wrapMode = TextureWrapMode.Clamp;
190165
RenderTexture renderTexture2 = renderTexture1;
@@ -227,8 +202,9 @@ protected void UpdateCubemap(int faceMask)
227202
if (_cam.RenderToCubemap(_rtex, faceMask))
228203
result = true;
229204

230-
_cam.farClipPlane = 60000.0f;
231-
_cam.cullingMask = (1 << 0) | (1 << 1) | (1 << 5) | (1 << 15);
205+
_cam.transform.position = this.transform.position;
206+
_cam.farClipPlane = scaledFaderEnd;
207+
_cam.cullingMask = (1 << 0) | (1 << 1) | (1 << 4);// | (1 << 15);
232208
if (_cam.RenderToCubemap(_rtex, faceMask))
233209
result = true;
234210

ReflectiveShaderModule.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class ReflectiveShaderModule : PartModule
7979
[KSPField(isPersistant = false)]
8080
public bool realTimeReflection = true;
8181
[KSPField(isPersistant = false)]
82-
public double updateRate = 60.0;
82+
public double updateRate = 300.0;
8383
[KSPField(isPersistant = false, guiActive = false, guiName = "Last Scene", guiUnits = "", guiFormat = "G")]
8484
public string lastScene = "";
8585
[KSPField(isPersistant = false, guiActive = false, guiName = "Shader", guiUnits = "", guiFormat = "G")]
@@ -94,6 +94,7 @@ public override void OnStart(PartModule.StartState state)
9494
{
9595
Debug.Log((object)"RP: Starting ReflectionPlugin .. ");
9696
GameEvents.onVesselGoOffRails.Add(RefreshReflection);
97+
GameEvents.onDominantBodyChange.Add(UpdateBody);
9798
if (ShaderName == string.Empty)
9899
{
99100
Debug.Log((object)"RP: Defaulting shader to \"Reflective/VertexLit\"");
@@ -104,6 +105,7 @@ public override void OnStart(PartModule.StartState state)
104105

105106
if ((UnityEngine.Object)_rShader == (UnityEngine.Object)null)
106107
{
108+
#if DEBUG
107109
Debug.LogWarning((object)string.Format("RP: Could not find the specified shader \"{0}\".", (object)ShaderName));
108110
Debug.LogWarning((object)"RP: Simple reflective shaders:");
109111
Debug.LogWarning((object)"RP: -\"Reflective/Diffuse\"");
@@ -116,6 +118,8 @@ public override void OnStart(PartModule.StartState state)
116118
Debug.LogWarning((object)"RP: -\"Reflective/Bumped VertexLit\"");
117119
Debug.LogWarning((object)"RP: -\"Reflective/Parallax Diffuse\"");
118120
Debug.LogWarning((object)"RP: -\"Reflective/Parallax Specular\"");
121+
#endif
122+
119123
// Try to handle fallback later during material building
120124
// This is so we can try to load and deserialize missing shaders from compiled shader code.
121125
_rShader = null;
@@ -260,9 +264,8 @@ private void ReplaceShader(UnityEngine.Renderer pRenderer)
260264

261265
print("RP: Set _Color");
262266
material.SetColor("_Color", _Color);
263-
// rim lighting experiment. Useless for Unity reflective shaders; only the KSP versions have it. Disabled as it requires setting to KSP shaders.
264-
//material.SetFloat("_RimFalloff", rimFalloff);
265-
//material.SetColor("_RimColor", rimColor);
267+
material.SetFloat("_RimFalloff", rimFalloff);
268+
material.SetColor("_RimColor", rimColor);
266269

267270
//}
268271
//catch (Exception e)
@@ -288,10 +291,24 @@ private void ReplaceShader(UnityEngine.Renderer pRenderer)
288291
else
289292
Debug.LogError((object)("RP: Unable to find a Renderer component on the part. Part: " + part.partName));
290293
}
294+
295+
public void UpdateBody(GameEvents.FromToAction<CelestialBody,CelestialBody> onDominantBodyChange)
296+
{
297+
CelestialBody toBody = onDominantBodyChange.to;
298+
if (toBody != null)
299+
{
300+
ScaledSpaceFader scaledSpaceFader = toBody.scaledBody.GetComponent<ScaledSpaceFader> ();
301+
if ((object)scaledSpaceFader != null)
302+
reflectiveScript.scaledFaderEnd = scaledSpaceFader.fadeEnd;
303+
}
304+
RefreshReflection(vessel);
305+
}
306+
291307
public void RefreshReflection(Vessel v)
292308
{
293309
reflectiveScript.dirty = 7;
294310
}
311+
295312
public void Update()
296313
{
297314
scriptStatus = reflectiveScript.status;

0 commit comments

Comments
 (0)