diff --git a/Operators/Lib/Assets/shaders/points/modify/OrientPoints.hlsl b/Operators/Lib/Assets/shaders/points/modify/OrientPoints.hlsl index f60df9a88..0be8b195a 100644 --- a/Operators/Lib/Assets/shaders/points/modify/OrientPoints.hlsl +++ b/Operators/Lib/Assets/shaders/points/modify/OrientPoints.hlsl @@ -5,7 +5,7 @@ cbuffer FloatParams : register(b0) { - float3 Center; + float3 Target; float Amount; float3 UpVector; } @@ -15,20 +15,26 @@ cbuffer IntParams : register(b1) int UseWAsWeight; int Flip; int AmountFactor; - // float3 Center; - // float Amount; - // float3 UpVector; - // float UseWAsWeight; - // float Flip; + int OrientationMode; // 0 = Look at Center, 2 = screen space, 3 = Billboard to camera } +cbuffer Transforms : register(b2) +{ + float4x4 CameraToClipSpace; + float4x4 ClipSpaceToCamera; + float4x4 WorldToCamera; + float4x4 CameraToWorld; + float4x4 WorldToClipSpace; + float4x4 ClipSpaceToWorld; + float4x4 ObjectToWorld; + float4x4 WorldToObject; + float4x4 ObjectToCamera; + float4x4 ObjectToClipSpace; +}; + StructuredBuffer SourcePoints : t0; RWStructuredBuffer ResultPoints : u0; -static const float PointSpace = 0; -static const float ObjectSpace = 1; -static const float WorldSpace = 2; - [numthreads(64, 1, 1)] void main(uint3 i : SV_DispatchThreadID) { uint numStructs, stride; @@ -47,18 +53,29 @@ static const float WorldSpace = 2; : (AmountFactor == 1) ? p.FX1 : p.FX2); - // float weight = UseWAsWeight > 0.5 - // ? p.FX1 - // : 1; + float sign = Flip > 0.5 ? -1 : 1; + - // weight *= Amount; + switch (OrientationMode) { + case 0: // Center + float4 newRot = qLookAt(normalize(Target - p.Position) * sign, normalize(UpVector)); + float3 forward = qRotateVec3(float3(0, 0, 1), newRot); + float4 alignment = qFromAngleAxis(3.141578, forward); + newRot = qMul(alignment, newRot); + p.Rotation = normalize(qSlerp(normalize(p.Rotation), normalize(newRot), strength)); + break; + + case 1: // Screen + p.Rotation = normalize(qSlerp(p.Rotation,qFromMatrix3((float3x3)WorldToCamera), strength)); + break; - float sign = Flip > 0.5 ? -1 : 1; - float4 newRot = qLookAt(normalize(Center - p.Position) * sign, normalize(UpVector)); + case 2: // Billboard to camera + float3 up=mul(float3(0,-1,0),(float3x3)CameraToWorld); + float3 dir=normalize(p.Position-CameraToWorld[3].xyz); + p.Rotation = normalize(qSlerp(p.Rotation, qLookAt(-dir,up), strength)); + break; + + } - float3 forward = qRotateVec3(float3(0, 0, 1), newRot); - float4 alignment = qFromAngleAxis(3.141578, forward); - newRot = qMul(alignment, newRot); - p.Rotation = normalize(qSlerp(normalize(p.Rotation), normalize(newRot), strength)); ResultPoints[i.x] = p; } diff --git a/Operators/Lib/point/transform/OrientPoints.cs b/Operators/Lib/point/transform/OrientPoints.cs index f7dea4d66..1f1d5c675 100644 --- a/Operators/Lib/point/transform/OrientPoints.cs +++ b/Operators/Lib/point/transform/OrientPoints.cs @@ -17,15 +17,17 @@ internal sealed class OrientPoints : Instance public readonly InputSlot AmountFactor = new InputSlot(); [Input(Guid = "607fd90d-57f3-4a6a-b843-86c7170c854c")] - public readonly InputSlot Center = new InputSlot(); + public readonly InputSlot Target = new InputSlot(); [Input(Guid = "2aa74709-65f3-49fa-9890-f0a0f6e76bbf")] public readonly InputSlot UpVector = new InputSlot(); - [Input(Guid = "02ae76ba-7be8-4112-a59b-55616343f1dd")] public readonly InputSlot Flip = new InputSlot(); - + + [Input(Guid = "0130d406-ff9a-419e-9294-fba52983dff5", MappedType = typeof(OModes))] + public readonly InputSlot OrientationMode = new InputSlot(); + [Input(Guid = "4358e71b-3f33-4868-af4d-97e8e04087a6")] public readonly InputSlot WIsWeight = new InputSlot(); @@ -35,4 +37,10 @@ private enum FModes F1, F2, } + private enum OModes + { + LootAtTarget, + Screen, + LookAtCamera, + } } \ No newline at end of file diff --git a/Operators/Lib/point/transform/OrientPoints.t3 b/Operators/Lib/point/transform/OrientPoints.t3 index 10bf77be3..b554c402c 100644 --- a/Operators/Lib/point/transform/OrientPoints.t3 +++ b/Operators/Lib/point/transform/OrientPoints.t3 @@ -1,6 +1,10 @@ { "Id": "acc71a14-daad-4b36-b0bc-cf0a796cc5d9"/*OrientPoints*/, "Inputs": [ + { + "Id": "0130d406-ff9a-419e-9294-fba52983dff5"/*OrientationMode*/, + "DefaultValue": 0 + }, { "Id": "02ae76ba-7be8-4112-a59b-55616343f1dd"/*Flip*/, "DefaultValue": false @@ -22,7 +26,7 @@ "DefaultValue": 1.0 }, { - "Id": "607fd90d-57f3-4a6a-b843-86c7170c854c"/*Center*/, + "Id": "607fd90d-57f3-4a6a-b843-86c7170c854c"/*Target*/, "DefaultValue": { "X": 0.0, "Y": 0.0, @@ -121,6 +125,12 @@ "InputValues": [], "Outputs": [] }, + { + "Id": "e2ffb3b1-9327-4cd8-83af-9f6c0d9e8842"/*TransformsConstBuffer*/, + "SymbolId": "a60adc26-d7c6-4615-af78-8d2d6da46b79", + "InputValues": [], + "Outputs": [] + }, { "Id": "e4fba79b-8ebe-44a8-b0d7-cf6dddc4e015"/*IntsToBuffer*/, "SymbolId": "2eb20a76-f8f7-49e9-93a5-1e5981122b50", @@ -213,6 +223,12 @@ "TargetParentOrChildId": "95d9a6d8-2336-4a50-b643-b73789451022", "TargetSlotId": "34cf06fe-8f63-4f14-9c59-35a2c021b817" }, + { + "SourceParentOrChildId": "e2ffb3b1-9327-4cd8-83af-9f6c0d9e8842", + "SourceSlotId": "7a76d147-4b8e-48cf-aa3e-aac3aa90e888", + "TargetParentOrChildId": "95d9a6d8-2336-4a50-b643-b73789451022", + "TargetSlotId": "34cf06fe-8f63-4f14-9c59-35a2c021b817" + }, { "SourceParentOrChildId": "620f6dca-1b38-455c-a686-51cc20f9f0bb", "SourceSlotId": "f03246a7-e39f-4a41-a0c3-22bc976a6000", @@ -267,6 +283,12 @@ "TargetParentOrChildId": "e4fba79b-8ebe-44a8-b0d7-cf6dddc4e015", "TargetSlotId": "49556d12-4cd1-4341-b9d8-c356668d296c" }, + { + "SourceParentOrChildId": "00000000-0000-0000-0000-000000000000", + "SourceSlotId": "0130d406-ff9a-419e-9294-fba52983dff5", + "TargetParentOrChildId": "e4fba79b-8ebe-44a8-b0d7-cf6dddc4e015", + "TargetSlotId": "49556d12-4cd1-4341-b9d8-c356668d296c" + }, { "SourceParentOrChildId": "8666fc66-a454-472f-9008-57f2034675dc", "SourceSlotId": "6d7a9493-6210-462a-b9c2-525b925de6c8", diff --git a/Operators/Lib/point/transform/OrientPoints.t3ui b/Operators/Lib/point/transform/OrientPoints.t3ui index 95cc32aad..d224fc354 100644 --- a/Operators/Lib/point/transform/OrientPoints.t3ui +++ b/Operators/Lib/point/transform/OrientPoints.t3ui @@ -1,8 +1,15 @@ { "Id": "acc71a14-daad-4b36-b0bc-cf0a796cc5d9"/*OrientPoints*/, - "Description": "Orients the rotation of points so that Z points towards a center.", + "Description": "Orients the rotation of points so that Z points towards a target position. You can also orient the point to the screen or the camera.", "SymbolTags": "1", "InputUis": [ + { + "InputId": "0130d406-ff9a-419e-9294-fba52983dff5"/*OrientationMode*/, + "Position": { + "X": 109.65976, + "Y": 1124.69 + } + }, { "InputId": "02ae76ba-7be8-4112-a59b-55616343f1dd"/*Flip*/, "Position": { @@ -35,11 +42,12 @@ "GroupTitle": "Settings" }, { - "InputId": "607fd90d-57f3-4a6a-b843-86c7170c854c"/*Center*/, + "InputId": "607fd90d-57f3-4a6a-b843-86c7170c854c"/*Target*/, "Position": { "X": -30.34024, "Y": 713.893 }, + "Description": "Target Position", "AddPadding": "True" }, { @@ -63,7 +71,7 @@ "ChildId": "519fa01d-8b43-4bdb-8cdd-499c35f156c0"/*ExecuteBufferUpdate*/, "Position": { "X": 577.38947, - "Y": 692.6048 + "Y": 727.6048 } }, { @@ -129,6 +137,13 @@ "Y": 528.57837 } }, + { + "ChildId": "e2ffb3b1-9327-4cd8-83af-9f6c0d9e8842"/*TransformsConstBuffer*/, + "Position": { + "X": 184.57353, + "Y": 1248.5173 + } + }, { "ChildId": "e4fba79b-8ebe-44a8-b0d7-cf6dddc4e015"/*IntsToBuffer*/, "Position": { @@ -161,7 +176,7 @@ "OutputId": "23a08560-9764-42a1-a889-dd8839476747"/*Output*/, "Position": { "X": 577.3895, - "Y": 762.6048 + "Y": 797.6048 } } ]