public void Render(Camera camera, int drawLayer = 8) { if (ReadyForDispatch) { if (!Generated) { Dispatch(); } } if (QuadAABB == null) { QuadAABB = GetQuadAABB(); } SetupBounds(this, QuadMesh); if (Planetoid.Atmosphere != null) { Planetoid.Atmosphere.SetUniforms(null, QuadMaterial, false, true); } //if (Planetoid.Ring != null) Planetoid.Ring.SetShadows(QuadMaterial, Planetoid.Shadows); //if (Planetoid.NPS != null) Planetoid.NPS.UpdateUniforms(QuadMaterial, null); //(WIP) For SE Coloring in fragment shader work... //if (Planetoid.tccps != null) Planetoid.tccps.UpdateUniforms(QuadMaterial); //(WIP) For SE Coloring in fragment shader work... if (QuadMaterial == null) { return; } if (!Uniformed) { QuadMaterial.SetBuffer("data", OutDataBuffer); QuadMaterial.SetBuffer("quadGenerationConstants", QuadGenerationConstantsBuffer); QuadMaterial.SetTexture("_HeightTexture", HeightTexture); QuadMaterial.SetTexture("_NormalTexture", NormalTexture); QuadMaterial.SetMatrix("_TRS", RotationMatrix); QuadMaterial.SetFloat("_LODLevel", LODLevel + 2); Uniformed = true; } QuadMaterial.SetFloat("_Atmosphere", (Planetoid.Atmosphere != null) ? 1.0f : 0.0f); QuadMaterial.SetFloat("_Normale", Planetoid.DrawNormals ? 1.0f : 0.0f); QuadMaterial.renderQueue = (int)Planetoid.RenderQueue + Planetoid.RenderQueueOffset; if (Generated && ShouldDraw && QuadMesh != null) { TryCull(); if (Visible) { Graphics.DrawMesh(QuadMesh, Planetoid.PlanetoidTRS, QuadMaterial, drawLayer, camera, 0, Planetoid.QuadAtmosphereMPB, true, true); } } }
public bool PlaneFrustumCheck(QuadAABB qaabb) { if (qaabb == null) { Log("QuadAABB problem!"); return(true); } //return GeometryUtility.TestPlanesAABB(GodManager.Instance.FrustumPlanes, QuadAABB.Bounds); return(PlaneFrustumCheck(qaabb.CullingAABB)); }
private bool PlaneFrustumCheck(QuadAABB qaabb) { for (byte i = 0; i < qaabb.CullingAABB.Length; i++) { if (BorderFrustumCheck(GodManager.Instance.FrustumPlanesTS, qaabb.CullingAABB[i])) { return(true); } } return(false); }
public void Render() { if (ReadyForDispatch) { if (!Generated) { Dispatch(); } } if (QuadAABB == null) { QuadAABB = GetVolumeBox(Planetoid.TerrainMaxHeight, 0); } //if (Planetoid.Ring != null) Planetoid.Ring.SetShadows(QuadMaterial, Planetoid.Shadows); //if (Planetoid.NPS != null) Planetoid.NPS.UpdateUniforms(QuadMaterial); //(WIP) For SE Coloring in fragment shader work... //if (Planetoid.tccps != null) Planetoid.tccps.UpdateUniforms(QuadMaterial); //(WIP) For SE Coloring in fragment shader work... if (QuadMaterial == null) { return; } QuadMaterial.renderQueue = (int)Planetoid.RenderQueue + Planetoid.RenderQueueOffset; if (Generated && ShouldDraw && QuadMesh != null) { // TODO : Setup bounds only once... QuadMesh.bounds = GetBounds(this); TryCull(); if (Visible) { Graphics.DrawMesh(QuadMesh, Planetoid.PlanetoidTRS, QuadMaterial, Planetoid.DrawLayer, CameraHelper.Main(), 0, Planetoid.MPB, true, true); } } }
/* * var localToCamera = CameraHelper.Main().GetWorldToCamera() * Matrix4x4.TRS(Planetoid.OriginTransform.TransformPoint(middleNormalized.normalized), Quaternion.Euler(middleNormalized.normalized * Mathf.Deg2Rad), Vector3.one); * var localToScreen = CameraHelper.Main().GetCameraToScreen() * localToCamera; * * var fp = Frustum.GetFrustumPlanes(localToScreen); * var visibility = Frustum.GetAABBVisibility(fp, QuadAABB, Planetoid.OriginTransform); * * if (visibility == Frustum.VISIBILITY.FULLY || visibility == Frustum.VISIBILITY.PARTIALLY) * Draw(); */ public static VISIBILITY GetAABBVisibility(Vector4d[] frustumPlanes, QuadAABB aabb, Transform origin = null) { var points = aabb.AABB; var v0 = GetPointVisibility(frustumPlanes, points[0], origin); if (v0 == VISIBILITY.INVISIBLE) { return(VISIBILITY.INVISIBLE); } var v1 = GetPointVisibility(frustumPlanes, points[1], origin); if (v1 == VISIBILITY.INVISIBLE) { return(VISIBILITY.INVISIBLE); } var v2 = GetPointVisibility(frustumPlanes, points[2], origin); if (v2 == VISIBILITY.INVISIBLE) { return(VISIBILITY.INVISIBLE); } var v3 = GetPointVisibility(frustumPlanes, points[3], origin); if (v3 == VISIBILITY.INVISIBLE) { return(VISIBILITY.INVISIBLE); } var v4 = GetPointVisibility(frustumPlanes, points[4], origin); if (v4 == VISIBILITY.INVISIBLE) { return(VISIBILITY.INVISIBLE); } var v5 = GetPointVisibility(frustumPlanes, points[5], origin); if (v5 == VISIBILITY.INVISIBLE) { return(VISIBILITY.INVISIBLE); } var v6 = GetPointVisibility(frustumPlanes, points[6], origin); if (v6 == VISIBILITY.INVISIBLE) { return(VISIBILITY.INVISIBLE); } var v7 = GetPointVisibility(frustumPlanes, points[7], origin); if (v7 == VISIBILITY.INVISIBLE) { return(VISIBILITY.INVISIBLE); } if (v0 == VISIBILITY.FULLY || v1 == VISIBILITY.FULLY || v2 == VISIBILITY.FULLY || v3 == VISIBILITY.FULLY || v4 == VISIBILITY.FULLY || v5 == VISIBILITY.FULLY || v6 == VISIBILITY.FULLY || v7 == VISIBILITY.FULLY) { return(VISIBILITY.FULLY); } return(VISIBILITY.PARTIALLY); }