public static Vector2 RayConeDistance(GHeightCone _cone, GRay _ray) { Vector2 distances = RayConeCalculate(_cone, _ray); GPlane bottomPlane = new GPlane(_cone.normal, _cone.origin + _cone.normal * _cone.height); float rayPlaneDistance = RayPlaneDistance(bottomPlane, _ray); float sqrRadius = _cone.Radius; sqrRadius *= sqrRadius; if ((_cone.Bottom - _ray.GetPoint(rayPlaneDistance)).sqrMagnitude > sqrRadius) { rayPlaneDistance = -1; } float surfaceDst = Vector3.Dot(_cone.normal, _ray.GetPoint(distances.x) - _cone.origin); if (surfaceDst < 0 || surfaceDst > _cone.height) { distances.x = rayPlaneDistance; } surfaceDst = Vector3.Dot(_cone.normal, _ray.GetPoint(distances.y) - _cone.origin); if (surfaceDst < 0 || surfaceDst > _cone.height) { distances.y = rayPlaneDistance; } return(distances); }
public static float RayPlaneDistance(GPlane _plane, Ray _ray) { float nrO = Vector3.Dot(_plane.normal, _ray.origin); float nrD = Vector3.Dot(_plane.normal, _ray.direction); return((_plane.distance - nrO) / nrD); }
public virtual ScriptableRenderPass Setup(int _index, GPlane _planeData, IEnumerable <SRC_ReflectionPlane> _planes, ScriptableRenderer _renderer) { m_Renderer = _renderer; m_Planes = _planes; m_PlaneData = _planeData; m_ReflectionTexture = Shader.PropertyToID(C_ReflectionTex + _index); m_ReflectionTextureID = new RenderTargetIdentifier(m_ReflectionTexture); m_ReflectionBlurTexture = Shader.PropertyToID(C_ReflectionTempTexture + _index); m_ReflectionBlurTextureID = new RenderTargetIdentifier(m_ReflectionBlurTexture); return(this); }
public static Matrix4x4 GetMirrorMatrix(this GPlane _plane) { Matrix4x4 mirrorMatrix = Matrix4x4.identity; mirrorMatrix.m00 = 1 - 2 * _plane.normal.x * _plane.normal.x; mirrorMatrix.m01 = -2 * _plane.normal.x * _plane.normal.y; mirrorMatrix.m02 = -2 * _plane.normal.x * _plane.normal.z; mirrorMatrix.m03 = 2 * _plane.normal.x * _plane.distance; mirrorMatrix.m10 = -2 * _plane.normal.x * _plane.normal.y; mirrorMatrix.m11 = 1 - 2 * _plane.normal.y * _plane.normal.y; mirrorMatrix.m12 = -2 * _plane.normal.y * _plane.normal.z; mirrorMatrix.m13 = 2 * _plane.normal.y * _plane.distance; mirrorMatrix.m20 = -2 * _plane.normal.x * _plane.normal.z; mirrorMatrix.m21 = -2 * _plane.normal.y * _plane.normal.z; mirrorMatrix.m22 = 1 - 2 * _plane.normal.z * _plane.normal.z; mirrorMatrix.m23 = 2 * _plane.normal.z * _plane.distance; mirrorMatrix.m30 = 0; mirrorMatrix.m31 = 0; mirrorMatrix.m32 = 0; mirrorMatrix.m33 = 1; return(mirrorMatrix); }
protected override void GenerateTarget(ScriptableRenderContext context, ref RenderingData renderingData, CommandBuffer cmd, RenderTextureDescriptor _descriptor, RenderTargetIdentifier _target, SRD_PlanarReflectionData _data, ref GPlane _plane) { ref CameraData cameraData = ref renderingData.cameraData;
public override ScriptableRenderPass Setup(int _index, GPlane _planeData, IEnumerable <SRC_ReflectionPlane> _planes, ScriptableRenderer _renderer) { m_ReflectionDepth = Shader.PropertyToID(C_ReflectionDepth + _index); m_ReflectionDepthID = new RenderTargetIdentifier(m_ReflectionDepth); return(base.Setup(_index, _planeData, _planes, _renderer)); }
protected override void GenerateTarget(ScriptableRenderContext context, ref RenderingData renderingData, CommandBuffer cmd, RenderTextureDescriptor _descriptor, RenderTargetIdentifier _target, SRD_PlanarReflectionData _data, ref GPlane _plane) { cmd.SetComputeIntParam(m_ReflectionComputeShader, ID_SampleCount, _data.m_Sample); cmd.SetComputeVectorParam(m_ReflectionComputeShader, ID_PlaneNormal, _plane.normal.normalized); cmd.SetComputeVectorParam(m_ReflectionComputeShader, ID_PlanePosition, _plane.distance * _plane.normal); cmd.SetComputeVectorParam(m_ReflectionComputeShader, ID_Result_TexelSize, _descriptor.GetTexelSize()); cmd.SetComputeTextureParam(m_ReflectionComputeShader, m_Kernels, ID_Input, m_Renderer.cameraColorTarget); cmd.SetComputeTextureParam(m_ReflectionComputeShader, m_Kernels, ID_Result, _target); cmd.DispatchCompute(m_ReflectionComputeShader, m_Kernels, m_ThreadGroups.m_X, m_ThreadGroups.m_Y, 1); }
protected abstract void GenerateTarget(ScriptableRenderContext context, ref RenderingData renderingData, CommandBuffer cmd, RenderTextureDescriptor _descriptor, RenderTargetIdentifier _target, SRD_PlanarReflectionData _data, ref GPlane _plane);
public static float PointPlaneDistance(Vector3 _point, GPlane _plane) { float nr = _point.x * _plane.normal.x + _point.y * _plane.normal.y + _point.z * _plane.normal.z + _plane.distance; return(nr / _plane.normal.magnitude); }