Skip to content

Commit 095833a

Browse files
committed
Switch back to old geometry shader method; fix volume hiding.
1 parent 0eff5b1 commit 095833a

File tree

3 files changed

+75
-54
lines changed

3 files changed

+75
-54
lines changed

Example/BoxClipTestScene.unity

+10-10
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,8 @@ Transform:
513513
m_LocalPosition: {x: 1.2, y: 0, z: 58.2}
514514
m_LocalScale: {x: 1, y: 1, z: 1}
515515
m_Children:
516-
- {fileID: 495176829}
517516
- {fileID: 1954980278}
517+
- {fileID: 495176829}
518518
m_Father: {fileID: 0}
519519
m_RootOrder: 5
520520
m_LocalEulerAnglesHint: {x: 0, y: 173.11, z: 0}
@@ -603,12 +603,12 @@ Transform:
603603
m_PrefabAsset: {fileID: 0}
604604
m_GameObject: {fileID: 495176825}
605605
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
606-
m_LocalPosition: {x: 0.03, y: 0, z: -0}
607-
m_LocalScale: {x: 1, y: 1, z: 1}
606+
m_LocalPosition: {x: 0, y: 0, z: 0}
607+
m_LocalScale: {x: 1.0000005, y: 1, z: 1.0000005}
608608
m_Children:
609609
- {fileID: 1758450028}
610610
m_Father: {fileID: 472783188}
611-
m_RootOrder: 0
611+
m_RootOrder: 1
612612
m_LocalEulerAnglesHint: {x: -90, y: 90, z: 0}
613613
--- !u!1 &537751360
614614
GameObject:
@@ -1470,17 +1470,17 @@ MeshFilter:
14701470
m_PrefabInstance: {fileID: 0}
14711471
m_PrefabAsset: {fileID: 0}
14721472
m_GameObject: {fileID: 1587443843}
1473-
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
1473+
m_Mesh: {fileID: 4300000, guid: de25be524fea1ea49aa7203c77156540, type: 2}
14741474
--- !u!4 &1587443847
14751475
Transform:
14761476
m_ObjectHideFlags: 0
14771477
m_CorrespondingSourceObject: {fileID: 0}
14781478
m_PrefabInstance: {fileID: 0}
14791479
m_PrefabAsset: {fileID: 0}
14801480
m_GameObject: {fileID: 1587443843}
1481-
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
1482-
m_LocalPosition: {x: 0, y: 0, z: 0}
1483-
m_LocalScale: {x: 1, y: 1, z: 1}
1481+
m_LocalRotation: {x: -0, y: 0.99819297, z: -0, w: 0.06009041}
1482+
m_LocalPosition: {x: 1.2, y: 0, z: 58.2}
1483+
m_LocalScale: {x: 1.0000005, y: 1, z: 1.0000005}
14841484
m_Children: []
14851485
m_Father: {fileID: 0}
14861486
m_RootOrder: 2
@@ -1719,7 +1719,7 @@ GameObject:
17191719
m_Icon: {fileID: 0}
17201720
m_NavMeshLayer: 0
17211721
m_StaticEditorFlags: 0
1722-
m_IsActive: 1
1722+
m_IsActive: 0
17231723
--- !u!4 &1758450028
17241724
Transform:
17251725
m_ObjectHideFlags: 0
@@ -6564,7 +6564,7 @@ Transform:
65646564
m_Children:
65656565
- {fileID: 1789326169}
65666566
m_Father: {fileID: 472783188}
6567-
m_RootOrder: 1
6567+
m_RootOrder: 0
65686568
m_LocalEulerAnglesHint: {x: -35.646, y: 27.922, z: 0.009000001}
65696569
--- !u!1 &1982550725
65706570
GameObject:

Example/SphereAdjusted2020-05-02T08_40_16.asset

+2-2
Large diffs are not rendered by default.

Shaders/BoxClipTemplate.cginc

+63-42
Original file line numberDiff line numberDiff line change
@@ -371,25 +371,6 @@ bool internalBoxPointWithinVolume(float3 p, internalBoxQuad q) {
371371
return all(abs(dotAxes) < 0.5);
372372
}
373373

374-
bool internalBoxPointWithinVolumeold1(float3 p, internalBoxQuad q) {
375-
float3 relvec = q.a - p;
376-
float3 planeNormal = q.planeNormalZComp.xyz;
377-
float3 uline = q.ulineAndLength.xyz;
378-
float3 vline = q.vlineAndLength.xyz;
379-
float3 dotAxes = float3(
380-
dot(relvec, uline),
381-
dot(relvec, vline),
382-
dot(relvec, planeNormal)
383-
);
384-
float3 compareLengths = float3(
385-
q.ulineAndLength.w,
386-
q.vlineAndLength.w,
387-
q.planeNormalZComp.w
388-
);
389-
return (//all(dotAxes >= 0) &&
390-
all(dotAxes * compareLengths <= 1));
391-
}
392-
393374
bool internalBoxTriangleIntersectsQuad(float3 p1, float3 p2, float3 p3, internalBoxQuad q) {
394375
float3 x1;
395376
float2 x2;
@@ -526,26 +507,19 @@ bool boxConditionCheck(float3 origvertpos) {
526507
}
527508
});
528509
BOXCLIP_FOR_EACH_QUAD(ShowVolume, {
529-
if (1){//q.planeNormalZComp.w < 0) {
530-
if (internalBoxPointWithinVolume(origvertpos.xyz, q)) {
531-
found = true;
532-
}
510+
if (internalBoxPointWithinVolume(origvertpos.xyz, q)) {
511+
found = true;
533512
}
534513
});
535514
BOXCLIP_FOR_EACH_QUAD(HideVolume, {
536-
if (1){//if (q.planeNormalZComp.w < 0) {
537-
if (internalBoxPointWithinVolume(origvertpos.xyz, q)) {
538-
found = false;
539-
}
515+
if (internalBoxPointWithinVolume(origvertpos.xyz, q)) {
516+
found = false;
540517
}
541518
});
542519
BOXCLIP_FOR_EACH_QUAD(ClipShow, {
543520
if (internalBoxPointInQuad(origvertpos.xyz, q, thispos, thisuv)) {
544521
found = true;
545522
}
546-
// if (internalBoxFrustumCheck(origvertpos.xyz, q, -3)) {
547-
// found = true;
548-
// }
549523
});
550524
BOXCLIP_FOR_EACH_QUAD(ClipHide, {
551525
if (internalBoxPointInQuad(origvertpos.xyz, q, thispos, thisuv)) {
@@ -571,6 +545,54 @@ void boxConditionalClipWorld(float4 worldPos) {
571545
clip(boxConditionCheck(mul(unity_WorldToObject, worldPos).xyz) ? 0 : -1);
572546
}
573547

548+
bool geometry_check(float3 v1, float3 v2, float3 v3) {
549+
float3 thispos = 0;
550+
float2 thisuv = 0;
551+
bool found = true;
552+
BOXCLIP_FOR_EACH_QUAD(ShowVolume, {
553+
found = false;
554+
});
555+
BOXCLIP_FOR_EACH_QUAD(ShowCameraWithin, {
556+
found = false;
557+
});
558+
BOXCLIP_FOR_EACH_QUAD(ClipShow, {
559+
found = false;
560+
});
561+
BOXCLIP_FOR_EACH_QUAD(ShowCameraWithin, {
562+
if (internalBoxPointWithinVolume(boxObjectSpaceCameraPosStereo, q)) {
563+
found = true;
564+
}
565+
});
566+
BOXCLIP_FOR_EACH_QUAD(HideCameraWithin, {
567+
if (internalBoxPointWithinVolume(boxObjectSpaceCameraPosStereo, q)) {
568+
found = false;
569+
}
570+
});
571+
BOXCLIP_FOR_EACH_QUAD(ShowVolume, {
572+
if (internalBoxPointWithinVolume(v1.xyz, q) || internalBoxPointWithinVolume(v2.xyz, q) || internalBoxPointWithinVolume(v3.xyz, q)) {
573+
found = true;
574+
}
575+
});
576+
BOXCLIP_FOR_EACH_QUAD(HideVolume, {
577+
if (internalBoxPointWithinVolume(v1.xyz, q) && internalBoxPointWithinVolume(v2.xyz, q) && internalBoxPointWithinVolume(v3.xyz, q)) {
578+
found = false;
579+
}
580+
});
581+
BOXCLIP_FOR_EACH_QUAD(ClipShow, {
582+
if (internalBoxTriangleIntersectsQuad(v1.xyz, v2.xyz, v3.xyz, q)) {
583+
found = true;
584+
}
585+
});
586+
BOXCLIP_FOR_EACH_QUAD(ClipHide, {
587+
if (internalBoxPointInQuad(v1.xyz, q, thispos, thisuv) &&
588+
internalBoxPointInQuad(v2.xyz, q, thispos, thisuv) &&
589+
internalBoxPointInQuad(v3.xyz, q, thispos, thisuv)) {
590+
found = true;
591+
}
592+
});
593+
return found;
594+
}
595+
574596
bool modified_vert_check(float3 localPos, float length) {
575597
bool found = true;
576598
BOXCLIP_FOR_EACH_QUAD(ShowVolume, {
@@ -593,17 +615,13 @@ bool modified_vert_check(float3 localPos, float length) {
593615
}
594616
});
595617
BOXCLIP_FOR_EACH_QUAD(ShowVolume, {
596-
if (q.planeNormalZComp.w < 0) {
597-
if (internalBoxPointWithinVolume(localPos, q)) {
598-
found = true;
599-
}
618+
if (internalBoxPointWithinVolume(localPos, q)) {
619+
found = true;
600620
}
601621
});
602622
BOXCLIP_FOR_EACH_QUAD(HideVolume, {
603-
if (q.planeNormalZComp.w < 0) {
604-
if (internalBoxPointWithinVolume(localPos, q)) {
605-
found = false;
606-
}
623+
if (internalBoxPointWithinVolume(localPos, q)) {
624+
found = false;
607625
}
608626
});
609627
BOXCLIP_FOR_EACH_QUAD(ClipShow, {
@@ -641,16 +659,19 @@ bool modified_vert_check(float3 localPos, float length) {
641659
float lengthVert0 = max(distance(localPos[0], localPos[1]),distance(localPos[0], localPos[2])); \
642660
float lengthVert1 = max(distance(localPos[0], localPos[1]),distance(localPos[1], localPos[2])); \
643661
float lengthVert2 = max(distance(localPos[0], localPos[2]),distance(localPos[1], localPos[2])); \
644-
/* if (geometry_check(localPos[0], localPos[1], localPos[2])) { */ \
645-
if ((modified_vert_check(localPos[0], lengthVert0) && \
646-
modified_vert_check(localPos[1], lengthVert1) && \
647-
modified_vert_check(localPos[2], lengthVert2))) { \
662+
if (geometry_check(localPos[0], localPos[1], localPos[2])) { \
648663
tristream.Append(IN[0]); \
649664
tristream.Append(IN[1]); \
650665
tristream.Append(IN[2]); \
651666
} \
652667
}
653668

669+
/*
670+
if ((modified_vert_check(localPos[0], lengthVert0) && \
671+
modified_vert_check(localPos[1], lengthVert1) && \
672+
modified_vert_check(localPos[2], lengthVert2))) {
673+
*/
674+
654675
#define BOXCLIP_GEOM_SHADER_WORLDPOS(V2FStruct, worldPosVar) \
655676
BOXCLIP_GEOM_SHADER_LOCALPOS(V2FStruct, mul(unity_WorldToObject, float4((worldPosVar).xyz, 1)).xyz)
656677

0 commit comments

Comments
 (0)