first commit
This commit is contained in:
commit
29e55b293e
60 files changed
+5793
No files matched your search
@@ -0,0 +1,438 @@
|
||||
{
|
||||
"m_SGVersion": 3,
|
||||
"m_Type": "UnityEditor.ShaderGraph.GraphData",
|
||||
"m_ObjectId": "4ea35b44b3fe4b25a7cb4e39a4b9b407",
|
||||
"m_Properties": [],
|
||||
"m_Keywords": [
|
||||
{
|
||||
"m_Id": "9ba4f485275c4fc9b2f1ce82a79369c4"
|
||||
}
|
||||
],
|
||||
"m_Dropdowns": [],
|
||||
"m_CategoryData": [
|
||||
{
|
||||
"m_Id": "480708220ad2491387a14ef84b7fe431"
|
||||
}
|
||||
],
|
||||
"m_Nodes": [
|
||||
{
|
||||
"m_Id": "281b26d889224fc487a79fa8214bd0b1"
|
||||
},
|
||||
{
|
||||
"m_Id": "c5119037ba0c48fbba1bb84ead9a5adb"
|
||||
},
|
||||
{
|
||||
"m_Id": "4e57f58cc3d24bf1b53cde5e846cbd31"
|
||||
},
|
||||
{
|
||||
"m_Id": "304803996acc4ca999953697d05a2515"
|
||||
}
|
||||
],
|
||||
"m_GroupDatas": [],
|
||||
"m_StickyNoteDatas": [],
|
||||
"m_Edges": [
|
||||
{
|
||||
"m_OutputSlot": {
|
||||
"m_Node": {
|
||||
"m_Id": "304803996acc4ca999953697d05a2515"
|
||||
},
|
||||
"m_SlotId": 1
|
||||
},
|
||||
"m_InputSlot": {
|
||||
"m_Node": {
|
||||
"m_Id": "281b26d889224fc487a79fa8214bd0b1"
|
||||
},
|
||||
"m_SlotId": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"m_OutputSlot": {
|
||||
"m_Node": {
|
||||
"m_Id": "4e57f58cc3d24bf1b53cde5e846cbd31"
|
||||
},
|
||||
"m_SlotId": 1
|
||||
},
|
||||
"m_InputSlot": {
|
||||
"m_Node": {
|
||||
"m_Id": "304803996acc4ca999953697d05a2515"
|
||||
},
|
||||
"m_SlotId": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"m_OutputSlot": {
|
||||
"m_Node": {
|
||||
"m_Id": "c5119037ba0c48fbba1bb84ead9a5adb"
|
||||
},
|
||||
"m_SlotId": 0
|
||||
},
|
||||
"m_InputSlot": {
|
||||
"m_Node": {
|
||||
"m_Id": "4e57f58cc3d24bf1b53cde5e846cbd31"
|
||||
},
|
||||
"m_SlotId": 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"m_VertexContext": {
|
||||
"m_Position": {
|
||||
"x": 0.0,
|
||||
"y": 0.0
|
||||
},
|
||||
"m_Blocks": []
|
||||
},
|
||||
"m_FragmentContext": {
|
||||
"m_Position": {
|
||||
"x": 0.0,
|
||||
"y": 0.0
|
||||
},
|
||||
"m_Blocks": []
|
||||
},
|
||||
"m_PreviewData": {
|
||||
"serializedMesh": {
|
||||
"m_SerializedMesh": "{\"mesh\":{\"instanceID\":0}}",
|
||||
"m_Guid": ""
|
||||
},
|
||||
"preventRotation": false
|
||||
},
|
||||
"m_Path": "Sub Graphs",
|
||||
"m_GraphPrecision": 1,
|
||||
"m_PreviewMode": 2,
|
||||
"m_OutputNode": {
|
||||
"m_Id": "281b26d889224fc487a79fa8214bd0b1"
|
||||
},
|
||||
"m_ActiveTargets": []
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot",
|
||||
"m_ObjectId": "13e38f92c90c4e709dc150f29929c84a",
|
||||
"m_Id": 0,
|
||||
"m_DisplayName": "Out",
|
||||
"m_SlotType": 1,
|
||||
"m_Hidden": false,
|
||||
"m_ShaderOutputName": "Out",
|
||||
"m_StageCapability": 3,
|
||||
"m_Value": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0
|
||||
},
|
||||
"m_DefaultValue": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0
|
||||
},
|
||||
"m_Labels": []
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.ShaderGraph.SubGraphOutputNode",
|
||||
"m_ObjectId": "281b26d889224fc487a79fa8214bd0b1",
|
||||
"m_Group": {
|
||||
"m_Id": ""
|
||||
},
|
||||
"m_Name": "Output",
|
||||
"m_DrawState": {
|
||||
"m_Expanded": true,
|
||||
"m_Position": {
|
||||
"serializedVersion": "2",
|
||||
"x": 25.00006866455078,
|
||||
"y": -310.0,
|
||||
"width": 96.99996185302735,
|
||||
"height": 77.00001525878906
|
||||
}
|
||||
},
|
||||
"m_Slots": [
|
||||
{
|
||||
"m_Id": "aca287a71573483789d5dcb380daa40c"
|
||||
}
|
||||
],
|
||||
"synonyms": [],
|
||||
"m_Precision": 0,
|
||||
"m_PreviewExpanded": true,
|
||||
"m_DismissedVersion": 0,
|
||||
"m_PreviewMode": 0,
|
||||
"m_CustomColors": {
|
||||
"m_SerializableColors": []
|
||||
},
|
||||
"IsFirstSlotValid": true
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 1,
|
||||
"m_Type": "UnityEditor.ShaderGraph.CustomFunctionNode",
|
||||
"m_ObjectId": "304803996acc4ca999953697d05a2515",
|
||||
"m_Group": {
|
||||
"m_Id": ""
|
||||
},
|
||||
"m_Name": "IncludeThoMagicRenderer (Custom Function)",
|
||||
"m_DrawState": {
|
||||
"m_Expanded": true,
|
||||
"m_Position": {
|
||||
"serializedVersion": "2",
|
||||
"x": -330.0,
|
||||
"y": -310.0,
|
||||
"width": 304.0,
|
||||
"height": 94.0
|
||||
}
|
||||
},
|
||||
"m_Slots": [
|
||||
{
|
||||
"m_Id": "59dd7ed4b8b14695ab4443b7b89ab9df"
|
||||
},
|
||||
{
|
||||
"m_Id": "79b2dd99d8ea4726856c03ea82ede95b"
|
||||
}
|
||||
],
|
||||
"synonyms": [
|
||||
"code",
|
||||
"HLSL"
|
||||
],
|
||||
"m_Precision": 0,
|
||||
"m_PreviewExpanded": false,
|
||||
"m_DismissedVersion": 0,
|
||||
"m_PreviewMode": 0,
|
||||
"m_CustomColors": {
|
||||
"m_SerializableColors": []
|
||||
},
|
||||
"m_SourceType": 0,
|
||||
"m_FunctionName": "IncludeThoMagicRenderer",
|
||||
"m_FunctionSource": "678dff042fe9c004cb7522c2233af44d",
|
||||
"m_FunctionBody": "Enter function body here..."
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot",
|
||||
"m_ObjectId": "45a92477b6a7449c9c4d29eac6f7f4c1",
|
||||
"m_Id": 0,
|
||||
"m_DisplayName": "In",
|
||||
"m_SlotType": 0,
|
||||
"m_Hidden": false,
|
||||
"m_ShaderOutputName": "In",
|
||||
"m_StageCapability": 3,
|
||||
"m_Value": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0
|
||||
},
|
||||
"m_DefaultValue": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0
|
||||
},
|
||||
"m_Labels": []
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.ShaderGraph.CategoryData",
|
||||
"m_ObjectId": "480708220ad2491387a14ef84b7fe431",
|
||||
"m_Name": "",
|
||||
"m_ChildObjectList": [
|
||||
{
|
||||
"m_Id": "9ba4f485275c4fc9b2f1ce82a79369c4"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 1,
|
||||
"m_Type": "UnityEditor.ShaderGraph.CustomFunctionNode",
|
||||
"m_ObjectId": "4e57f58cc3d24bf1b53cde5e846cbd31",
|
||||
"m_Group": {
|
||||
"m_Id": ""
|
||||
},
|
||||
"m_Name": "SetupThoMagicRenderer (Custom Function)",
|
||||
"m_DrawState": {
|
||||
"m_Expanded": true,
|
||||
"m_Position": {
|
||||
"serializedVersion": "2",
|
||||
"x": -694.0,
|
||||
"y": -310.0000305175781,
|
||||
"width": 296.9999694824219,
|
||||
"height": 94.00001525878906
|
||||
}
|
||||
},
|
||||
"m_Slots": [
|
||||
{
|
||||
"m_Id": "45a92477b6a7449c9c4d29eac6f7f4c1"
|
||||
},
|
||||
{
|
||||
"m_Id": "ca8752373fc04409ae302adfc1808024"
|
||||
}
|
||||
],
|
||||
"synonyms": [
|
||||
"code",
|
||||
"HLSL"
|
||||
],
|
||||
"m_Precision": 0,
|
||||
"m_PreviewExpanded": false,
|
||||
"m_DismissedVersion": 0,
|
||||
"m_PreviewMode": 0,
|
||||
"m_CustomColors": {
|
||||
"m_SerializableColors": []
|
||||
},
|
||||
"m_SourceType": 1,
|
||||
"m_FunctionName": "SetupThoMagicRenderer",
|
||||
"m_FunctionSource": "06018a56d442f704f82b130cdeaf74ef",
|
||||
"m_FunctionBody": "Out = In;\n#pragma instancing_options procedural:SetupThoMagicRenderer\r\r\n"
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot",
|
||||
"m_ObjectId": "59dd7ed4b8b14695ab4443b7b89ab9df",
|
||||
"m_Id": 0,
|
||||
"m_DisplayName": "In",
|
||||
"m_SlotType": 0,
|
||||
"m_Hidden": false,
|
||||
"m_ShaderOutputName": "In",
|
||||
"m_StageCapability": 3,
|
||||
"m_Value": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0
|
||||
},
|
||||
"m_DefaultValue": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0
|
||||
},
|
||||
"m_Labels": []
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot",
|
||||
"m_ObjectId": "79b2dd99d8ea4726856c03ea82ede95b",
|
||||
"m_Id": 1,
|
||||
"m_DisplayName": "Out",
|
||||
"m_SlotType": 1,
|
||||
"m_Hidden": false,
|
||||
"m_ShaderOutputName": "Out",
|
||||
"m_StageCapability": 3,
|
||||
"m_Value": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0
|
||||
},
|
||||
"m_DefaultValue": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0
|
||||
},
|
||||
"m_Labels": []
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 1,
|
||||
"m_Type": "UnityEditor.ShaderGraph.ShaderKeyword",
|
||||
"m_ObjectId": "9ba4f485275c4fc9b2f1ce82a79369c4",
|
||||
"m_Guid": {
|
||||
"m_GuidSerialized": "019818f3-0f1b-49f3-8508-39d308ae3731"
|
||||
},
|
||||
"m_Name": "PROCEDURAL_INSTANCING_ON",
|
||||
"m_DefaultRefNameVersion": 1,
|
||||
"m_RefNameGeneratedByDisplayName": "PROCEDURAL_INSTANCING_ON",
|
||||
"m_DefaultReferenceName": "_PROCEDURAL_INSTANCING_ON",
|
||||
"m_OverrideReferenceName": "",
|
||||
"m_GeneratePropertyBlock": true,
|
||||
"m_UseCustomSlotLabel": false,
|
||||
"m_CustomSlotLabel": "",
|
||||
"m_DismissedVersion": 0,
|
||||
"m_KeywordType": 0,
|
||||
"m_KeywordDefinition": 0,
|
||||
"m_KeywordScope": 1,
|
||||
"m_KeywordStages": 63,
|
||||
"m_Entries": [],
|
||||
"m_Value": 1,
|
||||
"m_IsEditable": true
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot",
|
||||
"m_ObjectId": "aca287a71573483789d5dcb380daa40c",
|
||||
"m_Id": 1,
|
||||
"m_DisplayName": "Position",
|
||||
"m_SlotType": 0,
|
||||
"m_Hidden": false,
|
||||
"m_ShaderOutputName": "Position",
|
||||
"m_StageCapability": 3,
|
||||
"m_Value": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0
|
||||
},
|
||||
"m_DefaultValue": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0
|
||||
},
|
||||
"m_Labels": []
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 1,
|
||||
"m_Type": "UnityEditor.ShaderGraph.PositionNode",
|
||||
"m_ObjectId": "c5119037ba0c48fbba1bb84ead9a5adb",
|
||||
"m_Group": {
|
||||
"m_Id": ""
|
||||
},
|
||||
"m_Name": "Position",
|
||||
"m_DrawState": {
|
||||
"m_Expanded": true,
|
||||
"m_Position": {
|
||||
"serializedVersion": "2",
|
||||
"x": -952.0,
|
||||
"y": -310.0,
|
||||
"width": 206.0,
|
||||
"height": 131.00003051757813
|
||||
}
|
||||
},
|
||||
"m_Slots": [
|
||||
{
|
||||
"m_Id": "13e38f92c90c4e709dc150f29929c84a"
|
||||
}
|
||||
],
|
||||
"synonyms": [
|
||||
"location"
|
||||
],
|
||||
"m_Precision": 1,
|
||||
"m_PreviewExpanded": false,
|
||||
"m_DismissedVersion": 0,
|
||||
"m_PreviewMode": 2,
|
||||
"m_CustomColors": {
|
||||
"m_SerializableColors": []
|
||||
},
|
||||
"m_Space": 0,
|
||||
"m_PositionSource": 0
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot",
|
||||
"m_ObjectId": "ca8752373fc04409ae302adfc1808024",
|
||||
"m_Id": 1,
|
||||
"m_DisplayName": "Out",
|
||||
"m_SlotType": 1,
|
||||
"m_Hidden": false,
|
||||
"m_ShaderOutputName": "Out",
|
||||
"m_StageCapability": 3,
|
||||
"m_Value": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0
|
||||
},
|
||||
"m_DefaultValue": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0
|
||||
},
|
||||
"m_Labels": []
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ac8f6239a1b8d94a9aa0ba4ece1f714
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3}
|
||||
@@ -0,0 +1,418 @@
|
||||
#pragma kernel Cull_32 GROUPS=32
|
||||
#pragma kernel Cull_64 GROUPS=64
|
||||
#pragma kernel Cull_128 GROUPS=128
|
||||
#pragma kernel Cull_256 GROUPS=256
|
||||
#pragma kernel Cull_512 GROUPS=512
|
||||
#pragma kernel Cull_1024 GROUPS=1024
|
||||
|
||||
#pragma kernel Clear_32 GROUPS=32
|
||||
#pragma kernel Clear_64 GROUPS=64
|
||||
#pragma kernel Clear_128 GROUPS=128
|
||||
#pragma kernel Clear_256 GROUPS=256
|
||||
#pragma kernel Clear_512 GROUPS=512
|
||||
#pragma kernel Clear_1024 GROUPS=1024
|
||||
|
||||
#pragma kernel Upload_32 GROUPS=32
|
||||
#pragma kernel Upload_64 GROUPS=64
|
||||
#pragma kernel Upload_128 GROUPS=128
|
||||
#pragma kernel Upload_256 GROUPS=256
|
||||
#pragma kernel Upload_512 GROUPS=512
|
||||
#pragma kernel Upload_1024 GROUPS=1024
|
||||
|
||||
#pragma kernel Resize_32 GROUPS=32
|
||||
#pragma kernel Resize_64 GROUPS=64
|
||||
#pragma kernel Resize_128 GROUPS=128
|
||||
#pragma kernel Resize_256 GROUPS=256
|
||||
#pragma kernel Resize_512 GROUPS=512
|
||||
#pragma kernel Resize_1024 GROUPS=1024
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct InstanceData
|
||||
{
|
||||
// position.xyz : position.xyz
|
||||
// position.w : rotation.x
|
||||
// scale.x : scale.xz
|
||||
// scale.y : scale.y
|
||||
// scale.zw : rotation.yz
|
||||
float4 position;
|
||||
float4 scale;
|
||||
uint prefabId;
|
||||
//Used to stream out new instances
|
||||
int uploadAction;
|
||||
int uploadId;
|
||||
int age;
|
||||
};
|
||||
|
||||
struct PrefabData
|
||||
{
|
||||
uint batchIndex;
|
||||
uint indexBufferStartOffset;
|
||||
uint maxCount;
|
||||
uint lodCount;
|
||||
uint fadeLods;//Todo: Use Bitwise and save memory?
|
||||
//x: density threshold, y: density range start, z: density range length, w: shadow distance
|
||||
float4 densityInDistance;
|
||||
float4 lodData[8];
|
||||
uint2 indirectArgsIndexAndCountPerLod[8];
|
||||
};
|
||||
|
||||
struct InstanceMeta
|
||||
{
|
||||
uint visibleLod;
|
||||
uint fadeOutLod;
|
||||
float fadeAnim;
|
||||
|
||||
// The scale of the instance can be adjusted
|
||||
float Scale;
|
||||
};
|
||||
|
||||
StructuredBuffer<InstanceData> globalUploadInstances;
|
||||
RWStructuredBuffer<InstanceData> globalInstances;
|
||||
RWStructuredBuffer<InstanceData> tempGlobalInstances;
|
||||
StructuredBuffer<PrefabData> perCamPrefabs;
|
||||
StructuredBuffer<uint> perCamCullableIndexesBuffer;
|
||||
RWStructuredBuffer<InstanceMeta> perCamMeta;
|
||||
RWStructuredBuffer<uint> perCamIndirectArgumentsBuffer;
|
||||
RWStructuredBuffer<uint> perCamVisibleIndexesBuffer;
|
||||
RWStructuredBuffer<uint> perCamShadowVisibleIndexesBuffer;
|
||||
|
||||
uint _CountClear;
|
||||
uint _CountUpload;
|
||||
uint _CountResize;
|
||||
uint _CountCull;
|
||||
float3 _CameraPosition;
|
||||
float3 _ShadowDirection;
|
||||
float4 _FrustumPlanes[6];
|
||||
|
||||
// Plane equation: {(a, b, c) = N, d = -dot(N, P)}.
|
||||
// Returns the distance from the plane to the point 'p' along the normal.
|
||||
// Positive -> in front (above), negative -> behind (below).
|
||||
float DistanceFromPlane(float3 p, float4 plane)
|
||||
{
|
||||
return dot(float4(p, 1.0), plane);
|
||||
}
|
||||
|
||||
// Returns 'true' if the object is outside of the frustum.
|
||||
// 'size' is the (negative) size of the object's bounds.
|
||||
bool CullFrustum(float3 center, float size, float4 frustumPlanes[6], int numPlanes)
|
||||
{
|
||||
bool outside = false;
|
||||
[unroll(6)]
|
||||
for (int i = 0; i < numPlanes; i++)
|
||||
outside = outside || DistanceFromPlane(center, frustumPlanes[i]) < size;
|
||||
|
||||
return outside;
|
||||
}
|
||||
|
||||
// Returns 'true' if the shadow of the object is outside of the frustum.
|
||||
// 'size' is the (negative) size of the object's bounds.
|
||||
bool CullShadowFrustum(float3 center, float size, float3 lightDirection, float4 frustumPlanes[6], int numPlanes)
|
||||
{
|
||||
bool outside = false;
|
||||
[unroll(6)]
|
||||
for (int i = 0; i < numPlanes; i++)
|
||||
outside = outside || max(DistanceFromPlane(center, frustumPlanes[i]), DistanceFromPlane(center + lightDirection, frustumPlanes[i])) < size;
|
||||
|
||||
return outside;
|
||||
}
|
||||
|
||||
// Calculates the adjusted scale of the instance based on the "Density in Distance"
|
||||
// setting. Instances get scaled down if the density is reduced.
|
||||
float ReduceDensityScale(inout InstanceData instance, float4 densityInDistance, float distance)
|
||||
{
|
||||
float rangeStart = densityInDistance.y;
|
||||
float rangeLength = densityInDistance.z;
|
||||
|
||||
// Calculate a dither pattern with range [0..1]
|
||||
float dither = frac(dot(float3((instance.position.xz) * 16.0f, 0), uint3(2, 7, 23) / 17.0f));
|
||||
|
||||
float densityThreshold = 1 - densityInDistance.x;
|
||||
float distanceNormalized = (distance - rangeStart) / (rangeLength * dither + 0.001f);
|
||||
|
||||
if(dither > densityInDistance.x && distanceNormalized > 0)
|
||||
return 1 - distanceNormalized;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ClearArgumentsBuffer(uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id.x >= _CountClear)
|
||||
return;
|
||||
|
||||
uint indirectArgsCountOffset = id.x * 5 + 1;
|
||||
perCamIndirectArgumentsBuffer[indirectArgsCountOffset] = 0;
|
||||
}
|
||||
|
||||
void Upload (uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id.x >= _CountUpload)
|
||||
return;
|
||||
|
||||
InstanceData instance = globalUploadInstances[id.x];
|
||||
|
||||
if (instance.uploadAction == 1)
|
||||
{
|
||||
globalInstances[instance.uploadId] = instance;
|
||||
}
|
||||
}
|
||||
|
||||
void Resize(uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id.x >= _CountResize)
|
||||
return;
|
||||
|
||||
tempGlobalInstances[id.x] = globalInstances[id.x];
|
||||
}
|
||||
|
||||
void Cull (uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if(id.x >= _CountCull)
|
||||
return;
|
||||
|
||||
uint instanceIndex = perCamCullableIndexesBuffer[id.x];
|
||||
InstanceData instance = globalInstances[instanceIndex];
|
||||
InstanceMeta meta = perCamMeta[instanceIndex];
|
||||
PrefabData prefab = perCamPrefabs[instance.prefabId];
|
||||
|
||||
if (instance.age == 0)
|
||||
{
|
||||
meta = (InstanceMeta)0;
|
||||
globalInstances[instanceIndex].age = 1;
|
||||
}
|
||||
|
||||
uint lodCount = prefab.lodCount;
|
||||
|
||||
uint visibleLod = 0;
|
||||
uint visibleShadowLod = 0;
|
||||
uint batchOffset = 0;
|
||||
uint indirectArgsCount = 0;
|
||||
uint indirectArgsCountOffset = 0;
|
||||
uint i = 0;
|
||||
uint u = 0;
|
||||
|
||||
// Calculate active LOD
|
||||
float dist = distance(instance.position.xyz, _CameraPosition.xyz);
|
||||
|
||||
[unroll(8)]
|
||||
for(i=0; i < lodCount; i++)
|
||||
{
|
||||
float maxDist =
|
||||
i < lodCount - 1 ? prefab.lodData[i].y * instance.scale.y : prefab.lodData[i].y;
|
||||
|
||||
if(dist >= prefab.lodData[i].x * instance.scale.y && dist < maxDist)
|
||||
{
|
||||
visibleLod = i + 1;
|
||||
if (dist < prefab.densityInDistance.w)//prefab.densityInDistance.w = max shadow distance
|
||||
visibleShadowLod = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Reduce density
|
||||
if(prefab.densityInDistance.x < 1)
|
||||
{
|
||||
meta.Scale = ReduceDensityScale(instance, prefab.densityInDistance, dist);
|
||||
if(meta.Scale < 0.3)
|
||||
{
|
||||
visibleLod = 0;
|
||||
visibleShadowLod = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
meta.Scale = 1;
|
||||
}
|
||||
|
||||
// Frustum Culling
|
||||
if(visibleLod > 0)
|
||||
{
|
||||
float size = -prefab.lodData[visibleLod - 1].z * length(instance.scale.xy);
|
||||
const int planeCount = 5; // Do not test near/far planes
|
||||
if (CullFrustum(instance.position.xyz, size, _FrustumPlanes, planeCount))
|
||||
{
|
||||
// Setting active LOD to 0 culls the instance. The LODs start from 1.
|
||||
visibleLod = 0;
|
||||
|
||||
if (CullShadowFrustum(
|
||||
instance.position.xyz,
|
||||
size,
|
||||
_ShadowDirection * 1000,
|
||||
_FrustumPlanes,
|
||||
planeCount))
|
||||
{
|
||||
visibleShadowLod = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint visibleCount = 0;
|
||||
|
||||
if (visibleLod > 0)
|
||||
{
|
||||
batchOffset = prefab.indexBufferStartOffset + ((visibleLod - 1) * prefab.maxCount);
|
||||
indirectArgsCount = prefab.indirectArgsIndexAndCountPerLod[visibleLod - 1].y;
|
||||
indirectArgsCountOffset = prefab.indirectArgsIndexAndCountPerLod[visibleLod - 1].x + 1;
|
||||
|
||||
InterlockedAdd(perCamIndirectArgumentsBuffer[indirectArgsCountOffset], 1, visibleCount);
|
||||
|
||||
for (i = 1, u = 5; i < indirectArgsCount; i++, u += 5)
|
||||
{
|
||||
InterlockedAdd(perCamIndirectArgumentsBuffer[indirectArgsCountOffset + u], 1);
|
||||
}
|
||||
|
||||
perCamVisibleIndexesBuffer[batchOffset + visibleCount] = instanceIndex;
|
||||
|
||||
if (meta.visibleLod != visibleLod && meta.visibleLod > 0 && prefab.fadeLods > 0)
|
||||
{
|
||||
meta.fadeOutLod = meta.visibleLod;
|
||||
meta.fadeAnim = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (visibleShadowLod > 0)
|
||||
{
|
||||
batchOffset = prefab.indexBufferStartOffset + ((visibleShadowLod - 1) * prefab.maxCount);
|
||||
indirectArgsCount = prefab.indirectArgsIndexAndCountPerLod[visibleShadowLod - 1].y;
|
||||
indirectArgsCountOffset = indirectArgsCount * 5 + prefab.indirectArgsIndexAndCountPerLod[visibleShadowLod - 1].x + 1;
|
||||
|
||||
InterlockedAdd(perCamIndirectArgumentsBuffer[indirectArgsCountOffset], 1, visibleCount);
|
||||
|
||||
for (i = 1, u = 5; i < indirectArgsCount; i++, u += 5)
|
||||
{
|
||||
InterlockedAdd(perCamIndirectArgumentsBuffer[indirectArgsCountOffset + u], 1);
|
||||
}
|
||||
|
||||
perCamShadowVisibleIndexesBuffer[batchOffset + visibleCount] = instanceIndex;
|
||||
|
||||
if (meta.visibleLod != visibleShadowLod && meta.visibleLod > 0 && prefab.fadeLods > 0)
|
||||
{
|
||||
meta.fadeOutLod = meta.visibleLod;
|
||||
meta.fadeAnim = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (meta.fadeOutLod == 0)
|
||||
meta.fadeAnim = 0;
|
||||
|
||||
if (meta.fadeAnim == 0)
|
||||
meta.fadeOutLod = 0;
|
||||
|
||||
//Add lod cross fade
|
||||
if (meta.fadeAnim > 0 && meta.fadeOutLod > 0)
|
||||
{
|
||||
meta.fadeAnim = max(0, meta.fadeAnim - unity_DeltaTime.z);
|
||||
|
||||
//Normal
|
||||
if (visibleLod > 0 && meta.fadeAnim > 0)
|
||||
{
|
||||
batchOffset = prefab.indexBufferStartOffset + ((meta.fadeOutLod - 1) * prefab.maxCount);
|
||||
indirectArgsCount = prefab.indirectArgsIndexAndCountPerLod[meta.fadeOutLod - 1].y;
|
||||
indirectArgsCountOffset = prefab.indirectArgsIndexAndCountPerLod[meta.fadeOutLod - 1].x + 1;
|
||||
|
||||
InterlockedAdd(perCamIndirectArgumentsBuffer[indirectArgsCountOffset], 1, visibleCount);
|
||||
|
||||
for (i = 1, u = 5; i < indirectArgsCount; i++, u += 5)
|
||||
{
|
||||
InterlockedAdd(perCamIndirectArgumentsBuffer[indirectArgsCountOffset + u], 1);
|
||||
}
|
||||
|
||||
perCamVisibleIndexesBuffer[batchOffset + visibleCount] = instanceIndex;
|
||||
}
|
||||
|
||||
//Shadow
|
||||
if (visibleShadowLod > 0 && meta.fadeAnim > 0)
|
||||
{
|
||||
batchOffset = prefab.indexBufferStartOffset + ((meta.fadeOutLod - 1) * prefab.maxCount);
|
||||
indirectArgsCount = prefab.indirectArgsIndexAndCountPerLod[meta.fadeOutLod - 1].y;
|
||||
indirectArgsCountOffset = indirectArgsCount * 5 + prefab.indirectArgsIndexAndCountPerLod[meta.fadeOutLod - 1].x + 1;
|
||||
|
||||
InterlockedAdd(perCamIndirectArgumentsBuffer[indirectArgsCountOffset], 1, visibleCount);
|
||||
|
||||
for (i = 1, u = 5; i < indirectArgsCount; i++, u += 5)
|
||||
{
|
||||
InterlockedAdd(perCamIndirectArgumentsBuffer[indirectArgsCountOffset + u], 1);
|
||||
}
|
||||
|
||||
perCamShadowVisibleIndexesBuffer[batchOffset + visibleCount] = instanceIndex;
|
||||
}
|
||||
}
|
||||
|
||||
meta.visibleLod = max(visibleLod, visibleShadowLod);
|
||||
perCamMeta[instanceIndex] = meta;
|
||||
}
|
||||
|
||||
[numthreads(GROUPS,1,1)]
|
||||
void Cull_32(uint3 id : SV_DispatchThreadID) { Cull(id); }
|
||||
|
||||
[numthreads(GROUPS,1,1)]
|
||||
void Cull_64(uint3 id : SV_DispatchThreadID) { Cull(id); }
|
||||
|
||||
[numthreads(GROUPS,1,1)]
|
||||
void Cull_128(uint3 id : SV_DispatchThreadID) { Cull(id); }
|
||||
|
||||
[numthreads(GROUPS,1,1)]
|
||||
void Cull_256(uint3 id : SV_DispatchThreadID) { Cull(id); }
|
||||
|
||||
[numthreads(GROUPS,1,1)]
|
||||
void Cull_512(uint3 id : SV_DispatchThreadID) { Cull(id); }
|
||||
|
||||
[numthreads(GROUPS,1,1)]
|
||||
void Cull_1024(uint3 id : SV_DispatchThreadID) { Cull(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Clear_32(uint3 id : SV_DispatchThreadID) { ClearArgumentsBuffer(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Clear_64(uint3 id : SV_DispatchThreadID) { ClearArgumentsBuffer(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Clear_128(uint3 id : SV_DispatchThreadID) { ClearArgumentsBuffer(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Clear_256(uint3 id : SV_DispatchThreadID) { ClearArgumentsBuffer(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Clear_512(uint3 id : SV_DispatchThreadID) { ClearArgumentsBuffer(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Clear_1024(uint3 id : SV_DispatchThreadID) { ClearArgumentsBuffer(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Upload_32(uint3 id : SV_DispatchThreadID) { Upload(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Upload_64(uint3 id : SV_DispatchThreadID) { Upload(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Upload_128(uint3 id : SV_DispatchThreadID) { Upload(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Upload_256(uint3 id : SV_DispatchThreadID) { Upload(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Upload_512(uint3 id : SV_DispatchThreadID) { Upload(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Upload_1024(uint3 id : SV_DispatchThreadID) { Upload(id); }
|
||||
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Resize_32(uint3 id : SV_DispatchThreadID) { Resize(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Resize_64(uint3 id : SV_DispatchThreadID) { Resize(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Resize_128(uint3 id : SV_DispatchThreadID) { Resize(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Resize_256(uint3 id : SV_DispatchThreadID) { Resize(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Resize_512(uint3 id : SV_DispatchThreadID) { Resize(id); }
|
||||
|
||||
[numthreads(GROUPS, 1, 1)]
|
||||
void Resize_1024(uint3 id : SV_DispatchThreadID) { Resize(id); }
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a840c1c229294d4996e80608a899881
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,136 @@
|
||||
#pragma multi_compile _LOD_FADE_CROSSFADE
|
||||
|
||||
#ifndef NODE_THOMAGIC_RENDERER_INCLUDED
|
||||
#define NODE_THOMAGIC_RENDERER_INCLUDED
|
||||
|
||||
#ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
|
||||
|
||||
|
||||
#define UNITY_INDIRECT_DRAW_ARGS IndirectDrawIndexedArgs
|
||||
#include "UnityIndirect.cginc"
|
||||
|
||||
#define Use_Macro_UNITY_MATRIX_M_instead_of_unity_ObjectToWorld unity_ObjectToWorld
|
||||
#define Use_Macro_UNITY_MATRIX_I_M_instead_of_unity_WorldToObject unity_WorldToObject
|
||||
|
||||
#define LOD_FADE_CROSSFADE
|
||||
|
||||
struct InstanceData
|
||||
{
|
||||
// position.xyz : position.xyz
|
||||
// position.w : rotation.x
|
||||
// scale.x : scale.xz
|
||||
// scale.y : scale.y
|
||||
// scale.zw : rotation.yz
|
||||
float4 position;
|
||||
float4 scale;
|
||||
uint prefabId;
|
||||
int3 padding;
|
||||
};
|
||||
|
||||
struct InstanceMeta
|
||||
{
|
||||
uint visibleLod;
|
||||
uint fadeOutLod;
|
||||
float fadeAnim;
|
||||
|
||||
// The scale of the instance can be adjusted
|
||||
float Scale;
|
||||
};
|
||||
|
||||
StructuredBuffer<InstanceData> trInstances;
|
||||
StructuredBuffer<uint> trPerCamVisibleIndexesBuffer;
|
||||
StructuredBuffer<InstanceMeta> trPerCamMeta;
|
||||
|
||||
float4x4 trInstanceMatrix;
|
||||
int trLodNr;
|
||||
|
||||
float4x4 TRS(float3 t, float4 r, float3 s)
|
||||
{
|
||||
float4x4 result = (float4x4)0;
|
||||
result[0][0] = (1.0f - 2.0f * (r.y * r.y + r.z * r.z)) * s.x;
|
||||
result[1][0] = (r.x * r.y + r.z * r.w) * s.x * 2.0f;
|
||||
result[2][0] = (r.x * r.z - r.y * r.w) * s.x * 2.0f;
|
||||
result[3][0] = 0.0f;
|
||||
result[0][1] = (r.x * r.y - r.z * r.w) * s.y * 2.0f;
|
||||
result[1][1] = (1.0f - 2.0f * (r.x * r.x + r.z * r.z)) * s.y;
|
||||
result[2][1] = (r.y * r.z + r.x * r.w) * s.y * 2.0f;
|
||||
result[3][1] = 0.0f;
|
||||
result[0][2] = (r.x * r.z + r.y * r.w) * s.z * 2.0f;
|
||||
result[1][2] = (r.y * r.z - r.x * r.w) * s.z * 2.0f;
|
||||
result[2][2] = (1.0f - 2.0f * (r.x * r.x + r.y * r.y)) * s.z;
|
||||
result[3][2] = 0.0f;
|
||||
result[0][3] = t.x;
|
||||
result[1][3] = t.y;
|
||||
result[2][3] = t.z;
|
||||
result[3][3] = 1.0f;
|
||||
return result;
|
||||
}
|
||||
|
||||
void DecompressInstanceMatrix(inout float4x4 m, InstanceData instanceData, InstanceMeta meta)
|
||||
{
|
||||
float3 position = instanceData.position.xyz;
|
||||
float4 rotation = float4(instanceData.position.w, instanceData.scale.zw, 0);
|
||||
float3 scale = instanceData.scale.xyx * meta.Scale;
|
||||
rotation.w = sqrt(1.0 - rotation.x * rotation.x - rotation.y * rotation.y - rotation.z * rotation.z);
|
||||
m = TRS(position, rotation, scale);
|
||||
}
|
||||
|
||||
float4x4 inverse(float4x4 input)
|
||||
{
|
||||
#define minor(a,b,c) determinant(float3x3(input.a, input.b, input.c))
|
||||
|
||||
float4x4 cofactors = float4x4(
|
||||
minor(_22_23_24, _32_33_34, _42_43_44),
|
||||
-minor(_21_23_24, _31_33_34, _41_43_44),
|
||||
minor(_21_22_24, _31_32_34, _41_42_44),
|
||||
-minor(_21_22_23, _31_32_33, _41_42_43),
|
||||
|
||||
-minor(_12_13_14, _32_33_34, _42_43_44),
|
||||
minor(_11_13_14, _31_33_34, _41_43_44),
|
||||
-minor(_11_12_14, _31_32_34, _41_42_44),
|
||||
minor(_11_12_13, _31_32_33, _41_42_43),
|
||||
|
||||
minor(_12_13_14, _22_23_24, _42_43_44),
|
||||
-minor(_11_13_14, _21_23_24, _41_43_44),
|
||||
minor(_11_12_14, _21_22_24, _41_42_44),
|
||||
-minor(_11_12_13, _21_22_23, _41_42_43),
|
||||
|
||||
-minor(_12_13_14, _22_23_24, _32_33_34),
|
||||
minor(_11_13_14, _21_23_24, _31_33_34),
|
||||
-minor(_11_12_14, _21_22_24, _31_32_34),
|
||||
minor(_11_12_13, _21_22_23, _31_32_33)
|
||||
);
|
||||
#undef minor
|
||||
return transpose(cofactors) / determinant(input);
|
||||
}
|
||||
#endif
|
||||
|
||||
void SetupThoMagicRenderer()
|
||||
{
|
||||
#ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
|
||||
InitIndirectDrawArgs(0);
|
||||
|
||||
uint instanceID = GetIndirectInstanceID_Base(unity_InstanceID);
|
||||
uint instanceIndex = trPerCamVisibleIndexesBuffer[instanceID];
|
||||
InstanceMeta meta = trPerCamMeta[instanceIndex];
|
||||
DecompressInstanceMatrix(unity_ObjectToWorld, trInstances[instanceIndex], meta);
|
||||
unity_ObjectToWorld = mul(unity_ObjectToWorld, trInstanceMatrix);
|
||||
unity_WorldToObject = inverse(unity_ObjectToWorld);
|
||||
|
||||
if (meta.visibleLod == trLodNr)
|
||||
unity_LODFade.x = (1.0f - meta.fadeAnim);
|
||||
else
|
||||
unity_LODFade.x = -(1.0f - meta.fadeAnim);
|
||||
|
||||
// {% hd %}
|
||||
// Instances are static so the previous matrix is the same as the current one.
|
||||
// These matrices are required for correct motion vectors in HDRP.
|
||||
#if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(SHADERPASS_CS_HLSL)
|
||||
unity_MatrixPreviousM = unity_ObjectToWorld;
|
||||
unity_MatrixPreviousMI = unity_WorldToObject;
|
||||
#endif
|
||||
// {% endhd %}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7fe5ed120e85ccf499d429b359f89173
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "ThoMagicRenderer.cginc"
|
||||
|
||||
#ifndef THOMAGICRENDERERSETUP_INClUDED
|
||||
#define THOMAGICRENDERERSETUP_INClUDED
|
||||
void IncludeThoMagicRenderer_float(float3 In, out float3 Out)
|
||||
{
|
||||
Out = In;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 678dff042fe9c004cb7522c2233af44d
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user