Skip to content

Commit

Permalink
Updated to allow the shader to run in the editor view as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Aelstraz committed May 13, 2024
1 parent 7f012ee commit 04f1c56
Show file tree
Hide file tree
Showing 4 changed files with 555 additions and 409 deletions.
150 changes: 82 additions & 68 deletions Editor/SunShaftsEditor.cs
Original file line number Diff line number Diff line change
@@ -1,86 +1,100 @@
using UnityEditor;
using UnityEngine;
using System.Collections;

[CustomEditor (typeof(SunShafts))]
class SunShaftsEditor : Editor
{
SerializedObject serObj;

SerializedProperty radialBlurIterations;
SerializedProperty sunColor;
SerializedProperty sunThreshold;
SerializedProperty sunShaftBlurRadius;
SerializedProperty sunShaftIntensity;
SerializedProperty useDepthTexture;

[CustomEditor(typeof(SunShafts))]
class SunShaftsEditor : Editor
{
SerializedObject serObj;

SerializedProperty radialBlurIterations;
SerializedProperty sunColor;
SerializedProperty sunThreshold;
SerializedProperty sunShaftBlurRadius;
SerializedProperty sunShaftIntensity;
SerializedProperty useDepthTexture;
SerializedProperty resolution;
SerializedProperty screenBlendMode;
SerializedProperty maxRadius;
SerializedProperty sunShaftsShader;
SerializedProperty simpleClearShader;

void OnEnable ()
#if UNITY_EDITOR
SerializedProperty syncWithEditorCamera;
#endif

void OnEnable()
{
serObj = new SerializedObject (target);

screenBlendMode = serObj.FindProperty("screenBlendMode");

sunColor = serObj.FindProperty("sunColor");
sunThreshold = serObj.FindProperty("sunThreshold");

sunShaftBlurRadius = serObj.FindProperty("sunShaftBlurRadius");
radialBlurIterations = serObj.FindProperty("radialBlurIterations");

sunShaftIntensity = serObj.FindProperty("sunShaftIntensity");

resolution = serObj.FindProperty("resolution");

maxRadius = serObj.FindProperty("maxRadius");

useDepthTexture = serObj.FindProperty("useDepthTexture");

sunShaftsShader = serObj.FindProperty("sunShaftsShader");

simpleClearShader = serObj.FindProperty("simpleClearShader");
serObj = new SerializedObject(target);

#if UNITY_EDITOR
syncWithEditorCamera = serObj.FindProperty("syncWithEditorCamera");
#endif
screenBlendMode = serObj.FindProperty("screenBlendMode");

sunColor = serObj.FindProperty("sunColor");
sunThreshold = serObj.FindProperty("sunThreshold");

sunShaftBlurRadius = serObj.FindProperty("sunShaftBlurRadius");
radialBlurIterations = serObj.FindProperty("radialBlurIterations");

sunShaftIntensity = serObj.FindProperty("sunShaftIntensity");

resolution = serObj.FindProperty("resolution");

maxRadius = serObj.FindProperty("maxRadius");

useDepthTexture = serObj.FindProperty("useDepthTexture");
}

public override void OnInspectorGUI()
{
serObj.Update();

#if UNITY_EDITOR
bool prevValue = syncWithEditorCamera.boolValue;
EditorGUILayout.PropertyField(syncWithEditorCamera, new GUIContent("Sync with Editor Camera?"));
EditorGUILayout.Separator();
#endif

EditorGUILayout.BeginHorizontal();

public override void OnInspectorGUI ()
{
serObj.Update ();

EditorGUILayout.BeginHorizontal();

EditorGUILayout.PropertyField (useDepthTexture, new GUIContent ("Rely on Z Buffer?"));
if((target as SunShafts).GetComponent<Camera>())
GUILayout.Label("Current camera mode: "+ (target as SunShafts).GetComponent<Camera>().depthTextureMode, EditorStyles.miniBoldLabel);

EditorGUILayout.EndHorizontal();

EditorGUILayout.PropertyField (resolution, new GUIContent("Resolution"));
EditorGUILayout.PropertyField (screenBlendMode, new GUIContent("Blend mode"));

EditorGUILayout.Separator ();

EditorGUILayout.PropertyField (sunThreshold, new GUIContent ("Threshold color"));
EditorGUILayout.PropertyField (sunColor, new GUIContent ("Shafts color"));
maxRadius.floatValue = 1.0f - EditorGUILayout.Slider ("Distance falloff", 1.0f - maxRadius.floatValue, 0.1f, 1.0f);

EditorGUILayout.Separator ();

sunShaftBlurRadius.floatValue = EditorGUILayout.Slider ("Blur size", sunShaftBlurRadius.floatValue, 1.0f, 10.0f);
radialBlurIterations.intValue = EditorGUILayout.IntSlider ("Blur iterations", radialBlurIterations.intValue, 1, 3);

EditorGUILayout.Separator ();

EditorGUILayout.PropertyField (sunShaftIntensity, new GUIContent("Intensity"));
EditorGUILayout.PropertyField(useDepthTexture, new GUIContent("Rely on Z Buffer?"));
if ((target as SunShafts).GetComponent<Camera>())
GUILayout.Label("Current camera mode: " + (target as SunShafts).GetComponent<Camera>().depthTextureMode, EditorStyles.miniBoldLabel);

EditorGUILayout.EndHorizontal();

EditorGUILayout.PropertyField(resolution, new GUIContent("Resolution"));
EditorGUILayout.PropertyField(screenBlendMode, new GUIContent("Blend mode"));

EditorGUILayout.Separator();

EditorGUILayout.PropertyField(sunShaftsShader, new GUIContent("Sun Shafts Shader"));
EditorGUILayout.PropertyField(sunThreshold, new GUIContent("Threshold color"));
EditorGUILayout.PropertyField(sunColor, new GUIContent("Shafts color"));
maxRadius.floatValue = 1.0f - EditorGUILayout.Slider("Distance falloff", 1.0f - maxRadius.floatValue, 0.1f, 1.0f);

EditorGUILayout.PropertyField(simpleClearShader, new GUIContent("Simple Clear Shader"));
EditorGUILayout.Separator();

sunShaftBlurRadius.floatValue = EditorGUILayout.Slider("Blur size", sunShaftBlurRadius.floatValue, 1.0f, 10.0f);
radialBlurIterations.intValue = EditorGUILayout.IntSlider("Blur iterations", radialBlurIterations.intValue, 1, 3);

EditorGUILayout.Separator();

EditorGUILayout.PropertyField(sunShaftIntensity, new GUIContent("Intensity"));

serObj.ApplyModifiedProperties();

#if UNITY_EDITOR
bool newValue = syncWithEditorCamera.boolValue;
if (newValue != prevValue)
{
if (newValue == true)
{
((SunShafts)target).OnEnable();
}
else
{
((SunShafts)target).OnDisable();
}
}
#endif
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
## Sun Shafts (Modified for PPSv2)

This is Unity's legacy Sun Shaft post processing effect, modified to work with the Post Processing Stack v2 (PPSv2). Tested using the Standard Rendering Pipeline.
This is Unity's legacy Sun Shaft post processing effect, modified to work with the Post Processing Stack v2 (PPSv2). Tested using the Standard Rendering Pipeline. Updated to run in the editor.

### IMPORTING/INSTALLING:

Simply add the entire folder into your Assets folder.

### USAGE:

Add the SunShafts script/component to the Main Camera. Set the shader properties to the shaders included. Check the example scene to learn more. Note: The effect isn't visible in the Editor. Enter Play mode or build the project in order for it to render.
Add the SunShafts script/component to the Main Camera. You can use the editor only toggle 'Sync With Editor Camera?' in order to enable syncing between the current camera and the editor camera (useful for when you have multiple cameras using SunShafts, in order to stop multiple cameras fighting to sync with the editor camera).

### Twitter: [@aelstraz](https://twitter.com/Aelstraz)
Loading

0 comments on commit 04f1c56

Please sign in to comment.