playMaker

Author Topic: Procedural Skybox  (Read 4470 times)

Hank

  • Playmaker Newbie
  • *
  • Posts: 5
Procedural Skybox
« on: October 05, 2015, 01:07:11 PM »
Is there a way to adjust the parameters of a procedural skybox material using Playmaker? I've tried the usual Get and Set but none of the parameters are exposed - true of other materials too.

Any work around? I'm teaching a class using Playmaker and don't want to dive into more complex scripting top achieve this...

Hank

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Procedural Skybox
« Reply #1 on: October 05, 2015, 01:42:59 PM »
Figured out how to write a custom action. First time. Amazingly easy. Here's my code for those who might have interest. It should be easily adaptable to adjust the other parameters.

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Skybox")]
[Tooltip("Allows Adjustment of Procedural Skybox")]
public class SkyBoxAdjust : FsmStateAction
{
public Material ProceduralSkyBox;
public bool everyFrame;
public float exposure;

public override void Reset()
{
ProceduralSkyBox = null;
everyFrame = false;

}

public override void OnEnter()
{
if (ProceduralSkyBox != null && exposure != null)
{
ProceduralSkyBox.SetFloat("_Exposure",exposure);
}

if (!everyFrame)
{
Finish();
}
}

public override void OnUpdate()
{
if (ProceduralSkyBox != null && exposure != null)
{
ProceduralSkyBox.SetFloat("_Exposure",exposure);
}
}

}
}

Hank

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Procedural Skybox
« Reply #2 on: October 06, 2015, 11:34:17 AM »
I can't seem to help myself and stop coding...

Here's a Get and then a Set playmaker actions for procedural skyboxes all the parameters of the shader are included.

Get:

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{

[ActionCategory("Skybox")]
[Tooltip("Gets material settings of a procedural skybox")]
public class GetProceduralSkyboxProperties : FsmStateAction
{
private Material ProceduralSkyBox;
[UIHint(UIHint.Variable)]
public FsmFloat SunSize;
[UIHint(UIHint.Variable)]
public FsmFloat AtmosphereThickness;
[UIHint(UIHint.Variable)]
public FsmColor SkyTint;
[UIHint(UIHint.Variable)]
public FsmColor GroundColor;
[UIHint(UIHint.Variable)]
public FsmFloat exposure;
public bool everyFrame;

// public override void Reset()
// {
// everyFrame = false;
// SunSize = null;
// AtmosphereThickness = null;
// SkyTint = null;
// GroundColor = null;
// exposure = null;
//
// }

public override void OnEnter()
{
if (RenderSettings.skybox.shader.name != "Skybox/Procedural")
Finish ();

ProceduralSkyBox = RenderSettings.skybox;

SunSize.Value = ProceduralSkyBox.GetFloat("_SunSize");
AtmosphereThickness.Value = ProceduralSkyBox.GetFloat("_AtmosphereThickness");
SkyTint.Value = ProceduralSkyBox.GetColor("_SkyTint");
GroundColor.Value = ProceduralSkyBox.GetColor("_GroundColor");
exposure.Value = ProceduralSkyBox.GetFloat("_Exposure");


if (!everyFrame)
{
Finish();
}
}
}
}

Set:

Code: [Select]
namespace HutongGames.PlayMaker.Actions
{

[ActionCategory("Skybox")]
[Tooltip("Sets the material settings of a procedural skybox")]
public class SetProceduralSkyboxProperties : FsmStateAction
{
private Material ProceduralSkyBox;
[UIHint(UIHint.Variable)]
public FsmFloat SunSize;
[UIHint(UIHint.Variable)]
public FsmFloat AtmosphereThickness;
[UIHint(UIHint.Variable)]
public FsmColor SkyTint;
[UIHint(UIHint.Variable)]
public FsmColor GroundColor;
[UIHint(UIHint.Variable)]
public FsmFloat exposure;
public bool everyFrame;

public override void Reset()
{
ProceduralSkyBox = null;
everyFrame = false;
SunSize = null;
AtmosphereThickness = null;
SkyTint = null;
GroundColor = null;
exposure = null;
}

public override void OnEnter()
{

if (RenderSettings.skybox.shader.name != "Skybox/Procedural")
Finish ();

ProceduralSkyBox = RenderSettings.skybox;


if (ProceduralSkyBox != null)
{
if(!SunSize.IsNone)
{
ProceduralSkyBox.SetFloat("_SunSize",SunSize.Value);
}
if(!AtmosphereThickness.IsNone)
{
ProceduralSkyBox.SetFloat("_AtmosphereThickness",AtmosphereThickness.Value);
}
if(!SkyTint.IsNone)
{
ProceduralSkyBox.SetColor("_SkyTint",SkyTint.Value);
}
if(!GroundColor.IsNone)
{
ProceduralSkyBox.SetColor("_GroundColor",GroundColor.Value);
}
if(!exposure.IsNone)
{
ProceduralSkyBox.SetFloat("_Exposure",exposure.Value);
}
}

if (!everyFrame)
{
Finish();
}
}

public override void OnUpdate()
{
if (ProceduralSkyBox != null)
{
if(!SunSize.IsNone)
{
ProceduralSkyBox.SetFloat("_SunSize",SunSize.Value);
}
if(!AtmosphereThickness.IsNone)
{
ProceduralSkyBox.SetFloat("_AtmosphereThickness",AtmosphereThickness.Value);
}
if(!SkyTint.IsNone)
{
ProceduralSkyBox.SetColor("_SkyTint",SkyTint.Value);
}
if(!GroundColor.IsNone)
{
ProceduralSkyBox.SetColor("_GroundColor",GroundColor.Value);
}
if(!exposure.IsNone)
{
ProceduralSkyBox.SetFloat("_Exposure",exposure.Value);
}
}
}

}
}
« Last Edit: October 06, 2015, 01:33:52 PM by Hank »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Procedural Skybox
« Reply #3 on: October 06, 2015, 11:49:30 AM »
Hi,
Nice actions.
I will test them and check if they don't exist yet on the EcoSystem

if you are planning to make more actions can you add :
Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2015. All rights reserved.
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/

at the top of the script?

Caro

  • Playmaker Newbie
  • *
  • Posts: 22
Re: Procedural Skybox
« Reply #4 on: April 27, 2020, 12:15:35 PM »
Was this ever implemented? Can't find it in the Ecosystem.
« Last Edit: April 28, 2020, 08:44:52 AM by Caro »