106 lines
3.8 KiB
C#
106 lines
3.8 KiB
C#
![]() |
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using Godot;
|
||
|
using System;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
|
||
|
|
||
|
namespace Rokojori
|
||
|
{
|
||
|
/** <summary for="class FoliageRenderLayer">
|
||
|
|
||
|
<title>
|
||
|
Is used by the FoliageRenderer to book keep and render a layer defined by the FoliageData.
|
||
|
|
||
|
</title>
|
||
|
|
||
|
<description>
|
||
|
|
||
|
|
||
|
</description>
|
||
|
|
||
|
</summary>
|
||
|
*/
|
||
|
|
||
|
public class FoliageRenderLayer
|
||
|
{
|
||
|
public FoliageRenderer renderer;
|
||
|
public FoliageData data;
|
||
|
public GpuParticles3D gpuParticles3D;
|
||
|
public GPUFoliageShaderMaterial gpuFoliageShaderMaterial;
|
||
|
float _lastCellSize = -1;
|
||
|
float _lastMaxVisibility = -1;
|
||
|
|
||
|
public static FoliageRenderLayer Create( FoliageRenderer renderer, FoliageData data )
|
||
|
{
|
||
|
var rl = new FoliageRenderLayer();
|
||
|
rl.renderer = renderer;
|
||
|
rl.data = data;
|
||
|
|
||
|
|
||
|
return rl;
|
||
|
}
|
||
|
|
||
|
public void Update( double delta )
|
||
|
{
|
||
|
if ( gpuFoliageShaderMaterial != null )
|
||
|
{
|
||
|
gpuFoliageShaderMaterial.cameraPosition.Set( renderer.GetAssignedCamera().GlobalPosition );
|
||
|
|
||
|
var sizeInt = Mathf.CeilToInt( data.visibilityRange / data.cellSize ) * 2;
|
||
|
|
||
|
if ( _lastCellSize != data.cellSize || _lastMaxVisibility != data.visibilityRange )
|
||
|
{
|
||
|
_lastCellSize = data.cellSize;
|
||
|
_lastMaxVisibility = data.visibilityRange;
|
||
|
|
||
|
gpuFoliageShaderMaterial.cellSize.Set( data.cellSize );
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
gpuParticles3D.Amount = sizeInt * sizeInt;
|
||
|
gpuFoliageShaderMaterial.width.Set( sizeInt );
|
||
|
gpuFoliageShaderMaterial.height.Set( sizeInt );
|
||
|
|
||
|
}
|
||
|
|
||
|
var hideStart = data.visibilityRange - ( data.visibilityRange * data.visibilityFadeRelative + data.visibilityFadeAbsolute );
|
||
|
gpuFoliageShaderMaterial.hideMax.Set( data.visibilityRange );
|
||
|
gpuFoliageShaderMaterial.hideStart.Set( hideStart );
|
||
|
gpuFoliageShaderMaterial.hideOffset.Set( data.visibilityFadeHidingOffset );
|
||
|
|
||
|
gpuFoliageShaderMaterial.positionVariance.Set( renderer.noise );
|
||
|
gpuFoliageShaderMaterial.rotationVariance.Set( renderer.noise );
|
||
|
gpuFoliageShaderMaterial.scaleVariance.Set( renderer.noise );
|
||
|
gpuFoliageShaderMaterial.occupancyVariance.Set( renderer.noise );
|
||
|
|
||
|
gpuFoliageShaderMaterial.maxPositionOffset.Set( data.positionVarianceMaxOffset );
|
||
|
gpuFoliageShaderMaterial.positionUvScale.Set( Vector2.One * data.positionVarianceScale );
|
||
|
gpuFoliageShaderMaterial.positionUvOffset.Set( Vector2.One * data.positionVarianceOffset );
|
||
|
|
||
|
gpuFoliageShaderMaterial.minRotation.Set( data.rotationMin );
|
||
|
gpuFoliageShaderMaterial.maxRotation.Set( data.rotationMax );
|
||
|
gpuFoliageShaderMaterial.rotationUvScale.Set( Vector2.One * data.rotationVarianceScale );
|
||
|
gpuFoliageShaderMaterial.rotationUvOffset.Set( Vector2.One * data.rotationVarianceOffset );
|
||
|
|
||
|
gpuFoliageShaderMaterial.minScale.Set( data.scaleVarianceMinScale );
|
||
|
gpuFoliageShaderMaterial.maxScale.Set( data.scaleVarianceMaxScale );
|
||
|
gpuFoliageShaderMaterial.scaleUvScale.Set( Vector2.One * data.scaleVarianceScale );
|
||
|
gpuFoliageShaderMaterial.scaleUvOffset.Set( Vector2.One * data.scaleVarianceOffset );
|
||
|
|
||
|
gpuFoliageShaderMaterial.occupancyAmount.Set( data.occupancyVarianceAmount );
|
||
|
gpuFoliageShaderMaterial.occupancyPower.Set( data.occupancyVariancePower );
|
||
|
gpuFoliageShaderMaterial.occupancyTreshold.Set( data.occupancyTreshold );
|
||
|
|
||
|
gpuFoliageShaderMaterial.occupancyHideOffset.Set( data.occupancyHideOffset );
|
||
|
gpuFoliageShaderMaterial.occupancyHideScale.Set( data.occupancyHideScale );
|
||
|
|
||
|
gpuFoliageShaderMaterial.occupancyUvScale.Set( Vector2.One * data.occupancyVarianceScale );
|
||
|
gpuFoliageShaderMaterial.occupancyUvOffset.Set( Vector2.One * data.occupancyVarianceOffset );
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|