- Home /
Creating Chalk-drawing Post Processing
I am new to C# and would like to create a chalk drawing post-processing effect. I want it to create a grain of chalk with the minimum radius GrainMinSize and the maximum radius GrainMaxSize, and the color of the grain will be a random pixel from the center of the grain within the distance GrainSampleDistance. If ToleranceOn is true, touching grains with a hue, saturation, and value within SameColorTolerance will be the same color. If RefreshGrains is true,the grains will redraw every RefreshRate seconds.
Can someone help me start out with this please?
This is my code so far.
ChalkyModel.cs
using System;
namespace UnityEngine.PostProcessing
{
[Serializable]
public class ChalkyModel : PostProcessingModel
{
[Serializable]
public struct Settings
{
[Tooltip("Minimum size of chalk grain in pixels")]
public int GrainMinSize;
[Tooltip("Maximum size of chalk grain in pixels")]
public int GrainMaxSize;
[Tooltip("Width & height of the area to get a random pixel for the grain")]
public int GrainSampleDistance;
[Tooltip("Turn on SameColorTolerance?")]
public bool ToleranceOn
[Tooltip("Tolerance for similarly colored grains to be the same color")]
public float SameColorTolerance;
[Tooltip("Redraw the grains every Refresh Rate seconds?")]
public bool RefreshGrains
[Tooltip("The rate in seconds the grains refresh.")]
public float RefreshRate
public static Settings DefaultSettings
{
get
{
return new Settings
{
GrainMinSize = 10,
GrainMaxSize = 20,
GrainSampleDistance = 15,
ToleranceOn = false,
SameColorTolerance = 2,
};
}
}
}
[SerializeField]
Settings m_Settings = Settings.DefaultSettings;
public Settings settings
{
get { return m_Settings; }
set { m_Settings = value; }
}
public override void Reset()
{
m_Settings = Settings.DefaultSettings;
}
}
}
ChalkyEditor.cs
using UnityEngine;
using UnityEngine.PostProcessing;
namespace UnityEditor.PostProcessing
{
using Settings = ChalkyModel.Settings;
[PostProcessingModelEditor(typeof(ChalkyModel))]
public class ChalkyModelEditor : PostProcessingModelEditor
{
struct ChalkySettings
{
public SerializedProperty GrainMinSize;
public SerializedProperty GrainMaxSize;
public SerializedProperty GrainSampleDistance;
public SerializedProperty ToleranceOn;
public SerializedProperty SameColorTolerance;
public SerializedProperty RefreshGrains;
public SerializedProperty RefreshRate;
}
ChalkySettings m_Chalky;
public override void OnEnable()
{
m_Chalky = new ChalkySettings
{
GrainMinSize = FindSetting((Settings x) => x.GrainMinSize),
GrainMaxSize = FindSetting((Settings x) => x.GrainMaxSize),
GrainSampleDistance = FindSetting((Settings x) => x.GrainSampleDistance),
ToleranceOn = FindSetting((Settings x) => x.ToleranceOn),
SameColorTolerance = FindSetting((Settings x) => x.SameColorTolerance),
RefreshGrains = FindSetting((Settings x) => x.RefreshGrains),
RefreshRate = FindSetting((Settings x) => x.RefreshRate),
};
}
public override void OnInspectorGUI()
{
EditorGUILayout.PropertyField(m_Chalky.GrainMinSize);
EditorGUILayout.PropertyField(m_Chalky.GrainMaxSize);
EditorGUILayout.PropertyField(m_Chalky.GrainSampleDistance);
EditorGUILayout.PropertyField(m_Chalky.ToleranceOn);
EditorGUILayout.PropertyField(m_Chalky.SameColorTolerance);
EditorGUILayout.PropertyField(m_Chalky.RefreshGrains);
EditorGUILayout.PropertyField(m_Chalky.RefreshRate);
}
}
}
I added 2 new values, refreshChalk, which redraws all grains every refreshRate seconds.
Your answer
Follow this Question
Related Questions
Script To Update Post Process Profile At Runtime [2018 HDRP] 1 Answer
How to use Post Processing Stack with stencil masking shaders 0 Answers
Change Post Process Volume Color Grading at runtime 0 Answers
How to manipulate PostProcessing effects settings during execution with c#? 1 Answer
Multiple Cars not working 1 Answer