Initial commit

This commit is contained in:
gunnbr committed 2021-01-11 22:20:43 -08:00
1 parent ee9615239e
commit 16feac691f
4093 files changed
+1030491

No files matched your search

@@ -0,0 +1,429 @@
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
Shader "Hidden/Gaia/BaseOperation" {
Properties {
//The main texture
_MainTex ("Main Texture", any) = "" {}
//The global mask texture
_GlobalMaskTex ("Global Mask Texture", any) = "" {}
//Flag to determine whether the image mask affects the total stamp result (global) or the stamp itself only (local)
// _ImageMaskIsGlobal("Image Mask is Global", Float) = 0
//Flag to determine whether the image mask is inverted or not
//_InvertImageMask("Invert Image Mask", Float) = 0
//1-pixel high gradient texture to bring the distance mask curve information in the shader
//_DistanceMaskTex ("Distance Mask Texture", any) = "" {}
//Flag to determine whether the distance mask affects the total stamp result (global) or the stamp itself only (local)
//_DistanceMaskIsGlobal("Distance Mask is Global", Float) = 0
//1-pixel high gradient texture to bring the transform height curve information in the shader
//_TransformHeightTex ("Transform Height Texture", any) = "" {}
//the y position of the stamp, in 0 to 1 relative to terrain height
_yPos ("y Position", Float) = 0
//the base level of the stamp
_BaseLevel ("Base Level", Float) = 0
//Flag to determine whether the base should be stamped or not
_StampBase("Stamp Base", Float) = 0
//Flag to determine whether the stamp should be adjusted automatically to the terrain when a base level is used
_AdaptiveBase("Adaptive Base", Float) = 0
//Blend strength from 0 to 1 for the blend terrain pass
//_BlendStrength ("Blend Strength", Float) = 0
//Erosion texture, contains the original heightmap changed by Erosion
//_ErosionTex("Erosion Texture", any) = ""
}
SubShader {
ZTest Always Cull Off ZWrite Off
CGINCLUDE
#include "UnityCG.cginc"
#include "TerrainTool.cginc"
sampler2D _MainTex;
sampler2D _GlobalMaskTex;
//float _ImageMaskIsGlobal;
//float _InvertImageMask;
//sampler2D _DistanceMaskTex;
//float _DistanceMaskIsGlobal;
//sampler2D _TransformHeightTex;
float _yPos;
float _BaseLevel;
float _StampBase;
float _AdaptiveBase;
float _BlendStrength;
//sampler2D _ErosionTex;
float4 _MainTex_TexelSize; // 1/width, 1/height, width, height
sampler2D _BrushTex;
float4 _BrushParams;
#define BRUSH_STRENGTH (_BrushParams[0])
#define BRUSH_TARGETHEIGHT (_BrushParams[1])
struct appdata_t {
float4 vertex : POSITION;
float2 pcUV : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
float2 pcUV : TEXCOORD0;
};
v2f vert(appdata_t v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.pcUV = v.pcUV;
return o;
}
float ApplyBrush(float height, float brushStrength)
{
float targetHeight = BRUSH_TARGETHEIGHT;
if (targetHeight > height)
{
height += brushStrength;
height = height < targetHeight ? height : targetHeight;
}
else
{
height -= brushStrength;
height = height > targetHeight ? height : targetHeight;
}
return height;
}
float GetFinalHeight(v2f i)
{
float2 brushUV = PaintContextUVToBrushUV(i.pcUV);
float2 heightmapUV = PaintContextUVToHeightmapUV(i.pcUV);
float height = UnpackHeightmap(tex2D(_MainTex, heightmapUV));
// out of bounds multiplier
float oob = all(saturate(brushUV) == brushUV) ? 1.0f : 0.0f;
//value from the image mask texture multiplied with the multiplicator
float globalMaskValue = UnpackHeightmap(tex2D(_GlobalMaskTex, brushUV));
float brushShape = oob * UnpackHeightmap(tex2D(_BrushTex, brushUV));
float finalBrushLevel = BRUSH_STRENGTH * brushShape; // * transformheight * localMaskValue;
//only return the height value changed by the brush if we are actually in bounds
//otherwise we get an ugly square base when rotating stamps
if(all(saturate(brushUV) == brushUV))
{
float finalResult = _yPos + finalBrushLevel;
return clamp(((_yPos + finalBrushLevel) * globalMaskValue) + height * (1.0f - globalMaskValue), 0, 1.0f);
}
else
{
return height;
}
}
ENDCG
Pass // 0 raise heights
{
Name "Raise Heights"
CGPROGRAM
#pragma vertex vert
#pragma fragment RaiseHeight
float4 RaiseHeight(v2f i) : SV_Target
{
float2 brushUV = PaintContextUVToBrushUV(i.pcUV);
float2 heightmapUV = PaintContextUVToHeightmapUV(i.pcUV);
float height = UnpackHeightmap(tex2D(_MainTex, heightmapUV));
float finalheight = GetFinalHeight(i);
//process baseLevel
if(_StampBase>0 || finalheight>_BaseLevel)
{
if(!all(saturate(brushUV) == brushUV))
{
_BaseLevel = 0;
}
if(_AdaptiveBase && _BaseLevel > height)
{
finalheight -= _BaseLevel - height;
}
else
{
finalheight = clamp (finalheight, _BaseLevel,0.5f);
}
}
else
{
finalheight = 0;
}
if(finalheight>=height)
return PackHeightmap(finalheight);
else
return PackHeightmap(height);
}
ENDCG
}
Pass // 1 Lower heights
{
Name "Lower Heights"
CGPROGRAM
#pragma vertex vert
#pragma fragment LowerHeight
float4 LowerHeight(v2f i) : SV_Target
{
float2 brushUV = PaintContextUVToBrushUV(i.pcUV);
float2 heightmapUV = PaintContextUVToHeightmapUV(i.pcUV);
float height = UnpackHeightmap(tex2D(_MainTex, heightmapUV));
float finalheight = GetFinalHeight(i);
//process baseLevel
if(_StampBase>0 || finalheight<_BaseLevel)
{
if(!all(saturate(brushUV) == brushUV))
{
_BaseLevel = 0.5f;
}
if(_AdaptiveBase && _BaseLevel < height)
{
finalheight += height - _BaseLevel;
}
else
{
finalheight = clamp (finalheight, 0.0f, _BaseLevel);
}
}
else
{
finalheight = 0.5f;
}
if(finalheight<=height)
return PackHeightmap(finalheight);
else
return PackHeightmap(height);
}
ENDCG
}
Pass // 2 Blend Heights
{
Name "Blend Heights"
CGPROGRAM
#pragma vertex vert
#pragma fragment BlendHeight
float4 BlendHeight(v2f i) : SV_Target
{
float2 heightmapUV = PaintContextUVToHeightmapUV(i.pcUV);
float height = UnpackHeightmap(tex2D(_MainTex, heightmapUV));
float finalheight = GetFinalHeight(i);
return PackHeightmap((finalheight * _BlendStrength) + (height * (1-_BlendStrength)));
}
ENDCG
}
Pass // 3 Set Height
{
Name "Set Height"
CGPROGRAM
#pragma vertex vert
#pragma fragment SetHeight
float4 SetHeight(v2f i) : SV_Target
{
float2 heightmapUV = PaintContextUVToHeightmapUV(i.pcUV);
float height = UnpackHeightmap(tex2D(_MainTex, heightmapUV));
float finalheight = GetFinalHeight(i);
return PackHeightmap(finalheight);
}
ENDCG
}
Pass // 4 Add Height
{
Name "Add Height"
CGPROGRAM
#pragma vertex vert
#pragma fragment AddHeight
float4 AddHeight(v2f i) : SV_Target
{
float2 brushUV = PaintContextUVToBrushUV(i.pcUV);
float2 heightmapUV = PaintContextUVToHeightmapUV(i.pcUV);
float height = UnpackHeightmap(tex2D(_MainTex, heightmapUV));
float oob = all(saturate(brushUV) == brushUV) ? 1.0f : 0.0f;
if(!oob)
{
return height;
}
float finalheight = GetFinalHeight(i);
//add the existing height
finalheight += height;
//process baseLevel
if(_StampBase>0 || finalheight>_BaseLevel)
{
if(!all(saturate(brushUV) == brushUV))
{
_BaseLevel = 0;
}
if(_AdaptiveBase && _BaseLevel > height)
{
finalheight -= _BaseLevel - height;
}
else
{
finalheight = clamp (finalheight, _BaseLevel,0.5f);
}
}
else
{
finalheight = 0;
}
if(finalheight>=height)
return PackHeightmap(finalheight);
else
return PackHeightmap(height);
}
ENDCG
}
Pass // 5 Subrtract Height
{
Name "Subtract Height"
CGPROGRAM
#pragma vertex vert
#pragma fragment SubtractHeight
float4 SubtractHeight(v2f i) : SV_Target
{
//invert ypos for better usability
_yPos*=-1;
float2 brushUV = PaintContextUVToBrushUV(i.pcUV);
float2 heightmapUV = PaintContextUVToHeightmapUV(i.pcUV);
float height = UnpackHeightmap(tex2D(_MainTex, heightmapUV));
float oob = all(saturate(brushUV) == brushUV) ? 1.0f : 0.0f;
if(!oob)
{
return height;
}
float finalheight = GetFinalHeight(i);
//subtract the existing height
finalheight = height - finalheight;
//process baseLevel
if(_StampBase>0 || finalheight<_BaseLevel)
{
if(!all(saturate(brushUV) == brushUV))
{
finalheight = height;
}
else
{
if(_AdaptiveBase && _BaseLevel < height)
{
finalheight += height - _BaseLevel;
}
else
{
finalheight = clamp (finalheight, 0.0f, _BaseLevel);
}
}
}
else
{
finalheight = height;
}
if(finalheight<=height)
return PackHeightmap(finalheight);
else
return PackHeightmap(height);
}
ENDCG
}
//This pass is special in so far as it relies on the heightmap changes being passed in
//_MainTex, it will not alter the heightmap by itself
Pass // 6 Effects
{
Name "Effects"
CGPROGRAM
#pragma vertex vert
#pragma fragment Effects
float4 Effects(v2f i) : SV_Target
{
float2 brushUV = PaintContextUVToBrushUV(i.pcUV);
float2 heightmapUV = PaintContextUVToHeightmapUV(i.pcUV);
float height = UnpackHeightmap(tex2D(_MainTex, heightmapUV));
float finalheight = GetFinalHeight(i);
return PackHeightmap(finalheight);
//float erodedHeight = UnpackHeightmap(tex2D(_ErosionTex, heightmapUV));
// out of bounds multiplier
/*float oob = all(saturate(brushUV) == brushUV) ? 1.0f : 0.0f;
//value from the image mask texture multiplied with the multiplicator
float imageMask = UnpackHeightmap(tex2D(_ImageMaskTex, brushUV));
if(_InvertImageMask>0)
{
//Invert the imagemask
imageMask=1.0f-imageMask;
}
float distanceMask = UnpackHeightmap(tex2D(_DistanceMaskTex, smoothstep(0,sqrt(1)/2,distance(brushUV,float2(0.5f,0.5f)))));
float globalMaskValue = 1.0f;
globalMaskValue *= imageMask;
globalMaskValue *= distanceMask;*/
//only return the height value changed by the brush if we are actually in bounds
//otherwise we get an ugly square base when rotating stamps
/*if(all(saturate(brushUV) == brushUV))
{
return PackHeightmap(clamp(erodedHeight, 0, 0.5f));
}
else
{
return PackHeightmap(height);;
}*/
}
ENDCG
}
}
Fallback Off
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 5d88451bb8cf495449b511f6dc5d08d1
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,366 @@
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
Shader "Hidden/Gaia/SpawnerPreview"
{
Properties
{
[Enum(UnityEngine.Rendering.CompareFunction)] _zTestMode ("Z Test mode", Int) = 4 //4 = LEqual
_previewColor0("Preview Color 1",Color) = (.99, .85, .92, 0)
_previewColor1("Preview Color 2",Color) = (.99, .85, .92, 0)
_previewColor2("Preview Color 3",Color) = (.99, .85, .92, 0)
_previewColor3("Preview Color 4",Color) = (.99, .85, .92, 0)
_previewColor4("Preview Color 5",Color) = (.99, .85, .92, 0)
_colorTexture0("Color Texture 1", any) = "" {}
_colorTexture1("Color Texture 2", any) = "" {}
_colorTexture2("Color Texture 3", any) = "" {}
_colorTexture3("Color Texture 4", any) = "" {}
_colorTexture4("Color Texture 5", any) = "" {}
_seaLevelTintColor ("Sea Level Tint Color",Color) = (.34, .85, .92, 1)
_normalMapColorPower ("Normal Map Color Power",Float) = 0.3
_seaLevel ("Sea Level",Float) = 0
}
SubShader
{
ZTest [_zTestMode] Cull Back ZWrite On
Blend SrcAlpha OneMinusSrcAlpha
CGINCLUDE
// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it uses non-square matrices
#pragma exclude_renderers gles
#include "UnityCG.cginc"
#include "TerrainPreview.cginc"
sampler2D _BrushTex;
ENDCG
Pass // 0
{
Name "TerrainPreviewProcedural"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
struct v2f {
float4 clipPosition : SV_POSITION;
float3 positionWorld : TEXCOORD0;
float3 positionWorldOrig : TEXCOORD1;
float2 pcPixels : TEXCOORD2;
float2 brushUV : TEXCOORD3;
};
v2f vert(uint vid : SV_VertexID)
{
// build a quad mesh, with one vertex per paint context pixel (pcPixel)
float2 pcPixels = BuildProceduralQuadMeshVertex(vid);
// compute heightmap UV and sample heightmap
float2 heightmapUV = PaintContextPixelsToHeightmapUV(pcPixels);
float heightmapSample = UnpackHeightmap(tex2Dlod(_Heightmap, float4(heightmapUV, 0, 0)));
// compute brush UV
float2 brushUV = PaintContextPixelsToBrushUV(pcPixels);
// compute object position (in terrain space) and world position
float3 positionObject = PaintContextPixelsToObjectPosition(pcPixels, heightmapSample);
float3 positionWorld = TerrainObjectToWorldPosition(positionObject);
v2f o;
o.pcPixels = pcPixels;
o.positionWorld = positionWorld;
o.positionWorldOrig = positionWorld;
o.clipPosition = UnityWorldToClipPos(positionWorld);
o.brushUV = brushUV;
return o;
}
float4 frag(v2f i) : SV_Target
{
float brushSample = UnpackHeightmap(tex2D(_BrushTex, i.brushUV));
// out of bounds multiplier
float oob = all(saturate(i.brushUV) == i.brushUV) ? 1.0f : 0.0f;
// brush outline stripe
float stripeWidth = 2.0f; // pixels
float stripeLocation = 0.2f; // at 20% alpha
float brushStripe = Stripe(brushSample, stripeLocation, stripeWidth);
//float4 color = float4(0.5f, 0.5f, 1.0f, 1.0f) * saturate(brushStripe + 0.5f * brushSample);
float4 color = float4(1.0f, 1.0f, 1.0f, 1.0f) * saturate(brushStripe + 0.5f * brushSample);
color.a = 0.6f * saturate(brushSample * 5.0f);
return color * oob;
}
ENDCG
}
Pass // 1
{
Name "TerrainPreviewProceduralDeltaNormals"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _HeightmapOrig;
float4 _previewColor0;
float4 _previewColor1;
float4 _previewColor2;
float4 _previewColor3;
float4 _previewColor4;
sampler2D _colorTexture0;
sampler2D _colorTexture1;
sampler2D _colorTexture2;
sampler2D _colorTexture3;
sampler2D _colorTexture4;
float4 _seaLevelTintColor;
float _normalMapColorPower;
float _seaLevel;
struct v2f {
float4 clipPosition : SV_POSITION;
float3 positionWorld : TEXCOORD0;
float3 positionWorldOrig : TEXCOORD1;
float2 pcPixels : TEXCOORD2;
float2 brushUV : TEXCOORD3;
};
v2f vert(uint vid : SV_VertexID)
{
// build a quad mesh, with one vertex per paint context pixel (pcPixel)
float2 pcPixels = BuildProceduralQuadMeshVertex(vid);
// compute heightmap UV and sample heightmap
float2 heightmapUV = PaintContextPixelsToHeightmapUV(pcPixels);
float heightmapSample = UnpackHeightmap(tex2Dlod(_Heightmap, float4(heightmapUV, 0, 0)));
float heightmapSampleOrig = UnpackHeightmap(tex2Dlod(_HeightmapOrig, float4(heightmapUV, 0, 0)));
// compute brush UV
float2 brushUV = PaintContextPixelsToBrushUV(pcPixels);
// compute object position (in terrain space) and world position
float3 positionObject = PaintContextPixelsToObjectPosition(pcPixels, heightmapSample);
float3 positionWorld = TerrainObjectToWorldPosition(positionObject);
float3 positionObjectOrig = PaintContextPixelsToObjectPosition(pcPixels, heightmapSampleOrig);
float3 positionWorldOrig = TerrainObjectToWorldPosition(positionObjectOrig);
v2f o;
o.pcPixels = pcPixels;
o.positionWorld = positionWorld;
o.positionWorldOrig = positionWorldOrig;
o.clipPosition = UnityWorldToClipPos(positionWorld);
o.brushUV = brushUV;
return o;
}
float4 frag(v2f i) : SV_Target
{
float brushSample = UnpackHeightmap(tex2D(_BrushTex, i.brushUV));
float colorSample0 = UnpackHeightmap(tex2D(_colorTexture0, i.brushUV));
float colorSample1 = UnpackHeightmap(tex2D(_colorTexture1, i.brushUV));
float colorSample2 = UnpackHeightmap(tex2D(_colorTexture2, i.brushUV));
float colorSample3 = UnpackHeightmap(tex2D(_colorTexture3, i.brushUV));
float colorSample4 = UnpackHeightmap(tex2D(_colorTexture4, i.brushUV));
// out of bounds multiplier
float oob = all(saturate(i.brushUV) == i.brushUV) ? 1.0f : 0.0f;
float deltaHeight = abs(i.positionWorld.y - i.positionWorldOrig.y);
// normal based coloring
float3 dx = ddx(i.positionWorld);
float3 dy = ddy(i.positionWorld);
float3 normal = normalize(cross(dy, dx));
float3 lightDir = UnityWorldSpaceLightDir(i.positionWorld.xyz);
// float4 color;
//color.r = 1.0f;
//color.g = 1.0f;
//color.b = 1.0f;
//color.a = 1.0f;
////positive or negative color?
//if(i.positionWorld.y - i.positionWorldOrig.y>=0)
//{
// //color.rgb = saturate(normal.xzy * (_positiveHeightColor.rgb + float3(-0.5f, -0.5f, 0.5f)) + 0.4f);
//// color.rgb = normal.xzy;// + float3(0.5f, 0.5f, 0.5f);
// color.rgb = _positiveHeightColor.rgb;
// color.a = _positiveHeightColor.a;
//}
//else
//{
// //color.rgb = saturate(normal.xzy * (_negativeHeightColor.rgb + float3(1.0f, -0.5f, -0.5f)) + 0.4f);
// //color.rgb = normal.xzy;
// color.rgb = _negativeHeightColor.rgb;
// color.a = _negativeHeightColor.a;
//}
//calculate color according to the color texture samples
/*_previewColor0.a *= colorSample0;
_previewColor1.a *= colorSample1;
_previewColor2.a *= colorSample2;
_previewColor3.a *= colorSample3;
_previewColor4.a *= colorSample4;*/
float4 color = float4(0,0,0,0);
//float totalStrength = colorSample0 + colorSample1 + colorSample2 + colorSample3 + colorSample4;
color = lerp(color, _previewColor0, _previewColor0.a*colorSample0);
color = lerp(color, _previewColor1, _previewColor1.a*colorSample1);
color = lerp(color, _previewColor2, _previewColor2.a*colorSample2);
color = lerp(color, _previewColor3, _previewColor3.a*colorSample3);
color = lerp(color, _previewColor4, _previewColor4.a*colorSample4);
/*color.rgb = _previewColor0.rgb * colorSample0 / totalStrength +
_previewColor1.rgb * colorSample1 / totalStrength +
_previewColor2.rgb * colorSample2 / totalStrength +
_previewColor3.rgb * colorSample3 / totalStrength +
_previewColor4.rgb * colorSample4 / totalStrength;*/
/*float4 color = (_previewColor0;
colorSample0;
if (colorSample1 > colorSample0)
{
color = _previewColor1;
color.a = colorSample1;
}
else if (colorSample2 > colorSample1)
{
color = _previewColor2;
color.a = colorSample2;
}
else if (colorSample3 > colorSample2)
{
color = _previewColor3;
color.a = colorSample3;
}
else if (colorSample4 > colorSample3)
{
color = _previewColor4;
color.a = colorSample4;
}*/
color.a *= brushSample;
////apply sea level tint
if(i.positionWorld.y<_seaLevel)
{
color.rgb = (color.rgb * (1-_seaLevelTintColor.a)) + (_seaLevelTintColor.rgb * _seaLevelTintColor.a);
}
//
////apply normal map influence
//color.rgb = color.rgb * (1-_normalMapColorPower) + normal.xzy * _normalMapColorPower;
//color.rgb = lerp(color.rgb, float3(1.0f, 1.0f, 1.0f), 0.3f);
color.rgb = color.rgb * (0.1f + 0.9f * dot(lightDir, normal/1.15f));
//color.a = 1.0f; // brushSample * _previewColor.a;
return color;
}
ENDCG
}
Pass // 2
{
Name "TerrainPreviewProceduralDeltaStripes"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _HeightmapOrig;
struct v2f {
float4 clipPosition : SV_POSITION;
float3 positionWorld : TEXCOORD0;
float3 positionWorldOrig : TEXCOORD1;
float2 pcPixels : TEXCOORD2;
float2 brushUV : TEXCOORD3;
};
v2f vert(uint vid : SV_VertexID)
{
// build a quad mesh, with one vertex per paint context pixel (pcPixel)
float2 pcPixels = BuildProceduralQuadMeshVertex(vid);
// compute heightmap UV and sample heightmap
float2 heightmapUV = PaintContextPixelsToHeightmapUV(pcPixels);
float heightmapSample = UnpackHeightmap(tex2Dlod(_Heightmap, float4(heightmapUV, 0, 0)));
float heightmapSampleOrig = UnpackHeightmap(tex2Dlod(_HeightmapOrig, float4(heightmapUV, 0, 0)));
// compute brush UV
float2 brushUV = PaintContextPixelsToBrushUV(pcPixels);
// compute object position (in terrain space) and world position
float3 positionObject = PaintContextPixelsToObjectPosition(pcPixels, heightmapSample);
float3 positionWorld = TerrainObjectToWorldPosition(positionObject);
float3 positionObjectOrig = PaintContextPixelsToObjectPosition(pcPixels, heightmapSampleOrig);
float3 positionWorldOrig = TerrainObjectToWorldPosition(positionObjectOrig);
v2f o;
o.pcPixels = pcPixels;
o.positionWorld = positionWorld;
o.positionWorldOrig = positionWorldOrig;
o.clipPosition = UnityWorldToClipPos(positionWorld);
o.brushUV = brushUV;
return o;
}
float MultiStripes(in float x, in float freq1, in float freq2)
{
float2 derivatives = float2(ddx(x), ddy(x));
float derivLen = length(derivatives);
float tweak = 0.5;
float sharpen = tweak / max(derivLen, 0.00001f);
float triwave1 = abs(frac(x * freq1) - 0.5f) - 0.25f;
float triwave2 = abs(frac(x * freq2) - 0.5f) - 0.25f;
float width = 0.95f;
float result1 = saturate((triwave1 - width * 0.25f) * sharpen / freq1 + 0.75f);
float result2 = saturate((triwave2 - width * 0.25f) * sharpen / freq2 + 0.75f);
return max(result1, result2);
}
float4 frag(v2f i) : SV_Target
{
float brushSample = UnpackHeightmap(tex2D(_BrushTex, i.brushUV));
// out of bounds multiplier
float oob = all(saturate(i.brushUV) == i.brushUV) ? 1.0f : 0.0f;
// brush outline stripe
float stripeWidth = 1.0f; // pixels
float stripeLocation = 0.2f; // at 20% alpha
float heightStripes = MultiStripes(i.positionWorld.y + 0.25f, 0.0625f, 1.0f);
float xStripes = MultiStripes(i.positionWorld.x, 0.03125f, 0.5f);
float zStripes = MultiStripes(i.positionWorld.z, 0.03125f, 0.5f);
float deltaHeight = saturate(abs(i.positionWorld.y - i.positionWorldOrig.y));
float4 color = lerp(float4(0.5f, 0.5f, 1.0f, 1.0f), float4(0.5f, 1.0f, 0.5f, 1.0f), deltaHeight);
return color * lerp(deltaHeight * 0.5f, (brushSample > 0.0f ? 1.0f : 0.0f), 0.5f * saturate(heightStripes + xStripes + zStripes));
}
ENDCG
}
}
Fallback Off
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4fd51b2c75db0da429366b40b1d38c45
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,294 @@
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
Shader "Hidden/Gaia/StampPreview"
{
Properties
{
[Enum(UnityEngine.Rendering.CompareFunction)] _zTestMode ("Z Test mode", Int) = 4 //4 = LEqual
_positiveHeightColor ("Positive Height Color",Color) = (.34, .85, .92, 1)
_negativeHeightColor ("Negative Height Color",Color) = (.34, .85, .92, 1)
_seaLevelTintColor ("Sea Level Tint Color",Color) = (.34, .85, .92, 1)
_normalMapColorPower ("Normal Map Color Power",Float) = 0.3
_seaLevel ("Sea Level",Float) = 0
}
SubShader
{
ZTest [_zTestMode] Cull Back ZWrite On
Blend SrcAlpha OneMinusSrcAlpha
CGINCLUDE
// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it uses non-square matrices
#pragma exclude_renderers gles
#include "UnityCG.cginc"
#include "TerrainPreview.cginc"
sampler2D _BrushTex;
ENDCG
Pass // 0
{
Name "TerrainPreviewProcedural"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
struct v2f {
float4 clipPosition : SV_POSITION;
float3 positionWorld : TEXCOORD0;
float3 positionWorldOrig : TEXCOORD1;
float2 pcPixels : TEXCOORD2;
float2 brushUV : TEXCOORD3;
};
v2f vert(uint vid : SV_VertexID)
{
// build a quad mesh, with one vertex per paint context pixel (pcPixel)
float2 pcPixels = BuildProceduralQuadMeshVertex(vid);
// compute heightmap UV and sample heightmap
float2 heightmapUV = PaintContextPixelsToHeightmapUV(pcPixels);
float heightmapSample = UnpackHeightmap(tex2Dlod(_Heightmap, float4(heightmapUV, 0, 0)));
// compute brush UV
float2 brushUV = PaintContextPixelsToBrushUV(pcPixels);
// compute object position (in terrain space) and world position
float3 positionObject = PaintContextPixelsToObjectPosition(pcPixels, heightmapSample);
float3 positionWorld = TerrainObjectToWorldPosition(positionObject);
v2f o;
o.pcPixels = pcPixels;
o.positionWorld = positionWorld;
o.positionWorldOrig = positionWorld;
o.clipPosition = UnityWorldToClipPos(positionWorld);
o.brushUV = brushUV;
return o;
}
float4 frag(v2f i) : SV_Target
{
float brushSample = UnpackHeightmap(tex2D(_BrushTex, i.brushUV));
// out of bounds multiplier
float oob = all(saturate(i.brushUV) == i.brushUV) ? 1.0f : 0.0f;
// brush outline stripe
float stripeWidth = 2.0f; // pixels
float stripeLocation = 0.2f; // at 20% alpha
float brushStripe = Stripe(brushSample, stripeLocation, stripeWidth);
//float4 color = float4(0.5f, 0.5f, 1.0f, 1.0f) * saturate(brushStripe + 0.5f * brushSample);
float4 color = float4(1.0f, 1.0f, 1.0f, 1.0f) * saturate(brushStripe + 0.5f * brushSample);
color.a = 0.6f * saturate(brushSample * 5.0f);
return color * oob;
}
ENDCG
}
Pass // 1
{
Name "TerrainPreviewProceduralDeltaNormals"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _HeightmapOrig;
float4 _positiveHeightColor;
float4 _negativeHeightColor;
float4 _seaLevelTintColor;
float _normalMapColorPower;
float _seaLevel;
struct v2f {
float4 clipPosition : SV_POSITION;
float3 positionWorld : TEXCOORD0;
float3 positionWorldOrig : TEXCOORD1;
float2 pcPixels : TEXCOORD2;
float2 brushUV : TEXCOORD3;
};
v2f vert(uint vid : SV_VertexID)
{
// build a quad mesh, with one vertex per paint context pixel (pcPixel)
float2 pcPixels = BuildProceduralQuadMeshVertex(vid);
// compute heightmap UV and sample heightmap
float2 heightmapUV = PaintContextPixelsToHeightmapUV(pcPixels);
float heightmapSample = UnpackHeightmap(tex2Dlod(_Heightmap, float4(heightmapUV, 0, 0)));
float heightmapSampleOrig = UnpackHeightmap(tex2Dlod(_HeightmapOrig, float4(heightmapUV, 0, 0)));
// compute brush UV
float2 brushUV = PaintContextPixelsToBrushUV(pcPixels);
// compute object position (in terrain space) and world position
float3 positionObject = PaintContextPixelsToObjectPosition(pcPixels, heightmapSample);
float3 positionWorld = TerrainObjectToWorldPosition(positionObject);
float3 positionObjectOrig = PaintContextPixelsToObjectPosition(pcPixels, heightmapSampleOrig);
float3 positionWorldOrig = TerrainObjectToWorldPosition(positionObjectOrig);
v2f o;
o.pcPixels = pcPixels;
o.positionWorld = positionWorld;
o.positionWorldOrig = positionWorldOrig;
o.clipPosition = UnityWorldToClipPos(positionWorld);
o.brushUV = brushUV;
return o;
}
float4 frag(v2f i) : SV_Target
{
float brushSample = UnpackHeightmap(tex2D(_BrushTex, i.brushUV));
// out of bounds multiplier
float oob = all(saturate(i.brushUV) == i.brushUV) ? 1.0f : 0.0f;
float deltaHeight = abs(i.positionWorld.y - i.positionWorldOrig.y);
// normal based coloring
float3 dx = ddx(i.positionWorld);
float3 dy = ddy(i.positionWorld);
float3 normal = normalize(cross(dy, dx));
float3 lightDir = UnityWorldSpaceLightDir(i.positionWorld.xyz);
float4 color;
color.r = 1.0f;
color.g = 1.0f;
color.b = 1.0f;
color.a = 1.0f;
//positive or negative color?
if(i.positionWorld.y - i.positionWorldOrig.y>=0)
{
//color.rgb = saturate(normal.xzy * (_positiveHeightColor.rgb + float3(-0.5f, -0.5f, 0.5f)) + 0.4f);
// color.rgb = normal.xzy;// + float3(0.5f, 0.5f, 0.5f);
color.rgb = _positiveHeightColor.rgb;
color.a = _positiveHeightColor.a;
}
else
{
//color.rgb = saturate(normal.xzy * (_negativeHeightColor.rgb + float3(1.0f, -0.5f, -0.5f)) + 0.4f);
//color.rgb = normal.xzy;
color.rgb = _negativeHeightColor.rgb;
color.a = _negativeHeightColor.a;
}
//apply sea level tint
if(i.positionWorld.y<_seaLevel)
{
color.rgb = (color.rgb * (1-_seaLevelTintColor.a)) + (_seaLevelTintColor.rgb * _seaLevelTintColor.a);
}
//apply normal map influence
color.rgb = color.rgb * (1-_normalMapColorPower) + normal.xzy * _normalMapColorPower;
//color.rgb = lerp(color.rgb, float3(1.0f, 1.0f, 1.0f), 0.3f);
color.rgb = color.rgb * (0.1f + 0.9f * dot(lightDir, normal/1.15f));
color.a = saturate(1.0f * deltaHeight) * color.a;
return color;
}
ENDCG
}
Pass // 2
{
Name "TerrainPreviewProceduralDeltaStripes"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _HeightmapOrig;
struct v2f {
float4 clipPosition : SV_POSITION;
float3 positionWorld : TEXCOORD0;
float3 positionWorldOrig : TEXCOORD1;
float2 pcPixels : TEXCOORD2;
float2 brushUV : TEXCOORD3;
};
v2f vert(uint vid : SV_VertexID)
{
// build a quad mesh, with one vertex per paint context pixel (pcPixel)
float2 pcPixels = BuildProceduralQuadMeshVertex(vid);
// compute heightmap UV and sample heightmap
float2 heightmapUV = PaintContextPixelsToHeightmapUV(pcPixels);
float heightmapSample = UnpackHeightmap(tex2Dlod(_Heightmap, float4(heightmapUV, 0, 0)));
float heightmapSampleOrig = UnpackHeightmap(tex2Dlod(_HeightmapOrig, float4(heightmapUV, 0, 0)));
// compute brush UV
float2 brushUV = PaintContextPixelsToBrushUV(pcPixels);
// compute object position (in terrain space) and world position
float3 positionObject = PaintContextPixelsToObjectPosition(pcPixels, heightmapSample);
float3 positionWorld = TerrainObjectToWorldPosition(positionObject);
float3 positionObjectOrig = PaintContextPixelsToObjectPosition(pcPixels, heightmapSampleOrig);
float3 positionWorldOrig = TerrainObjectToWorldPosition(positionObjectOrig);
v2f o;
o.pcPixels = pcPixels;
o.positionWorld = positionWorld;
o.positionWorldOrig = positionWorldOrig;
o.clipPosition = UnityWorldToClipPos(positionWorld);
o.brushUV = brushUV;
return o;
}
float MultiStripes(in float x, in float freq1, in float freq2)
{
float2 derivatives = float2(ddx(x), ddy(x));
float derivLen = length(derivatives);
float tweak = 0.5;
float sharpen = tweak / max(derivLen, 0.00001f);
float triwave1 = abs(frac(x * freq1) - 0.5f) - 0.25f;
float triwave2 = abs(frac(x * freq2) - 0.5f) - 0.25f;
float width = 0.95f;
float result1 = saturate((triwave1 - width * 0.25f) * sharpen / freq1 + 0.75f);
float result2 = saturate((triwave2 - width * 0.25f) * sharpen / freq2 + 0.75f);
return max(result1, result2);
}
float4 frag(v2f i) : SV_Target
{
float brushSample = UnpackHeightmap(tex2D(_BrushTex, i.brushUV));
// out of bounds multiplier
float oob = all(saturate(i.brushUV) == i.brushUV) ? 1.0f : 0.0f;
// brush outline stripe
float stripeWidth = 1.0f; // pixels
float stripeLocation = 0.2f; // at 20% alpha
float heightStripes = MultiStripes(i.positionWorld.y + 0.25f, 0.0625f, 1.0f);
float xStripes = MultiStripes(i.positionWorld.x, 0.03125f, 0.5f);
float zStripes = MultiStripes(i.positionWorld.z, 0.03125f, 0.5f);
float deltaHeight = saturate(abs(i.positionWorld.y - i.positionWorldOrig.y));
float4 color = lerp(float4(0.5f, 0.5f, 1.0f, 1.0f), float4(0.5f, 1.0f, 0.5f, 1.0f), deltaHeight);
return color * lerp(deltaHeight * 0.5f, (brushSample > 0.0f ? 1.0f : 0.0f), 0.5f * saturate(heightStripes + xStripes + zStripes));
}
ENDCG
}
}
Fallback Off
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 244c2096627f7794c98f3c1bcea2b306
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,20 @@
License for the shader files found in this directory:
Copyright (c) 2016 Unity Technologies
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 798730c727db147449b5eaa74a01e263
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: