You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.2 KiB
Plaintext
69 lines
2.2 KiB
Plaintext
// Each #kernel tells which function to compile; you can have many kernels
|
|
#pragma kernel Paint
|
|
#include "../Includes/GPUNoiseParams.cginc"
|
|
#include "../Includes/GPUNoise.cginc"
|
|
|
|
Texture2D<float> _InputDisplacement;
|
|
Texture2D<float> _InputBrushTexture;
|
|
RWTexture2D<float> _OutputDisplacement;
|
|
|
|
int _EffectType = 0; // Raise = 0, Lower = 1, Flatten = 2, ClearTrees = 3, ClearDetails = 4, Texture = 5, Detail = 6
|
|
float _PaintStrength;
|
|
float _FlattenHeight = 0.0f;
|
|
float2 _iResolution = 513.0f;
|
|
float2 _Offset = 0.0f;
|
|
|
|
float MoveTowards(float current, float target, float maxDelta)
|
|
{
|
|
if (abs(target - current) <= maxDelta)
|
|
return target;
|
|
return current + sign(target - current) * maxDelta;
|
|
}
|
|
|
|
[numthreads(32,32,1)]
|
|
void Paint(uint3 id : SV_DispatchThreadID)
|
|
{
|
|
const uint2 coord = id.xy;
|
|
//---------------
|
|
float height = _InputDisplacement[coord];
|
|
float brush = _InputBrushTexture[coord] * 2.0f;
|
|
const uint2 mid = _iResolution.xy / 2;
|
|
float2 center = ((float2)mid + _Offset) / _iResolution.xy;
|
|
float2 coordinate = ((float2)coord + _Offset) / _iResolution.xy;
|
|
const float xRes = _iResolution.x;
|
|
const float yRes = _iResolution.y;
|
|
float xPos = coordinate.x * xRes;
|
|
float yPos = coordinate.y * yRes;
|
|
const float2 worldPos = float2(xPos, yPos);
|
|
if (_NoisemapEnabled)
|
|
{
|
|
const float distance = length(center.xy - coordinate.xy);
|
|
const float falloff = EvaluateFalloff(distance, _NoiseFalloff, _NoiseFalloffCount);
|
|
const float noise = GetNoise(worldPos) * falloff * _NoisemapStrength;
|
|
brush *= 1.0f + noise;
|
|
}
|
|
const float displacement = brush * _PaintStrength;
|
|
switch (_EffectType)
|
|
{
|
|
case 0: // Raise
|
|
height += displacement;
|
|
break;
|
|
case 1: // Lower
|
|
height -= displacement;
|
|
break;
|
|
case 2: // Flatten
|
|
//height = MoveTowards(height, flattenHeight * .5f, brush * strength);
|
|
const float delta = clamp(displacement, 0.f, 1.f);
|
|
height = lerp(height, _FlattenHeight * .5f, delta);
|
|
break;
|
|
case 3: // Clear Trees
|
|
case 4: // Clear Details
|
|
case 5: // Texture
|
|
case 6: // Details
|
|
height = displacement;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
_OutputDisplacement[coord] = height;
|
|
} |