Skip to content

Commit

Permalink
Small tweaks made when looking through code for final paper
Browse files Browse the repository at this point in the history
  • Loading branch information
AIP21 committed May 21, 2023
1 parent a0ecfea commit a1daf16
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Assets/DataStructure/Data/AbstractGridData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Copies the data from the given object to this AbstractGridData.

/**
<summary>
Dispose this data. (Dispose any buffers, textures, etc from memory)
Dispose this data. (Dispose of any buffers, textures, etc from memory)
This should ALWAYS be called before this object is destroyed or discarded. (Although, this should not be commonly used because you want to keep the same data object at runtime)
</summary>
**/
Expand Down
14 changes: 8 additions & 6 deletions Assets/TreeGrowth/Scripts/Generation/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ public IEnumerable<Node> GetTree()
}

/**
Try to branch off of this branch. Only for if this branch already has any children.
Try to branch off of this branch. Only for if this branch already has children.
**/
public Node Branch()
{
if (this.Children.Count() == 0) // If this branch already has any children
if (this.Children.Count() == 0) // If this branch doesn't already has any children then don't branch off of it
return null;

// The math for the falloff is as follows: (branch length falloff param ^ depth of this branch in the tree)
Expand Down Expand Up @@ -212,7 +212,7 @@ private Vector3 getGrowthDirection(Func<Vector3> vectorGenerator, float minDista

if (System.Single.IsPositiveInfinity(range)) // There is no obstacle in the way, so just return the growth direction
{
Debug.DrawRay(this.Tree.transform.position + this.Position + growthDirection.normalized * 0.01f, growthDirection, Color.green, 10);
Debug.DrawRay(this.Tree.transform.position + this.Position + growthDirection * 0.01f, growthDirection, Color.green, 10);
return growthDirection;
}

Expand All @@ -222,11 +222,11 @@ private Vector3 getGrowthDirection(Func<Vector3> vectorGenerator, float minDista
result = growthDirection;
longestDistance = range;

Debug.DrawRay(this.Tree.transform.position + this.Position + growthDirection.normalized * 0.01f, growthDirection, Color.yellow, 10);
Debug.DrawRay(this.Tree.transform.position + this.Position + growthDirection * 0.01f, growthDirection, Color.yellow, 10);
}
else
{
Debug.DrawRay(this.Tree.transform.position + this.Position + growthDirection.normalized * 0.01f, growthDirection, Color.red, 10);
Debug.DrawRay(this.Tree.transform.position + this.Position + growthDirection * 0.01f, growthDirection, Color.red, 10);
}
}

Expand All @@ -248,14 +248,16 @@ public void RecalculateEnergy()
Cast a ray from a given position in a given direction
Returns the distance to the first object hit by the ray
ASSUMES THAT THE GIVEN DIRECTION IS ALREADY NORMALIZED
**/
private float raycast(Vector3 position, Vector3 direction, Color color, float skip = 0f, bool debug = false)
{
this.Tree.RayCastCount++; // Increment the raycast count done by this branch's tree

// Create a ray from the calculated position(tree root position + the given position + the normalized given direction * the skip distance) with the given direction
// Skip is used to offset the origin a tiny bit, so that it doesn't hit this branch
Ray ray = new Ray(this.Tree.transform.position + position + direction.normalized * skip, direction);
Ray ray = new Ray(this.Tree.transform.position + position + direction * skip, direction);

if (debug)
Debug.DrawRay(ray.origin, ray.direction, color, 10);
Expand Down
16 changes: 3 additions & 13 deletions Assets/TreeGrowth/Scripts/Generation/TreeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ private List<Node> chooseRandomLeafNodes(int num)

public float CalculateWaterUseThisTick()
{
recalculateEnergy();
// recalculateEnergy();

float waterUse = 0;
foreach (Node node in this.Root.GetTree())
Expand All @@ -491,18 +491,8 @@ private float nodeWaterUse(Node node)

public float CalculateWaterAbsorptionThisTick()
{
float waterAbsorption = 0;
foreach (Node node in this.Root.GetTree())
{
// If this is a stem node
if (Mathf.Pow(map(1, this.Root.SubtreeSize, 1, 0, node.SubtreeSize), this.parameters.SizeFalloff) == 0)
{
float stemAbsorptionMult = 0.3f;
waterAbsorption += stemAbsorptionMult * (getBranchRadius(node) + node.GetLength());
}
}

return waterAbsorption;
float stemAbsorptionMult = 0.3f;
return stemAbsorptionMult * (getBranchRadius(this.Root) + this.Root.GetLength());
}
#endregion

Expand Down
8 changes: 5 additions & 3 deletions Assets/WaterSimulation/Shaders/CompShader_Water.compute
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ float gauss(float x, float radius)

// Surface evaporation
if (evaporationConstant > 0) {
newSurfaceWater = max(newSurfaceWater - evaporationConstant, 0.0);
// Less water evaporates the more water there is
float evaporation = min(0.0, -2.4389 * pow(newSurfaceWater - 0.689655, 3))
newSurfaceWater = min(0.0, newSurfaceWater - evaporation * evaporationConstant);
}


Expand All @@ -134,10 +136,10 @@ float gauss(float x, float radius)
// Scale pos to external texture size
int2 externalPos = int2(pos * externalSize);

float externalUnit = (size / externalSize); // basically how many soil cells there are in a single external cell
float externalUnit = pow(size / externalSize, 2); // basically how many soil cells there are in a single external cell

// Get how much water is being used in this cell
float use = (soilUseMap[externalPos] * externalUnit) * soilUseMultiplier; // TODO: * (1 - soilData);
float use = (soilUseMap[externalPos] / externalUnit) * soilUseMultiplier; // TODO: * (1 - soilData);

// Make sure we don't use more water than there is in this cell
use = min(use, newSoilSaturation);
Expand Down

0 comments on commit a1daf16

Please sign in to comment.