Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
keijiro committed May 28, 2017
0 parents commit 94fc82d
Show file tree
Hide file tree
Showing 522 changed files with 32,703 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitattributes
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.swp

/Library/
/Temp/

.DS_Store
Thumbs.db
Desktop.ini
9 changes: 9 additions & 0 deletions Assets/DFVolume.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/DFVolume/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Assets/DFVolume/Editor/VolumeDataEditor.cs
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.
}
}
}
12 changes: 12 additions & 0 deletions Assets/DFVolume/Editor/VolumeDataEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions Assets/DFVolume/Editor/VolumeSamplerEditor.cs
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
);
}
}
}
12 changes: 12 additions & 0 deletions Assets/DFVolume/Editor/VolumeSamplerEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions Assets/DFVolume/Editor/VolumeVisualizer.cs
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();
}
}
}
12 changes: 12 additions & 0 deletions Assets/DFVolume/Editor/VolumeVisualizer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/DFVolume/Shader.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions Assets/DFVolume/Shader/Visualizer.shader
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
}
}
}
9 changes: 9 additions & 0 deletions Assets/DFVolume/Shader/Visualizer.shader.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions Assets/DFVolume/VolumeData.cs
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
}
}
12 changes: 12 additions & 0 deletions Assets/DFVolume/VolumeData.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 94fc82d

Please sign in to comment.