Merge pull request #6 from denistribouillois/SlicingPlaneAnyDirection
Slicing Plane in any direction
This commit is contained in:
Коммит
0448ed9e50
|
@ -0,0 +1,14 @@
|
|||
using UnityEngine;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class SlicingPlaneAnyDirection : MonoBehaviour
|
||||
{
|
||||
public Material mat;
|
||||
public Transform volumeTransform;
|
||||
|
||||
void Update()
|
||||
{
|
||||
mat.SetVector("_PlanePos", volumeTransform.position - transform.position);
|
||||
mat.SetVector("_PlaneNormal", transform.forward);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 030645f63ce11d14ea77ce39291d70da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -48,6 +48,9 @@
|
|||
float _MinVal;
|
||||
float _MaxVal;
|
||||
|
||||
float3 _PlanePos;
|
||||
float3 _PlaneNormal;
|
||||
|
||||
// Gets the colour from a 1D Transfer Function (x = density)
|
||||
float4 getTF1DColour(float density)
|
||||
{
|
||||
|
@ -116,6 +119,18 @@
|
|||
if (density < _MinVal || density > _MaxVal)
|
||||
src.a = 0.0f;
|
||||
|
||||
// Move the reference in the middle of the mesh, like the pivot
|
||||
float3 pivotPos = currPos - float3(0.5f, 0.5f, 0.5f);
|
||||
|
||||
// Convert to world position
|
||||
float3 pos = mul(unity_ObjectToWorld, -pivotPos);
|
||||
|
||||
// If the dot product is < 0, the current position is "below" the plane, if it's > 0 it's "above"
|
||||
// Then cull if the current position is below
|
||||
float cull = dot(_PlaneNormal, pos - _PlanePos);
|
||||
if (cull < 0)
|
||||
src.a = 0;
|
||||
|
||||
col.rgb = src.a * src.rgb + (1.0f - src.a)*col.rgb;
|
||||
col.a = src.a + (1.0f - src.a)*col.a;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче