Procedural Planets
Integrated Sebastian Lague's Planet Generator Created Tour function in SectorRenderer which makes the camera follow each terrestrial planet in turn
This commit is contained in:
parent
f8165878e0
commit
53a91351b7
332 changed files with 11904 additions and 78 deletions
|
|
@ -0,0 +1,37 @@
|
|||
#pragma kernel CSMain
|
||||
|
||||
Texture2D<float4> SourceTex;
|
||||
RWTexture2D<float4> Result;
|
||||
|
||||
uint textureSize;
|
||||
int blurSize;
|
||||
|
||||
uint2 Wrap(int x, int y) {
|
||||
x = (x < 0) ? textureSize + x : x;
|
||||
x = (x >= (int)textureSize) ? x - textureSize : x;
|
||||
y = (y < 0) ? textureSize + y : y;
|
||||
y = (y >= (int)textureSize) ? y - textureSize : y;
|
||||
return uint2(x, y);
|
||||
}
|
||||
|
||||
[numthreads(8,8,1)]
|
||||
void CSMain (uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id.x >= textureSize || id.y >= textureSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
float4 sum = 0;
|
||||
for (int offsetX = -blurSize; offsetX <= blurSize; offsetX ++) {
|
||||
for (int offsetY = -blurSize; offsetY <= blurSize; offsetY ++) {
|
||||
uint2 sampleCoord = Wrap(id.x + offsetX, id.y + offsetY);
|
||||
float4 sample = SourceTex[sampleCoord];
|
||||
sum += sample;
|
||||
}
|
||||
}
|
||||
|
||||
int numSamples = (blurSize * 2 + 1) * (blurSize * 2 + 1);
|
||||
float4 result = sum / numSamples;
|
||||
|
||||
Result[id.xy] = result;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3bbb70231abe74a25b57d54568b663d9
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 65536
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
// Each #kernel tells which function to compile; you can have many kernels
|
||||
#pragma kernel CSMain
|
||||
#include "../../Includes/Math.cginc"
|
||||
//
|
||||
|
||||
// Create a RenderTexture with enableRandomWrite flag and set it
|
||||
// with cs.SetTexture
|
||||
RWTexture2D<float4> Result;
|
||||
StructuredBuffer<float4> spots;
|
||||
uint resolution;
|
||||
int numSpots;
|
||||
float background;
|
||||
float4 params;
|
||||
float smoothing;
|
||||
|
||||
[numthreads(8,8,1)]
|
||||
void CSMain (uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
|
||||
if (id.x >= resolution || id.y >= resolution) {
|
||||
return;
|
||||
}
|
||||
|
||||
float2 pos = id.xy / (float)resolution;
|
||||
float alpha = 0;
|
||||
|
||||
|
||||
float minDst = 999;
|
||||
for (int i = 0; i < numSpots; i ++) {
|
||||
float4 spot = spots[i];
|
||||
float r = spot.z;
|
||||
|
||||
float dst = length(spot.xy - pos);
|
||||
|
||||
|
||||
float minDstOld = minDst;
|
||||
// minDst = smoothMin(dst, minDst, smoothing * 0.001);
|
||||
|
||||
if ( dst <= r) {
|
||||
//alpha = max(alpha, spot.w);
|
||||
//float v = 1-dst/r;
|
||||
//alpha += v*v*spot.w;
|
||||
alpha = max(alpha,spot.w);
|
||||
}
|
||||
}
|
||||
alpha = 1-saturate(background + alpha);
|
||||
Result[id.xy] = float4(alpha, alpha, alpha, 1);//
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a06a7dddd79684a96a2169e2128e5f88
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 65536
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
#pragma kernel CSMain
|
||||
#pragma kernel Normalize
|
||||
#include "../../Includes/SimplexNoise3.cginc"
|
||||
|
||||
static const int minMaxAccuracy = 1000000;
|
||||
RWTexture2D<float4> Result;
|
||||
uint resolution;
|
||||
|
||||
RWStructuredBuffer<int> minMax;
|
||||
float4 noiseParams_simple[3];
|
||||
float4 noiseParams_warp[3];
|
||||
float valueFloor;
|
||||
float4 params;
|
||||
|
||||
// Remap a value (with a known mininum and maximum) to a value between 0 and 1
|
||||
float remap01(float v, float minOld, float maxOld) {
|
||||
return saturate((v-minOld) / (maxOld-minOld));
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
float tilingNoise(float2 pos, float4 noiseParams[3], float warp) {
|
||||
static const int x1 =-1, y1=-1, x2=1, y2=1;
|
||||
static const float dx = x2 - x1;
|
||||
static const float dy = y2 - y1;
|
||||
static const float tau = 3.14159265359 * 2;
|
||||
|
||||
// Params
|
||||
float3 offset = warp;
|
||||
float3 offset3d = noiseParams[0].xyz;//
|
||||
int numLayers = int(noiseParams[0].w);
|
||||
float persistence = noiseParams[1].x;
|
||||
float lacunarity = noiseParams[1].y;
|
||||
float scale = noiseParams[1].z;
|
||||
float multiplier = noiseParams[1].w;
|
||||
|
||||
// web.archive.org/web/20160304043608/https://www.gamedev.net/blog/33/entry-2138456-seamless-noise/
|
||||
float nx = x1 + cos(pos.x * tau) * dx;
|
||||
float ny = y1 + cos(pos.y * tau) * dy;
|
||||
float nz = x1 + sin(pos.x * tau) * dx;
|
||||
float nw = y1 + sin (pos.y * tau) * dy;
|
||||
float4 pos4D = float4(nx, ny, nz, nw) / tau;
|
||||
float4 dir = normalize(pos4D);
|
||||
pos4D += dir * 0.1 * params.x;
|
||||
//pos4D += snoise(pos4D * params.w * 0.001);
|
||||
|
||||
float noise = 0;
|
||||
float amplitude = 1;
|
||||
float frequency = scale;
|
||||
|
||||
for (int i = 0; i < numLayers; i ++) {
|
||||
float layerVal = snoise((pos4D + warp) * frequency);//
|
||||
//layerVal = 1-abs(layerVal);
|
||||
//layerVal *= layerVal;
|
||||
noise += layerVal * amplitude;
|
||||
amplitude *= persistence;
|
||||
frequency *= lacunarity;
|
||||
}
|
||||
|
||||
return noise * multiplier;
|
||||
}
|
||||
|
||||
[numthreads(8,8,1)]
|
||||
void CSMain (uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id.x >= resolution || id.y >= resolution) {
|
||||
return;
|
||||
}
|
||||
|
||||
float2 pos = id.xy/(float)resolution;
|
||||
|
||||
float warpNoise = tilingNoise(pos, noiseParams_warp, 0) * 0.1;
|
||||
float noise = tilingNoise(pos, noiseParams_simple, warpNoise);
|
||||
|
||||
// keep inside range [0,1] as will be clamped in texture
|
||||
float approxMax = 2;
|
||||
noise = saturate((noise + approxMax * 0.5) / approxMax);
|
||||
|
||||
|
||||
Result[id.xy] = noise;
|
||||
|
||||
// keep track of min max (using int to support atomic operation)
|
||||
int val = (int)(noise * minMaxAccuracy);
|
||||
InterlockedMin(minMax[0],val);
|
||||
InterlockedMax(minMax[1],val);
|
||||
}
|
||||
|
||||
[numthreads(8,8,1)]
|
||||
void Normalize (uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id.x >= resolution || id.y >= resolution) {
|
||||
return;
|
||||
}
|
||||
|
||||
float minVal = (float)minMax[0]/minMaxAccuracy;
|
||||
float maxVal = (float)minMax[1]/minMaxAccuracy;
|
||||
float4 normalizedValue = (Result[id.xy]-minVal)/(maxVal-minVal);
|
||||
|
||||
|
||||
Result[id.xy] = normalizedValue;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2821ce0c209074cf9bb487300949b8f6
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 65536
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue