Archived
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53c23effe5 | ||
|
|
76edfff94f | ||
|
|
ca8149da1f | ||
|
|
d7a908352a |
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c5c09c79ba995b4cbb07fc6eecd341b
|
||||
guid: a4c7a03a44f1e434eb0e7deeafc7b4d2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -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
|
||||
guid: 8f3914ac4291e664ba60ae208ae66460
|
||||
guid: 9c4aff419950b8d489cd03e743b1cfdd
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
@@ -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
|
||||
guid: 0ed85852d1001bf44b1fef32640df23b
|
||||
guid: dc209e68d98853d44a1454b74031fae0
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
@@ -1,5 +1,18 @@
|
||||
%YAML 1.1
|
||||
%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
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
@@ -7,12 +20,12 @@ Material:
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Fractal URP
|
||||
m_Shader: {fileID: -6465566751694194690, guid: 2ccc118ffa0f0574ba86592258e86a9e,
|
||||
m_Name: Point URP
|
||||
m_Shader: {fileID: -6465566751694194690, guid: fe43f72b38287ef4ea811bd1e2d4981b,
|
||||
type: 3}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_EnableInstancingVariants: 1
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
@@ -49,7 +62,7 @@ Material:
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- Vector1_8EEC20FB: 0.5
|
||||
- Vector1_5DB27E09: 0.5
|
||||
- _AlphaClip: 0
|
||||
- _Blend: 0
|
||||
- _BumpScale: 1
|
||||
@@ -72,21 +85,7 @@ Material:
|
||||
- _WorkflowMode: 1
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- Vector3_32FB817D: {r: 1, g: 1, b: 0, a: 0}
|
||||
- _BaseColor: {r: 1, g: 1, b: 0, a: 1}
|
||||
- _BaseColor: {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}
|
||||
- _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
|
||||
@@ -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
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ccc118ffa0f0574ba86592258e86a9e
|
||||
guid: fe43f72b38287ef4ea811bd1e2d4981b
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
@@ -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}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d73a635284aa0ca4eb9cc40879b3267d
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -121,7 +121,7 @@ NavMeshSettings:
|
||||
debug:
|
||||
m_Flags: 0
|
||||
m_NavMeshData: {fileID: 0}
|
||||
--- !u!1 &197491472
|
||||
--- !u!1 &75389714
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
@@ -129,43 +129,47 @@ GameObject:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 197491476}
|
||||
- component: {fileID: 197491473}
|
||||
- component: {fileID: 75389716}
|
||||
- component: {fileID: 75389715}
|
||||
m_Layer: 0
|
||||
m_Name: Fractal
|
||||
m_Name: Graph
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &197491473
|
||||
--- !u!114 &75389715
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 197491472}
|
||||
m_GameObject: {fileID: 75389714}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: bef3764eec961e04db4297ce68f82391, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: 14cd06bfa92d53e4ebc0cde4a0e39db8, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
depth: 8
|
||||
mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
|
||||
material: {fileID: 2100000, guid: 8f3914ac4291e664ba60ae208ae66460, type: 2}
|
||||
--- !u!4 &197491476
|
||||
pointPrefab: {fileID: 5221897554875366738, guid: d73a635284aa0ca4eb9cc40879b3267d,
|
||||
type: 3}
|
||||
resolution: 50
|
||||
function: 4
|
||||
transitionMode: 2
|
||||
functionDuration: 1
|
||||
transitionDuration: 1
|
||||
--- !u!4 &75389716
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 197491472}
|
||||
m_GameObject: {fileID: 75389714}
|
||||
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: 4
|
||||
m_RootOrder: 2
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &705507993
|
||||
GameObject:
|
||||
@@ -336,8 +340,8 @@ Transform:
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 963194225}
|
||||
m_LocalRotation: {x: -0.20025373, y: -0.15736002, z: 0.032605395, w: -0.96647465}
|
||||
m_LocalPosition: {x: -0.7724853, y: 1.44468, z: -2.6019344}
|
||||
m_LocalRotation: {x: -0.32403755, y: -0.3351304, z: 0.123971656, w: -0.87596714}
|
||||
m_LocalPosition: {x: -1.7640238, y: 2.0069275, z: -2.0079021}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
@@ -466,7 +470,7 @@ RectTransform:
|
||||
m_Children:
|
||||
- {fileID: 1243679486}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 2
|
||||
m_RootOrder: 3
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
@@ -612,7 +616,7 @@ Transform:
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 3
|
||||
m_RootOrder: 4
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &1844483589
|
||||
GameObject:
|
||||
|
||||
@@ -1,184 +0,0 @@
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using Unity.Jobs;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
|
||||
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 spinAngleDelta;
|
||||
public float scale;
|
||||
|
||||
[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 += spinAngleDelta;
|
||||
part.worldRotation = mul(parent.worldRotation,
|
||||
mul(part.rotation, quaternion.RotateY(part.spinAngle))
|
||||
);
|
||||
part.worldPosition =
|
||||
parent.worldPosition +
|
||||
mul(parent.worldRotation, 1.5f * scale * part.direction);
|
||||
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 direction, worldPosition;
|
||||
public quaternion rotation, worldRotation;
|
||||
public float spinAngle;
|
||||
}
|
||||
|
||||
NativeArray<FractalPart>[] parts;
|
||||
|
||||
NativeArray<float3x4>[] matrices;
|
||||
|
||||
[SerializeField, Range(1, 8)]
|
||||
int depth = 4;
|
||||
|
||||
[SerializeField]
|
||||
Mesh mesh = default;
|
||||
|
||||
[SerializeField]
|
||||
Material material = default;
|
||||
|
||||
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()
|
||||
{
|
||||
direction = directions[childIndex],
|
||||
rotation = rotations[childIndex]
|
||||
};
|
||||
}
|
||||
|
||||
ComputeBuffer[] matricesBuffers;
|
||||
|
||||
static readonly int matricesId = Shader.PropertyToID("_Matrices");
|
||||
|
||||
static MaterialPropertyBlock propertyBlock;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
parts = new NativeArray<FractalPart>[depth];
|
||||
matrices = new NativeArray<float3x4>[depth];
|
||||
matricesBuffers = new ComputeBuffer[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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
if (parts != null && enabled)
|
||||
{
|
||||
OnDisable();
|
||||
OnEnable();
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
float spinAngleDelta = 0.125f * PI * Time.deltaTime;
|
||||
FractalPart rootPart = parts[0][0];
|
||||
rootPart.spinAngle += spinAngleDelta;
|
||||
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
|
||||
{
|
||||
spinAngleDelta = spinAngleDelta,
|
||||
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));
|
||||
for (int i = 0; i < matricesBuffers.Length; i++)
|
||||
{
|
||||
ComputeBuffer buffer = matricesBuffers[i];
|
||||
buffer.SetData(matrices[i]);
|
||||
propertyBlock.SetBuffer(matricesId, buffer);
|
||||
Graphics.DrawMeshInstancedProcedural(mesh, 0, material, bounds, buffer.count, propertyBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
guid: bef3764eec961e04db4297ce68f82391
|
||||
guid: e5d4ebe0e863dfd49b58925b59880bf7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14cd06bfa92d53e4ebc0cde4a0e39db8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,21 +0,0 @@
|
||||
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
|
||||
StructuredBuffer<float3x4> _Matrices;
|
||||
#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 = In;
|
||||
}
|
||||
|
||||
void ShaderGraphFunction_half (half3 In, out half3 Out) {
|
||||
Out = In;
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"com.unity.burst": "1.4.4",
|
||||
"com.unity.render-pipelines.universal": "7.5.3",
|
||||
"com.unity.textmeshpro": "2.1.3",
|
||||
"com.unity.modules.ai": "1.0.0",
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
{
|
||||
"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": {
|
||||
"version": "7.5.3",
|
||||
"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
|
||||
}
|
||||
}
|
||||
@@ -584,8 +584,7 @@ PlayerSettings:
|
||||
webGLWasmStreaming: 0
|
||||
scriptingDefineSymbols: {}
|
||||
platformArchitecture: {}
|
||||
scriptingBackend:
|
||||
Standalone: 0
|
||||
scriptingBackend: {}
|
||||
il2cppCompilerConfiguration: {}
|
||||
managedStrippingLevel: {}
|
||||
incrementalIl2cppBuild: {}
|
||||
|
||||
Reference in New Issue
Block a user