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,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 375b93914a7154241b14ccf7df35e859
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
#pragma kernel CSMain
|
||||
#include "../../Includes/Math.cginc"
|
||||
|
||||
RWTexture2D<float4> Result;
|
||||
int textureSize;
|
||||
int numOutScatteringSteps;
|
||||
float atmosphereRadius;
|
||||
float avgDensityHeight01;
|
||||
float densityFalloff;
|
||||
float4 params;
|
||||
|
||||
float densityAtPoint(float2 densitySamplePoint) {
|
||||
float planetRadius = 1;
|
||||
float2 planetCentre = 0;
|
||||
|
||||
float heightAboveSurface = length(densitySamplePoint - planetCentre) - planetRadius;
|
||||
float height01 = heightAboveSurface / (atmosphereRadius - planetRadius);
|
||||
float localDensity = exp(-height01 * densityFalloff) * (1 - height01);
|
||||
return localDensity;
|
||||
}
|
||||
|
||||
float opticalDepth(float2 rayOrigin, float2 rayDir, float rayLength) {
|
||||
int numOpticalDepthPoints = numOutScatteringSteps;
|
||||
|
||||
float2 densitySamplePoint = rayOrigin;
|
||||
float stepSize = rayLength / (numOpticalDepthPoints - 1);
|
||||
float opticalDepth = 0;
|
||||
|
||||
for (int i = 0; i < numOpticalDepthPoints; i ++) {
|
||||
float localDensity = densityAtPoint(densitySamplePoint);
|
||||
opticalDepth += localDensity * stepSize;
|
||||
densitySamplePoint += rayDir * stepSize;
|
||||
}
|
||||
return opticalDepth;
|
||||
}
|
||||
|
||||
|
||||
float calculateOutScattering(float2 inPoint, float2 outPoint) {
|
||||
float planetRadius = 1;
|
||||
float skinWidth = planetRadius / 1000.0;
|
||||
|
||||
|
||||
float lightTravelDst = length(outPoint - inPoint);
|
||||
float2 outScatterPoint = inPoint;
|
||||
float2 rayDir = (outPoint - inPoint) / lightTravelDst;
|
||||
float stepSize = (lightTravelDst - skinWidth) / (numOutScatteringSteps);
|
||||
|
||||
float outScatterAmount = 0;
|
||||
|
||||
for (int i = 0; i < numOutScatteringSteps; i ++) {
|
||||
outScatterPoint += rayDir * stepSize;
|
||||
|
||||
// height at planet surface = 0, at furthest extent of atmosphere = 1
|
||||
float height = length(outScatterPoint - 0) - planetRadius;//
|
||||
|
||||
|
||||
|
||||
float height01 = saturate(height / (atmosphereRadius - planetRadius));
|
||||
outScatterAmount += exp(-height01 * densityFalloff) * stepSize;
|
||||
|
||||
}
|
||||
|
||||
return outScatterAmount;
|
||||
}
|
||||
|
||||
[numthreads(8,8,1)]
|
||||
void CSMain (uint2 id : SV_DispatchThreadID)
|
||||
{
|
||||
const float planetRadius = 1;
|
||||
|
||||
float2 uv = id / (float)textureSize;
|
||||
float height01 = uv.y;
|
||||
float angle = uv.x * PI;
|
||||
//angle = (1-cos(angle))/2;
|
||||
float2 dir = float2(sin(angle), cos(angle));
|
||||
float y = -2 * uv.x + 1;
|
||||
float x = sin(acos(y));
|
||||
dir = float2(x,y);
|
||||
|
||||
float2 inPoint = float2(0, lerp(planetRadius, atmosphereRadius, height01));
|
||||
float dstThroughAtmosphere = raySphere(0, atmosphereRadius, float3(inPoint,0), float3(dir,0)).y;
|
||||
float2 outPoint = inPoint + dir * raySphere(0, atmosphereRadius, float3(inPoint,0), float3(dir,0)).y;
|
||||
//float outScattering = calculateOutScattering(inPoint, outPoint);
|
||||
float outScattering = opticalDepth(inPoint + dir * 0.0001, dir, dstThroughAtmosphere-0.0002);
|
||||
|
||||
Result[id.xy] = outScattering;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 463adb4526f5a48bdb8c71df4c6dd88d
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 65536
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 44fb59fda0e1d49dda281e0401d4dc76
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
#pragma kernel CSMain
|
||||
|
||||
#include "../../Includes/FractalNoise.cginc"
|
||||
#include "../../Includes/Craters.cginc"
|
||||
//
|
||||
|
||||
StructuredBuffer<float3> vertices;
|
||||
RWStructuredBuffer<float> heights;
|
||||
uint numVertices;
|
||||
|
||||
|
||||
// Continent settings:
|
||||
float oceanDepthMultiplier;
|
||||
float oceanFloorDepth;
|
||||
float oceanFloorSmoothing;
|
||||
float mountainBlend;
|
||||
|
||||
// Old:
|
||||
float4 noiseParams_continents[3];
|
||||
float4 noiseParams_mask[3];
|
||||
float4 noiseParams_mountains[3];
|
||||
float4 noiseParams_warp[3];
|
||||
float4 params;
|
||||
|
||||
|
||||
[numthreads(512,1,1)]
|
||||
void CSMain (uint id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id >= numVertices) {
|
||||
return;
|
||||
}
|
||||
|
||||
float3 pos = vertices[id];
|
||||
float3 warpNoise = float3(simpleNoise(pos, noiseParams_warp),simpleNoise(pos-100, noiseParams_warp),simpleNoise(pos+100, noiseParams_warp)) * 0.01;
|
||||
float3 warpedPos = pos + warpNoise;
|
||||
float craterDepth = calculateCraterDepth(pos);
|
||||
|
||||
float continentShape = simpleNoise(pos + warpNoise * params.x, noiseParams_continents);
|
||||
|
||||
continentShape = smoothMax(continentShape, -oceanFloorDepth, oceanFloorSmoothing);
|
||||
|
||||
|
||||
if (continentShape < 0) {
|
||||
continentShape *= 1 + oceanDepthMultiplier;
|
||||
}
|
||||
|
||||
float ridgeNoise = smoothedRidgidNoise(pos + warpNoise * params.y, noiseParams_mountains);
|
||||
|
||||
|
||||
float mask = Blend(0, mountainBlend, simpleNoise(pos + warpNoise * params.z, noiseParams_mask));
|
||||
// Calculate final height
|
||||
float finalHeight = 1 + continentShape * 0.01 + ridgeNoise * 0.01 * mask + craterDepth;
|
||||
//finalHeight = 1 + Blend(0, params.x, simpleNoise(pos, noiseParams_mask)) * 0.05;
|
||||
|
||||
// Set terrain data
|
||||
heights[id] = finalHeight;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b33d87d0482194cf2a21c78c2cc775f8
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 65536
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
#pragma kernel CSMain
|
||||
|
||||
#include "../../Includes/FractalNoise.cginc"
|
||||
#include "../../Includes/Math.cginc"
|
||||
//
|
||||
|
||||
StructuredBuffer<float3> vertices;
|
||||
RWStructuredBuffer<float> heights;
|
||||
uint numVertices;
|
||||
|
||||
|
||||
// Continent settings:
|
||||
float oceanDepthMultiplier;
|
||||
float oceanFloorDepth;
|
||||
float oceanFloorSmoothing;
|
||||
float mountainBlend;
|
||||
|
||||
float4 noiseParams_continents[3];
|
||||
float4 noiseParams_mask[3];
|
||||
float4 noiseParams_mountains[3];
|
||||
float4 params;
|
||||
|
||||
[numthreads(512,1,1)]
|
||||
void CSMain (uint id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id >= numVertices) {
|
||||
return;
|
||||
}
|
||||
|
||||
float3 pos = vertices[id];
|
||||
|
||||
float continentShape = simpleNoise(pos, noiseParams_continents);
|
||||
|
||||
continentShape = smoothMax(continentShape, -oceanFloorDepth, oceanFloorSmoothing);
|
||||
|
||||
|
||||
if (continentShape < 0) {
|
||||
continentShape *= 1 + oceanDepthMultiplier;
|
||||
}
|
||||
|
||||
float ridgeNoise = smoothedRidgidNoise(pos, noiseParams_mountains);
|
||||
|
||||
|
||||
float mask = Blend(0, mountainBlend, simpleNoise(pos, noiseParams_mask));
|
||||
// Calculate final height
|
||||
float finalHeight = 1 + continentShape * 0.01 + ridgeNoise * 0.01 * mask;
|
||||
//finalHeight = 1 + Blend(0, params.x, simpleNoise(pos, noiseParams_mask)) * 0.05;
|
||||
|
||||
// Set terrain data
|
||||
heights[id] = finalHeight;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d6df9e6cc324e48a892dd6a9cf741d65
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 65536
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
#pragma kernel CSMain
|
||||
|
||||
#include "../../Includes/FractalNoise.cginc"
|
||||
#include "../../Includes/Craters.cginc"
|
||||
//
|
||||
|
||||
StructuredBuffer<float3> vertices;
|
||||
RWStructuredBuffer<float> heights;
|
||||
uint numVertices;
|
||||
|
||||
// Continent settings:
|
||||
float shoreSteepness;
|
||||
float continentFlatness;
|
||||
float continentLevel;
|
||||
float2 maskMinMax;
|
||||
float mountainBlend;
|
||||
float4 noiseParams_continents[3];//
|
||||
float4 noiseParams_mask[3];
|
||||
|
||||
// Ridge noise
|
||||
float4 noiseParams_mountains[3];
|
||||
float4 params;
|
||||
float mountainSmoothing;
|
||||
|
||||
|
||||
float calculateMountainNoise(float3 pos) {
|
||||
float3 sphereNormal = pos;
|
||||
float3 axisA = cross(sphereNormal, float3(0,1,0));
|
||||
float3 axisB = cross(sphereNormal, axisA);
|
||||
|
||||
// Sample the noise several times at small offsets from the centre and average the result
|
||||
// This reduces some of the harsh jaggedness that can occur
|
||||
float offsetDst = mountainSmoothing * 0.01;
|
||||
float sample0 = ridgidNoise(pos, noiseParams_mountains);
|
||||
float sample1 = ridgidNoise(pos - axisA * offsetDst, noiseParams_mountains);
|
||||
float sample2 = ridgidNoise(pos + axisA * offsetDst, noiseParams_mountains);
|
||||
float sample3 = ridgidNoise(pos - axisB * offsetDst, noiseParams_mountains);
|
||||
float sample4 = ridgidNoise(pos + axisB * offsetDst, noiseParams_mountains);
|
||||
return (sample0 + sample1 + sample2 + sample3 + sample4) / 5;
|
||||
}
|
||||
|
||||
[numthreads(512,1,1)]
|
||||
void CSMain (uint id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id >= numVertices) {
|
||||
return;
|
||||
}
|
||||
|
||||
float3 pos = vertices[id];
|
||||
|
||||
float continentShape = simpleNoise(pos, noiseParams_continents);
|
||||
continentShape = continentShape * (1 + continentShape / continentLevel * shoreSteepness);
|
||||
if (continentShape < 0) {
|
||||
continentShape *= 1+mountainSmoothing * abs(continentShape);
|
||||
}
|
||||
|
||||
float craterDepth = calculateCraterDepth(pos);
|
||||
|
||||
//float heightAboveShore = max(0, continentShape);
|
||||
//float k = (1 - saturate(heightAboveShore / continentLevel)) * shoreSteepness;
|
||||
// continentShape = smoothMin(continentShape, 0, shoreSteepness);
|
||||
|
||||
|
||||
// Calculate final height
|
||||
float finalHeight = 1 + continentShape * 0.01 + craterDepth;
|
||||
|
||||
// Set terrain data
|
||||
heights[id] = finalHeight;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e32322f519a614092915aa9cbc4cb7c2
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 65536
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
#pragma kernel CSMain
|
||||
#include "../../Includes/Craters.cginc"
|
||||
#include "../../Includes/FractalNoise.cginc"
|
||||
|
||||
//
|
||||
StructuredBuffer<float3> vertices;
|
||||
RWStructuredBuffer<float> heights;
|
||||
uint numVertices;
|
||||
|
||||
float4 testParams;
|
||||
|
||||
// Noise settings
|
||||
float4 noiseParams_shape[3];
|
||||
float4 noiseParams_ridge[3];
|
||||
float4 noiseParams_ridge2[3];
|
||||
|
||||
[numthreads(512, 1, 1)]
|
||||
void CSMain (uint id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id >= numVertices) { return; }
|
||||
static const float elevationMultiplier = 0.01;
|
||||
|
||||
float3 pos = vertices[id];
|
||||
|
||||
// Craters
|
||||
float craterDepth = calculateCraterDepth(pos);
|
||||
// Low-frequency noise to add some slight deformation to the base sphere shape of the moon
|
||||
float shapeNoise = simpleNoise(pos, noiseParams_shape);
|
||||
|
||||
// Ridge noise
|
||||
float ridgeNoise = smoothedRidgidNoise(pos, noiseParams_ridge);
|
||||
float ridge2 = smoothedRidgidNoise(pos, noiseParams_ridge2);
|
||||
|
||||
float noiseSum = (shapeNoise + ridgeNoise + ridge2) * elevationMultiplier;
|
||||
float finalHeight = 1 + craterDepth + noiseSum;
|
||||
heights[id] = finalHeight;
|
||||
|
||||
// Debug ridge mask
|
||||
//terrainHeights[id] = 1 + ridgeMask * .1;
|
||||
//terrainHeights[id] = 1 + ridgeNoise * elevationMultiplier;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1c8bff6c5dfd7461f8403bd2cef35625
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 65536
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
#pragma kernel CSMain
|
||||
|
||||
#include "../../Includes/FractalNoise.cginc"
|
||||
#include "../../Includes/Craters.cginc"
|
||||
//
|
||||
|
||||
StructuredBuffer<float3> vertices;
|
||||
RWStructuredBuffer<float> heights;
|
||||
uint numVertices;
|
||||
|
||||
|
||||
float plateauHeight;
|
||||
float plateauSmoothing;
|
||||
|
||||
float4 noiseParams_continents[3];
|
||||
float4 noiseParams_mountains[3];
|
||||
float4 noiseParams_mountains2[3];
|
||||
float4 noiseParams_warp[3];
|
||||
float4 params;
|
||||
|
||||
|
||||
[numthreads(512,1,1)]
|
||||
void CSMain (uint id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id >= numVertices) {
|
||||
return;
|
||||
}
|
||||
|
||||
float3 pos = vertices[id];
|
||||
float3 warpNoise = float3(simpleNoise(pos, noiseParams_warp),simpleNoise(pos-100, noiseParams_warp),simpleNoise(pos+100, noiseParams_warp)) * 0.01;
|
||||
float craterDepth = calculateCraterDepth(pos);
|
||||
float continentShape = simpleNoise(pos + warpNoise, noiseParams_continents);
|
||||
continentShape = smoothMin(continentShape, plateauHeight, plateauSmoothing);
|
||||
|
||||
float ridgeNoise = smoothedRidgidNoise(pos, noiseParams_mountains);
|
||||
float ridgeNoise2 = smoothedRidgidNoise(pos, noiseParams_mountains2); //
|
||||
|
||||
// Calculate final height
|
||||
float finalHeight = 1 + (continentShape + ridgeNoise + ridgeNoise2) * 0.01 + craterDepth;
|
||||
//finalHeight = 1 + Blend(0, params.x, simpleNoise(pos, noiseParams_mask)) * 0.05;
|
||||
|
||||
// Set terrain data
|
||||
heights[id] = finalHeight;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 13008f929df404f2c9c4d64443449aed
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 65536
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: caff2a8a0d5b640a9a75ebb6a10c3fa8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
Shader "Hidden/OceanMask"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Cull Off ZWrite Off ZTest Always
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "../../Includes/Math.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertex : SV_POSITION;
|
||||
float3 viewVector : TEXCOORD1;
|
||||
};
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = v.uv;
|
||||
// Camera space matches OpenGL convention where cam forward is -z. In unity forward is positive z.
|
||||
// (https://docs.unity3d.com/ScriptReference/Camera-cameraToWorldMatrix.html)
|
||||
float3 viewVector = mul(unity_CameraInvProjection, float4(v.uv.xy * 2 - 1, 0, -1));
|
||||
o.viewVector = mul(unity_CameraToWorld, float4(viewVector,0));
|
||||
return o;
|
||||
}
|
||||
|
||||
sampler2D _MainTex;
|
||||
static const int maxNumSpheres = 10;
|
||||
float4 spheres[maxNumSpheres];
|
||||
int numSpheres;
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
float3 rayOrigin = _WorldSpaceCameraPos;
|
||||
float3 rayDir = normalize(i.viewVector);
|
||||
|
||||
//return float4(rayDir,1);
|
||||
|
||||
float nearest = 0;
|
||||
for (int sphereIndex = 0; sphereIndex < numSpheres; sphereIndex ++) {
|
||||
float2 hitInfo = raySphere(spheres[sphereIndex].xyz, spheres[sphereIndex].w, rayOrigin, rayDir);
|
||||
if (hitInfo.y > 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5c954f4bd730d46199b888d542aded55
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
#pragma kernel CSMain
|
||||
#include "../../Includes/FractalNoise.cginc"
|
||||
|
||||
RWStructuredBuffer<float3> points;
|
||||
uint numPoints;
|
||||
float maxStrength;
|
||||
|
||||
float3 perturb(float3 pos) {
|
||||
float scale = 50;
|
||||
float fx = simpleNoise(pos * 1, 2, scale, .5, 2, 1);
|
||||
float fy = simpleNoise(pos * 2, 2, scale, .5, 2, 1);
|
||||
float fz = simpleNoise(pos * 3, 2, scale, .5, 2, 1);
|
||||
float3 offset = float3(fx, fy, fz);
|
||||
offset = smoothstep(-1,1,offset) * 2 -1;
|
||||
return offset;
|
||||
}
|
||||
|
||||
[numthreads(512,1,1)]
|
||||
void CSMain (uint id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id >= numPoints) {
|
||||
return;
|
||||
}
|
||||
|
||||
float3 pos = points[id];
|
||||
float height = length(pos);
|
||||
|
||||
float3 offset = perturb(pos);
|
||||
float3 newPos = pos + offset * maxStrength;
|
||||
|
||||
newPos = normalize(newPos) * height;
|
||||
points[id] = newPos;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c95c667630d66481daf208e2a7a4d95d
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 65536
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
#pragma kernel CSMain
|
||||
#include "../../Includes/FractalNoise.cginc"
|
||||
|
||||
RWStructuredBuffer<float3> points;
|
||||
uint numPoints;
|
||||
float maxStrength;
|
||||
|
||||
float3 perturb(float3 pos) {
|
||||
float3 noise = fractalNoiseGrad(pos, 4, 25, .5, 2).xyz;
|
||||
noise = smoothstep(-1,1,noise) * 2 -1;
|
||||
return noise;
|
||||
}
|
||||
|
||||
[numthreads(512,1,1)]
|
||||
void CSMain (uint id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id >= numPoints) {
|
||||
return;
|
||||
}
|
||||
|
||||
float3 pos = points[id];
|
||||
float height = length(pos);
|
||||
|
||||
float3 offset = perturb(pos);
|
||||
float3 newPos = pos + offset * maxStrength;
|
||||
|
||||
newPos = normalize(newPos) * height;
|
||||
points[id] = newPos;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0cc4782d709194aa5a22ed5e9ab8bf09
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 65536
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
#pragma kernel CSMain
|
||||
|
||||
StructuredBuffer<float3> vertices;
|
||||
StructuredBuffer<int> triangles;
|
||||
RWStructuredBuffer<float> steepness;
|
||||
int numTriangles;
|
||||
|
||||
[numthreads(256,1,1)]
|
||||
void CSMain (uint id : SV_DispatchThreadID)
|
||||
{
|
||||
if ((int)id >= numTriangles) {
|
||||
return;
|
||||
}
|
||||
|
||||
int triangleIndex = id * 3;
|
||||
float3 a = vertices[triangles[triangleIndex]];
|
||||
float3 b = vertices[triangles[triangleIndex+1]];
|
||||
float3 c = vertices[triangles[triangleIndex+2]];
|
||||
|
||||
float3 faceNormal = normalize(cross(a-b, a-c));
|
||||
float3 sphereNormal = normalize((a+b+c)/3);
|
||||
steepness[id] = 1 - dot(faceNormal, sphereNormal);
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b65c4a31f112141149dfdfb7d00a93f2
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 65536
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1b6ba54c403c749d3935a2e0e7a34e83
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
#pragma kernel CSMain
|
||||
|
||||
#include "../../Includes/FractalNoise.cginc"
|
||||
#include "../../Includes/Math.cginc"
|
||||
|
||||
StructuredBuffer<float3> vertices;
|
||||
RWStructuredBuffer<float4> shadingData;
|
||||
uint numVertices;
|
||||
|
||||
// Noise settings
|
||||
float4 noiseParams_detailWarp[3];
|
||||
float4 noiseParams_detail[3];
|
||||
|
||||
float4 noiseParams_large[3];
|
||||
float4 noiseParams_small[3];
|
||||
|
||||
// Second warp
|
||||
float4 noiseParams_warp2[3];
|
||||
float4 noiseParams_noise2[3];
|
||||
|
||||
[numthreads(512, 1, 1)]
|
||||
void CSMain (uint id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id >= numVertices) { return; }
|
||||
|
||||
float3 pos = vertices[id];
|
||||
|
||||
// Large, low frequency noise
|
||||
float largeNoise = simpleNoise(pos, noiseParams_large);
|
||||
float smallNoise = simpleNoise(pos, noiseParams_small);
|
||||
|
||||
// Warped detail noise
|
||||
float detailWarp = simpleNoise(pos, noiseParams_detailWarp);
|
||||
float detailNoise = simpleNoise(pos + detailWarp * 0.1, noiseParams_detail);
|
||||
|
||||
// Second warp noise
|
||||
float3 warpOffset2;
|
||||
warpOffset2.x = simpleNoise(pos, noiseParams_warp2);
|
||||
warpOffset2.y = simpleNoise(pos + 99999, noiseParams_warp2);
|
||||
warpOffset2.z = simpleNoise(pos - 99999, noiseParams_warp2);
|
||||
float warpedNoise2 = simpleNoise(pos + warpOffset2 * 0.1, noiseParams_noise2);
|
||||
|
||||
|
||||
|
||||
shadingData[id] = float4(largeNoise, detailNoise, smallNoise, warpedNoise2);
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f3a2904f78271471481822700022a157
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 65536
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
#pragma kernel CSMain
|
||||
|
||||
#include "../../Includes/FractalNoise.cginc"
|
||||
#include "../../Includes/Math.cginc"
|
||||
//
|
||||
StructuredBuffer<float3> vertices;
|
||||
RWStructuredBuffer<float4> shadingData;
|
||||
uint numVertices;
|
||||
|
||||
StructuredBuffer<float4> points;
|
||||
int numRandomPoints;
|
||||
|
||||
float4 noiseParams_biomeWarp[3];
|
||||
float4 noiseParams_detailWarp[3];
|
||||
float4 noiseParams_detail[3];
|
||||
|
||||
float4 params;
|
||||
|
||||
StructuredBuffer<float4> ejectaCraters;
|
||||
int numEjectaCraters;
|
||||
|
||||
float calcSphereNoise(float3 pos) {
|
||||
float sphereNoise = 1.#INF;
|
||||
for (int i = 0; i < numRandomPoints; i ++) {
|
||||
float3 sphereCentre = points[i].xyz;
|
||||
float sphereRadius = points[i].w;
|
||||
float dst = length(pos - sphereCentre);
|
||||
float t = dst / sphereRadius;
|
||||
sphereNoise = min(sphereNoise, t);
|
||||
}
|
||||
return sphereNoise;
|
||||
}
|
||||
|
||||
[numthreads(512,1,1)]
|
||||
void CSMain (uint id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id >= numVertices) { return; }
|
||||
|
||||
float3 pos = vertices[id];
|
||||
|
||||
float3 domainWarp = 0;
|
||||
domainWarp.x = simpleNoise(pos, noiseParams_biomeWarp);
|
||||
domainWarp.y = simpleNoise(pos + 100, noiseParams_biomeWarp);
|
||||
domainWarp.z = simpleNoise(pos - 100, noiseParams_biomeWarp);
|
||||
|
||||
float3 detailWarp = 0;
|
||||
detailWarp.x = simpleNoise(pos, noiseParams_detailWarp);
|
||||
detailWarp.y = simpleNoise(pos + 100, noiseParams_detailWarp);
|
||||
detailWarp.z = simpleNoise(pos - 100, noiseParams_detailWarp);
|
||||
|
||||
float domainWarp2 = simpleNoise(pos, noiseParams_detailWarp);
|
||||
|
||||
// Sphere noise
|
||||
float3 warpedPos = pos + (domainWarp) * 0.1;
|
||||
float sphereNoise = calcSphereNoise(warpedPos);
|
||||
|
||||
float detailNoise = simpleNoise(pos + domainWarp2 * 0.1, noiseParams_detail);
|
||||
|
||||
// Calculate uv coords for crater 'ejecta ray' texture to be projected onto the surface around select craters
|
||||
float2 ejectaUV = 1;
|
||||
float minDst = 999;
|
||||
for (int craterIndex = 0; craterIndex < numEjectaCraters; craterIndex ++) {
|
||||
float3 craterCentre = ejectaCraters[craterIndex].xyz;
|
||||
float dst = length(craterCentre - pos);
|
||||
float scaledDst = dst / ejectaCraters[craterIndex].w;
|
||||
|
||||
if (scaledDst < minDst) {
|
||||
minDst = scaledDst;
|
||||
|
||||
float3 craterUp = craterCentre;
|
||||
float3 craterForward = normalize(cross(craterUp, float3(0,1,0)));
|
||||
float3 forward = normalize(cross(pos, craterUp));
|
||||
|
||||
float cross_x = forward.y * craterForward.z - forward.z * craterForward.y;
|
||||
float cross_y = forward.z * craterForward.x - forward.x * craterForward.z;
|
||||
float cross_z = forward.x * craterForward.y - forward.y * craterForward.x;
|
||||
float angleSign = sign(craterUp.x * cross_x + craterUp.y * cross_y + craterUp.z * cross_z);
|
||||
|
||||
float angle = acos(dot(craterForward, forward)) * angleSign;
|
||||
//float estBiomeVal = Blend(7 * 0.8, 0.8, calcSphereNoise(craterCentre));
|
||||
//float biomeSign = (estBiomeVal < 0.5)?-1:1;
|
||||
ejectaUV = float2 (angle, scaledDst);
|
||||
}
|
||||
}
|
||||
|
||||
shadingData[id] = float4(ejectaUV.xy, detailNoise, sphereNoise);
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8f6c3d86008df43ca88b9d64cf8e0514
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 65536
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 717e98688348e475da7adb47d0d1c7ec
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -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