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:
Reinier Vens 2020-12-05 23:43:02 +00:00
commit 53a91351b7
332 changed files with 11904 additions and 78 deletions

View file

@ -0,0 +1,197 @@
Shader "Celestial/Alien"
{
Properties
{
[Header(Flat Terrain)]
_ShoreCol("Shore Colour", Color) = (0,0,0,1)
_FlatColA("Flat Colour A", Color) = (0,0,0,1)
_FlatColB("Flat Colour B", Color) = (0,0,0,1)
_FlatColBlend("Colour Blend", Range(0,3)) = 1.5
_FlatColBlendNoise("Blend Noise", Range(0,1)) = 0.3
_ShoreHeight("Shore Height", Range(0,0.2)) = 0.05
_ShoreBlend("Shore Blend", Range(0,0.2)) = 0.03
_MaxFlatHeight("Max Flat Height", Range(0,1)) = 0.5
[Header(Steep Terrain)]
_SteepColA("Steep Colour A", Color) = (0,0,0,1)
_SteepColB("Steep Colour B", Color) = (0,0,0,1)
_SteepBands("Steep Bands", Range(1, 20)) = 8
_SteepBandStrength("Band Strength", Range(-1,1)) = 0.5
[Header(Flat to Steep Transition)]
_SteepnessThreshold("Steep Threshold", Range(0,1)) = 0.5
_FlatToSteepBlend("Flat to Steep Blend", Range(0,1)) = 0.1
_FlatToSteepNoise("Flat to Steep Noise", Range(0,1)) = 0.1
[Header(Noise)]
[NoScaleOffset] _NoiseTex ("Noise Texture", 2D) = "white" {}
_NoiseScale("Noise Scale", Float) = 1
[Header(Other)]
_FresnelCol("Fresnel Colour", Color) = (1,1,1,1)
_FresnelStrengthNear("Fresnel Strength Min", float) = 2
_FresnelStrengthFar("Fresnel Strength Max", float) = 5
_FresnelPow("Fresnel Power", float) = 2
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_GlossinessFlat ("Smoothness Flat", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_TestParams ("Test Params", Vector) = (0,0,0,0)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows vertex:vert
#pragma target 3.5
#include "../Includes/Triplanar.cginc"
#include "../Includes/Math.cginc"
struct Input
{
float2 uv_MainTex;
float4 terrainData;
float3 vertPos;
float3 normal;
float4 tangent;
float fresnel;
};
float4 _FresnelCol;
float _FresnelStrengthNear;
float _FresnelStrengthFar;
float _FresnelPow;
float bodyScale;
void vert (inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
o.vertPos = v.vertex;
o.normal = v.normal;
o.terrainData = v.texcoord;
o.tangent = v.tangent;
// Fresnel (fade out when close to body)
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
float3 bodyWorldCentre = mul(unity_ObjectToWorld, float4(0, 0, 0, 1)).xyz;
float camRadiiFromSurface = (length(bodyWorldCentre - _WorldSpaceCameraPos.xyz) - bodyScale) / bodyScale;
float fresnelT = smoothstep(0,1,camRadiiFromSurface);
float3 viewDir = normalize(worldPos - _WorldSpaceCameraPos.xyz);
float3 normWorld = normalize(mul(unity_ObjectToWorld, float4(v.normal,0)));
float fresStrength = lerp(_FresnelStrengthNear, _FresnelStrengthFar, fresnelT);
o.fresnel = saturate(fresStrength * pow(1 + dot(viewDir, normWorld), _FresnelPow));
}
// Flat terrain:
float4 _ShoreCol;
float4 _FlatColA;
float4 _FlatColA2;
float4 _FlatColB;
float4 _FlatColB2;
float _FlatColBlend;
float _FlatColBlendNoise;
float _ShoreHeight;
float _ShoreBlend;
float _MaxFlatHeight;
// Steep terrain
float4 _SteepColA;
float4 _SteepColB;
float _SteepBands;
float _SteepBandStrength;
// Flat to steep transition
float _SteepnessThreshold;
float _FlatToSteepBlend;
float _FlatToSteepNoise;
// Other:
float _Glossiness;
float _GlossinessFlat;
float _Metallic;
sampler2D _NoiseTex;
float _NoiseScale;
float4 _TestParams;
// Height data:
float2 heightMinMax;
float oceanLevel;
float Blend2(float startHeight, float blendDst, float height) {
float t = remap01(height, startHeight, startHeight + blendDst / 2);
return t;
}
void surf (Input IN, inout SurfaceOutputStandard o)
{
// Calculate steepness: 0 where totally flat, 1 at max steepness
float3 sphereNormal = normalize(IN.vertPos);
float steepness = 1 - dot (sphereNormal, IN.normal);
steepness = remap01(steepness, 0, 0.65);
// Calculate heights
float terrainHeight = length(IN.vertPos);
float shoreHeight = lerp(heightMinMax.x, 1, oceanLevel);
float aboveShoreHeight01 = remap01(terrainHeight, shoreHeight, heightMinMax.y);
float flatHeight01 = remap01(aboveShoreHeight01, 0, _MaxFlatHeight);
// Sample noise texture at two different scales
float4 texNoise = triplanar(IN.vertPos, IN.normal, _NoiseScale, _NoiseTex);
// Flat terrain colour
float biomeWeight = saturate(Blend(0, 0.5, IN.terrainData.x + IN.terrainData.y * -0.15));
float channelBlend = Blend(0, 1, IN.terrainData.w);
float flatBlendA = lerp(texNoise.r, texNoise.b, channelBlend);
//flatBlendA = (int)(flatBlendA * (_TestParams.w + 1)) / _TestParams.w;
float spotBlend = lerp(-0.7, 0.7, Blend(0, 2, IN.terrainData.w));
float3 flatColA = lerp(_FlatColA, _FlatColA2, saturate(flatHeight01 + (flatBlendA-0.5) * spotBlend));
float3 flatColB = lerp(_FlatColB, _FlatColB2, saturate(flatHeight01 + (flatBlendA-0.5) * spotBlend));
float3 flatTerrainCol = lerp(flatColA, flatColB, biomeWeight);
//flatTerrainCol = flatColB;
float shoreBlendWeight = 1-Blend(_ShoreHeight, _ShoreBlend, flatHeight01);
flatTerrainCol = lerp(flatTerrainCol, _ShoreCol, shoreBlendWeight);
// Steep terrain colour
float3 sphereTangent = normalize(float3(-sphereNormal.z, 0, sphereNormal.x));
float3 normalTangent = normalize(IN.normal - sphereNormal * dot(IN.normal, sphereNormal));
float banding = dot(sphereTangent, normalTangent) * .5 + .5;
banding += (texNoise.a-0.5) * 0.1;
banding = (int)(banding * (_SteepBands + 1)) / _SteepBands;
banding = (abs(banding - 0.5) * 2 - 0.5) * _SteepBandStrength;
float3 steepTerrainCol = lerp(_SteepColA, _SteepColB, aboveShoreHeight01 + banding);
// Flat to steep colour transition
float flatBlendNoise = (texNoise.b - 0.5) * -_FlatToSteepNoise;
//float b = lerp(0, _TestParams.x, Blend(0, 3, 5)) * 0.1;
float flatStrength = 1 - Blend2(_SteepnessThreshold + flatBlendNoise, saturate(_FlatToSteepBlend), steepness);
// Set surface colour
float3 compositeCol = lerp(steepTerrainCol, flatTerrainCol, flatStrength);
compositeCol = lerp(compositeCol, _FresnelCol, IN.fresnel);
o.Albedo = compositeCol;
// Glossiness
//float glossiness = dot(o.Albedo, 1) / 3 * _Glossiness;
//glossiness = max(glossiness, snowWeight * _SnowSpecular);
o.Smoothness = max(steepness * _Glossiness, _GlossinessFlat);
o.Metallic = _Metallic;
//o.Albedo = camRadiiFromSurface;
}
ENDCG
}
FallBack "Diffuse"
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e2fd5031f5b4f42e6a8fdb6eced29985
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,245 @@

Shader "Celestial/Earth"
{
Properties
{
[Header(Flat Terrain)]
_ShoreLow("Shore Low", Color) = (0,0,0,1)
_ShoreHigh("Shore High", Color) = (0,0,0,1)
_FlatLowA("Flat Low A", Color) = (0,0,0,1)
_FlatHighA("Flat High A", Color) = (0,0,0,1)
_FlatLowB("Flat Low B", Color) = (0,0,0,1)
_FlatHighB("Flat High B", Color) = (0,0,0,1)
_FlatColBlend("Colour Blend", Range(0,3)) = 1.5
_FlatColBlendNoise("Blend Noise", Range(0,1)) = 0.3
_ShoreHeight("Shore Height", Range(0,0.2)) = 0.05
_ShoreBlend("Shore Blend", Range(0,0.2)) = 0.03
_MaxFlatHeight("Max Flat Height", Range(0,1)) = 0.5
[Header(Steep Terrain)]
_SteepLow("Steep Colour Low", Color) = (0,0,0,1)
_SteepHigh("Steep Colour High", Color) = (0,0,0,1)
_SteepBands("Steep Bands", Range(1, 20)) = 8
_SteepBandStrength("Band Strength", Range(-1,1)) = 0.5
[Header(Flat to Steep Transition)]
_SteepnessThreshold("Steep Threshold", Range(0,1)) = 0.5
_FlatToSteepBlend("Flat to Steep Blend", Range(0,0.3)) = 0.1
_FlatToSteepNoise("Flat to Steep Noise", Range(0,0.2)) = 0.1
[Header(Snowy Poles)]
[Toggle()]
_UseSnowyPoles("Use Poles", float) = 0
_SnowCol("Snow Colour", Color) = (1,1,1,1)
_SnowLongitude("Snow Longitude", Range(0,1)) = 0.8
_SnowBlend("Snow Blend", Range(0, 0.2)) = 0.1
_SnowSpecular("Snow Specular", Range(0,1)) = 1
_SnowHighlight("Snow Highlight", Range(1,2)) = 1.2
_SnowNoiseA("Snow Noise A", Range(0,10)) = 5
_SnowNoiseB("Snow Noise B", Range(0,10)) = 4
[Header(Noise)]
[NoScaleOffset] _NoiseTex ("Noise Texture", 2D) = "white" {}
_NoiseScale("Noise Scale", Float) = 1
_NoiseScale2("Noise Scale2", Float) = 1
[Header(Other)]
_FresnelCol("Fresnel Colour", Color) = (1,1,1,1)
_FresnelStrengthNear("Fresnel Strength Min", float) = 2
_FresnelStrengthFar("Fresnel Strength Max", float) = 5
_FresnelPow("Fresnel Power", float) = 2
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_TestParams ("Test Params", Vector) = (0,0,0,0)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows vertex:vert
#pragma target 3.5
#include "../Includes/Triplanar.cginc"
#include "../Includes/Math.cginc"
float4 _TestParams;
float4 _FresnelCol;
float _FresnelStrengthNear;
float _FresnelStrengthFar;
float _FresnelPow;
float bodyScale;
struct Input
{
float2 uv_MainTex;
float3 worldPos;
float4 terrainData;
float3 vertPos;
float3 normal;
float4 tangent;
float fresnel;
};
void vert (inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
o.vertPos = v.vertex;
o.normal = v.normal;
o.terrainData = v.texcoord;
o.tangent = v.tangent;
// Fresnel (fade out when close to body)
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
float3 bodyWorldCentre = mul(unity_ObjectToWorld, float4(0, 0, 0, 1)).xyz;
float camRadiiFromSurface = (length(bodyWorldCentre - _WorldSpaceCameraPos.xyz) - bodyScale) / bodyScale;
float fresnelT = smoothstep(0,1,camRadiiFromSurface);
float3 viewDir = normalize(worldPos - _WorldSpaceCameraPos.xyz);
float3 normWorld = normalize(mul(unity_ObjectToWorld, float4(v.normal,0)));
float fresStrength = lerp(_FresnelStrengthNear, _FresnelStrengthFar, fresnelT);
o.fresnel = saturate(fresStrength * pow(1 + dot(viewDir, normWorld), _FresnelPow));
}
// Flat terrain:
float4 _ShoreLow;
float4 _ShoreHigh;
float4 _FlatLowA;
float4 _FlatHighA;
float4 _FlatLowB;
float4 _FlatHighB;
float _FlatColBlend;
float _FlatColBlendNoise;
float _ShoreHeight;
float _ShoreBlend;
float _MaxFlatHeight;
// Steep terrain
float4 _SteepLow;
float4 _SteepHigh;
float _SteepBands;
float _SteepBandStrength;
// Flat to steep transition
float _SteepnessThreshold;
float _FlatToSteepBlend;
float _FlatToSteepNoise;
// Snowy poles
float _UseSnowyPoles;
float3 _SnowCol;
float _SnowLongitude;
float _SnowBlend;
float _SnowSpecular;
float _SnowHighlight;
float _SnowNoiseA;
float _SnowNoiseB;
// Other:
float _Glossiness;
float _Metallic;
sampler2D _NoiseTex;
sampler2D _SnowNormal;
float _NoiseScale;
float _NoiseScale2;
// Height data:
float2 heightMinMax;
float oceanLevel;
fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten)
{
fixed4 c;
c.rgb = s.Albedo * 0.8;
c.a = s.Alpha;
return c;
}
void surf (Input IN, inout SurfaceOutputStandard o)
{
// Calculate steepness: 0 where totally flat, 1 at max steepness
float3 sphereNormal = normalize(IN.vertPos);
float steepness = 1 - dot (sphereNormal, IN.normal);
steepness = remap01(steepness, 0, 0.65);
// Calculate heights
float terrainHeight = length(IN.vertPos);
float shoreHeight = lerp(heightMinMax.x, 1, oceanLevel);
float aboveShoreHeight01 = remap01(terrainHeight, shoreHeight, heightMinMax.y);
float flatHeight01 = remap01(aboveShoreHeight01, 0, _MaxFlatHeight);
// Sample noise texture at two different scales
float4 texNoise = triplanar(IN.vertPos, IN.normal, _NoiseScale, _NoiseTex);
float4 texNoise2 = triplanar(IN.vertPos, IN.normal, _NoiseScale2, _NoiseTex);
// Flat terrain colour A and B
float flatColBlendWeight = Blend(0, _FlatColBlend, (flatHeight01-.5) + (texNoise.b - 0.5) * _FlatColBlendNoise);
float3 flatTerrainColA = lerp(_FlatLowA, _FlatHighA, flatColBlendWeight);
flatTerrainColA = lerp(flatTerrainColA, (_FlatLowA + _FlatHighA) / 2, texNoise.a);
float3 flatTerrainColB = lerp(_FlatLowB, _FlatHighB, flatColBlendWeight);
flatTerrainColB = lerp(flatTerrainColB, (_FlatLowB + _FlatHighB) / 2, texNoise.a);
// Biome
float biomeWeight = Blend(_TestParams.x, _TestParams.y,IN.terrainData.x);
biomeWeight = Blend(0, _TestParams.z, IN.vertPos.x + IN.terrainData.x * _TestParams.x + IN.terrainData.y * _TestParams.y);
float3 flatTerrainCol = lerp(flatTerrainColA, flatTerrainColB, biomeWeight);
// Shore
float shoreBlendWeight = 1-Blend(_ShoreHeight, _ShoreBlend, flatHeight01);
float4 shoreCol = lerp(_ShoreLow, _ShoreHigh, remap01(aboveShoreHeight01, 0, _ShoreHeight));
shoreCol = lerp(shoreCol, (_ShoreLow + _ShoreHigh) / 2, texNoise.g);
flatTerrainCol = lerp(flatTerrainCol, shoreCol, shoreBlendWeight);
// Steep terrain colour
float3 sphereTangent = normalize(float3(-sphereNormal.z, 0, sphereNormal.x));
float3 normalTangent = normalize(IN.normal - sphereNormal * dot(IN.normal, sphereNormal));
float banding = dot(sphereTangent, normalTangent) * .5 + .5;
banding = (int)(banding * (_SteepBands + 1)) / _SteepBands;
banding = (abs(banding - 0.5) * 2 - 0.5) * _SteepBandStrength;
float3 steepTerrainCol = lerp(_SteepLow, _SteepHigh, aboveShoreHeight01 + banding);
// Flat to steep colour transition
float flatBlendNoise = (texNoise2.r - 0.5) * _FlatToSteepNoise;
float flatStrength = 1 - Blend(_SteepnessThreshold + flatBlendNoise, _FlatToSteepBlend, steepness);
float flatHeightFalloff = 1 - Blend(_MaxFlatHeight + flatBlendNoise, _FlatToSteepBlend, aboveShoreHeight01);
flatStrength *= flatHeightFalloff;
// Snowy poles
float3 snowCol = 0;
float snowWeight = 0;
float snowLineNoise = IN.terrainData.y * _SnowNoiseA * 0.01 + (texNoise.b-0.5) * _SnowNoiseB * 0.01;
snowWeight = Blend(_SnowLongitude, _SnowBlend, abs(IN.vertPos.y + snowLineNoise)) * _UseSnowyPoles;
float snowSpeckle = 1 - texNoise2.g * 0.5 * 0.1;
snowCol = _SnowCol * lerp (1, _SnowHighlight, aboveShoreHeight01 + banding) * snowSpeckle;
// Set surface colour
float3 compositeCol = lerp(steepTerrainCol, flatTerrainCol, flatStrength);
compositeCol = lerp(compositeCol, snowCol, snowWeight);
compositeCol = lerp(compositeCol, _FresnelCol, IN.fresnel);
o.Albedo = compositeCol;
// Glossiness
float glossiness = dot(o.Albedo, 1) / 3 * _Glossiness;
glossiness = max(glossiness, snowWeight * _SnowSpecular);
o.Smoothness = glossiness;
o.Metallic = _Metallic;
}
ENDCG
}
FallBack "Diffuse"
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: fa2bee6d3f5064024b6434575359a23b
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,200 @@
Shader "Celestial/MoonA"
{
Properties
{
[Header(Colours)]
_PrimaryColA ("Primary A", Color) = (1,1,1,1)
_SecondaryColA ("Secondary A", Color) = (1,1,1,1)
_PrimaryColB ("Primary B", Color) = (1,1,1,1)
_SecondaryColB ("Secondary B", Color) = (1,1,1,1)
_EjectaCol ("Ejecta Col", Color) = (1,1,1,1)
_BiomeBlendStrength ("Biome Blend", Float) = 2
_BiomeWarpStrength("Biome Warp", Float) = 0
[Toggle()]
_UseEjecta("Use Ejecta", float) = 1
_EjectaBrightness("Ejecta Brightness", Float) = 0.1
[Header(Normals)]
[NoScaleOffset] _CraterRay ("Crater Ray", 2D) = "white" {}
[NoScaleOffset] _MainTex ("Albedo (RGB)", 2D) = "white" {}
[NoScaleOffset] _NormalMapFlat ("Normal Map Flat", 2D) = "bump" {}
[NoScaleOffset] _NormalMapSteep ("Normal Map Steep", 2D) = "bump" {}
_NormalMapFlatScale ("Normal Map Flat Scale", Float) = 10
_NormalMapSteepScale ("Normal Map Steep Scale", Float) = 10
_MainTexScale ("Main Tex Scale", Float) = 10
_RandomBiomeValues ("Random Biome Values", Vector) = (0,0,0,0)
_NormalMapStrength ("Normal Map Strength", Range(0,1)) = 0.3
[Header(Other)]
_FresnelCol("Fresnel Colour", Color) = (1,1,1,1)
_FresnelStrengthNear("Fresnel Strength Min", float) = 2
_FresnelStrengthFar("Fresnel Strength Max", float) = 5
_FresnelPow("Fresnel Power", float) = 12
_SmoothnessA ("Smoothness A", Range(0,1)) = 0.5
_SmoothnessB ("Smoothness B", Range(0,1)) = 0.5
_SmoothnessEjecta ("Smoothness Ejecta", Range(0,1)) = 0.5
_MetallicA ("Metallic A", Range(0,1)) = 0.0
_MetallicB ("Metallic B", Range(0,1)) = 0.0
_TestParams ("Test Params", Vector) = (0,0,0,0)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows vertex:vert
#pragma target 3.5
#include "../Includes/Triplanar.cginc"
#include "../Includes/Math.cginc"
sampler2D _MainTex;
sampler2D _CraterRay;
sampler2D _NormalMapFlat;
sampler2D _NormalMapSteep;
float _NormalMapStrength;
float _NormalMapFlatScale;
float _NormalMapSteepScale;
float _MainTexScale;
float _SmoothnessA;
float _SmoothnessB;
float _SmoothnessEjecta;
float _MetallicA;
float _MetallicB;
float2 heightMinMax;
float _EjectaBrightness;
float _UseEjecta;
float _BiomeBlendStrength;
float _BiomeWarpStrength;
float4 _RandomBiomeValues;
float4 _TestParams;
float _AvgBiomeNoiseDst;
// Colors:
float4 _PrimaryColA;
float4 _SecondaryColA;
float4 _PrimaryColB;
float4 _SecondaryColB;
float4 _EjectaCol;
float4 _FresnelCol;
float _FresnelStrengthNear;
float _FresnelStrengthFar;
float _FresnelPow;
float bodyScale;
struct Input
{
float3 vertPos;
float3 normal;
float4 terrainData;
float3 worldNormal;
float4 tangent;
float4 craterUV;
float fresnel;
INTERNAL_DATA
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT (Input,o);
o.vertPos = v.vertex;
o.terrainData = v.texcoord;
o.normal = v.normal;
o.tangent = v.tangent;
//
float craterDst = v.texcoord.y;
float2 craterUV = 0.5 + float2(cos(v.texcoord.x), sin(v.texcoord.x)) * craterDst;
o.craterUV = float4(craterUV.xy, craterDst, 0);
// Fresnel (fade out when close to body)
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
float3 bodyWorldCentre = mul(unity_ObjectToWorld, float4(0, 0, 0, 1)).xyz;
float camRadiiFromSurface = (length(bodyWorldCentre - _WorldSpaceCameraPos.xyz) - bodyScale) / bodyScale;
float fresnelT = smoothstep(0,1,camRadiiFromSurface);
float3 viewDir = normalize(worldPos - _WorldSpaceCameraPos.xyz);
float3 normWorld = normalize(mul(unity_ObjectToWorld, float4(v.normal,0)));
float fresStrength = lerp(_FresnelStrengthNear, _FresnelStrengthFar, fresnelT);
o.fresnel = saturate(fresStrength * pow(1 + dot(viewDir, normWorld), _FresnelPow));
}
fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten)
{
fixed4 c;
c.rgb = s.Albedo * 0.8;
c.a = s.Alpha;
return c;
}
void surf (Input IN, inout SurfaceOutputStandard o)
{
float4 terrainData = IN.terrainData;
float height01 = remap01(length(IN.vertPos), heightMinMax.x, heightMinMax.y);
// Calculate steepness: 0 where totally flat, 1 at max steepness
const float maxSteepnessApprox = 0.3;
float steepness = 1 - dot(IN.normal, normalize(IN.vertPos));
steepness = remap01(steepness, 0, maxSteepnessApprox);
float warpNoise = Blend(0, 3, IN.terrainData.z);
// Sample noise texture
float4 texNoise = triplanar(IN.vertPos, IN.normal, _MainTexScale, _MainTex);
// Sample normal maps:
// There are two maps, one for steep slopes like mountains and crater walls, and one for flat regions
// Slopes always use the steep map, but flat regions blend between the flat and steep maps to add variety
float3 normalMapFlat = triplanarNormalTangentSpace(IN.vertPos, IN.normal, _NormalMapFlatScale, IN.tangent, _NormalMapFlat);
float3 normalMapSteep = triplanarNormalTangentSpace(IN.vertPos, IN.normal, _NormalMapSteepScale, IN.tangent, _NormalMapSteep);
//float normalBlend = Blend(_AvgBiomeNoiseDst * 0.8, 1.2, terrainData.w);
//float normalBlend = warpNoise;
float normalBlend = lerp(texNoise.r, texNoise.g, Blend(0, 2, terrainData.z));
float3 flatAndSteepNormal = lerp(normalMapFlat, normalMapSteep, normalBlend);
float3 normal = lerp(flatAndSteepNormal, normalMapSteep, steepness);
normal = lerp(float3(0,0,1), normal, _NormalMapStrength);
o.Normal = normal;
// Blend between primary and secondary colours by height (plus some noise)
float heightNoiseA = -texNoise.g * steepness - (texNoise.b - 0.5) * 0.7 + (texNoise.a - 0.5) * _RandomBiomeValues.x;
float heightNoiseB = (texNoise.g-0.5) * _RandomBiomeValues.y + (texNoise.r-0.5) * _RandomBiomeValues.z;
float heightBlendWeightA = Blend(0.5, 0.6, height01 + heightNoiseA) * warpNoise;
float heightBlendWeightB = Blend(0.5, 0.6, height01 + heightNoiseB) * warpNoise;
float3 colBiomeA = lerp(_PrimaryColA, _SecondaryColA, heightBlendWeightA);
float3 colBiomeB = lerp(_PrimaryColB, _SecondaryColB, heightBlendWeightB);
// Blend between colour A and B based on terrain data noise
float biomeNoise = dot(texNoise.ga - 0.5, _RandomBiomeValues.zw) * 4;
float biomeWeight = Blend(_AvgBiomeNoiseDst * 0.8 + terrainData.z * _BiomeWarpStrength, _BiomeBlendStrength + warpNoise * 15, terrainData.w + biomeNoise);
float3 biomeCol = lerp(colBiomeA, colBiomeB, biomeWeight);
// Crater ejecta
float ejecta = tex2D(_CraterRay, IN.craterUV.xy).r;
float craterAlpha = IN.craterUV.z < 1;
craterAlpha = abs(IN.terrainData.y) < 0.5;
float3 compositeCol = lerp(biomeCol, _EjectaCol, saturate(ejecta * 1.5) * craterAlpha * _UseEjecta);
compositeCol = lerp(compositeCol, _FresnelCol, IN.fresnel);
o.Albedo = compositeCol;
// Set metallic and smoothness
o.Metallic = lerp(_MetallicA, _MetallicB, biomeWeight);;
float smoothness = lerp(_SmoothnessA, _SmoothnessB, biomeWeight);
smoothness = lerp(smoothness, _SmoothnessEjecta, saturate(ejecta * 1.5) * craterAlpha);
o.Smoothness = smoothness;
}
ENDCG
}
FallBack "Diffuse"
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: ebd63f199114146ddacca96d32c18d9e
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,190 @@
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader "Celestial/MoonB"
{
Properties
{
[Header(Colours)]
_PrimaryColA ("Primary A", Color) = (1,1,1,1)
_SecondaryColA ("Secondary A", Color) = (1,1,1,1)
_PrimaryColB ("Primary B", Color) = (1,1,1,1)
_SecondaryColB ("Secondary B", Color) = (1,1,1,1)
_BiomeBlendStrength ("Biome Blend", Float) = 2
_BiomeWeight ("Biome Weight", Float) = 1.6
_BiomeWarpStrength("Biome Warp", Float) = 0
_EjectaBrightness("Ejecta Brightness", Float) = 0.1
[Header(Normals)]
[NoScaleOffset] _CraterRay ("Crater Ray", 2D) = "white" {}
[NoScaleOffset] _MainTex ("Albedo (RGB)", 2D) = "white" {}
[NoScaleOffset] _NormalMapFlat ("Normal Map Flat", 2D) = "bump" {}
[NoScaleOffset] _NormalMapSteep ("Normal Map Steep", 2D) = "bump" {}
_NormalMapFlatScale ("Normal Map Flat Scale", Float) = 10
_NormalMapSteepScale ("Normal Map Steep Scale", Float) = 10
_MainTexScale ("Main Tex Scale", Float) = 10
_RandomBiomeValues ("Random Biome Values", Vector) = (0,0,0,0)
_NormalMapStrength ("Normal Map Strength", Range(0,1)) = 0.3
[Header(Other)]
_FresnelCol("Fresnel Colour", Color) = (1,1,1,1)
_FresnelStrength("Fresnel Strength", float) = 0.5
_FresnelPow("Fresnel Power", float) = 2
_SmoothnessA ("Smoothness A", Range(0,1)) = 0.5
_SmoothnessB ("Smoothness B", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_TestParams ("Test Params", Vector) = (0,0,0,0)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows vertex:vert
#pragma target 3.5
#include "../Includes/Triplanar.cginc"
#include "../Includes/Math.cginc"
sampler2D _MainTex;
sampler2D _CraterRay;
sampler2D _NormalMapFlat;
sampler2D _NormalMapSteep;
float _NormalMapStrength;
float _NormalMapFlatScale;
float _NormalMapSteepScale;
float _MainTexScale;
float _SmoothnessA;
float _SmoothnessB;
float _Metallic;
float2 heightMinMax;
float _EjectaBrightness;
float _BiomeBlendStrength;
float _BiomeWeight;
float _BiomeWarpStrength;
float4 _RandomBiomeValues;
float4 _TestParams;
float _AvgBiomeNoiseDst;
// Colors:
float4 _PrimaryColA;
float4 _SecondaryColA;
float4 _PrimaryColB;
float4 _SecondaryColB;
float4 _SteepCol;
float4 _FresnelCol;
float _FresnelStrength;
float _FresnelPow;
float bodyScale;
struct Input
{
float3 vertPos;
float3 normal;
float4 terrainData;
float3 worldNormal;
float4 tangent;
float4 craterUV;
float3 viewDir;
float fresnel;
INTERNAL_DATA
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT (Input,o);
o.vertPos = v.vertex;
o.terrainData = v.texcoord;
o.normal = v.normal;
o.tangent = v.tangent;
//
float craterDst = abs(v.texcoord.y);
float craterColWeight = (v.texcoord.y < 0)? 0 : 1;
float2 craterUV = 0.5 + float2(cos(v.texcoord.x), sin(v.texcoord.x)) * craterDst;
o.craterUV = float4(craterUV.xy, craterDst, craterColWeight);
// Fresnel (fade out when close to body)
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
float3 bodyWorldCentre = mul(unity_ObjectToWorld, float4(0, 0, 0, 1)).xyz;
float camRadiiFromSurface = (length(bodyWorldCentre - _WorldSpaceCameraPos.xyz) - bodyScale) / bodyScale;
float fresnelT = smoothstep(0,1,camRadiiFromSurface);
float3 viewDir = normalize(worldPos - _WorldSpaceCameraPos.xyz);
float3 normWorld = normalize(mul(unity_ObjectToWorld, float4(v.normal,0)));
o.fresnel = saturate(_FresnelStrength * fresnelT * pow(1 + dot(viewDir, normWorld), _FresnelPow));
}
fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten)
{
fixed4 c;
c.rgb = s.Albedo * 0.8;
c.a = s.Alpha;
return c;
}
void surf (Input IN, inout SurfaceOutputStandard o)
{
float4 texNoise = triplanar(IN.vertPos, IN.normal, _MainTexScale, _MainTex);
float steepness = 1 - dot(IN.normal, normalize(IN.vertPos));
float height01 = remap01(length(IN.vertPos), heightMinMax.x, heightMinMax.y);
float t = 1-Blend(_TestParams.y,_TestParams.z, height01);
float highAndFlat = (1 - remap01(steepness, 0.08, 0.2)) * Blend(0.6, 0.4, height01);
float biomeWeight = Blend(_AvgBiomeNoiseDst * _BiomeWeight, _BiomeBlendStrength, IN.terrainData.w + IN.terrainData.z * _BiomeWarpStrength);
//o.Albedo = lerp(_PrimaryColA, _PrimaryColB, biomeWeight);
//o.Albedo = steepness;
float heightBanded01 = saturate(int((height01+(texNoise.b-.5)*_TestParams.w) * _TestParams.z) / (_TestParams.z));
float3 colA = lerp(_PrimaryColA, _SecondaryColA, height01);
float3 colB = lerp(_PrimaryColB, _SecondaryColB, height01);
float3 compositeCol = lerp(colA, colB, biomeWeight);// * lerp(0.7, 1, texNoise.b);
compositeCol = lerp(compositeCol, _SteepCol, Blend(0.5, 0.18, height01));
//compositeCol = lerp(compositeCol, 1, highAndFlat);
// Ejecta
// Crater ejecta
//float ejectaColorWeight = IN.craterUV.w;
//float3 ejectaCol = _SecondaryColA;
float ejecta = tex2D(_CraterRay, IN.craterUV.xy).r;
float craterAlpha = IN.craterUV.z < 1;
//o.Albedo = lerp(biomeCol, ejectaCol, saturate(ejecta * 1.5) * craterAlpha);
//compositeCol = lerp(compositeCol, _SteepCol, steepness);
// compositeCol = lerp(compositeCol, float3(1,0,0), ejecta * craterAlpha);
compositeCol = lerp(compositeCol, _FresnelCol, IN.fresnel);
//o.Albedo = craterAlpha;
o.Albedo =compositeCol;
// Normals
float3 normalMapFlat = triplanarNormalTangentSpace(IN.vertPos, IN.normal, _NormalMapFlatScale, IN.tangent, _NormalMapFlat);
//float3 normalMapSteep = triplanarNormalTangentSpace(IN.vertPos, IN.normal, _NormalMapSteepScale, IN.tangent, _NormalMapSteep);
//float normalBlend = lerp(texNoise.r, texNoise.g, Blend(0, 2, terrainData.z));
//float3 flatAndSteepNormal = lerp(normalMapFlat, normalMapSteep, normalBlend);
//float3 normal = lerp(flatAndSteepNormal, normalMapSteep, steepness);
float3 normal = lerp(float3(0,0,1), normalMapFlat, _NormalMapStrength);
o.Normal = normal;
//o.Albedo = highAndFlat;
//o.Albedo = );
// Set metallic and smoothness
o.Metallic = 0;
o.Smoothness = 0;
}
ENDCG
}
FallBack "Diffuse"
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f79830fda856b457787d53ac8babfe6f
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant: