Serialize LOD distances
This commit is contained in:
parent
93fc3e5da1
commit
ad66f824ee
@ -16,10 +16,12 @@ public class GrassField : MonoBehaviour {
|
||||
[Range(0f, 1f)] public float densityLOD0 = 1f;
|
||||
public bool enableShadowsLOD0 = true;
|
||||
[Header("LOD 1")]
|
||||
public float distanceLOD1 = 7.5f;
|
||||
public Material grassMaterialLOD1;
|
||||
[Range(0f, 1f)] public float densityLOD1 = 0.5f;
|
||||
public bool enableShadowsLOD1 = true;
|
||||
[Header("LOD 2")]
|
||||
public float distanceLOD2 = 7.5f + Mathf.Sqrt(2 * ((100f / 10f) * (100f / 10f))) + 5f;
|
||||
public Material grassMaterialLOD2;
|
||||
[Range(0f, 1f)] public float densityLOD2 = 0.2f;
|
||||
public bool enableShadowsLOD2 = false;
|
||||
@ -43,6 +45,11 @@ public class GrassField : MonoBehaviour {
|
||||
}
|
||||
|
||||
private void OnEnable() {
|
||||
var minDistLOD2 = distanceLOD1 + Mathf.Sqrt( 2 * Mathf.Pow( (float)size / numChunks, 2f ) );
|
||||
if (distanceLOD2 < minDistLOD2) {
|
||||
Debug.LogWarning("It is recommended that minDistLOD2 is greater than " + minDistLOD2 + ".");
|
||||
}
|
||||
|
||||
if (_chunks.Length != numChunks * numChunks) {
|
||||
Debug.LogError(this.name + ": Existing chunks does not match numChunks.");
|
||||
gameObject.SetActive(false);
|
||||
@ -76,10 +83,10 @@ public class GrassField : MonoBehaviour {
|
||||
var localCamPos = camPos - chunkPos; // cam position relative to chunk
|
||||
|
||||
var sqrCamDist = bounds.SqrDistance(localCamPos);
|
||||
if (sqrCamDist > 15f * 15f) {
|
||||
if (sqrCamDist > distanceLOD2 * distanceLOD2) {
|
||||
_chunks[x + y * numChunks].LOD = 2;
|
||||
}
|
||||
else if (sqrCamDist > 7.5f * 7.5f) {
|
||||
else if (sqrCamDist > distanceLOD1 * distanceLOD1) {
|
||||
_chunks[x + y * numChunks].LOD = 1;
|
||||
}
|
||||
else {
|
||||
@ -199,8 +206,15 @@ public class GrassField : MonoBehaviour {
|
||||
// draw a circle instead of a sphere
|
||||
Gizmos.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1f, 0.001f, 1f));
|
||||
}
|
||||
Gizmos.color = new Color(1.0f, 0.0f, 1f, 2f);
|
||||
Gizmos.DrawWireSphere(center, 7.5f);
|
||||
|
||||
Gizmos.color = new Color(1.0f, 0.0f, 1.0f, 1f);
|
||||
Gizmos.DrawWireSphere(center, distanceLOD1);
|
||||
Gizmos.DrawWireSphere(center, distanceLOD2);
|
||||
|
||||
Gizmos.color = new Color(1.0f, 1.0f, 0.0f, 1f);
|
||||
var minDistLOD2 = distanceLOD1 + Mathf.Sqrt( 2 * Mathf.Pow( (float)size / numChunks, 2f ) );
|
||||
Gizmos.DrawWireSphere(center, minDistLOD2);
|
||||
|
||||
Gizmos.matrix = oldMatrix;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user