Release v0.9.6
This commit is contained in:
@@ -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:
|
||||
Reference in New Issue
Block a user