Hello,
I am trying to refresh my math knowledge since I have not done my vectors for a while and have run into trouble trying to make this shader work.
What I would like to do is create a material (shader) that culls part of a mesh (think of it as if you are pulling something out of a portal and it is slowly appearing on one side of it). A plane (any location, any orientation) can be placed over an object and it will clip one side of the mesh.
However, as I have it now, nothing is happening… the shader gets applied to a cube and there is an intersecting plane, but everything is still being rendered. Does anyone have an idea as to where I am going wrong with this shader to achieve the effect I am looking for? I remember finding a similar shader (regular HLSL) but I wanted to try and make it with shadergraph, resulting in a few headaches… I assume my vector logic is wrong, but I can’t seem to find the solution.
The Shadergraph is as follows:
It has a script attached to it like this:
using UnityEngine;
[ExecuteInEditMode]
public class PortalPullProperties : MonoBehaviour
{
[SerializeField] private GameObject _clippingPlane = null;
[SerializeField] private Vector3 _rotationOffset = new Vector3(0, 90, 0);
private Material _material = null;
private MeshRenderer _renderer = null;
public GameObject ClippingPlane { get => _clippingPlane; }
private void Start()
{
_renderer = gameObject.GetComponent<MeshRenderer>();
_material = _renderer.sharedMaterial;
}
void Update()
{
if((_clippingPlane && _clippingPlane.transform.hasChanged) || transform.hasChanged)
{
Vector3 position = _clippingPlane.transform.position;
Vector3 rotation = _clippingPlane.transform.forward + _rotationOffset;
_material.SetVector("_ClippingPlanePosition", new Vector4(position.x, position.y, position.z));
_material.SetVector("_ClippingPlaneOrientation", new Vector4(rotation.x, rotation.y, rotation.z));
}
}
private void Reset()
{
this.GetComponent<MeshRenderer>().material = new Material(Shader.Find("Shader Graphs/PortalPull"));
}
}


