Commit f67e10e2 authored by Patrick's avatar Patrick

added test scene and test vfx graph that shows that squared pow2 version of 000.vf is correct

added Texture3D asset that allows visualizing 3d textures in editor
changed Texture3D asset to display density in range 0-500 instead of 0-5
parent f2cf4524
......@@ -67,4 +67,6 @@ crashlytics-build.properties
# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*
\ No newline at end of file
/[Aa]ssets/[Ss]treamingAssets/aa/*
Assets/PS_vf_files_squaredGrid_2pow/000.vf
Assets/PS_vf_files_squaredGrid_2pow.meta
fileFormatVersion: 2
guid: 776ee4065329b9f4a82ae4b27cb58e47
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 336709e79a7c5ad4f8611c5f160d050b, type: 3}
outputFormat: 0
wrapMode: 0
filterMode: 2
generateMipMaps: 0
anisoLevel: 1
This diff is collapsed.
fileFormatVersion: 2
guid: fb6d3c3d9956cb44ab93db20d50ad489
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 8
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
m_GIWorkflowMode: 0
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 1
m_LightmapEditorSettings:
serializedVersion: 9
m_Resolution: 2
m_BakeResolution: 40
m_TextureWidth: 1024
m_TextureHeight: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 0
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVRBounces: 2
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVRFilteringMode: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &1729229721
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1729229723}
- component: {fileID: 1729229722}
m_Layer: 0
m_Name: Texture3D preview in Inspector
m_TagString: Untagged
m_Icon: {fileID: 3936346786652291628, guid: 0000000000000000d000000000000000, type: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1729229722
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1729229721}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 308d5e80d1df35543bd2ec9636edd96a, type: 3}
m_Name:
m_EditorClassIdentifier:
texture3D: {fileID: 11700000, guid: 64677355665b5684c822c245cb6a495b, type: 2}
--- !u!4 &1729229723
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1729229721}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
fileFormatVersion: 2
guid: febdae0f126b8174e86af88be2bbfdc2
timeCreated: 1507537286
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: d16d2cfdf00294d4eb7065e758b27a24
folderAsset: yes
timeCreated: 1507536992
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 17cf46f2ccde500418af03434fb6629d
folderAsset: yes
timeCreated: 1507549806
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
/// <summary>
/// Attribute enabling Texture3D preview in a Monobehaviour component in the Inspector
/// </summary>
public class Texture3DPreviewAttribute : PropertyAttribute
{
#region Members
/// <summary>
/// Allows to show the field (when user drags/drops another Texture3D for example) or not (when Texture3D is changed in code only for example)
/// </summary>
public readonly bool showField;
#endregion
#region Constructor
/// <summary>
/// Declare this attribute in front of the Texture3D field to enable previewing in a Monobehaviour component in the Inspector
/// </summary>
/// <param name="showField">Shows or not the Texture3D field on top of the preview (default = true)</param>
public Texture3DPreviewAttribute(bool showField = true)
{
this.showField = showField;
}
#endregion
}
\ No newline at end of file
fileFormatVersion: 2
guid: 655fce24071158842896531956f42d6f
timeCreated: 1507549815
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 5a90d828c78ec4c45af1a8fc441309e8
folderAsset: yes
timeCreated: 1507537066
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 7fb0cffe903e81840976ed03aaca4141
folderAsset: yes
timeCreated: 1507550383
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System;
using UnityEditor;
using UnityEngine;
/// <summary>
/// Custom drawer for Texture3DPreview attribute
/// </summary>
[CustomPropertyDrawer(typeof(Texture3DPreviewAttribute))]
internal sealed class Texture3DPreviewDrawer : PropertyDrawer
{
#region Members
/// <summary>
/// Maximum preview size in the Inspector
/// </summary>
private const int _maxSize = 512;
/// <summary>
/// The material which the preview will be rendered with
/// </summary>
private static Material _material;
/// <summary>
/// String to show if the field is not a Texture3D
/// </summary>
private const string _notObjectOrTexture3DString = "Texture3DPreview attribute can only be used with Texture3D fields.";
/// <summary>
/// The angle of the camera preview
/// </summary>
private Vector2 _cameraAngle = new Vector2(127.5f, -22.5f);
/// <summary>
/// The raymarch interations
/// </summary>
private int _samplingIterations = 64;
/// <summary>
/// The factor of the Texture3D
/// </summary>
private float _density = 1;
#endregion
#region Functions
/// <summary>
/// Gets if the Texture3D should be displayed
/// </summary>
private bool ShowField
{
get
{
return ((Texture3DPreviewAttribute)attribute).showField;
}
}
/// <summary>
/// Checks if the drawn property is a UnityEngine.Object derived type
/// </summary>
/// <param name="property">The drawn object</param>
/// <returns>True if the drawn object is a UnityEngine.Object derived type, false otherwise</returns>
private bool CheckIfObjectType(SerializedProperty property)
{
return property.propertyType == SerializedPropertyType.ObjectReference;
}
/// <summary>
/// Checks if the drawn property is a Texture3D
/// </summary>
/// <param name="property">The drawn object</param>
/// <returns>True if the drawn object is a Texture3D, false otherwise</returns>
private bool CheckIfTexture3D(SerializedProperty property)
{
return property.objectReferenceValue.GetType() == typeof(Texture3D);
}
/// <summary>
/// Checks if the drawn property is null
/// </summary>
/// <param name="property">The drawn object</param>
/// <returns>True if the drawn object is null, false otherwise</returns>
private bool CheckIfNull(SerializedProperty property)
{
return property.objectReferenceValue == null;
}
/// <summary>
/// Computes the size of the preview accordingly to the Inspector width
/// </summary>
/// <param name="rightMargin">The margin reserved on the right of the preview</param>
/// <returns>The size of the preview</returns>
private int ComputePreviewSize(int rightMargin)
{
int size = Mathf.FloorToInt(EditorGUIUtility.currentViewWidth) - rightMargin;
size = Mathf.Min(size, Texture3DPreviewDrawer._maxSize);
return size;
}
/// <summary>
/// Sets back the camera angle
/// </summary>
public void ResetPreviewCameraAngle()
{
_cameraAngle = new Vector2(127.5f, -22.5f);
}
#endregion
#region Overriden base class functions (https://docs.unity3d.com/ScriptReference/PropertyDrawer.html)
/// <summary>
/// Sets the height of the custom drawer
/// </summary>
/// <param name="property">The drawn object</param>
/// <param name="label">The "made readable" name of the object (as would be seen in the Insprector)</param>
/// <returns></returns>
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
float size = 0;
if (CheckIfObjectType(property))
{
if (ShowField)
{
size += EditorGUIUtility.singleLineHeight;
}
if (!CheckIfNull(property))
{
if (CheckIfTexture3D(property))
{
size += ComputePreviewSize((int)EditorGUIUtility.singleLineHeight);
size += EditorGUIUtility.singleLineHeight;
}
else
{
size += EditorGUIUtility.singleLineHeight;
}
}
else
{
size += EditorGUIUtility.singleLineHeight;
}
}
else
{
size += EditorGUIUtility.singleLineHeight;
}
return size;
}
/// <summary>
/// Fills drawer area
/// </summary>
/// <param name="position">The area of the drawer</param>
/// <param name="property">The drawn object</param>
/// <param name="label">The "made readable" name of the object (as would be seen in the Insprector)</param>
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if(CheckIfObjectType(property))
{
if(ShowField)
{
Rect rect = position;
rect.height = EditorGUIUtility.singleLineHeight;
EditorGUI.ObjectField(rect, property, typeof(Texture3D));
position.y += EditorGUIUtility.singleLineHeight;
}
if(!CheckIfNull(property))
{
if(CheckIfTexture3D(property))
{
if (Event.current.type == EventType.Layout)
{
return;
}
int size = ComputePreviewSize((int)position.x * 2);
Rect drawArea = position;
drawArea.width = size;
drawArea.height = drawArea.width;
drawArea.x += position.width * 0.5f - drawArea.width * 0.5f;
_cameraAngle = PreviewRenderUtilityHelpers.DragToAngles(_cameraAngle, drawArea);
if (Event.current.type == EventType.Repaint)
{
GUI.DrawTexture(drawArea, ((Texture3D)property.objectReferenceValue).RenderTexture3DPreview(drawArea, EditorStyles.helpBox, _cameraAngle, 6.5f /*TODO : Find distance with fov and boundingsphere, when non uniform size will be supported*/, _samplingIterations, _density), ScaleMode.StretchToFill, true);
}
Rect rect = drawArea;
rect.y += drawArea.height;
rect.height = EditorGUIUtility.singleLineHeight;
rect.width = 100; // TODO : not use magic numbers
if (GUI.Button(rect, "Reset Camera", EditorStyles.miniButton))
{
ResetPreviewCameraAngle();
}
rect.x += rect.width;
rect.width = 60; // TODO : not use magic numbers
EditorGUI.LabelField(rect, "Quality :");
rect.x += rect.width;
_samplingIterations = EditorGUI.IntPopup(rect, _samplingIterations, new string[] { "16", "32", "64", "128", "256", "512" }, new int[] { 16, 32, 64, 128, 256, 512 });
rect.x += rect.width;
rect.width = 60; // TODO : not use magic numbers
EditorGUI.LabelField(rect, "Density :");
rect.x += rect.width;
rect.width = drawArea.width - 280; // TODO : not use magic numbers
_density = EditorGUI.Slider(rect, _density, 0, 5);
}
else
{
EditorGUI.LabelField(position, label.text, _notObjectOrTexture3DString, EditorStyles.boldLabel);
}
}
else
{
EditorGUI.LabelField(position, label.text, "Texture3D field is empty.", EditorStyles.boldLabel);
}
}
else
{
EditorGUI.LabelField(position, label.text, _notObjectOrTexture3DString, EditorStyles.boldLabel);
}
}
#endregion
}
fileFormatVersion: 2
guid: 52365bda6b1ad8945b713f96ada31cf3
timeCreated: 1507550391
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: bd30b7eb46077044b84d3daf863dada2
folderAsset: yes
timeCreated: 1507537074
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEditor;
using UnityEngine;
/// <summary>
/// Draws a custom Inspector for Texture3D assets
/// Actually, we will draw the default inspector but use the ability to draw a custom preview and render a custom asset's thumbnail
/// </summary>
[CustomEditor(typeof(Texture3D))]
public class Texture3DEditor : Editor
{
#region Members
/// <summary>
/// The angle of the camera preview
/// </summary>
private Vector2 _cameraAngle = new Vector2(127.5f, -22.5f); // This default value will be used when rendering the asset thumbnail (see RenderStaticPreview)
/// <summary>
/// The raymarch interations
/// </summary>
private int _samplingIterations = 64;
/// <summary>
/// The factor of the Texture3D
/// </summary>
private float _density = 1;
//// TODO : Investigate to access those variables as the default inspector is ugly
//private SerializedProperty wrapModeProperty;
//private SerializedProperty filterModeProperty;
//private SerializedProperty anisotropyLevelProperty;
#endregion
#region Functions
/// <summary>
/// Sets back the camera angle
/// </summary>
public void ResetPreviewCameraAngle()
{
_cameraAngle = new Vector2(127.5f, -22.5f);
}
#endregion
#region Overriden base class functions (https://docs.unity3d.com/ScriptReference/Editor.html)
/// <summary>
/// Draws the content of the Inspector
/// </summary>
public override void OnInspectorGUI()
{
serializedObject.Update();
//// Had to disable the default Inspector as it makes preview lag
//DrawDefaultInspector();
serializedObject.ApplyModifiedProperties();
}
#region Preview
/// <summary>
/// Tells if the Object has a custom preview
/// </summary>
public override bool HasPreviewGUI()
{
return true;
}
/// <summary>
/// Draws the toolbar area on top of the preview window
/// </summary>
public override void OnPreviewSettings()
{
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Reset Camera", EditorStyles.miniButton))
{
ResetPreviewCameraAngle();
}
EditorGUILayout.LabelField("Quality", GUILayout.MaxWidth(50));
_samplingIterations = EditorGUILayout.IntPopup(_samplingIterations, new string[] { "16", "32", "64", "128", "256", "512" }, new int[] { 16, 32, 64, 128, 256, 512 }, GUILayout.MaxWidth(50));
EditorGUILayout.LabelField("Density", GUILayout.MaxWidth(50));
_density = EditorGUILayout.Slider(_density, 0, 500, GUILayout.MaxWidth(200));
EditorGUILayout.EndHorizontal();
}
/// <summary>