riversong code showcase

This commit is contained in:
Daniele Marotta
2026-05-21 15:52:18 +02:00
commit 4c9eea1c02
462 changed files with 23406 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
using Unity.Collections;
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Rendering;
using Random = Unity.Mathematics.Random;
namespace DanieleMarotta.RiversongCodeShowcase
{
public class GrassChunkMeshGenerator : GrassChunkMeshGeneratorBase<GrassTileMask>
{
public GrassChunkMeshGenerator(World world, GameConfig config) : base(world, config)
{
}
protected override int GetLodCount()
{
return Config.Terrain.GrassLODs.Length;
}
protected override string GetGameObjectName(string chunkName, int2 chunkCoords, int lod)
{
return $"{chunkName}_Grass_LOD{lod}";
}
protected override void InitializeChunk(TerrainChunk chunk, int lod, GameObject gameObject, Mesh mesh, Renderer renderer)
{
base.InitializeChunk(chunk, lod, gameObject, mesh, renderer);
renderer.shadowCastingMode = ShadowCastingMode.Off;
chunk.GrassLODs[lod] = new TerrainChunk.RenderData(mesh, renderer);
}
protected override Mesh GetMesh(TerrainChunk chunk, int lod)
{
return chunk.GrassLODs[lod].Mesh;
}
protected override JobHandle ScheduleJob(ChunkGenerationJobState jobState, NativeArray<int2> chunkCoords, NativeArray<Random> randomArray)
{
var job = new GenerateGrassChunkJob<GrassTileMask>();
PrepareJob(jobState, chunkCoords, randomArray, jobState.Lod, ref job);
return job.Schedule(chunkCoords.Length, Config.WorldGen.ChunksPerThread);
}
protected override Renderer GetRenderer(TerrainChunk chunk, int lod)
{
return chunk.GrassLODs[lod].Renderer;
}
protected override Material GetMaterial(int lod)
{
return Config.Terrain.GrassMaterial;
}
protected override GameConfig.WorldGenConfig.GrassConfig GetGrassGenerationConfig()
{
return Config.WorldGen.Grass;
}
protected override GrassTileMask GetMask()
{
var heightmap = World.Heightmap.GetNativeArray();
var fertility = World.Fertility.GetNativeArray();
return new GrassTileMask
{
Heightmap = heightmap,
Fertility = fertility
};
}
protected override int GetDensityForLOD(int lod)
{
return Config.Terrain.GrassLODs[lod].Density;
}
}
}