Skip to content

Commit

Permalink
Merge r4m0n's alpha curves
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbian committed Aug 10, 2014
2 parents 6946102 + d171ec9 commit 2e2d831
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions ModelMultiParticlePersistFX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ public class ModelMultiParticlePersistFX : EffectBehaviour

public MultiInputCurve linGrow;

public MultiInputCurve alpha;

public MultiInputCurve logAlphaDecay;

public MultiInputCurve linAlphaDecay;

// Those 2 curve are related to the angle and distance to cam
public FXCurve angle = new FXCurve("angle", 1f);

Expand Down Expand Up @@ -400,6 +406,20 @@ public void UpdateEmitters(float power)

pkpe.linearGrow = linGrow.Value(inputs);

if (this.alpha.Value(inputs) != 1 || this.linAlphaDecay.Value(inputs) != 0 || this.logAlphaDecay.Value(inputs) != 0)
{
Color[] cols = new Color[5];

for (int t = 0; t < 5; t++)
{
float a = Mathf.Clamp01(alpha.Value(inputs) * (1 - linAlphaDecay.Value(inputs) * (t / 4) - Mathf.Log(logAlphaDecay.Value(inputs) * (t / 4) + 1)));
cols[t] = new Color(a, a, a, a);
}

pkpe.pe.colorAnimation = cols;
pkpe.pe.doesAnimateColor = true;
}

pkpe.go.transform.localPosition = localPosition
+ offsetDirection.normalized * offset.Value(inputs) * fixedScale;

Expand Down Expand Up @@ -504,6 +524,12 @@ public override void OnInitialize()
GameObject emitterGameObject = UnityEngine.Object.Instantiate(model) as GameObject;
KSPParticleEmitter childKSPParticleEmitter = emitterGameObject.GetComponentInChildren<KSPParticleEmitter>();

if (shader != null)
{
childKSPParticleEmitter.material.shader = shader;
childKSPParticleEmitter.pr.material.shader = shader;
}

if (childKSPParticleEmitter != null)
{
PersistentKSPParticleEmitter pkpe = new PersistentKSPParticleEmitter(
Expand Down Expand Up @@ -565,6 +591,9 @@ public override void OnLoad(ConfigNode node)
logGrow = new MultiInputCurve("logGrow", true);
linGrow = new MultiInputCurve("linGrow", true);
logGrowScale = new MultiInputCurve("logGrowScale");
alpha = new MultiInputCurve("alpha");
linAlphaDecay = new MultiInputCurve("linAlphaDecay", true);
logAlphaDecay = new MultiInputCurve("logAlphaDecay", true);

ConfigNode.LoadObjectFromConfig(this, node);
emission.Load(node);
Expand All @@ -578,6 +607,9 @@ public override void OnLoad(ConfigNode node)
logGrowScale.Load(node);
logGrow.Load(node);
linGrow.Load(node);
alpha.Load(node);
linAlphaDecay.Load(node);
logAlphaDecay.Load(node);

angle.Load("angle", node);
distance.Load("distance", node);
Expand All @@ -598,6 +630,9 @@ public override void OnSave(ConfigNode node)
logGrow.Save(node);
linGrow.Save(node);
logGrowScale.Save(node);
alpha.Save(node);
linAlphaDecay.Save(node);
logAlphaDecay.Save(node);

angle.Save(node);
distance.Save(node);
Expand Down Expand Up @@ -655,6 +690,11 @@ private void windowGUI(int ID)
GUIInput((int)MultiInputCurve.Inputs.parttemp, "Part Temperature");
GUIInput((int)MultiInputCurve.Inputs.externaltemp, "External Temperature");

if (persistentEmitters.Count > 0)
{
GUILayout.Label("Shader: " + persistentEmitters[0].pe.pr.material.shader.name);
}

GUILayout.Space(10);

GUILayout.BeginHorizontal();
Expand Down Expand Up @@ -764,6 +804,10 @@ private float minInput(int id)
min = Mathf.Min(min, linGrow.minInput[id]);
min = Mathf.Min(min, logGrowScale.minInput[id]);

min = Mathf.Min(min, alpha.minInput[id]);
min = Mathf.Min(min, linAlphaDecay.minInput[id]);
min = Mathf.Min(min, logAlphaDecay.minInput[id]);

return min;
}

Expand All @@ -781,6 +825,10 @@ private float maxInput(int id)
max = Mathf.Max(max, linGrow.maxInput[id]);
max = Mathf.Max(max, logGrowScale.maxInput[id]);

max = Mathf.Max(max, alpha.maxInput[id]);
max = Mathf.Max(max, linAlphaDecay.maxInput[id]);
max = Mathf.Max(max, logAlphaDecay.maxInput[id]);

return max;
}
}

0 comments on commit 2e2d831

Please sign in to comment.