Author SHA1 Message Date
Redstone1024 53c23effe5 Transitioning - Done! 2021-01-30 15:43:16 +08:00
Redstone1024 76edfff94f Random Functions 2021-01-30 15:30:35 +08:00
Redstone1024 ca8149da1f From Mathematical Surfaces 2021-01-30 11:09:57 +08:00
Redstone1024 d7a908352a init commit 2021-01-30 11:06:42 +08:00
23 changed files with 584 additions and 523 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 5c5c09c79ba995b4cbb07fc6eecd341b guid: a4c7a03a44f1e434eb0e7deeafc7b4d2
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
+78
View File
@@ -0,0 +1,78 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Point Surface
m_Shader: {fileID: 4800000, guid: dc209e68d98853d44a1454b74031fae0, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 8f3914ac4291e664ba60ae208ae66460 guid: 9c4aff419950b8d489cd03e743b1cfdd
NativeFormatImporter: NativeFormatImporter:
externalObjects: {} externalObjects: {}
mainObjectFileID: 0 mainObjectFileID: 0
+31
View File
@@ -0,0 +1,31 @@
Shader "Graph/Point Surface"
{
Properties
{
_Smoothness("Smoothness", Range(0, 1)) = 0.5
}
SubShader
{
CGPROGRAM
#pragma surface ConfigureSurface Standard fullforwardshadows
#pragma target 3.0
struct Input
{
float3 worldPos;
};
float _Smoothness;
void ConfigureSurface(Input input, inout SurfaceOutputStandard surface)
{
surface.Albedo = saturate(input.worldPos * 0.5 + 0.5);
surface.Smoothness = _Smoothness;
}
ENDCG
}
FallBack "Diffuse"
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 0ed85852d1001bf44b1fef32640df23b guid: dc209e68d98853d44a1454b74031fae0
ShaderImporter: ShaderImporter:
externalObjects: {} externalObjects: {}
defaultTextures: [] defaultTextures: []
@@ -1,5 +1,18 @@
%YAML 1.1 %YAML 1.1
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!114 &-7663591078679327442
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 2
--- !u!21 &2100000 --- !u!21 &2100000
Material: Material:
serializedVersion: 6 serializedVersion: 6
@@ -7,12 +20,12 @@ Material:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: Fractal URP m_Name: Point URP
m_Shader: {fileID: -6465566751694194690, guid: 2ccc118ffa0f0574ba86592258e86a9e, m_Shader: {fileID: -6465566751694194690, guid: fe43f72b38287ef4ea811bd1e2d4981b,
type: 3} type: 3}
m_ShaderKeywords: m_ShaderKeywords:
m_LightmapFlags: 4 m_LightmapFlags: 4
m_EnableInstancingVariants: 0 m_EnableInstancingVariants: 1
m_DoubleSidedGI: 0 m_DoubleSidedGI: 0
m_CustomRenderQueue: -1 m_CustomRenderQueue: -1
stringTagMap: {} stringTagMap: {}
@@ -49,7 +62,7 @@ Material:
m_Scale: {x: 1, y: 1} m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0} m_Offset: {x: 0, y: 0}
m_Floats: m_Floats:
- Vector1_8EEC20FB: 0.5 - Vector1_5DB27E09: 0.5
- _AlphaClip: 0 - _AlphaClip: 0
- _Blend: 0 - _Blend: 0
- _BumpScale: 1 - _BumpScale: 1
@@ -72,21 +85,7 @@ Material:
- _WorkflowMode: 1 - _WorkflowMode: 1
- _ZWrite: 1 - _ZWrite: 1
m_Colors: m_Colors:
- Vector3_32FB817D: {r: 1, g: 1, b: 0, a: 0} - _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _BaseColor: {r: 1, g: 1, b: 0, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
--- !u!114 &8940294238544827188
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 2
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8aefffdd80e5d2749a29b66e8618da01
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 2ccc118ffa0f0574ba86592258e86a9e guid: fe43f72b38287ef4ea811bd1e2d4981b
ScriptedImporter: ScriptedImporter:
internalIDToNameTable: [] internalIDToNameTable: []
externalObjects: {} externalObjects: {}
+95
View File
@@ -0,0 +1,95 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &5221897554875366702
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5221897554875366738}
- component: {fileID: 5221897554875366737}
- component: {fileID: 5221897554875366736}
- component: {fileID: 5221897554875366703}
m_Layer: 0
m_Name: Point
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5221897554875366738
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5221897554875366702}
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}
--- !u!33 &5221897554875366737
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5221897554875366702}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &5221897554875366736
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5221897554875366702}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 8aefffdd80e5d2749a29b66e8618da01, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!65 &5221897554875366703
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5221897554875366702}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: d73a635284aa0ca4eb9cc40879b3267d
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+23 -82
View File
@@ -121,7 +121,7 @@ NavMeshSettings:
debug: debug:
m_Flags: 0 m_Flags: 0
m_NavMeshData: {fileID: 0} m_NavMeshData: {fileID: 0}
--- !u!1 &197491472 --- !u!1 &75389714
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
@@ -129,107 +129,48 @@ GameObject:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 197491476} - component: {fileID: 75389716}
- component: {fileID: 197491473} - component: {fileID: 75389715}
m_Layer: 0 m_Layer: 0
m_Name: Fractal m_Name: Graph
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 1
--- !u!114 &197491473 --- !u!114 &75389715
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 197491472} m_GameObject: {fileID: 75389714}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bef3764eec961e04db4297ce68f82391, type: 3} m_Script: {fileID: 11500000, guid: 14cd06bfa92d53e4ebc0cde4a0e39db8, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
depth: 8 pointPrefab: {fileID: 5221897554875366738, guid: d73a635284aa0ca4eb9cc40879b3267d,
mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} type: 3}
leafMesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} resolution: 50
material: {fileID: 2100000, guid: 8f3914ac4291e664ba60ae208ae66460, type: 2} function: 4
gradientA: transitionMode: 2
serializedVersion: 2 functionDuration: 1
key0: {r: 0.764151, g: 0.18413278, b: 0, a: 0.3137255} transitionDuration: 1
key1: {r: 1, g: 1, b: 0, a: 0.3529412} --- !u!4 &75389716
key2: {r: 0, g: 0, b: 0, a: 0}
key3: {r: 0, g: 0, b: 0, a: 0}
key4: {r: 0, g: 0, b: 0, a: 0}
key5: {r: 0, g: 0, b: 0, a: 0}
key6: {r: 0, g: 0, b: 0, a: 0}
key7: {r: 0, g: 0, b: 0, a: 0}
ctime0: 0
ctime1: 65535
ctime2: 65535
ctime3: 0
ctime4: 0
ctime5: 0
ctime6: 0
ctime7: 0
atime0: 0
atime1: 65535
atime2: 0
atime3: 0
atime4: 0
atime5: 0
atime6: 0
atime7: 0
m_Mode: 0
m_NumColorKeys: 2
m_NumAlphaKeys: 2
gradientB:
serializedVersion: 2
key0: {r: 0.40392157, g: 0.14109339, b: 0, a: 0.54901963}
key1: {r: 0, g: 0.6320754, b: 0, a: 0.627451}
key2: {r: 1, g: 1, b: 0, a: 0}
key3: {r: 0, g: 0, b: 0, a: 0}
key4: {r: 0, g: 0, b: 0, a: 0}
key5: {r: 0, g: 0, b: 0, a: 0}
key6: {r: 0, g: 0, b: 0, a: 0}
key7: {r: 0, g: 0, b: 0, a: 0}
ctime0: 0
ctime1: 65535
ctime2: 65535
ctime3: 0
ctime4: 0
ctime5: 0
ctime6: 0
ctime7: 0
atime0: 0
atime1: 65535
atime2: 0
atime3: 0
atime4: 0
atime5: 0
atime6: 0
atime7: 0
m_Mode: 0
m_NumColorKeys: 2
m_NumAlphaKeys: 2
leafColorA: {r: 0.45882356, g: 0.97647065, b: 0.29803923, a: 0.49803922}
leafColorB: {r: 0.21568629, g: 0.4901961, b: 0.13333334, a: 0.9019608}
maxSagAngleA: 15
maxSagAngleB: 25
--- !u!4 &197491476
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 197491472} m_GameObject: {fileID: 75389714}
m_LocalRotation: {x: 0, y: 0, z: 0.17364816, w: 0.9848078} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 4 m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 20} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &705507993 --- !u!1 &705507993
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -399,8 +340,8 @@ Transform:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225} m_GameObject: {fileID: 963194225}
m_LocalRotation: {x: -0.20025373, y: -0.15736002, z: 0.032605395, w: -0.96647465} m_LocalRotation: {x: -0.32403755, y: -0.3351304, z: 0.123971656, w: -0.87596714}
m_LocalPosition: {x: -0.7724853, y: 1.44468, z: -2.6019344} m_LocalPosition: {x: -1.7640238, y: 2.0069275, z: -2.0079021}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
@@ -529,7 +470,7 @@ RectTransform:
m_Children: m_Children:
- {fileID: 1243679486} - {fileID: 1243679486}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 2 m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}
@@ -675,7 +616,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 3 m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1844483589 --- !u!1 &1844483589
GameObject: GameObject:
-253
View File
@@ -1,253 +0,0 @@
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;
using Random = UnityEngine.Random;
using static Unity.Mathematics.math;
using quaternion = Unity.Mathematics.quaternion;
public class Fractal : MonoBehaviour
{
[BurstCompile(FloatPrecision.Standard, FloatMode.Fast, CompileSynchronously = true)]
private struct UpdateFractalLevelJob : IJobFor
{
public float scale;
public float deltaTime;
[ReadOnly]
public NativeArray<FractalPart> parents;
public NativeArray<FractalPart> parts;
[WriteOnly]
public NativeArray<float3x4> matrices;
public void Execute(int i)
{
var parent = parents[i / 5];
var part = parts[i];
part.spinAngle += part.spinVelocity * deltaTime;
float3 upAxis =
mul(mul(parent.worldRotation, part.rotation), up());
float3 sagAxis = cross(up(), upAxis);
float sagMagnitude = length(sagAxis);
quaternion baseRotation;
if (sagMagnitude > 0f)
{
sagAxis /= sagMagnitude;
quaternion sagRotation =
quaternion.AxisAngle(sagAxis, part.maxSagAngle * sagMagnitude);
baseRotation = mul(sagRotation, parent.worldRotation);
}
else
{
baseRotation = parent.worldRotation;
}
part.worldRotation = mul(baseRotation,
mul(part.rotation, quaternion.RotateY(part.spinAngle))
);
part.worldPosition =
parent.worldPosition +
mul(part.worldRotation, float3(0f, 1.5f * scale, 0f));
parts[i] = part;
float3x3 r = float3x3(part.worldRotation) * scale;
matrices[i] = float3x4(r.c0, r.c1, r.c2, part.worldPosition);
}
}
private struct FractalPart
{
public float3 worldPosition;
public quaternion rotation, worldRotation;
public float maxSagAngle, spinAngle, spinVelocity;
}
NativeArray<FractalPart>[] parts;
NativeArray<float3x4>[] matrices;
[SerializeField, Range(3, 8)]
int depth = 4;
[SerializeField]
Mesh mesh = default, leafMesh = default;
[SerializeField]
Material material = default;
[SerializeField]
Gradient gradientA = default, gradientB = default;
[SerializeField]
Color leafColorA = default, leafColorB = default;
[SerializeField, Range(0f, 90f)]
float maxSagAngleA = 15f, maxSagAngleB = 25f;
[SerializeField, Range(0f, 90f)]
float spinSpeedA = 20f, spinSpeedB = 25f;
[SerializeField, Range(0f, 1f)]
float reverseSpinChance = 0.25f;
static float3[] directions =
{
up(), right(), left(), forward(), back()
};
static quaternion[] rotations =
{
quaternion.identity,
quaternion.RotateZ(-0.5f * PI), quaternion.RotateZ(0.5f * PI),
quaternion.RotateX(0.5f * PI), quaternion.RotateX(-0.5f * PI)
};
private FractalPart CreatePart(int childIndex)
{
return new FractalPart()
{
maxSagAngle = radians(Random.Range(maxSagAngleA, maxSagAngleB)),
rotation = rotations[childIndex],
spinVelocity =
(Random.value < reverseSpinChance ? -1f : 1f) *
radians(Random.Range(spinSpeedA, spinSpeedB))
};
}
ComputeBuffer[] matricesBuffers;
Vector4[] sequenceNumbers;
static readonly int colorAId = Shader.PropertyToID("_ColorA");
static readonly int colorBId = Shader.PropertyToID("_ColorB");
static readonly int matricesId = Shader.PropertyToID("_Matrices");
static readonly int sequenceNumbersId = Shader.PropertyToID("_SequenceNumbers");
static MaterialPropertyBlock propertyBlock;
private void OnEnable()
{
parts = new NativeArray<FractalPart>[depth];
matrices = new NativeArray<float3x4>[depth];
matricesBuffers = new ComputeBuffer[depth];
sequenceNumbers = new Vector4[depth];
int stride = 12 * 4;
for (int i = 0, length = 1; i < parts.Length; i++, length *= 5)
{
parts[i] = new NativeArray<FractalPart>(length, Allocator.Persistent);
matrices[i] = new NativeArray<float3x4>(length, Allocator.Persistent);
matricesBuffers[i] = new ComputeBuffer(length, stride);
sequenceNumbers[i] = new Vector4(Random.value, Random.value, Random.value, Random.value);
}
parts[0][0] = CreatePart(0);
for (int li = 1; li < parts.Length; li++)
{
NativeArray<FractalPart> levelParts = parts[li];
for (int fpi = 0; fpi < levelParts.Length; fpi += 5)
{
for (int ci = 0; ci < 5; ci++)
{
levelParts[fpi + ci] = CreatePart(ci);
}
}
}
if (propertyBlock == null)
{
propertyBlock = new MaterialPropertyBlock();
}
}
private void OnDisable()
{
for (int i = 0; i < matricesBuffers.Length; i++)
{
matricesBuffers[i].Release();
parts[i].Dispose();
matrices[i].Dispose();
}
parts = null;
matrices = null;
matricesBuffers = null;
sequenceNumbers = null;
}
void OnValidate()
{
if (parts != null && enabled)
{
OnDisable();
OnEnable();
}
}
private void Update()
{
float deltaTime = Time.deltaTime;
FractalPart rootPart = parts[0][0];
rootPart.spinAngle += rootPart.spinVelocity * deltaTime;
rootPart.worldRotation = mul(transform.rotation,
mul(rootPart.rotation, quaternion.RotateY(rootPart.spinAngle))
);
rootPart.worldPosition = transform.position;
parts[0][0] = rootPart;
float objectScale = transform.lossyScale.x;
float3x3 r = float3x3(rootPart.worldRotation) * objectScale;
matrices[0][0] = float3x4(r.c0, r.c1, r.c2, rootPart.worldPosition);
float scale = objectScale;
JobHandle jobHandle = default;
for (int li = 1; li < parts.Length; li++)
{
scale *= 0.5f;
jobHandle = new UpdateFractalLevelJob
{
deltaTime = deltaTime,
scale = scale,
parents = parts[li - 1],
parts = parts[li],
matrices = matrices[li]
}.ScheduleParallel(parts[li].Length, 5, jobHandle);
}
jobHandle.Complete();
var bounds = new Bounds(rootPart.worldPosition, float3(3f * objectScale));
int leafIndex = matricesBuffers.Length - 1;
for (int i = 0; i < matricesBuffers.Length; i++)
{
Mesh instanceMesh;
Color colorA, colorB;
if (i == leafIndex)
{
colorA = leafColorA;
colorB = leafColorB;
instanceMesh = leafMesh;
}
else
{
colorA = gradientA.Evaluate(i / (matricesBuffers.Length - 2f));
colorB = gradientB.Evaluate(i / (matricesBuffers.Length - 2f));
instanceMesh = mesh;
}
propertyBlock.SetColor(colorAId, colorA);
propertyBlock.SetColor(colorBId, colorB);
ComputeBuffer buffer = matricesBuffers[i];
buffer.SetData(matrices[i]);
float gradientInterpolator = i / (matricesBuffers.Length - 1f);
propertyBlock.SetColor(colorAId, gradientA.Evaluate(gradientInterpolator));
propertyBlock.SetColor(colorBId, gradientB.Evaluate(gradientInterpolator));
propertyBlock.SetBuffer(matricesId, buffer);
propertyBlock.SetVector(sequenceNumbersId, sequenceNumbers[i]);
Graphics.DrawMeshInstancedProcedural(instanceMesh, 0, material, bounds, buffer.count, propertyBlock);
}
}
}
+92
View File
@@ -0,0 +1,92 @@
using UnityEngine;
using static UnityEngine.Mathf;
public static class FunctionLibrary
{
public delegate Vector3 Function(float u, float v, float t);
public enum FunctionName { Wave, MultiWave, Ripple, Sphere, Torus }
private static Function[] functions = { Wave, MultiWave, Ripple, Sphere, Torus };
public static Function GetFunction(FunctionName name)
{
return functions[(int)name];
}
public static FunctionName GetNextFunctionName(FunctionName name)
{
return (int)name < functions.Length - 1 ? name + 1 : 0;
}
public static FunctionName GetRandomFunctionName()
{
return (FunctionName)Random.Range(0, functions.Length);
}
public static FunctionName GetRandomFunctionNameOtherThan(FunctionName name)
{
var choice = (FunctionName)Random.Range(1, functions.Length);
return choice == name ? 0 : choice;
}
public static Vector3 Wave(float u, float v, float t)
{
Vector3 p;
p.x = u;
p.y = Sin(PI * (u + v + t));
p.z = v;
return p;
}
public static Vector3 MultiWave(float u, float v, float t)
{
Vector3 p;
p.x = u;
p.y = Sin(PI * (u + 0.5f * t));
p.y += 0.5f * Sin(2f * PI * (v + t));
p.y += Sin(PI * (u + v + 0.25f * t));
p.y *= 1f / 2.5f;
p.z = v;
return p;
}
public static Vector3 Ripple(float u, float v, float t)
{
var d = Sqrt(u * u + v * v);
Vector3 p;
p.x = u;
p.y = Sin(PI * (4f * d - t));
p.y /= 1f + 10f * d;
p.z = v;
return p;
}
public static Vector3 Sphere(float u, float v, float t)
{
float r = 0.9f + 0.1f * Sin(PI * (6f * u + 4f * v + t));
float s = r * Cos(0.5f * PI * v);
Vector3 p;
p.x = s * Sin(PI * u);
p.y = r * Sin(0.5f * PI * v);
p.z = s * Cos(PI * u);
return p;
}
public static Vector3 Torus(float u, float v, float t)
{
float r1 = 0.7f + 0.1f * Sin(PI * (6f * u + 0.5f * t));
float r2 = 0.15f + 0.05f * Sin(PI * (8f * u + 4f * v + 2f * t));
float s = r1 + r2 * Cos(PI * v);
Vector3 p;
p.x = s * Sin(PI * u);
p.y = r2 * Sin(PI * v);
p.z = s * Cos(PI * u);
return p;
}
public static Vector3 Morph(float u, float v, float t, Function from, Function to, float progress)
{
return Vector3.LerpUnclamped(from(u, v, t), to(u, v, t), SmoothStep(0.0f, 1.0f, progress));
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: bef3764eec961e04db4297ce68f82391 guid: e5d4ebe0e863dfd49b58925b59880bf7
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
+123
View File
@@ -0,0 +1,123 @@
using UnityEngine;
public class Graph : MonoBehaviour
{
[SerializeField]
Transform pointPrefab = default;
[SerializeField, Range(10, 100)]
int resolution = 10;
[SerializeField]
FunctionLibrary.FunctionName function = default;
public enum TransitionMode { Normal, Cycle, Random }
[SerializeField]
TransitionMode transitionMode = TransitionMode.Normal;
[SerializeField, Min(0.0f)]
float functionDuration = 1.0f;
[SerializeField, Min(0.0f)]
float transitionDuration = 1.0f;
Transform[] points;
float duration = 0.0f;
bool transitioning;
FunctionLibrary.FunctionName transitionFunction;
private void Awake()
{
var step = 2f / resolution;
var scale = Vector3.one * step;
points = new Transform[resolution * resolution];
for (int i = 0; i < points.Length; i++)
{
Transform point = Instantiate(pointPrefab);
point.localScale = scale;
point.SetParent(transform, false);
points[i] = point;
}
}
private void Update()
{
duration += Time.deltaTime;
if (transitioning)
{
if (duration >= transitionDuration)
{
duration -= transitionDuration;
transitioning = false;
}
}
else if (duration >= functionDuration)
{
duration -= functionDuration;
transitioning = true;
transitionFunction = function;
PickNextFunction();
}
if (transitioning)
{
UpdateFunctionTransition();
}
else
{
UpdateFunction();
}
}
private void PickNextFunction()
{
if (transitionMode == TransitionMode.Normal) return;
function = transitionMode == TransitionMode.Cycle ?
FunctionLibrary.GetNextFunctionName(function) :
FunctionLibrary.GetRandomFunctionNameOtherThan(function);
}
private void UpdateFunction()
{
FunctionLibrary.Function f = FunctionLibrary.GetFunction(function);
var time = Time.time;
var step = 2.0f / resolution;
var v = 0.5f * step - 1f;
for (int i = 0, x = 0, z = 0; i < points.Length; i++, x++)
{
if (x == resolution)
{
x = 0;
z += 1;
v = (z + 0.5f) * step - 1f;
}
float u = (x + 0.5f) * step - 1f;
points[i].localPosition = f(u, v, time);
}
}
private void UpdateFunctionTransition()
{
FunctionLibrary.Function
from = FunctionLibrary.GetFunction(transitionFunction),
to = FunctionLibrary.GetFunction(function);
float progress = duration / transitionDuration;
float time = Time.time;
float step = 2f / resolution;
float v = 0.5f * step - 1f;
for (int i = 0, x = 0, z = 0; i < points.Length; i++, x++)
{
if (x == resolution)
{
x = 0;
z += 1;
v = (z + 0.5f) * step - 1f;
}
float u = (x + 0.5f) * step - 1f;
points[i].localPosition = FunctionLibrary.Morph(u, v, time, from, to, progress);
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 14cd06bfa92d53e4ebc0cde4a0e39db8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
-44
View File
@@ -1,44 +0,0 @@
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
StructuredBuffer<float3x4> _Matrices;
#endif
float4 _ColorA, _ColorB;
float4 _SequenceNumbers;
float4 GetFractalColor () {
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
float4 color;
color.rgb = lerp(
_ColorA.rgb, _ColorB.rgb,
frac(unity_InstanceID * _SequenceNumbers.x + _SequenceNumbers.y)
);
color.a = lerp(
_ColorA.a, _ColorB.a,
frac(unity_InstanceID * _SequenceNumbers.z + _SequenceNumbers.w)
);
return color;
#else
return _ColorA;
#endif
}
void ConfigureProcedural () {
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
float3x4 m = _Matrices[unity_InstanceID];
unity_ObjectToWorld._m00_m01_m02_m03 = m._m00_m01_m02_m03;
unity_ObjectToWorld._m10_m11_m12_m13 = m._m10_m11_m12_m13;
unity_ObjectToWorld._m20_m21_m22_m23 = m._m20_m21_m22_m23;
unity_ObjectToWorld._m30_m31_m32_m33 = float4(0.0, 0.0, 0.0, 1.0);
#endif
}
void ShaderGraphFunction_float (float3 In, out float3 Out, out float4 FractalColor) {
Out = In;
FractalColor = GetFractalColor();
}
void ShaderGraphFunction_half (half3 In, out half3 Out, out half4 FractalColor) {
Out = In;
FractalColor = GetFractalColor();
}
-1
View File
@@ -1,6 +1,5 @@
{ {
"dependencies": { "dependencies": {
"com.unity.burst": "1.4.4",
"com.unity.render-pipelines.universal": "7.5.3", "com.unity.render-pipelines.universal": "7.5.3",
"com.unity.textmeshpro": "2.1.3", "com.unity.textmeshpro": "2.1.3",
"com.unity.modules.ai": "1.0.0", "com.unity.modules.ai": "1.0.0",
-16
View File
@@ -1,21 +1,5 @@
{ {
"dependencies": { "dependencies": {
"com.unity.burst": {
"version": "1.4.4",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.mathematics": "1.2.1"
},
"url": "https://packages.unity.cn"
},
"com.unity.mathematics": {
"version": "1.2.1",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.cn"
},
"com.unity.render-pipelines.core": { "com.unity.render-pipelines.core": {
"version": "7.5.3", "version": "7.5.3",
"depth": 1, "depth": 1,
@@ -1,16 +0,0 @@
{
"MonoBehaviour": {
"Version": 3,
"EnableBurstCompilation": true,
"EnableOptimisations": true,
"EnableSafetyChecks": false,
"EnableDebugInAllBuilds": false,
"UsePlatformSDKLinker": false,
"CpuMinTargetX32": 0,
"CpuMaxTargetX32": 0,
"CpuMinTargetX64": 0,
"CpuMaxTargetX64": 0,
"CpuTargetsX32": 6,
"CpuTargetsX64": 72
}
}
+1 -2
View File
@@ -584,8 +584,7 @@ PlayerSettings:
webGLWasmStreaming: 0 webGLWasmStreaming: 0
scriptingDefineSymbols: {} scriptingDefineSymbols: {}
platformArchitecture: {} platformArchitecture: {}
scriptingBackend: scriptingBackend: {}
Standalone: 0
il2cppCompilerConfiguration: {} il2cppCompilerConfiguration: {}
managedStrippingLevel: {} managedStrippingLevel: {}
incrementalIl2cppBuild: {} incrementalIl2cppBuild: {}