Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class CreateAssetBundles
static void BuildAllAssetBundles ()
{
// Put the bundles in a folder called "AssetBundles"
//var outDir = "Assets/AssetBundles";
var outDir = "C:/Steam/steamapps/common/Kerbal Space Program/GameData/Singularity/shaders";
var outDir = "Assets/AssetBundles";
//var outDir = "C:/Steam/steamapps/common/Kerbal Space Program/GameData/Singularity/shaders";
var outDir2 = "C:/Steam/steamapps/common/Kerbal Space Program 1.8.1/GameData/Singularity/shaders";

if (!Directory.Exists (outDir))
Expand Down
17 changes: 17 additions & 0 deletions Singularity/Shaders/SingularityShaders/Assets/Scripts/BlackHole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ public class BlackHole : MonoBehaviour
[SerializeField]
float rotationSpeed;

[SerializeField]
float dopplerIntensityRate;

[SerializeField]
float dopplerIntensityFactor;

[SerializeField]
float dopplerIntensityOffset;

[SerializeField]
float dopplerColorFactor;

RenderTexture screenBuffer;
CommandBuffer screenCopyCommandBuffer;

Expand Down Expand Up @@ -79,6 +91,11 @@ void Update()
blackHoleMaterial.SetFloat("diskInnerRadius", DiskInnerRadius);
blackHoleMaterial.SetFloat("diskOuterRadius", DiskOuterRadius);

blackHoleMaterial.SetFloat ("dopplerIntensityRate", dopplerIntensityRate);
blackHoleMaterial.SetFloat ("dopplerIntensityFactor", dopplerIntensityFactor);
blackHoleMaterial.SetFloat ("dopplerIntensityOffset", dopplerIntensityOffset);
blackHoleMaterial.SetFloat ("dopplerColorFactor", dopplerColorFactor);

//gameObject.transform.position = new Vector3(Mathf.Sin(0.53f*Time.time), 2f+3f*Mathf.Cos(0.74f*Time.time), Mathf.Cos(0.22f*Time.time));

sceneCam.transform.RotateAround(gameObject.transform.position, Vector3.up, 10 * Time.deltaTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
uniform float diskInnerRadius;
uniform float diskOuterRadius;

uniform float dopplerIntensityRate;
uniform float dopplerIntensityFactor;
uniform float dopplerIntensityOffset;
uniform float dopplerColorFactor;

uniform float rotationSpeed;
uniform float universalTime;

Expand All @@ -91,30 +96,29 @@
return o;
}


float3 accretionDiskColor(float3 pos, float3 base1, float3 base2, float3 blackHoleOrigin)
{

pos = pos - blackHoleOrigin;

float3 posOrigin = pos - blackHoleOrigin;
float dist = length(posOrigin);
#if defined (RADIAL_DISK_MAPPING_ON)
//TODO: make this rotate, move TWOPI to defines
//need to rotate base1 and base2?
float dist = length(pos);


float v = clamp((dist - diskInnerRadius) / (diskOuterRadius - diskInnerRadius), 0.0, 1.0);

// float3 base = cross(blackholeDisk.xyz, float3(0.0, 0.0, 1.0));
float angle = acos(dot(normalize(base1), normalize(pos)));
if (dot(cross(base1, pos), diskNormal) < 0.0) angle = -angle;
float angle = acos(dot(normalize(base1), normalize(posOrigin)));
if (dot(cross(base1, posOrigin), diskNormal) < 0.0) angle = -angle;
angle-= universalTime * rotationSpeed;

float u = 0.5 - angle / TWOPI;

float4 color = tex2Dlod(AccretionDisk, float4(u, v,0.0,0.0));
#else
float u = dot (base1,normalize(pos)) * (length(pos)-diskInnerRadius) / (diskOuterRadius-diskInnerRadius);
float v = dot (base2,normalize(pos)) * (length(pos)-diskInnerRadius) / (diskOuterRadius-diskInnerRadius);
float u = dot (base1,normalize(posOrigin)) * (length(posOrigin)-diskInnerRadius) / (diskOuterRadius-diskInnerRadius);
float v = dot (base2,normalize(posOrigin)) * (length(posOrigin)-diskInnerRadius) / (diskOuterRadius-diskInnerRadius);

float2 UV = float2(u,v);

Expand All @@ -133,6 +137,25 @@

float4 color = tex2Dlod(AccretionDisk, float4(UV,0.0,0.0));
#endif
float3 posCamera = pos - _WorldSpaceCameraPos.xyz;
float dopplerIntensity = dot(diskNormal, cross(normalize(posOrigin), normalize(posCamera))) / pow(dist / diskInnerRadius, 0.25);
/*
color.r *= ((dopplerIntensityFactor - dopplerColorFactor) * tanh(dopplerIntensityRate * dopplerIntensity) + dopplerIntensityOffset);
color.g *= (dopplerIntensityFactor * tanh(dopplerIntensityRate * dopplerIntensity) + dopplerIntensityOffset);
color.b *= ((dopplerIntensityFactor + dopplerColorFactor) * tanh(dopplerIntensityRate * dopplerIntensity) + dopplerIntensityOffset);
*/
if (dopplerIntensity>=0)
{
color.r *= ((dopplerIntensityFactor - dopplerColorFactor) * (-1.0f/(dopplerIntensityRate * dopplerIntensity + 1.0f) + 1.0f) + dopplerIntensityOffset);
color.g *= (dopplerIntensityFactor * (-1.0f/(dopplerIntensityRate * dopplerIntensity + 1.0f) + 1.0f) + dopplerIntensityOffset);
color.b *= ((dopplerIntensityFactor + dopplerColorFactor) * (-1.0f/(dopplerIntensityRate * dopplerIntensity + 1.0f) + 1.0f) + dopplerIntensityOffset);
}
else
{
color.r *= ((dopplerIntensityFactor - dopplerColorFactor) * (-1.0f/(dopplerIntensityRate * dopplerIntensity - 1.0f) - 1.0f) + dopplerIntensityOffset);
color.g *= (dopplerIntensityFactor * (-1.0f/(dopplerIntensityRate * dopplerIntensity - 1.0f) - 1.0f) + dopplerIntensityOffset);
color.b *= ((dopplerIntensityFactor + dopplerColorFactor) * (-1.0f/(dopplerIntensityRate * dopplerIntensity - 1.0f) - 1.0f) + dopplerIntensityOffset);
}
return color.rgb*color.a;
}

Expand Down
4 changes: 2 additions & 2 deletions Singularity/Singularity/Singularity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Reflection;
using UnityEngine;

[assembly: AssemblyVersion("0.991.*")]
[assembly: AssemblyVersion("0.994.*")]
namespace Singularity
{
[KSPAddon(KSPAddon.Startup.AllGameScenes, false)]
Expand Down Expand Up @@ -178,7 +178,7 @@ void LoadSingularities()

void AddSingularityObject (ConfigNode _cn)
{
if (_cn.HasValue ("name") && _cn.HasValue ("gravity"))
if (_cn.HasValue ("name") && (_cn.HasValue ("gravity") || _cn.HasValue ("schwarzschildRadius")))
{
Transform scaledBodyTransform = ScaledSpace.Instance.transform.FindChild (_cn.GetValue ("name"));
if (!ReferenceEquals (scaledBodyTransform, null))
Expand Down
19 changes: 19 additions & 0 deletions Singularity/Singularity/SingularityObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class SingularityObject : MonoBehaviour
[Persistent] public string name;

[Persistent] public float gravity = 1f;
[Persistent] public float schwarzschildRadius = 32400f;

[Persistent] public bool hideCelestialBody = true;

Expand All @@ -30,6 +31,11 @@ public class SingularityObject : MonoBehaviour

[Persistent] public bool depthWrite = true;

[Persistent] public float dopplerEffectIntensityRate = 0f;
[Persistent] public float dopplerEffectIntensityFactor = 0.8f;
[Persistent] public float dopplerEffectIntensityOffset = 1.0f;
[Persistent] public float dopplerEffectColorFactor = 0f;

float scaledRadius = 1f;
float enclosingMeshRadius = 1f;

Expand Down Expand Up @@ -58,6 +64,10 @@ public void Init(ConfigNode _cn)

singularityMaterial = new Material(Singularity.LoadedShaders ["Singularity/BlackHoleAccretionDisk"]);

if (_cn.HasValue ("schwarzschildRadius"))
{
gravity = schwarzschildRadius * schwarzschildRadius / 32400f / 32400f;
}
scaledRadius = Mathf.Sqrt (Mathf.Max(gravity,0f)) * 5f; // The apparent radius (in scaled Space) of the black hole (or event horizon), not physically correct
singularityMaterial.SetFloat("blackHoleRadius", scaledRadius);

Expand Down Expand Up @@ -160,6 +170,11 @@ void ConfigureAccretionDisk ()
singularityMaterial.SetFloat ("diskInnerRadius", accretionDiskInnerRadius / 6000f); //change to scaledSpace scale
singularityMaterial.SetFloat ("diskOuterRadius", accretionDiskOuterRadius / 6000f);

singularityMaterial.SetFloat ("dopplerIntensityRate", dopplerEffectIntensityRate);
singularityMaterial.SetFloat ("dopplerIntensityFactor", dopplerEffectIntensityFactor);
singularityMaterial.SetFloat ("dopplerIntensityOffset", dopplerEffectIntensityOffset);
singularityMaterial.SetFloat ("dopplerColorFactor", dopplerEffectColorFactor);

//convert from RPM to rad/s
singularityMaterial.SetFloat("rotationSpeed", accretionDiskRotationSpeed * (Mathf.PI * 2) / 60);

Expand Down Expand Up @@ -286,6 +301,10 @@ public void ApplyFromUI(ConfigNode _cn)
Utils.LogError("Apply failed");
return;
}
if (_cn.HasValue ("schwarzschildRadius"))
{
gravity = schwarzschildRadius * schwarzschildRadius / 32400f / 32400f;
}

scaledRadius = Mathf.Sqrt (Mathf.Max(gravity,0f)) * 5f;
singularityMaterial.SetFloat("blackHoleRadius", scaledRadius);
Expand Down
2 changes: 1 addition & 1 deletion Singularity/Singularity/SingularityUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void OnGUI ()
{
if (uiVisible)
{
windowRect = GUILayout.Window (windowId, windowRect, DrawWindow,"Singularity 0.991");
windowRect = GUILayout.Window (windowId, windowRect, DrawWindow,"Singularity 0.994");

//prevent window from going offscreen
windowRect.x = Mathf.Clamp(windowRect.x,0,Screen.width-windowRect.width);
Expand Down
Binary file not shown.
Binary file added Singularity/Singularity/obj/Debug/Singularity.dll
Binary file not shown.