Release v0.9.6
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20fa72b659e90fa43968c87a232b37f8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
// Licensed under the Non-Profit Open Software License version 3.0
|
||||
|
||||
// Variables
|
||||
float2 ClampRange;
|
||||
|
||||
// Kernel
|
||||
[numthreads(32,1,1)]
|
||||
void Clamp (uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if(id.x < HeightMapLength){ // Keep in bounds
|
||||
// Update texture
|
||||
HeightBuffer[id.x] = clamp(HeightBuffer[id.x], ClampRange.x, ClampRange.y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87cf122e8f207694aa255ce415696591
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
// Licensed under the Non-Profit Open Software License version 3.0
|
||||
|
||||
// Variables
|
||||
float2 ExpanderMinMax;
|
||||
|
||||
// Kernel
|
||||
[numthreads(32,1,1)]
|
||||
void Expand (uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if(id.x < HeightMapLength){ // Keep in bounds
|
||||
// Expand height
|
||||
HeightBuffer[id.x] = clamp((HeightBuffer[id.x] - ExpanderMinMax.x) / ExpanderMinMax.y, 0, 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32af8ef11d4f6e24289de4765f4d6347
|
||||
timeCreated: 1556402402
|
||||
@@ -0,0 +1,12 @@
|
||||
// Licensed under the Non-Profit Open Software License version 3.0
|
||||
|
||||
// Variables
|
||||
float HeightContrastPow;
|
||||
|
||||
// Kernel
|
||||
[numthreads(32,1,1)]
|
||||
void HeightContrast (uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
// Expand height
|
||||
HeightBuffer[id.x] = clamp(pow(abs(HeightBuffer[id.x] + 0.5), HeightContrastPow) - 0.5, 0, 1);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2386040a4e4bbb04faa3dcc57c80e435
|
||||
timeCreated: 1556405164
|
||||
@@ -0,0 +1,21 @@
|
||||
// Licensed under the Non-Profit Open Software License version 3.0
|
||||
|
||||
// Kernel
|
||||
[numthreads(32,32,1)]
|
||||
void HeightMapToTexture (uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
// Get width and height of texture
|
||||
int w,h;
|
||||
Texture.GetDimensions(w,h);
|
||||
|
||||
// Calculate position relative to heightmap
|
||||
float2 relativeID = RelativizeVector(id.x, id.y, w, h);
|
||||
float2 heightMapPos = float2(relativeID.x * HeightMapResolution, relativeID.y * HeightMapResolution);
|
||||
|
||||
// Calculate height
|
||||
float3 gradient = CalculateGradientAndHeight(heightMapPos, HeightMapResolution, HeightBuffer);
|
||||
|
||||
// Set height
|
||||
|
||||
Texture[id.xy] = float4(gradient.z,gradient.z,gradient.z,1);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ae8d18f40ac1974db9ed6523037bda7
|
||||
timeCreated: 1556291579
|
||||
@@ -0,0 +1,103 @@
|
||||
// Licensed under the Non-Profit Open Software License version 3.0
|
||||
|
||||
// Variables
|
||||
uint ErosionParticleCount;
|
||||
uint ErosionMaxLifeTime;
|
||||
float ErosionInertia;
|
||||
float ErosionParticleStartSpeed;
|
||||
float ErosionParticleStartWater;
|
||||
float ErosionSedimentCapacityFactor;
|
||||
float ErosionMinSedimentCapacity;
|
||||
float ErosionSpeed;
|
||||
float ErosionEvaporateSpeed;
|
||||
float ErosionGravity;
|
||||
float ErosionDepositSpeed;
|
||||
|
||||
// Kernel
|
||||
[numthreads(32,1,1)]
|
||||
void HydraulicErosion (uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if(id.x < ErosionParticleCount){ // Keep in bounds
|
||||
float randomNormalizedX = Random(id.x);
|
||||
float randomNormalizedY = Random(id.x + HeightMapResolution * randomNormalizedX);
|
||||
|
||||
float2 pos = float2(
|
||||
randomNormalizedX * HeightMapResolution,
|
||||
randomNormalizedY * HeightMapResolution
|
||||
);
|
||||
|
||||
// Particle values
|
||||
float2 dir = float2(0,0);
|
||||
float speed = ErosionParticleStartSpeed;
|
||||
float water = ErosionParticleStartWater;
|
||||
float sediment = 0;
|
||||
|
||||
for(uint lifeTime = 0; lifeTime < ErosionMaxLifeTime; lifeTime++){
|
||||
// Calculate texture coords
|
||||
uint2 coord = uint2(
|
||||
(uint) pos.x,
|
||||
(uint) pos.y
|
||||
);
|
||||
|
||||
int index = PosToIndex(coord, HeightMapResolution);
|
||||
|
||||
// Calculate cell offset
|
||||
float2 cellOffset = float2(
|
||||
pos.x - float(coord.x),
|
||||
pos.y - float(coord.y)
|
||||
);
|
||||
|
||||
// Calculate interpolated gradient and height
|
||||
float3 heightAndGradient = CalculateGradientAndHeight(pos, HeightMapResolution, HeightBuffer);
|
||||
|
||||
// Update the droplet's direction and position (move position 1 unit regardless of speed)
|
||||
dir.x = (dir.x * ErosionInertia - heightAndGradient.x * (1 - ErosionInertia));
|
||||
dir.y = (dir.y * ErosionInertia - heightAndGradient.y * (1 - ErosionInertia));
|
||||
|
||||
// Normalize dir
|
||||
dir = Normalize2D(dir);
|
||||
|
||||
// Add to position
|
||||
pos += dir;
|
||||
|
||||
// Header guard to check wheter particle is still inside texture and moving
|
||||
if((dir.x == 0 && dir.y == 0) || pos.x <= 0 || pos.y <= 0 || pos.x >= float(HeightMapResolution - 2) || pos.y >= float(HeightMapResolution - 2)){ break; }
|
||||
|
||||
// Calculate new height and deltaHeight
|
||||
float height = CalculateGradientAndHeight(pos, HeightMapResolution, HeightBuffer).z;
|
||||
float deltaHeight = height - heightAndGradient.z;
|
||||
|
||||
// Calculate the droplet's sediment capacity (higher when moving fast down a slope and contains lots of water)
|
||||
float sedimentCapacity = max(-deltaHeight, ErosionMinSedimentCapacity) * speed * water * ErosionSedimentCapacityFactor;
|
||||
|
||||
// If carrying more sediment than capacity, or if flowing uphill:
|
||||
if (sediment > sedimentCapacity || deltaHeight > 0) {
|
||||
// If moving uphill (deltaHeight > 0) try fill up to the current height, otherwise deposit a fraction of the excess sediment
|
||||
float amountToDeposit = (deltaHeight > 0) ?
|
||||
min(deltaHeight, sediment) :
|
||||
(sediment - sedimentCapacity) * ErosionDepositSpeed;
|
||||
|
||||
// Remove deposited sediment
|
||||
sediment -= amountToDeposit;
|
||||
|
||||
// Add the sediment to the four nodes of the current cell using bilinear interpolation
|
||||
AddToBuffer(index, HeightMapResolution, cellOffset, amountToDeposit, HeightBuffer);
|
||||
}
|
||||
else {
|
||||
// Erode a fraction of the droplet's current carry capacity.
|
||||
// Clamp the erosion to the change in height so that it doesn't dig a hole in the terrain behind the droplet
|
||||
float amountToErode = min((sedimentCapacity - sediment) * ErosionSpeed, -deltaHeight);
|
||||
|
||||
// Remove erosion amount from heightmap
|
||||
AddToBuffer(index, HeightMapResolution, cellOffset, -amountToErode, HeightBuffer);
|
||||
|
||||
// Add eroded amount to sediment currently carried
|
||||
sediment += amountToErode;
|
||||
}
|
||||
|
||||
// Update droplet's speed and water content
|
||||
speed = sqrt (max(0,speed * speed + deltaHeight * ErosionGravity));
|
||||
water *= (1 - ErosionEvaporateSpeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa4ceb37d27b27746821c24bfb4c208b
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
// Licensed under the Non-Profit Open Software License version 3.0
|
||||
|
||||
// Variables
|
||||
uint PerlinType;
|
||||
float PerlinAmplitude;
|
||||
float PerlinFrequency;
|
||||
float2 PerlinOffset;
|
||||
uint PerlinOctaves;
|
||||
float PerlinOctavesStrength;
|
||||
|
||||
// Methods
|
||||
float StandardPerlinNoise(uint id, float amplitude, float2 offset){
|
||||
// Calculate vector
|
||||
float2 pos = IndexToFloatVector(id, HeightMapResolution);
|
||||
|
||||
// Calculate x and y position
|
||||
float x = float(pos.x) / HeightMapResolution;
|
||||
float y = float(pos.y) / HeightMapResolution;
|
||||
|
||||
// Generate noise
|
||||
return cnoise(float2(x * amplitude + offset.x, y * amplitude + offset.y));
|
||||
}
|
||||
|
||||
float BillowyPerlinNoise(uint id, float amplitude, float2 offset){
|
||||
float noise = StandardPerlinNoise(id, amplitude, offset);
|
||||
return abs(noise * 2 - 1);
|
||||
}
|
||||
|
||||
float RigidPerlinNoise(uint id, float amplitude, float2 offset){
|
||||
return 1 - BillowyPerlinNoise(id, amplitude, offset);;
|
||||
}
|
||||
|
||||
// Kernel
|
||||
[numthreads(32,1,1)]
|
||||
void PerlinNoise (uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if(id.x < HeightMapLength){ // Keep in bounds
|
||||
float total = 0;
|
||||
float frequency = PerlinFrequency;
|
||||
float amplitude = 1;
|
||||
float maxvalue = 0;
|
||||
|
||||
for(uint i = 0; i < PerlinOctaves; i++){
|
||||
|
||||
// Types
|
||||
if(PerlinType == 0){ // Standard
|
||||
total += StandardPerlinNoise(id.x, frequency, PerlinOffset) * amplitude;
|
||||
} else if(PerlinType == 1){ // Billowy
|
||||
total += BillowyPerlinNoise(id.x, frequency, PerlinOffset) * amplitude;
|
||||
} else if(PerlinType == 2){ // Rigid
|
||||
total += RigidPerlinNoise(id.x, frequency, PerlinOffset) * amplitude;
|
||||
}
|
||||
|
||||
maxvalue += amplitude;
|
||||
amplitude *= PerlinOctavesStrength;
|
||||
frequency *= 2;
|
||||
}
|
||||
|
||||
// Update buffer
|
||||
HeightBuffer[id.x] = total/maxvalue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0260ec8f278be834195f00cac6315f59
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
// Licensed under the Non-Profit Open Software License version 3.0
|
||||
|
||||
// Variables
|
||||
uint PseudoRandomNoiseSeed;
|
||||
|
||||
// Kernel
|
||||
[numthreads(32,1,1)]
|
||||
void PseudoRandomNoise (uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if(id.x < HeightMapLength){ // Keep in bounds
|
||||
// Calculate vector
|
||||
uint2 pos = IndexToVector(id.x, HeightMapResolution);
|
||||
|
||||
// Generate noise
|
||||
float noise = Random((pos.x + (pos.y * HeightMapResolution)) * PseudoRandomNoiseSeed);
|
||||
|
||||
// Update buffer
|
||||
HeightBuffer[id.x] = noise;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73e7265746e81774ebca11f4b98413e4
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,30 @@
|
||||
// Licensed under the Non-Profit Open Software License version 3.0
|
||||
|
||||
// Variables
|
||||
uint TerraceCount;
|
||||
float TerraceShape;
|
||||
bool Smooth;
|
||||
|
||||
// Kernel
|
||||
[numthreads(1024,1,1)]
|
||||
void Terrace (uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if(id.x < HeightMapLength){ // Keep in bounds
|
||||
float height = HeightBuffer[id.x] * TerraceCount; // Calculate height inside the terrace range
|
||||
uint heightFloor = uint(height); // Floor the height
|
||||
float difference = height - heightFloor; // Difference between height and floor. Normalized terrace
|
||||
|
||||
if(Smooth){ // Should the terraces be smooth or sharp. Changes what part of the sigmoid is used
|
||||
difference = (NormalisedSigmoid(difference * 2 - 1, TerraceShape) + 1) / 2;
|
||||
} else {
|
||||
difference = NormalisedSigmoid(difference, TerraceShape);
|
||||
}
|
||||
|
||||
// Calculate floor and ceil of terrace
|
||||
float floor = float(heightFloor) / TerraceCount;
|
||||
float ceil = float(heightFloor + 1) / TerraceCount;
|
||||
|
||||
// Update buffer
|
||||
HeightBuffer[id.x] = lerp(floor, ceil, difference);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f9c8c3b289cae746b013fe7e3d21d3c
|
||||
timeCreated: 1557500706
|
||||
@@ -0,0 +1,34 @@
|
||||
Shader "Hidden/NimbleFox/DepthToGrayscale"
|
||||
{
|
||||
SubShader
|
||||
{
|
||||
Cull Off
|
||||
ZWrite Off
|
||||
ZTest Always
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert_img
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
UNITY_DECLARE_DEPTH_TEXTURE(_MainTex);
|
||||
|
||||
float _DepthRangeNear;
|
||||
float _DepthRangeFar;
|
||||
|
||||
fixed4 frag(v2f_img i) : SV_Target
|
||||
{
|
||||
float rawDepth = SAMPLE_DEPTH_TEXTURE(_MainTex, i.uv);
|
||||
float linearDepth = LinearEyeDepth(rawDepth);
|
||||
float normalizedDepth = saturate((linearDepth - _DepthRangeNear) / max(0.0001, _DepthRangeFar - _DepthRangeNear));
|
||||
float grayscale = 1.0 - normalizedDepth;
|
||||
return fixed4(grayscale, grayscale, grayscale, 1.0);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
Fallback Off
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e57ab23464b9b773bcae5cab8d1f466
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cba69cdcca6e7cd4fac00498c7d4f6aa
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,106 @@
|
||||
// Licensed under the Non-Profit Open Software License version 3.0
|
||||
|
||||
float4 mod(float4 x, float4 y)
|
||||
{
|
||||
return x - y * floor(x / y);
|
||||
}
|
||||
|
||||
float4 mod289(float4 x)
|
||||
{
|
||||
return x - floor(x / 289.0) * 289.0;
|
||||
}
|
||||
|
||||
float4 permute(float4 x)
|
||||
{
|
||||
return mod289(((x*34.0)+1.0)*x);
|
||||
}
|
||||
|
||||
float4 taylorInvSqrt(float4 r)
|
||||
{
|
||||
return (float4)1.79284291400159 - r * 0.85373472095314;
|
||||
}
|
||||
|
||||
float2 fade(float2 t) {
|
||||
return t*t*t*(t*(t*6.0-15.0)+10.0);
|
||||
}
|
||||
|
||||
// Classic Perlin noise
|
||||
float cnoise(float2 P)
|
||||
{
|
||||
float4 Pi = floor(P.xyxy) + float4(0.0, 0.0, 1.0, 1.0);
|
||||
float4 Pf = frac (P.xyxy) - float4(0.0, 0.0, 1.0, 1.0);
|
||||
Pi = mod289(Pi); // To avoid truncation effects in permutation
|
||||
float4 ix = Pi.xzxz;
|
||||
float4 iy = Pi.yyww;
|
||||
float4 fx = Pf.xzxz;
|
||||
float4 fy = Pf.yyww;
|
||||
|
||||
float4 i = permute(permute(ix) + iy);
|
||||
|
||||
float4 gx = frac(i / 41.0) * 2.0 - 1.0 ;
|
||||
float4 gy = abs(gx) - 0.5 ;
|
||||
float4 tx = floor(gx + 0.5);
|
||||
gx = gx - tx;
|
||||
|
||||
float2 g00 = float2(gx.x,gy.x);
|
||||
float2 g10 = float2(gx.y,gy.y);
|
||||
float2 g01 = float2(gx.z,gy.z);
|
||||
float2 g11 = float2(gx.w,gy.w);
|
||||
|
||||
float4 norm = taylorInvSqrt(float4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
|
||||
g00 *= norm.x;
|
||||
g01 *= norm.y;
|
||||
g10 *= norm.z;
|
||||
g11 *= norm.w;
|
||||
|
||||
float n00 = dot(g00, float2(fx.x, fy.x));
|
||||
float n10 = dot(g10, float2(fx.y, fy.y));
|
||||
float n01 = dot(g01, float2(fx.z, fy.z));
|
||||
float n11 = dot(g11, float2(fx.w, fy.w));
|
||||
|
||||
float2 fade_xy = fade(Pf.xy);
|
||||
float2 n_x = lerp(float2(n00, n01), float2(n10, n11), fade_xy.x);
|
||||
float n_xy = lerp(n_x.x, n_x.y, fade_xy.y);
|
||||
return (2.3 * n_xy) / 2 + 0.5;
|
||||
}
|
||||
|
||||
// Classic Perlin noise, periodic variant
|
||||
float pnoise(float2 P, float2 rep)
|
||||
{
|
||||
float4 Pi = floor(P.xyxy) + float4(0.0, 0.0, 1.0, 1.0);
|
||||
float4 Pf = frac (P.xyxy) - float4(0.0, 0.0, 1.0, 1.0);
|
||||
Pi = mod(Pi, rep.xyxy); // To create noise with explicit period
|
||||
Pi = mod289(Pi); // To avoid truncation effects in permutation
|
||||
float4 ix = Pi.xzxz;
|
||||
float4 iy = Pi.yyww;
|
||||
float4 fx = Pf.xzxz;
|
||||
float4 fy = Pf.yyww;
|
||||
|
||||
float4 i = permute(permute(ix) + iy);
|
||||
|
||||
float4 gx = frac(i / 41.0) * 2.0 - 1.0 ;
|
||||
float4 gy = abs(gx) - 0.5 ;
|
||||
float4 tx = floor(gx + 0.5);
|
||||
gx = gx - tx;
|
||||
|
||||
float2 g00 = float2(gx.x,gy.x);
|
||||
float2 g10 = float2(gx.y,gy.y);
|
||||
float2 g01 = float2(gx.z,gy.z);
|
||||
float2 g11 = float2(gx.w,gy.w);
|
||||
|
||||
float4 norm = taylorInvSqrt(float4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
|
||||
g00 *= norm.x;
|
||||
g01 *= norm.y;
|
||||
g10 *= norm.z;
|
||||
g11 *= norm.w;
|
||||
|
||||
float n00 = dot(g00, float2(fx.x, fy.x));
|
||||
float n10 = dot(g10, float2(fx.y, fy.y));
|
||||
float n01 = dot(g01, float2(fx.z, fy.z));
|
||||
float n11 = dot(g11, float2(fx.w, fy.w));
|
||||
|
||||
float2 fade_xy = fade(Pf.xy);
|
||||
float2 n_x = lerp(float2(n00, n01), float2(n10, n11), fade_xy.x);
|
||||
float n_xy = lerp(n_x.x, n_x.y, fade_xy.y);
|
||||
return 2.3 * n_xy;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8a6a61a2747363409cee3af98e65684
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
// Licensed under the Non-Profit Open Software License version 3.0
|
||||
|
||||
uint Hash(uint s)
|
||||
{
|
||||
s ^= 2747636419u;
|
||||
s *= 2654435769u;
|
||||
s ^= s >> 16;
|
||||
s *= 2654435769u;
|
||||
s ^= s >> 16;
|
||||
s *= 2654435769u;
|
||||
return s;
|
||||
}
|
||||
|
||||
float Random(uint seed)
|
||||
{
|
||||
return float(Hash(seed)) / 4294967295.0; // 2^32-1
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be8762190190dc54c8f77d4d86a95899
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,116 @@
|
||||
// Licensed under the Non-Profit Open Software License version 3.0
|
||||
|
||||
float Magnitude2D(float2 dir){
|
||||
return max(0.01,sqrt(dir.x * dir.x + dir.y * dir.y));
|
||||
}
|
||||
|
||||
float Magnitude3D(float3 dir){
|
||||
return max(0.01,sqrt(dir.x * dir.x + dir.y * dir.y + dir.z * dir.z));
|
||||
}
|
||||
|
||||
float2 Normalize2D(float2 dir){
|
||||
float magnitude = Magnitude2D(dir);
|
||||
dir.x /= magnitude;
|
||||
dir.y /= magnitude;
|
||||
return dir;
|
||||
}
|
||||
|
||||
float3 Normalize3D(float3 dir){
|
||||
float magnitude = Magnitude3D(dir);
|
||||
dir.x /= magnitude;
|
||||
dir.y /= magnitude;
|
||||
dir.z /= magnitude;
|
||||
return dir;
|
||||
}
|
||||
|
||||
int PosToIndex(uint2 pos, int width){
|
||||
return pos.x + (pos.y * width);
|
||||
}
|
||||
|
||||
uint2 IndexToVector(int index, int width){
|
||||
float division = float(index) / float(width);
|
||||
int rounded = int(division);
|
||||
return uint2((division - float(rounded)) * width,rounded);
|
||||
}
|
||||
|
||||
float2 IndexToFloatVector(int index, int width){
|
||||
float division = float(index) / float(width);
|
||||
int rounded = int(division);
|
||||
return float2((division - float(rounded)) * width,rounded);
|
||||
}
|
||||
|
||||
|
||||
float2 RelativizeVector(float x, float y, float w, float h){
|
||||
return float2(
|
||||
x / w,
|
||||
y / h
|
||||
);
|
||||
}
|
||||
|
||||
float3 RelativizeVector(float3 vec, float3 size){
|
||||
return float3(
|
||||
vec.x / size.x,
|
||||
vec.y / size.y,
|
||||
vec.z / size.z
|
||||
);
|
||||
}
|
||||
|
||||
void AddToBuffer(int index, int resolution, float2 cellOffset, float value, RWStructuredBuffer<float> buffer){
|
||||
buffer[index] += value * (1 - cellOffset.x) * (1 - cellOffset.y);
|
||||
buffer[index + 1] += value * cellOffset.x * (1 - cellOffset.y);
|
||||
buffer[index + resolution] += value * (1 - cellOffset.x) * cellOffset.y;
|
||||
buffer[index + resolution + 1] += value * cellOffset.x * cellOffset.y;
|
||||
}
|
||||
|
||||
float3 CalculateNormal(uint2 pos, int resolution, float3 size, RWStructuredBuffer<float> buffer){
|
||||
// Calculate multiplier direction
|
||||
float multiplier = -1;
|
||||
if(pos.x <= 0 || pos.y <= 0){ multiplier = 1; }
|
||||
|
||||
// Calculate left, right, up and down vertex positions
|
||||
float3 c = float3(pos.x, 0, pos.y);
|
||||
float3 l = float3(pos.x - 1, 0, pos.y);
|
||||
float3 u = float3(pos.x, 0, pos.y - 1);
|
||||
|
||||
// Gather heights for left, right, up and down vertices
|
||||
c.y = buffer[PosToIndex(uint2(c.xz), resolution)] * size.y;
|
||||
l.y = buffer[PosToIndex(uint2(l.xz), resolution)] * size.y;
|
||||
u.y = buffer[PosToIndex(uint2(u.xz), resolution)] * size.y;
|
||||
|
||||
// calculate normal direction
|
||||
return Normalize3D(cross(l - c, u - c)) * multiplier;
|
||||
}
|
||||
|
||||
float NormalisedSigmoid(float x, float k){
|
||||
return (x - x * k) / (k - abs(x) * 2 * k + 1);
|
||||
}
|
||||
|
||||
float3 CalculateGradientAndHeight (float2 pos, int resolution, RWStructuredBuffer<float> buffer) {
|
||||
// Calculate coords
|
||||
uint2 coord = uint2(
|
||||
(int) pos.x,
|
||||
(int) pos.y
|
||||
);
|
||||
|
||||
// Calculate index
|
||||
int index = PosToIndex(coord, resolution);
|
||||
|
||||
// Calculate droplet's offset inside the cell (0,0) = at NW node, (1,1) = at SE node
|
||||
float x = pos.x - float(coord.x);
|
||||
float y = pos.y - float(coord.y);
|
||||
|
||||
// Calculate heights of the four nodes of the droplet's cell
|
||||
float heightNW = buffer[index];
|
||||
float heightNE = buffer[index + 1];
|
||||
float heightSW = buffer[index + HeightMapResolution];
|
||||
float heightSE = buffer[index + HeightMapResolution + 1];
|
||||
|
||||
// Calculate droplet's direction of flow with bilinear interpolation of height difference along the edges
|
||||
float gradientX = (heightNE - heightNW) * (1 - y) + (heightSE - heightSW) * y;
|
||||
float gradientY = (heightSW - heightNW) * (1 - x) + (heightSE - heightNE) * x;
|
||||
|
||||
// Calculate height with bilinear interpolation of the heights of the nodes of the cell
|
||||
float height = heightNW * (1 - x) * (1 - y) + heightNE * x * (1 - y) + heightSW * (1 - x) * y + heightSE * x * y;
|
||||
|
||||
return float3(gradientX,gradientY,height);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59e6ae1a6b22ad441a32c557dd169a70
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
// Licensed under the Non-Profit Open Software License version 3.0
|
||||
|
||||
// Each #kernel tells which function to compile; you can have many kernels
|
||||
#pragma kernel PerlinNoise
|
||||
#pragma kernel Clamp
|
||||
#pragma kernel HydraulicErosion
|
||||
#pragma kernel PseudoRandomNoise
|
||||
#pragma kernel HeightMapToTexture
|
||||
#pragma kernel Expand
|
||||
#pragma kernel HeightContrast
|
||||
#pragma kernel Terrace
|
||||
|
||||
// Declare global buffers
|
||||
float BlendStrength;
|
||||
|
||||
// Texture buffer
|
||||
RWTexture2D<float4> Texture;
|
||||
|
||||
// Height buffer
|
||||
uint HeightMapResolution;
|
||||
uint HeightMapLength;
|
||||
RWStructuredBuffer<float> HeightBuffer;
|
||||
|
||||
// Global includes
|
||||
#include "Utils/PRNG.hlsl"
|
||||
#include "Utils/ClassicNoise2D.hlsl"
|
||||
#include "Utils/WorldKitUtils.hlsl"
|
||||
|
||||
// Kernel includes
|
||||
#include "Layers/PerlinNoise.hlsl"
|
||||
#include "Layers/Clamp.hlsl"
|
||||
#include "Layers/HydraulicErosion.hlsl"
|
||||
#include "Layers/PseudoRandomNoise.hlsl"
|
||||
#include "Layers/HeightMapToTexture.hlsl"
|
||||
#include "Layers/Expand.hlsl"
|
||||
#include "Layers/HeightContrast.hlsl"
|
||||
#include "Layers/Terrace.hlsl"
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8b62a14992acf549a4ee7cbec513922
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 4
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user