-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto | ||
|
||
# Custom for Visual Studio | ||
*.cs diff=csharp | ||
|
||
# Standard to msysgit | ||
*.doc diff=astextplain | ||
*.DOC diff=astextplain | ||
*.docx diff=astextplain | ||
*.DOCX diff=astextplain | ||
*.dot diff=astextplain | ||
*.DOT diff=astextplain | ||
*.pdf diff=astextplain | ||
*.PDF diff=astextplain | ||
*.rtf diff=astextplain | ||
*.RTF diff=astextplain |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.swp | ||
|
||
/Library/ | ||
/Temp/ | ||
|
||
.DS_Store | ||
Thumbs.db | ||
Desktop.ini |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// DFVolume - Distance field volume generator for Unity | ||
// https://github.com/keijiro/DFVolume | ||
|
||
using UnityEngine; | ||
using UnityEditor; | ||
|
||
namespace DFVolume | ||
{ | ||
[CustomEditor(typeof(VolumeData))] | ||
class VolumeDataEditor : Editor | ||
{ | ||
public override void OnInspectorGUI() | ||
{ | ||
// There is nothing to show in the inspector. | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// DFVolume - Distance field volume generator for Unity | ||
// https://github.com/keijiro/DFVolume | ||
|
||
using UnityEngine; | ||
using UnityEditor; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace DFVolume | ||
{ | ||
[CanEditMultipleObjects] | ||
[CustomEditor(typeof(VolumeSampler))] | ||
class VolumeSamplerEditor : Editor | ||
{ | ||
SerializedProperty _resolution; | ||
SerializedProperty _extent; | ||
|
||
void OnEnable() | ||
{ | ||
_resolution = serializedObject.FindProperty("_resolution"); | ||
_extent = serializedObject.FindProperty("_extent"); | ||
} | ||
|
||
public override void OnInspectorGUI() | ||
{ | ||
serializedObject.Update(); | ||
|
||
EditorGUILayout.PropertyField(_resolution); | ||
EditorGUILayout.PropertyField(_extent); | ||
|
||
serializedObject.ApplyModifiedProperties(); | ||
|
||
if (GUILayout.Button("Create Volume Data")) CreateVolumeData(); | ||
|
||
CheckSkewedTransform(); | ||
} | ||
|
||
void CreateVolumeData() | ||
{ | ||
var output = new List<Object>(); | ||
|
||
foreach (VolumeSampler sampler in targets) | ||
{ | ||
var path = "Assets/New Volume Data.asset"; | ||
path = AssetDatabase.GenerateUniqueAssetPath(path); | ||
|
||
var asset = ScriptableObject.CreateInstance<VolumeData>(); | ||
asset.Initialize(sampler); | ||
|
||
AssetDatabase.CreateAsset(asset, path); | ||
AssetDatabase.AddObjectToAsset(asset.texture, asset); | ||
} | ||
|
||
AssetDatabase.SaveAssets(); | ||
|
||
EditorUtility.FocusProjectWindow(); | ||
Selection.objects = output.ToArray(); | ||
} | ||
|
||
void CheckSkewedTransform() | ||
{ | ||
if (targets.Any(o => ((Component)o).transform.lossyScale != Vector3.one)) | ||
EditorGUILayout.HelpBox( | ||
"Using scale in transform may introduce error in output volumes.", | ||
MessageType.Warning | ||
); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// DFVolume - Distance field volume generator for Unity | ||
// https://github.com/keijiro/DFVolume | ||
|
||
using UnityEngine; | ||
using UnityEditor; | ||
|
||
namespace DFVolume | ||
{ | ||
[CanEditMultipleObjects] | ||
[CustomEditor(typeof(VolumeVisualizer))] | ||
class VolumeVisualizerEditor : Editor | ||
{ | ||
SerializedProperty _data; | ||
SerializedProperty _mode; | ||
SerializedProperty _depth; | ||
|
||
void OnEnable() | ||
{ | ||
_data = serializedObject.FindProperty("_data"); | ||
_mode = serializedObject.FindProperty("_mode"); | ||
_depth = serializedObject.FindProperty("_depth"); | ||
} | ||
|
||
public override void OnInspectorGUI() | ||
{ | ||
serializedObject.Update(); | ||
|
||
EditorGUILayout.PropertyField(_data); | ||
EditorGUILayout.PropertyField(_mode); | ||
EditorGUILayout.PropertyField(_depth); | ||
|
||
serializedObject.ApplyModifiedProperties(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// DFVolume - Distance field volume generator for Unity | ||
// https://github.com/keijiro/DFVolume | ||
|
||
Shader "Hidden/DFVolume/Visualizer" | ||
{ | ||
Properties | ||
{ | ||
_MainTex("", 3D) = "white" {} | ||
} | ||
|
||
CGINCLUDE | ||
|
||
#include "UnityCG.cginc" | ||
|
||
struct appdata | ||
{ | ||
float4 vertex : POSITION; | ||
float2 texcoord : TEXCOORD; | ||
}; | ||
|
||
struct v2f | ||
{ | ||
float4 vertex : SV_POSITION; | ||
float2 texcoord : TEXCOORD; | ||
}; | ||
|
||
sampler3D _MainTex; | ||
float _Depth; | ||
float _Mode; | ||
|
||
v2f vert(appdata v) | ||
{ | ||
v2f o; | ||
o.vertex = UnityObjectToClipPos(v.vertex); | ||
o.texcoord = v.texcoord; | ||
return o; | ||
} | ||
|
||
fixed4 frag(v2f i) : SV_Target | ||
{ | ||
fixed4 data = tex3D(_MainTex, float3(i.texcoord, _Depth)); | ||
fixed dist = abs(0.5 - frac(data.a * 10)) * 2; | ||
fixed3 grad = data.rgb + 0.5; | ||
return fixed4(lerp(dist, grad, _Mode), 1); | ||
} | ||
|
||
ENDCG | ||
|
||
SubShader | ||
{ | ||
Tags { "RenderType"="Opaque" } | ||
Pass | ||
{ | ||
CGPROGRAM | ||
#pragma vertex vert | ||
#pragma fragment frag | ||
ENDCG | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// DFVolume - Distance field volume generator for Unity | ||
// https://github.com/keijiro/DFVolume | ||
|
||
using UnityEngine; | ||
|
||
namespace DFVolume | ||
{ | ||
public class VolumeData : ScriptableObject | ||
{ | ||
#region Exposed attributes | ||
|
||
[SerializeField] Texture3D _texture; | ||
|
||
public Texture3D texture { | ||
get { return _texture; } | ||
} | ||
|
||
#endregion | ||
|
||
#if UNITY_EDITOR | ||
|
||
#region Editor functions | ||
|
||
public void Initialize(VolumeSampler sampler) | ||
{ | ||
var dim = sampler.resolution; | ||
_texture = new Texture3D(dim, dim, dim, TextureFormat.RGBAHalf, true); | ||
|
||
_texture.name = "Distance Field Texture"; | ||
_texture.filterMode = FilterMode.Bilinear; | ||
_texture.wrapMode = TextureWrapMode.Clamp; | ||
_texture.SetPixels(sampler.GenerateBitmap2()); | ||
_texture.Apply(); | ||
} | ||
|
||
#endregion | ||
|
||
#endif | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.