Inheritance: MonoBehaviour
示例#1
0
        public void UpdateNode()
        {
            LocalToWorld = /*Matrix4x4d.ToMatrix4x4d(transform.localToWorldMatrix) * */ FaceToLocal;

            Matrix4x4d localToCamera    = View.WorldToCamera * LocalToWorld;
            Matrix4x4d localToScreen    = View.CameraToScreen * localToCamera;
            Matrix4x4d invLocalToCamera = localToCamera.Inverse;

            DeformedCameraPos = invLocalToCamera * (new Vector3d(0));

            Frustum3d.SetPlanes(DeformedFrustumPlanes, localToScreen);
            LocalCameraPos = Deform.DeformedToLocal(DeformedCameraPos);

            Matrix4x4d m = Deform.LocalToDeformedDifferential(LocalCameraPos, true);

            DistFactor = (float)Math.Max((new Vector3d(m[0, 0], m[1, 0], m[2, 0])).Magnitude, (new Vector3d(m[0, 1], m[1, 1], m[2, 1])).Magnitude);

            Vector3d left  = DeformedFrustumPlanes[0].xyz.Normalized;
            Vector3d right = DeformedFrustumPlanes[1].xyz.Normalized;

            float fov   = (float)MathUtility.Safe_Acos(-Vector3d.Dot(left, right));
            float width = (float)Screen.width;

            SplitDist = m_splitFactor * width / 1024.0f * Mathf.Tan(40.0f * Mathf.Deg2Rad) / Mathf.Tan(fov / 2.0f);

            if (SplitDist < 1.1f || !MathUtility.IsFinite(SplitDist))
            {
                SplitDist = 1.1f;
            }

            // initializes data structures for horizon occlusion culling
            if (HorizonCulling && LocalCameraPos.z <= Root.ZMax)
            {
                Vector3d deformedDir = invLocalToCamera * (new Vector3d(0, 0, 1));
                Vector2d localDir    = (Deform.DeformedToLocal(deformedDir) - LocalCameraPos).xy.Normalized;

                LocalCameraDir = new Matrix2x2d(localDir.y, -localDir.x, -localDir.x, -localDir.y);

                for (int i = 0; i < HORIZON_SIZE; ++i)
                {
                    m_horizon[i] = float.NegativeInfinity;
                }
            }

            Root.Update();

            World.SkyNode.SetUniforms(m_terrainMaterial);
            World.SunNode.SetUniforms(m_terrainMaterial);
            World.SetUniforms(m_terrainMaterial);
            Deform.SetUniforms(this, m_terrainMaterial);

            if (World.OceanNode != null)
            {
                World.OceanNode.SetUniforms(m_terrainMaterial);
            }
            else
            {
                m_terrainMaterial.SetFloat("_Ocean_DrawBRDF", 0.0f);
            }
        }
示例#2
0
                    public override bool Equals(System.Object target)
                    {
                        if ((null == target) || (GetType() != target.GetType()))
                        {
                            return(false);
                        }

                        Deform targetData = (Deform)target;

                        if (null == TableCoordinate)
                        {
                            if ((null == targetData.TableCoordinate) || (0 == targetData.TableCoordinate.Length))
                            {
                                return(true);
                            }
                            return(false);
                        }
                        if (null == targetData.TableCoordinate)
                        {
                            if (0 == TableCoordinate.Length)
                            {
                                return(true);
                            }
                        }

                        int countVertex = TableCoordinate.Length;

                        if (countVertex != targetData.TableCoordinate.Length)
                        {
                            return(false);
                        }

                        for (int i = 0; i < countVertex; i++)
                        {
                            if (TableCoordinate[i] != targetData.TableCoordinate[i])
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
示例#3
0
                    public void Duplicate(Deform original)
                    {
#if ATTRIBUTE_DUPLICATE_DEEP
                        /* MEMO: Deep copy */
                        if (null == original.TableCoordinate)
                        {
                            TableCoordinate = null;
                        }
                        else
                        {
                            int countVertex = original.TableCoordinate.Length;
                            TableCoordinate = new Vector2[countVertex];
                            for (int i = 0; i < countVertex; i++)
                            {
                                TableCoordinate[i] = original.TableCoordinate[i];
                            }
                        }
#else
                        /* MEMO: Shallow copy */
                        TableCoordinate = original.TableCoordinate;
#endif
                    }
示例#4
0
 /// <summary>
 /// Returns the visibility of the given bounding box from the current viewer position.
 /// This visibility is computed with Deformation::GetVisbility.
 /// </summary>
 /// <param name="localBox"></param>
 /// <returns></returns>
 public FRUSTUM_VISIBILTY GetVisibility(Box3d localBox)
 {
     return(Deform.GetVisibility(this, localBox));
 }
示例#5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="quad"></param>
 /// <param name="matPropertyBlock"></param>
 public void SetPerQuadUniforms(TerrainQuad quad, MaterialPropertyBlock matPropertyBlock)
 {
     Deform.SetUniforms(this, quad, matPropertyBlock);
 }