This commit is contained in:
CortexCore
2025-03-14 21:04:19 +08:00
parent ff8670c453
commit 757ffe79ee
1282 changed files with 104378 additions and 3 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9bf6ac87932cb754c908fe9795a0dbec
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,59 @@
Shader "Griffin/~Internal/Billboard Creator/Atlas"
{
Properties
{
_Color ("_Color", Color) = (1,1,1,1)
_MainTex ("_Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="AlphaTest+0"}
LOD 100
Pass
{
//Blend SrcAlpha OneMinusSrcAlpha
Cull Off
//ZWrite Off
//ZTest LEqual
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
float4 _Color;
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv)*_Color;
clip(col.a-0.5);
return col;
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,63 @@
Shader "Griffin/~Internal/Billboard Creator/Normal"
{
Properties
{
}
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="AlphaTest"}
LOD 100
Pass
{
ZWrite On
ZTest LEqual
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f
{
float4 vertex : SV_POSITION;
float3 normal : NORMAL;
};
#define CAMERA_RIGHT UNITY_MATRIX_V[0].xyz
#define CAMERA_UP UNITY_MATRIX_V[1].xyz
#define CAMERA_FORWARD UNITY_MATRIX_V[2].xyz
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.normal = UnityObjectToWorldNormal(v.normal);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float3 normal = normalize(i.normal);
float r = (dot(normal, CAMERA_RIGHT) + 1)*0.5f;
float g = (dot(normal, CAMERA_UP) + 1)*0.5f;
float b = (dot(normal, CAMERA_FORWARD) + 1)*0.5f;
float a = 1;
fixed4 col = float4(r,g,b,a);
#if UNITY_COLORSPACE_GAMMA
return col;
#else
return float4(GammaToLinearSpace(col.rgb), 1);
#endif
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 92165c30f01a6794984527bf358bcf05
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,68 @@
Shader "Hidden/Polaris/ApplyErosion"
{
Properties
{
_HeightMap ("Height Map", 2D) = "white" {}
_SimulationData("Simulation Data", 2D) = "black"{}
_FalloffTexture("Falloff", 2D) = "black"{}
_Bounds("Bounds", Vector) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "ErosionToolCommon.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 localPos : TEXCOORD1;
};
sampler2D _HeightMap;
sampler2D _SimulationData;
sampler2D _FalloffTexture;
float4 _Bounds;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.localPos = v.vertex;
o.uv = v.uv;
return o;
}
float4 frag (v2f i) : SV_Target
{
float4 data = tex2D(_HeightMap, i.localPos);
float currentHeight = DecodeFloatRG(data.rg);
float simHeight = tex2D(_SimulationData, i.uv).r/_Bounds.y;
float f = saturate(2*length(i.uv - float2(0.5,0.5)));
float falloff = tex2D(_FalloffTexture, float2(f, 0.5)).r;
float h = lerp(currentHeight, simHeight, falloff);
data.rg = EncodeFloatRG(min(0.999999, h));
return data;
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,60 @@
Shader "Hidden/Polaris/ErosionDataView"
{
Properties
{
_MainTex ("Texture", 2D) = "white" { }
_Scale ("Scale", float) = 1
_Channel ("Channel", float) = 0
}
SubShader
{
Tags { "RenderType" = "Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex: POSITION;
float2 uv: TEXCOORD0;
};
struct v2f
{
float2 uv: TEXCOORD0;
float4 vertex: SV_POSITION;
};
sampler2D _MainTex;
float _Scale;
float _Channel;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
float4 frag(v2f i): SV_Target
{
float4 data = tex2D(_MainTex, i.uv);
float value = data[_Channel] * _Scale;
float4 tint = float4(1, 0, 0, 1) * (_Channel == 0) + float4(0, 1, 0, 1) * (_Channel == 1) + float4(0, 0, 1, 1) * (_Channel == 2) + float4(1, 1, 1, 1) * (_Channel == 3);
return tint * value;
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,139 @@
Shader "Hidden/Polaris/ErosionTexturer"
{
Properties { }
CGINCLUDE
#pragma vertex vert
#include "UnityCG.cginc"
struct appdata
{
float4 vertex: POSITION;
float2 uv: TEXCOORD0;
};
struct v2f
{
float2 uv: TEXCOORD0;
float4 vertex: SV_POSITION;
float4 localPos: TEXCOORD1;
};
sampler2D _MainTex;
sampler2D _ErosionMap;
sampler2D _FalloffTexture;
float4 _ErosionAlbedo;
float _ErosionMetallic;
float _ErosionSmoothness;
float _ErosionChannelIndex;
float _ErosionIntensity;
float _ErosionExponent;
float4 _DepositionAlbedo;
float _DepositionMetallic;
float _DepositionSmoothness;
float _DepositionChannelIndex;
float _DepositionIntensity;
float _DepositionExponent;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.localPos = v.vertex;
return o;
}
ENDCG
SubShader
{
Tags { "RenderType" = "Opaque" }
LOD 100
Pass
{
Name "Splat"
CGPROGRAM
#pragma fragment fragSplat
float4 fragSplat(v2f i): SV_Target
{
float f = saturate(2 * length(i.uv - float2(0.5, 0.5)));
float falloff = tex2D(_FalloffTexture, float2(f, 0.5)).r;
float4 currentColor = tex2D(_MainTex, i.localPos);
float2 erosionData = tex2D(_ErosionMap, i.uv);
float erosionStrength = saturate(pow(erosionData.r * _ErosionIntensity * falloff, _ErosionExponent));
float4 erosionChannel = float4(_ErosionChannelIndex == 0, _ErosionChannelIndex == 1, _ErosionChannelIndex == 2, _ErosionChannelIndex == 3);
currentColor = lerp(currentColor, erosionChannel, erosionStrength);
float depositionStrength = saturate(pow(erosionData.g * _DepositionIntensity * falloff, _DepositionExponent));
float4 depositionChannel = float4(_DepositionChannelIndex == 0, _DepositionChannelIndex == 1, _DepositionChannelIndex == 2, _DepositionChannelIndex == 3);
currentColor = lerp(currentColor, depositionChannel, depositionStrength);
return currentColor;
}
ENDCG
}
Pass
{
Name "Albedo"
CGPROGRAM
#pragma fragment fragAlbedo
float4 fragAlbedo(v2f i): SV_Target
{
float f = saturate(2 * length(i.uv - float2(0.5, 0.5)));
float falloff = tex2D(_FalloffTexture, float2(f, 0.5)).r;
float4 currentColor = tex2D(_MainTex, i.localPos);
float2 erosionData = tex2D(_ErosionMap, i.uv);
float erosionStrength = saturate(pow(erosionData.r * _ErosionIntensity * falloff, _ErosionExponent));
currentColor = lerp(currentColor, _ErosionAlbedo, erosionStrength);
float depositionStrength = saturate(pow(erosionData.g * _DepositionIntensity * falloff, _DepositionExponent));
currentColor = lerp(currentColor, _DepositionAlbedo, depositionStrength);
return currentColor;
}
ENDCG
}
Pass
{
Name "Metallic Smoothness"
CGPROGRAM
#pragma fragment fragMetallicSmoothness
float4 fragMetallicSmoothness(v2f i): SV_Target
{
float f = saturate(2 * length(i.uv - float2(0.5, 0.5)));
float falloff = tex2D(_FalloffTexture, float2(f, 0.5)).r;
float4 currentColor = tex2D(_MainTex, i.localPos);
float2 erosionData = tex2D(_ErosionMap, i.uv);
float erosionStrength = saturate(pow(erosionData.r * _ErosionIntensity * falloff, _ErosionExponent));
float4 targetMS = float4(_ErosionMetallic, currentColor.g, currentColor.b, _ErosionSmoothness);
currentColor = lerp(currentColor, targetMS, erosionStrength);
float depositionStrength = saturate(pow(erosionData.g * _DepositionIntensity * falloff, _DepositionExponent));
targetMS = float4(_DepositionMetallic, currentColor.g, currentColor.b, _DepositionSmoothness);
currentColor = lerp(currentColor, targetMS, depositionStrength);
return currentColor;
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,99 @@
#ifndef EROSION_COMMON_INCLUDED
#define EROSION_COMMON_INCLUDED
#define M2CM 100
#define CM2M 0.01
#define DT 1.0/30.0
#define G 9.8
#define FLOW_CONST 0.5
#define LEFT 0
#define TOP 1
#define RIGHT 2
#define BOTTOM 3
#define LEFT_TOP 0
#define TOP_RIGHT 1
#define RIGHT_BOTTOM 2
#define BOTTOM_LEFT 3
int To1DIndex(int x, int z, int width)
{
return z * width + x;
}
float4 SampleTextureBilinear(Texture2D<float4> buffer, float width, float height, float2 uv)
{
float4 value = 0;
float2 pixelCoord = float2(lerp(0, width - 1, uv.x), lerp(0, height - 1, uv.y));
//apply a bilinear filter
int xFloor = floor(pixelCoord.x);
int xCeil = ceil(pixelCoord.x);
int yFloor = floor(pixelCoord.y);
int yCeil = ceil(pixelCoord.y);
float4 f00 = buffer[uint2(xFloor, yFloor)];
float4 f01 = buffer[uint2(xFloor, yCeil)];
float4 f10 = buffer[uint2(xCeil, yFloor)];
float4 f11 = buffer[uint2(xCeil, yCeil)];
float2 unitCoord = float2(pixelCoord.x - xFloor, pixelCoord.y - yFloor);
value = f00 * (1 - unitCoord.x) * (1 - unitCoord.y) + f01 * (1 - unitCoord.x) * unitCoord.y + f10 * unitCoord.x * (1 - unitCoord.y) + f11 * unitCoord.x * unitCoord.y;
return value;
}
float4 SampleTextureBilinear(RWTexture2D<float4> buffer, float width, float height, float2 pixelCoord)
{
float4 value = 0;
pixelCoord.x = clamp(pixelCoord.x, 0, width - 1);
pixelCoord.y = clamp(pixelCoord.y, 0, height - 1);
//apply a bilinear filter
int xFloor = floor(pixelCoord.x);
int xCeil = ceil(pixelCoord.x);
int yFloor = floor(pixelCoord.y);
int yCeil = ceil(pixelCoord.y);
float4 f00 = buffer[uint2(xFloor, yFloor)];
float4 f01 = buffer[uint2(xFloor, yCeil)];
float4 f10 = buffer[uint2(xCeil, yFloor)];
float4 f11 = buffer[uint2(xCeil, yCeil)];
float2 unitCoord = float2(pixelCoord.x - xFloor, pixelCoord.y - yFloor);
value = f00 * (1 - unitCoord.x) * (1 - unitCoord.y) + f01 * (1 - unitCoord.x) * unitCoord.y + f10 * unitCoord.x * (1 - unitCoord.y) + f11 * unitCoord.x * unitCoord.y;
return value;
}
float DecodeFloatRG(float2 enc)
{
float2 kDecodeDot = float2(1.0, 1 / 255.0);
return dot(enc, kDecodeDot);
}
float2 EncodeFloatRG(float v)
{
float2 kEncodeMul = float2(1.0, 255.0);
float kEncodeBit = 1.0 / 255.0;
float2 enc = kEncodeMul * v;
enc = frac(enc);
enc.x -= enc.y * kEncodeBit;
return enc;
}
float RandomValue (float2 uv)
{
return frac(sin(dot(uv, float2(12.9898, 78.233)))*43758.5453);
}
float InverseLerpUnclamped(float a, float b, float value)
{
//adding a==b check if needed
return (value - a) / (b - a + 0.0000001);
}
#endif //GRIFFIN_GRASS_COMMON_INCLUDED

View File

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

View File

@@ -0,0 +1,97 @@
Shader "Hidden/Polaris/FetchWorldData"
{
Properties
{
_MainTex ("Texture", 2D) = "white" { }
_Bounds ("Bounds", Vector) = (1, 1, 1, 1)
_EnableTerrainMask ("Enable Terrain Mask", Float) = 0
}
CGINCLUDE
#include "ErosionToolCommon.cginc"
struct appdata
{
float4 vertex: POSITION;
float2 uv: TEXCOORD0;
};
struct v2f
{
float2 uv: TEXCOORD0;
float4 vertex: SV_POSITION;
};
sampler2D _MainTex;
float4 _Bounds;
float _EnableTerrainMask;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
ENDCG
SubShader
{
Tags { "RenderType" = "Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
float4 frag(v2f i): SV_Target
{
float2 enc = tex2D(_MainTex, i.uv).rg;
float h = DecodeFloatRG(enc) * _Bounds.y;
float4 color = float4(h, 0, h, 0);
return color;
}
ENDCG
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
float4 frag(v2f i): SV_Target
{
float4 mask = tex2D(_MainTex, i.uv);
float4 color = float4(mask.b, 1, 0, 1 - mask.r * _EnableTerrainMask); //water source, rain, unused, erosion strength
return color;
}
ENDCG
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
float4 frag(v2f i): SV_Target
{
return float4(0, 0, 0, 0);
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,291 @@
#pragma kernel Simulate
#include "ErosionToolCommon.cginc"
float3 _Bounds;
RWTexture2D<float4> _SimulationData; //r: current height, g: suspended sediment, b: last height, a: water level
RWTexture2D<float4> _OutflowVHData;
RWTexture2D<float4> _OutflowDiagData;
RWTexture2D<float2> _VelocityData;
RWTexture2D<float2> _ErosionMap;
//RWTexture2D<float4> _VisualizeData;
float _WaterSourceAmount;
float _RainRate;
float _FlowRate;
float _ErosionRate;
float _DepositionRate;
float _EvaporationRate;
Texture2D<float4> _MaskMap; //r: water source, g: rain, b: unused, a: erosion intensity
float2 _MaskMapResolution;
float2 _RandomSeed;
float3 CalculateNormal(inout float4 srcData, inout uint3 id)
{
float3 centerPos = float3(id.x, 0, id.z);
centerPos.y = srcData.r;
float3 leftPos = float3(id.x - 1, 0, id.z);
float3 topPos = float3(id.x, 0, id.z + 1);
float3 rightPos = float3(id.x + 1, 0, id.z);
float3 bottomPos = float3(id.x, 0, id.z - 1);
float3 leftTopPos = float3(id.x - 1, 0, id.z + 1);
float3 topRightPos = float3(id.x + 1, 0, id.z + 1);
float3 rightBottomPos = float3(id.x + 1, 0, id.z - 1);
float3 bottomLeftPos = float3(id.x - 1, 0, id.z - 1);
leftPos.y = _SimulationData[leftPos.xz].r;
topPos.y = _SimulationData[topPos.xz].r;
rightPos.y = _SimulationData[rightPos.xz].r;
bottomPos.y = _SimulationData[bottomPos.xz].r;
leftTopPos.y = _SimulationData[leftTopPos.xz].r;
topRightPos.y = _SimulationData[topRightPos.xz].r;
rightBottomPos.y = _SimulationData[rightBottomPos.xz].r;
bottomLeftPos.y = _SimulationData[bottomLeftPos.xz].r;
float3 n0 = cross(leftPos - centerPos, leftTopPos - centerPos);
float3 n1 = cross(topPos - centerPos, topRightPos - centerPos);
float3 n2 = cross(rightPos - centerPos, rightBottomPos - centerPos);
float3 n3 = cross(bottomPos - centerPos, bottomLeftPos - centerPos);
float3 n4 = cross(leftTopPos - centerPos, topPos - centerPos);
float3 n5 = cross(topRightPos - centerPos, rightPos - centerPos);
float3 n6 = cross(rightBottomPos - centerPos, bottomPos - centerPos);
float3 n7 = cross(bottomLeftPos - centerPos, leftPos - centerPos);
float3 nc = (n0 + n1 + n2 + n3 + n4 + n5 + n6 + n7) / 8;
float3 normal = normalize(nc);
return normal;
}
void AddWaterSource(inout float4 srcData, float waterSourceMask)
{
float water = _WaterSourceAmount * waterSourceMask * DT;
srcData.a += water;
}
void Rain(inout float4 srcData, float2 uv, float rainMask)
{
float rand = RandomValue(uv + _RandomSeed);
float rainValue = rand < (_RainRate * rainMask);
srcData.a += rainValue * DT;
}
void Outflow(inout float4 srcData, inout uint3 id)
{
float srcHeight = srcData.r + srcData.a;
float F_CONST = DT * G * FLOW_CONST * _FlowRate;
float3 leftPos = float3(id.x - 1, 0, id.z);
float4 leftData = _SimulationData[leftPos.xz];
float deltaHeightL = srcHeight - leftData.r - leftData.a;
float fL = max(0, F_CONST * deltaHeightL) * (leftPos.x >= 0);
float3 topPos = float3(id.x, 0, id.z + 1);
float4 topData = _SimulationData[topPos.xz];
float deltaHeightT = srcHeight - topData.r - topData.a;
float fT = max(0, F_CONST * deltaHeightT) * (topPos.y < _Bounds.z);
float3 rightPos = float3(id.x + 1, 0, id.z);
float4 rightData = _SimulationData[rightPos.xz];
float deltaHeightR = srcHeight - rightData.r - rightData.a;
float fR = max(0, F_CONST * deltaHeightR) * (rightPos.x < _Bounds.x);
float3 bottomPos = float3(id.x, 0, id.z - 1);
float4 bottomData = _SimulationData[bottomPos.xz];
float deltaHeightB = srcHeight - bottomData.r - bottomData.a;
float fB = max(0, F_CONST * deltaHeightB) * (bottomPos.y >= 0);
float3 leftTopPos = float3(id.x - 1, 0, id.z + 1);
float4 leftTopData = _SimulationData[leftTopPos.xz];
float deltaHeightLT = srcHeight - leftTopData.r - leftTopData.a;
float fLT = max(0, F_CONST * deltaHeightLT) * (leftTopPos.x >= 0) * (leftTopPos.y < _Bounds.z);
float3 topRightPos = float3(id.x + 1, 0, id.z + 1);
float4 topRightData = _SimulationData[topRightPos.xz];
float deltaHeightTR = srcHeight - topRightData.r - topRightData.a;
float fTR = max(0, F_CONST * deltaHeightTR) * (topRightPos.x < _Bounds.x) * (topRightPos.y < _Bounds.z);
float3 rightBottomPos = float3(id.x + 1, 0, id.z - 1);
float4 rightBottomData = _SimulationData[rightBottomPos.xz];
float deltaHeightRB = srcHeight - rightBottomData.r - rightBottomData.a;
float fRB = max(0, F_CONST * deltaHeightRB) * (rightBottomPos.x < _Bounds.x) * (rightBottomPos.y >= 0);
float3 bottomLeftPos = float3(id.x - 1, 0, id.z - 1);
float4 bottomLeftData = _SimulationData[bottomLeftPos.xz];
float deltaHeightBL = srcHeight - bottomLeftData.r - bottomLeftData.a;
float fBL = max(0, F_CONST * deltaHeightBL) * (bottomLeftPos.x >= 0) * (bottomLeftPos.y >= 0);
float fSum = fL + fT + fR + fB + fLT + fTR + fRB + fBL;
float fScale = min(1, srcData.a / (fSum + 0.0001));
float4 fVH = float4(fL, fT, fR, fB) * fScale;
_OutflowVHData[id.xz] = fVH;
float4 fDiag = float4(fLT, fTR, fRB, fBL) * fScale;
_OutflowDiagData[id.xz] = fDiag;
srcData.a -= fSum * fScale;
}
void Inflow(inout float4 srcData, inout uint3 id)
{
float3 leftPos = float3(id.x - 1, 0, id.z);
float4 leftData = _OutflowVHData[leftPos.xz];
float fL = leftData[RIGHT];
float3 topPos = float3(id.x, 0, id.z + 1);
float4 topData = _OutflowVHData[topPos.xz];
float fT = topData[BOTTOM];
float3 rightPos = float3(id.x + 1, 0, id.z);
float4 rightData = _OutflowVHData[rightPos.xz];
float fR = rightData[LEFT];
float3 bottomPos = float3(id.x, 0, id.z - 1);
float4 bottomData = _OutflowVHData[bottomPos.xz];
float fB = bottomData[TOP];
float3 leftTopPos = float3(id.x - 1, 0, id.z + 1);
float4 leftTopData = _OutflowDiagData[leftTopPos.xz];
float fLT = leftTopData[RIGHT_BOTTOM];
float3 topRightPos = float3(id.x + 1, 0, id.z + 1);
float4 topRightData = _OutflowDiagData[topRightPos.xz];
float fTR = topRightData[BOTTOM_LEFT];
float3 rightBottomPos = float3(id.x + 1, 0, id.z - 1);
float4 rightBottomData = _OutflowDiagData[rightBottomPos.xz];
float fRB = rightBottomData[LEFT_TOP];
float3 bottomLeftPos = float3(id.x - 1, 0, id.z - 1);
float4 bottomLeftData = _OutflowDiagData[bottomLeftPos.xz];
float fBL = bottomLeftData[TOP_RIGHT];
float fSum = fL + fT + fR + fB + fLT + fTR + fRB + fBL;
srcData.a += fSum;
}
void UpdateVelocity(inout uint3 id)
{
float3 leftPos = float3(id.x - 1, 0, id.z);
float3 topPos = float3(id.x, 0, id.z + 1);
float3 rightPos = float3(id.x + 1, 0, id.z);
float3 bottomPos = float3(id.x, 0, id.z - 1);
float4 leftOutflow = _OutflowVHData[leftPos.xz];
float4 topOutflow = _OutflowVHData[topPos.xz];
float4 rightOutflow = _OutflowVHData[rightPos.xz];
float4 bottomOutflow = _OutflowVHData[bottomPos.xz];
float3 leftTopPos = float3(id.x - 1, 0, id.z + 1);
float3 topRightPos = float3(id.x + 1, 0, id.z + 1);
float3 rightBottomPos = float3(id.x + 1, 0, id.z - 1);
float3 bottomLeftPos = float3(id.x - 1, 0, id.z - 1);
float4 leftTopOutflow = _OutflowDiagData[leftTopPos.xz];
float4 topRightOutflow = _OutflowDiagData[topRightPos.xz];
float4 rightBottomOutflow = _OutflowDiagData[rightBottomPos.xz];
float4 bottomLeftOutflow = _OutflowDiagData[bottomLeftPos.xz];
float4 srcVHOutflow = _OutflowVHData[id.xz];
float4 srcDiagOutflow = _OutflowDiagData[id.xz];
float vX0 = leftTopOutflow[RIGHT_BOTTOM] + leftOutflow[RIGHT] + bottomLeftOutflow[TOP_RIGHT];
float vX1 = srcDiagOutflow[TOP_RIGHT] + srcVHOutflow[RIGHT] + srcDiagOutflow[RIGHT_BOTTOM];
float vX2 = srcDiagOutflow[LEFT_TOP] + srcVHOutflow[LEFT] + srcDiagOutflow[BOTTOM_LEFT];
float vX3 = topRightOutflow[BOTTOM_LEFT] + rightOutflow[LEFT] + rightBottomOutflow[LEFT_TOP];
float vX = vX0 + vX1 - vX2 - vX3;
float vY0 = bottomLeftOutflow[TOP_RIGHT] + bottomOutflow[TOP] + rightBottomOutflow[LEFT_TOP];
float vY1 = srcDiagOutflow[LEFT_TOP] + srcVHOutflow[TOP] + srcDiagOutflow[TOP_RIGHT];
float vY2 = srcDiagOutflow[BOTTOM_LEFT] + srcVHOutflow[BOTTOM] + srcDiagOutflow[RIGHT_BOTTOM];
float vY3 = leftTopOutflow[RIGHT_BOTTOM] + topOutflow[BOTTOM] + topRightOutflow[BOTTOM_LEFT];
float vY = vY0 + vY1 - vY2 - vY3;
float2 v = float2(vX, vY);
_VelocityData[id.xz] = v;
}
void ErosionAndDeposition(inout float4 srcData, inout uint3 id, float erosionMask)
{
float2 velocity = _VelocityData[id.xz];
float3 surfaceNormal = CalculateNormal(srcData, id);
float2 nextPixel = float2(id.x + velocity.x, id.z + velocity.y);
float nextHeight = SampleTextureBilinear(_SimulationData, _Bounds.x, _Bounds.z, nextPixel).b;
float deltaHeight = max(0, srcData.r - nextHeight);
//float erosionFactor = pow(abs(1 - surfaceNormal.y), 1.0 / 10.0);
//erosionFactor = 1;
float erosionFactor = 1;
float erodedAmount = _ErosionRate * erosionMask * saturate(erosionFactor * length(velocity)) * DT;
erodedAmount = clamp(erodedAmount, 0, deltaHeight);
erodedAmount = clamp(erodedAmount, 0, srcData.r);
srcData.r -= erodedAmount;
srcData.g += erodedAmount;
float depositFactor = surfaceNormal.y;
float depositAmount = _DepositionRate * depositFactor * DT;
depositAmount = clamp(depositAmount, 0, srcData.g);
srcData.r += depositAmount;
srcData.g -= depositAmount;
float2 erosionMapData = _ErosionMap[id.xz];
erosionMapData.r = max(0, erosionMapData.r + erodedAmount);
erosionMapData.g = max(0, erosionMapData.g + depositAmount - erodedAmount);
_ErosionMap[id.xz] = erosionMapData;
}
void SedimentTransportation(inout float4 srcData, inout uint3 id)
{
float2 velocity = _VelocityData[id.xz];
float2 pixelCoord = float2(id.x - velocity.x, id.z - velocity.y);
float sediment = SampleTextureBilinear(_SimulationData, _Bounds.x, _Bounds.z, pixelCoord).g;
srcData.g = sediment;
}
void Evaporate(inout float4 srcData)
{
srcData.a = max(0, srcData.a - _EvaporationRate * DT);
}
void UpdateSimData(inout float4 srcData, inout uint3 id)
{
srcData.b = srcData.r;
_SimulationData[id.xz] = srcData;
}
[numthreads(8, 1, 8)]
void Simulate(uint3 id: SV_DISPATCHTHREADID)
{
float2 uv = id.xz / _Bounds.xz;
float4 mask = SampleTextureBilinear(_MaskMap, _MaskMapResolution.x, _MaskMapResolution.y, uv);
float4 srcData = _SimulationData[id.xz];
AddWaterSource(srcData, mask.r);
Rain(srcData, uv, mask.g);
UpdateSimData(srcData, id);
GroupMemoryBarrierWithGroupSync(); //Outflow read water data
Outflow(srcData, id);
GroupMemoryBarrierWithGroupSync(); //Inflow read outflow data
Inflow(srcData, id);
UpdateVelocity(id);
GroupMemoryBarrierWithGroupSync(); //Erosion read velocity data
ErosionAndDeposition(srcData, id, mask.a);
UpdateSimData(srcData, id);
GroupMemoryBarrierWithGroupSync(); //Sediment transport read source data
SedimentTransportation(srcData, id);
Evaporate(srcData);
UpdateSimData(srcData, id);
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5a8f6fd8bb447824185ed7786e38a535
ComputeShaderImporter:
externalObjects: {}
currentAPIMask: 4
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
#pragma kernel Init
#include "ErosionToolCommon.cginc"
Texture2D<float4> _HeightMap;
int _HeightMapResolution;
float3 _TerrainSize;
RWTexture2D<float4> _SimulationData; //r: current height, g: suspended sediment, b: last height, a: water level
[numthreads(8, 1, 8)]
void Init(uint3 id: SV_DISPATCHTHREADID)
{
float2 uv = id.xz / _TerrainSize.xz;
float2 encHeight = SampleTextureBilinear(_HeightMap, _HeightMapResolution, _HeightMapResolution, uv).rg;
float h = DecodeFloatRG(encHeight) * _TerrainSize.y;
float4 data = float4(h, 0, h, 0);
_SimulationData[id.xz] = data;
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 36498da77a2c00540b0cf4547b5400a3
ComputeShaderImporter:
externalObjects: {}
currentAPIMask: 4
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,191 @@
#pragma kernel Simulate
#include "ErosionToolCommon.cginc"
RWTexture2D<float4> _SimulationData;
RWTexture2D<float4> _SoilVHData;
RWTexture2D<float4> _SoilDiagData;
RWTexture2D<float2> _ErosionMap;
float3 _Bounds;
float _ErosionRate;
float _RestingAngle;
Texture2D<float4> _MaskMap;
float2 _MaskMapResolution;
void Outflow(inout float4 srcData, inout uint3 id, float erosionMask)
{
float F_CONST = DT * G * _ErosionRate * 0.5;
float3 centerPos = float3(id.x, srcData.r, id.z);
float3 downVector = float3(0, -1, 0);
float3 direction;
float angleFactor;
float minFactor = sin(radians(_RestingAngle));
float maxDh = -10000;
float3 leftPos = float3(id.x - 1, 0, id.z);
float4 leftData = _SimulationData[leftPos.xz];
leftPos.y = leftData.r;
direction = normalize(leftPos - centerPos);
angleFactor = saturate(dot(direction, downVector));
angleFactor = saturate(InverseLerpUnclamped(minFactor, 1, angleFactor));
float deltaHeightL = srcData.r - leftData.r;
maxDh = max(maxDh, deltaHeightL);
float fL = max(0, F_CONST * angleFactor * deltaHeightL) * (leftPos.x >= 0);
float3 topPos = float3(id.x, 0, id.z + 1);
float4 topData = _SimulationData[topPos.xz];
topPos.y = topData.r;
direction = normalize(topPos - centerPos);
angleFactor = saturate(dot(direction, downVector));
angleFactor = saturate(InverseLerpUnclamped(minFactor, 1, angleFactor));
float deltaHeightT = srcData.r - topData.r;
maxDh = max(maxDh, deltaHeightT);
float fT = max(0, F_CONST * angleFactor * deltaHeightT) * (topPos.y < _Bounds.z);
float3 rightPos = float3(id.x + 1, 0, id.z);
float4 rightData = _SimulationData[rightPos.xz];
rightPos.y = rightData.r;
direction = normalize(rightPos - centerPos);
angleFactor = saturate(dot(direction, downVector));
angleFactor = saturate(InverseLerpUnclamped(minFactor, 1, angleFactor));
float deltaHeightR = srcData.r - rightData.r;
maxDh = max(maxDh, deltaHeightR);
float fR = max(0, F_CONST * angleFactor * deltaHeightR) * (rightPos.x < _Bounds.x);
float3 bottomPos = float3(id.x, 0, id.z - 1);
float4 bottomData = _SimulationData[bottomPos.xz];
bottomPos.y = bottomData.r;
direction = normalize(bottomPos - centerPos);
angleFactor = saturate(dot(direction, downVector));
angleFactor = saturate(InverseLerpUnclamped(minFactor, 1, angleFactor));
float deltaHeightB = srcData.r - bottomData.r;
maxDh = max(maxDh, deltaHeightB);
float fB = max(0, F_CONST * angleFactor * deltaHeightB) * (bottomPos.y >= 0);
//---
float3 leftTopPos = float3(id.x - 1, 0, id.z + 1);
float4 leftTopData = _SimulationData[leftTopPos.xz];
leftTopPos.y = leftTopData.r;
direction = normalize(leftTopPos - centerPos);
angleFactor = saturate(dot(direction, downVector));
angleFactor = saturate(InverseLerpUnclamped(minFactor, 1, angleFactor));
float deltaHeightLT = srcData.r - leftTopData.r;
maxDh = max(maxDh, deltaHeightLT);
float fLT = max(0, F_CONST * angleFactor * deltaHeightLT) * (leftTopPos.x >= 0) * (leftTopPos.y < _Bounds.z);
float3 topRightPos = float3(id.x + 1, 0, id.z + 1);
float4 topRightData = _SimulationData[topRightPos.xz];
topRightPos.y = topRightData.r;
direction = normalize(topRightPos - centerPos);
angleFactor = saturate(dot(direction, downVector));
angleFactor = saturate(InverseLerpUnclamped(minFactor, 1, angleFactor));
float deltaHeightTR = srcData.r - topRightData.r;
maxDh = max(maxDh, deltaHeightTR);
float fTR = max(0, F_CONST * angleFactor * deltaHeightTR) * (topRightPos.x < _Bounds.x) * (topRightPos.y < _Bounds.z);
float3 rightBottomPos = float3(id.x + 1, 0, id.z - 1);
float4 rightBottomData = _SimulationData[rightBottomPos.xz];
rightBottomPos.y = rightBottomData.r;
direction = normalize(rightBottomPos - centerPos);
angleFactor = saturate(dot(direction, downVector));
angleFactor = saturate(InverseLerpUnclamped(minFactor, 1, angleFactor));
float deltaHeightRB = srcData.r - rightBottomData.r;
maxDh = max(maxDh, deltaHeightRB);
float fRB = max(0, F_CONST * angleFactor * deltaHeightRB) * (rightBottomPos.x < _Bounds.x) * (rightBottomPos.y >= 0);
float3 bottomLeftPos = float3(id.x - 1, 0, id.z - 1);
float4 bottomLeftData = _SimulationData[bottomLeftPos.xz];
bottomLeftPos.y = bottomLeftData.r;
direction = normalize(bottomLeftPos - centerPos);
angleFactor = saturate(dot(direction, downVector));
angleFactor = saturate(InverseLerpUnclamped(minFactor, 1, angleFactor));
float deltaHeightBL = srcData.r - bottomLeftData.r;
maxDh = max(maxDh, deltaHeightBL);
float fBL = max(0, F_CONST * angleFactor * deltaHeightBL) * (bottomLeftPos.x >= 0) * (bottomLeftPos.y >= 0);
float fSum = fL + fT + fR + fB + fLT + fTR + fRB + fBL;
float fScale = erosionMask * min(1, maxDh / (fSum + 0.0001));
float4 fVH = float4(fL, fT, fR, fB) * fScale;
_SoilVHData[id.xz] = fVH;
float4 fDiag = float4(fLT, fTR, fRB, fBL) * fScale;
_SoilDiagData[id.xz] = fDiag;
srcData.r = max(0, srcData.r - fSum * fScale);
float2 erosionMapData = _ErosionMap[id.xz];
erosionMapData.r += fSum * fScale;
//erosionMapData.g -= fSum * fScale;
_ErosionMap[id.xz] = erosionMapData;
}
void Inflow(inout float4 srcData, inout uint3 id)
{
float3 leftPos = float3(id.x - 1, 0, id.z);
float4 leftData = _SoilVHData[leftPos.xz];
float fL = leftData[RIGHT];
float3 topPos = float3(id.x, 0, id.z + 1);
float4 topData = _SoilVHData[topPos.xz];
float fT = topData[BOTTOM];
float3 rightPos = float3(id.x + 1, 0, id.z);
float4 rightData = _SoilVHData[rightPos.xz];
float fR = rightData[LEFT];
float3 bottomPos = float3(id.x, 0, id.z - 1);
float4 bottomData = _SoilVHData[bottomPos.xz];
float fB = bottomData[TOP];
float3 leftTopPos = float3(id.x - 1, 0, id.z + 1);
float4 leftTopData = _SoilDiagData[leftTopPos.xz];
float fLT = leftTopData[RIGHT_BOTTOM];
float3 topRightPos = float3(id.x + 1, 0, id.z + 1);
float4 topRightData = _SoilDiagData[topRightPos.xz];
float fTR = topRightData[BOTTOM_LEFT];
float3 rightBottomPos = float3(id.x + 1, 0, id.z - 1);
float4 rightBottomData = _SoilDiagData[rightBottomPos.xz];
float fRB = rightBottomData[LEFT_TOP];
float3 bottomLeftPos = float3(id.x - 1, 0, id.z - 1);
float4 bottomLeftData = _SoilDiagData[bottomLeftPos.xz];
float fBL = bottomLeftData[TOP_RIGHT];
float fSum = fL + fT + fR + fB + fLT + fTR + fRB + fBL;
srcData.r += fSum;
float2 erosionMapData = _ErosionMap[id.xz];
erosionMapData.r -= fSum;
erosionMapData.g += fSum;
erosionMapData.r = max(0, erosionMapData.r);
erosionMapData.g = max(0, erosionMapData.g);
_ErosionMap[id.xz] = erosionMapData;
}
void UpdateSimData(inout float4 srcData, inout uint3 id)
{
//srcData.b = srcData.r;
_SimulationData[id.xz] = srcData;
}
[numthreads(8, 1, 8)]
void Simulate(uint3 id: SV_DISPATCHTHREADID)
{
float2 uv = id.xz / _Bounds.xz;
float4 mask = SampleTextureBilinear(_MaskMap, _MaskMapResolution.x, _MaskMapResolution.y, uv);
float4 srcData = _SimulationData[id.xz];
Outflow(srcData, id, mask.a);
UpdateSimData(srcData, id);
GroupMemoryBarrierWithGroupSync();
Inflow(srcData, id);
UpdateSimData(srcData, id);
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 26b74d9d4e2359445b3f198ab5431a8b
ComputeShaderImporter:
externalObjects: {}
currentAPIMask: 4
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 67678e22d4ef9234bb3e6c9cc189fa97
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,150 @@
Shader "Hidden/Griffin/ErosionGeometryLivePreview"
{
Properties
{
_Transparency ("Transparency", Range(0, 1)) = 0.5
_FadeDistance ("Fade Distance", Float) = 0.5
_SimulationData ("Sim Data", 2D) = "black" { }
_FalloffTexture ("Falloff Texture", 2D) = "black" { }
_HeightMap ("Height Map", 2D) = "black" { }
_Height ("Height", Float) = 1
_ErosionMap ("Erosion Map", 2D) = "black" { }
_ErosionSplat ("Erosion Splat", 2D) = "black" { }
_DepositionSplat ("Deposition Splat", 2D) = "black" { }
}
SubShader
{
Tags { "Queue" = "Transparent" "RenderType" = "Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
ZTest Off
Offset -1, -1
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#pragma shader_feature_local SHOW_TEXTURE
#pragma shader_feature_local SHOW_COLOR
#include "UnityCG.cginc"
#include "LivePreviewCommon.cginc"
struct appdata
{
float4 vertex: POSITION;
float2 uv: TEXCOORD0;
};
struct v2f
{
float2 uv: TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex: SV_POSITION;
float4 worldPos: TEXCOORD2;
float4 vertexColor: TEXCOORD3;
};
float _Transparency;
float _FadeDistance;
float4x4 _WorldToSim;
float4x4 _WorldToTerrainUV;
sampler2D _SimulationData;
sampler2D _FalloffTexture;
sampler2D _HeightMap;
float _Height;
sampler2D _ErosionMap;
sampler2D _ErosionSplat;
float4 _ErosionSplat_ST;
float _ErosionIntensity;
float4 _ErosionAlbedo;
sampler2D _DepositionSplat;
float4 _DepositionSplat_ST;
float _DepositionIntensity;
float4 _DepositionAlbedo;
v2f vert(appdata v)
{
v2f o;
float4 worldPos = mul(unity_ObjectToWorld, v.vertex);
float4 simPos = mul(_WorldToSim, float4(worldPos.xyz, 1));
float2 terrainUV = mul(_WorldToTerrainUV, float4(worldPos.xyz, 1)).xz;
float oldHeight = GriffinDecodeFloatRG(tex2Dlod(_HeightMap, float4(terrainUV, 0, 0)).rg) * _Height;
float2 simUv = simPos.xz + float2(0.5, 0.5);
float newHeight = tex2Dlod(_SimulationData, float4(simUv, 0, 0));
float f = saturate(2 * length(simUv - float2(0.5, 0.5)));
float falloff = tex2Dlod(_FalloffTexture, float4(f, 0.5, 0, 0)).r;
newHeight = lerp(oldHeight, newHeight, falloff);
v.vertex.y = newHeight;
o.uv = simUv;
o.vertex = UnityObjectToClipPos(v.vertex);
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
o.vertexColor = float4(
1, 1, 1,
clamp(abs(newHeight - oldHeight) / _FadeDistance, 0, 1)
);
UNITY_TRANSFER_FOG(o, o.vertex);
return o;
}
fixed4 frag(v2f i): SV_Target
{
int isInside = (i.uv.x >= 0) * (i.uv.x <= 1) * (i.uv.y >= 0) * (i.uv.y <= 1);
if (isInside == 0)
{
discard;
}
float4 color = 0;
#if SHOW_TEXTURE || SHOW_COLOR
float4 simPos = mul(_WorldToSim, float4(i.worldPos.xyz, 1));
float2 simUv = simPos.xz + float2(0.5, 0.5);
float2 terrainUV = mul(_WorldToTerrainUV, float4(i.worldPos.xyz, 1)).xz;
float f = saturate(2 * length(simUv - float2(0.5, 0.5)));
float falloff = tex2Dlod(_FalloffTexture, float4(f, 0.5, 0, 0)).r;
float2 erosionData = tex2D(_ErosionMap, simUv).rg;
float4 erosionColor = 0;
#if SHOW_TEXTURE
erosionColor = tex2D(_ErosionSplat, terrainUV * _ErosionSplat_ST.xy + _ErosionSplat_ST.zw);
#elif SHOW_COLOR
erosionColor = _ErosionAlbedo;
#endif
color = lerp(float4(0, 0, 0, 0), erosionColor, saturate(_ErosionIntensity * erosionData.r));
float4 depositionColor = 0;
#if SHOW_TEXTURE
depositionColor = tex2D(_DepositionSplat, terrainUV * _DepositionSplat_ST.xy + _DepositionSplat_ST.zw);
#elif SHOW_COLOR
depositionColor = _DepositionAlbedo;
#endif
color = lerp(color, depositionColor, saturate(_DepositionIntensity * erosionData.g));
color.a = saturate(falloff * max(_ErosionIntensity * erosionData.r, _DepositionIntensity * erosionData.g));
#else
float3 dpdx = ddx(i.worldPos);
float3 dpdy = ddy(i.worldPos);
float3 normal = normalize(cross(dpdy, dpdx));
color = float4((normal.x + 1) * 0.5, (normal.z + 1) * 0.5, (normal.y + 1) * 0.5, _Transparency * i.vertexColor.a);
#endif
UNITY_APPLY_FOG(i.fogCoord, col);
return color;
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,98 @@
Shader "Hidden/Griffin/GeometryLivePreview"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_OldHeightMap ("Old Height Map", 2D) = "black" {}
_NewHeightMap ("New Height Map", 2D) = "black" {}
_Height ("Height", Float) = 1
_Transparency ("Transparency", Range(0,1)) = 0.5
_BoundMin ("Bound Min", Vector) = (0,0,0,1)
_BoundMax ("Bound Max", Vector) = (1,1,1,1)
_FadeDistance ("Fade Distance", Float) = 2
}
SubShader
{
Tags { "Queue"="Transparent" "RenderType"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha
ZTest Off
Offset -1, -1
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#include "UnityCG.cginc"
#include "LivePreviewCommon.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
float4 worldPos : TEXCOORD2;
float4 vertexColor : TEXCOORD3;
};
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _OldHeightMap;
sampler2D _NewHeightMap;
float _Height;
float _Transparency;
float4 _BoundMin;
float4 _BoundMax;
float _FadeDistance;
v2f vert (appdata v)
{
v2f o;
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
float4 worldPos = mul(unity_ObjectToWorld, v.vertex);
float4 heightMapUv = float4(
(worldPos.x-_BoundMin.x)/(_BoundMax.x-_BoundMin.x),
(worldPos.z-_BoundMin.z)/(_BoundMax.z-_BoundMin.z),
0, 0
);
float oldHeight = GriffinDecodeFloatRG(tex2Dlod(_OldHeightMap, heightMapUv).rg)*_Height;
float newHeight = GriffinDecodeFloatRG(tex2Dlod(_NewHeightMap, heightMapUv).rg)*_Height;
v.vertex.y = newHeight;
o.vertex = UnityObjectToClipPos(v.vertex);
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
o.vertexColor = float4(
1,1,1,
clamp(abs(newHeight-oldHeight)/_FadeDistance,0,1)
);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float3 dpdx = ddx(i.worldPos);
float3 dpdy = ddy(i.worldPos);
float3 normal = normalize(cross(dpdy, dpdx));
float4 col = float4(
(normal.x + 1)*0.5,
(normal.z + 1)*0.5,
(normal.y + 1)*0.5,
_Transparency*i.vertexColor.a);
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,68 @@
Shader "Hidden/Griffin/~Internal/GrassPreview"
{
Properties
{
_Color ("Color", Color) = (0, 1, 0, 0.5)
//_MainTex ("Main Texture", 2D) = "white" {}
}
SubShader
{
Tags { "Queue"="Transparent" "RenderType"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha
Cull Off
ZWrite Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
//UNITY_VERTEX_INPUT_INSTANCE_ID
};
//UNITY_INSTANCING_BUFFER_START(Props)
//UNITY_DEFINE_INSTANCED_PROP(float4, _Color)
//UNITY_DEFINE_INSTANCED_PROP(sampler2D, _MainTex)
//UNITY_INSTANCING_BUFFER_END(Props)
//CBUFFER_START(UnityPerMaterial)
float4 _Color;
//CBUFFER_END
//sampler2D _MainTex;
v2f vert (appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
//UNITY_TRANSFER_INSTANCE_ID(v, o);
o.vertex = UnityObjectToClipPos(v.vertex);
//o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
//UNITY_SETUP_INSTANCE_ID(i);
//float4 texColor = tex2D(UNITY_ACCESS_INSTANCED_PROP(Props, _MainTex), i.uv);
///float4 col = float4(texColor.rgb*_Color.rgb, texColor.a*_Color.a);
//return col;
return _Color;
//return float4(0,1,0,0.5);
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,129 @@
#ifndef LIVE_PREVIEW_COMMON_INCLUDED
#define LIVE_PREVIEW_COMMON_INCLUDED
float2 GradientNoise_dir(float2 p)
{
p = p % 289;
float x = (34 * p.x + 1) * p.x % 289 + p.y;
x = (34 * x + 1) * x % 289;
x = frac(x / 41) * 2 - 1;
return normalize(float2(x - floor(x + 0.5), abs(x) - 0.5));
}
float GradientNoise(float2 p)
{
float2 ip = floor(p);
float2 fp = frac(p);
float d00 = dot(GradientNoise_dir(ip), fp);
float d01 = dot(GradientNoise_dir(ip + float2(0, 1)), fp - float2(0, 1));
float d10 = dot(GradientNoise_dir(ip + float2(1, 0)), fp - float2(1, 0));
float d11 = dot(GradientNoise_dir(ip + float2(1, 1)), fp - float2(1, 1));
fp = fp * fp * fp * (fp * (fp * 6 - 15) + 10);
return lerp(lerp(d00, d01, fp.y), lerp(d10, d11, fp.y), fp.x);
}
float InverseLerpUnclamped(float a, float b, float value)
{
//adding a==b check if needed
return (value - a) / (b - a + 0.0000001);
}
float RandomValue(float seed)
{
return frac(sin(dot(float2(seed, seed+1), float2(12.9898, 78.233)))*43758.5453);
}
float RandomValue(float u, float v)
{
return frac(sin(dot(float2(u, v), float2(12.9898, 78.233)))*43758.5453);
}
float2 VoronoiRandomVector (float2 UV, float offset)
{
float2x2 m = float2x2(15.27, 47.63, 99.41, 89.98);
UV = frac(sin(mul(UV, m)) * 46839.32);
return float2(sin(UV.y*+offset)*0.5+0.5, cos(UV.x*offset)*0.5+0.5);
}
float Voronoi(float2 UV, float AngleOffset, float CellDensity)
{
float2 g = floor(UV * CellDensity);
float2 f = frac(UV * CellDensity);
float t = 8.0;
float3 res = float3(8.0, 0.0, 0.0);
float noiseValue = 0;
for(int y=-1; y<=1; y++)
{
for(int x=-1; x<=1; x++)
{
float2 lattice = float2(x,y);
float2 offset = VoronoiRandomVector(lattice + g, AngleOffset);
float d = distance(lattice + offset, f);
if(d < res.x)
{
res = float3(d, offset.x, offset.y);
noiseValue = res.x;
}
}
}
return noiseValue;
}
inline float ValueNoiseInterpolate (float a, float b, float t)
{
return (1.0-t)*a + (t*b);
}
inline float ValueNoise (float2 uv)
{
float2 i = floor(uv);
float2 f = frac(uv);
f = f * f * (3.0 - 2.0 * f);
uv = abs(frac(uv) - 0.5);
float2 c0 = i + float2(0.0, 0.0);
float2 c1 = i + float2(1.0, 0.0);
float2 c2 = i + float2(0.0, 1.0);
float2 c3 = i + float2(1.0, 1.0);
float r0 = RandomValue(c0.x, c0.y);
float r1 = RandomValue(c1.x, c1.y);
float r2 = RandomValue(c2.x, c2.y);
float r3 = RandomValue(c3.x, c3.y);
float bottomOfGrid = ValueNoiseInterpolate(r0, r1, f.x);
float topOfGrid = ValueNoiseInterpolate(r2, r3, f.x);
float t = ValueNoiseInterpolate(bottomOfGrid, topOfGrid, f.y);
return t;
}
float4 MoveTowards(float4 current, float4 target, float maxDistanceDelta)
{
float4 a = target - current;
float magnitude = length(a);
if (magnitude <= maxDistanceDelta || magnitude == 0)
{
return target;
}
return current + a / magnitude * maxDistanceDelta;
}
// Encoding/decoding [0..1) floats into 8 bit/channel RG. Note that 1.0 will not be encoded properly.
inline float2 GriffinEncodeFloatRG(float v)
{
float2 kEncodeMul = float2(1.0, 255.0);
float kEncodeBit = 1.0 / 255.0;
float2 enc = kEncodeMul * v;
enc = frac(enc);
enc.x -= enc.y * kEncodeBit;
return enc;
}
inline float GriffinDecodeFloatRG(float2 enc)
{
float2 kDecodeDot = float2(1.0, 1 / 255.0);
return dot(enc, kDecodeDot);
}
#endif //GRIFFIN_CG_INCLUDED

View File

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

View File

@@ -0,0 +1,87 @@
Shader "Hidden/Griffin/Mask4Channels"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "Queue"="Transparent" "RenderType"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
ZTest LEqual
Offset -1, -1
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#include "UnityCG.cginc"
#include "LivePreviewCommon.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 screenPos : TEXCOORD1;
UNITY_FOG_COORDS(2)
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.uv = v.uv;
o.pos = UnityObjectToClipPos(v.vertex);
o.screenPos = ComputeScreenPos(o.pos);
return o;
}
fixed4 Blend(fixed4 src, fixed4 des)
{
return src*src.a + des*(1-src.a);
}
fixed4 frag(v2f i) : SV_Target
{
float2 screenPos = i.screenPos.xy / i.screenPos.w;
float2 pixel = screenPos.xy * _ScreenParams.xy;
if (floor(pixel.x) % 2 != 0 || floor(pixel.y) % 2 != 0)
{
discard;
}
fixed4 texColor = tex2D(_MainTex, i.uv);
fixed4 baseColor = fixed4(0,0,0,0);
fixed4 red = fixed4(1,0,0,texColor.r);
fixed4 green = fixed4(0,1,0,texColor.g);
fixed4 blue = fixed4(0,0,1,texColor.b);
fixed4 alpha = fixed4(0.8, 0.8, 0.8, texColor.a);
fixed4 rgb=baseColor;
rgb = Blend(red, rgb);
rgb = Blend(green,rgb);
rgb = Blend(blue, rgb);
rgb = Blend(alpha, rgb);
rgb.a = max(max(red.a, green.a), max(blue.a, alpha.a));
UNITY_APPLY_FOG(i.fogCoord, rgb);
return rgb;
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,75 @@
Shader "Hidden/Griffin/MaskVisualizer"
{
Properties
{
_Color ("Color", Color) = (1,0,0,1)
_MainTex ("Texture", 2D) = "white" {}
_Channel ("Channel", Int) = 0
}
SubShader
{
Tags { "Queue"="Transparent" "RenderType"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
ZTest LEqual
Offset -1, -1
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#include "UnityCG.cginc"
#include "LivePreviewCommon.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 screenPos : TEXCOORD1;
UNITY_FOG_COORDS(2)
};
fixed4 _Color;
sampler2D _MainTex;
float4 _MainTex_ST;
int _Channel;
v2f vert (appdata v)
{
v2f o;
o.uv = v.uv;
o.pos = UnityObjectToClipPos(v.vertex);
o.screenPos = ComputeScreenPos(o.pos);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
float2 screenPos = i.screenPos.xy / i.screenPos.w;
float2 pixel = screenPos.xy * _ScreenParams.xy;
if (floor(pixel.x) % 2 != 0 || floor(pixel.y) % 2 != 0)
{
discard;
}
fixed4 texColor = tex2D(_MainTex, i.uv);
fixed4 col = float4(_Color.rgb, _Color.a*texColor[_Channel]);
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,89 @@
Shader "Hidden/Griffin/SubdivLivePreview2"
{
Properties
{
_Color ("Line Color", Color) = (1,1,1,1)
_HeightMap ("Height Map", 2D) = "black" {}
_Dimension ("Dimension", Vector) = (0,0,0,0)
_SubdivMap ("Subdiv Map", 2D) = "black" {}
_SubdivRange("Subdiv Range", Vector) = (0,0,0,0)
_Mask ("Mask", 2D) = "white" {}
}
SubShader
{
Pass
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
ZTest Always
LOD 200
CGPROGRAM
#include "UnityCG.cginc"
#include "LivePreviewCommon.cginc"
#pragma vertex vert
#pragma fragment frag
struct v2f
{
float4 pos : POSITION; // vertex position
float2 heightMapUv : TEXCOORD1;
float4 worldPos : TEXCOORD2;
};
float4 _Color;
sampler2D _HeightMap;
float4 _Dimension;
float4 _BoundMin;
float4 _BoundMax;
sampler2D _SubdivMap;
float4 _SubdivRange;
sampler2D _Mask;
float4x4 _WorldPointToMask;
v2f vert(appdata_base v)
{
v2f output;
float4 worldPos = mul(unity_ObjectToWorld, v.vertex);
float4 heightMapUv = float4(
(worldPos.x-_BoundMin.x)/(_BoundMax.x-_BoundMin.x),
(worldPos.z-_BoundMin.z)/(_BoundMax.z-_BoundMin.z),
0, 0
);
float newHeight = GriffinDecodeFloatRG(tex2Dlod(_HeightMap, heightMapUv).rg)*_Dimension.y;
v.vertex.y = newHeight;
output.pos = UnityObjectToClipPos(v.vertex);
output.heightMapUv = heightMapUv;
output.worldPos = worldPos;
return output;
}
float4 frag(v2f input) : COLOR
{
float2 maskUv = mul(_WorldPointToMask, input.worldPos).xz;
if (maskUv.x < 0) discard;
if (maskUv.x > 1) discard;
if (maskUv.y < 0) discard;
if (maskUv.y > 1) discard;
float4 col = _Color;
float subdivValue = tex2D(_SubdivMap, input.heightMapUv.xy).r;
float maskValue = tex2D(_Mask, maskUv).r;
col.a *= col.a*maskValue*(subdivValue >= _SubdivRange.x)*(subdivValue <= _SubdivRange.y);
return col;
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,102 @@
Shader "Hidden/Griffin/VisibilityLivePreview2"
{
Properties
{
_Color ("Line Color", Color) = (1,1,1,1)
_HeightMap ("Height Map", 2D) = "black" {}
_Dimension ("Dimension", Vector) = (0,0,0,0)
_SubdivMap ("Subdiv Map", 2D) = "black" {}
_SubdivRange("Subdiv Range", Vector) = (0,0,0,0)
_Mask ("Mask", 2D) = "white" {}
}
SubShader
{
Pass
{
Tags { "RenderType"="AlphaTest" "Queue"="Overlay" }
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
ZTest Always
LOD 200
CGPROGRAM
#include "UnityCG.cginc"
#include "LivePreviewCommon.cginc"
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ USE_MASK
struct v2f
{
float4 pos : POSITION;
float2 heightMapUv : TEXCOORD1;
float4 worldPos : TEXCOORD2;
};
float4 _Color;
sampler2D _HeightMap;
float4 _Dimension;
float4 _BoundMin;
float4 _BoundMax;
sampler2D _SubdivMap;
float4 _SubdivRange;
sampler2D _Mask;
float4x4 _WorldPointToMask;
v2f vert(appdata_base v)
{
v2f output;
float4 worldPos = mul(unity_ObjectToWorld, v.vertex);
float4 heightMapUv = float4(
(worldPos.x-_BoundMin.x)/(_BoundMax.x-_BoundMin.x),
(worldPos.z-_BoundMin.z)/(_BoundMax.z-_BoundMin.z),
0, 0
);
float newHeight = GriffinDecodeFloatRG(tex2Dlod(_HeightMap, heightMapUv).rg)*_Dimension.y;
v.vertex.y = newHeight;
output.pos = UnityObjectToClipPos(v.vertex);
output.heightMapUv = heightMapUv;
output.worldPos = worldPos;
return output;
}
float4 frag(v2f input) : COLOR
{
#if USE_MASK
float2 maskUv = mul(_WorldPointToMask, input.worldPos).xz;
if (maskUv.x < 0) discard;
if (maskUv.x > 1) discard;
if (maskUv.y < 0) discard;
if (maskUv.y > 1) discard;
#endif
float visibilityValue = tex2D(_HeightMap, input.heightMapUv.xy).a;
if (visibilityValue >= 0.5)
discard;
float subdivValue = tex2D(_SubdivMap, input.heightMapUv.xy).r;
#if USE_MASK
float maskValue = tex2D(_Mask, maskUv).r;
#else
float maskValue = 1;
#endif
float4 col = _Color;
col.a *= col.a*maskValue*(subdivValue >= _SubdivRange.x)*(subdivValue <= _SubdivRange.y);
return col;
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,113 @@
Shader "Hidden/Griffin/Wireframe"
{
Properties
{
_Color("Line Color", Color) = (1,1,1,1)
_MainTex("Main Texture", 2D) = "white" {}
_Thickness("Thickness", Float) = 1
}
SubShader
{
Pass
{
Tags { "RenderType" = "Opaque" "Queue" = "Geometry" }
Blend SrcAlpha OneMinusSrcAlpha
LOD 200
CGPROGRAM
#pragma target 5.0
#include "UnityCG.cginc"
#pragma vertex vert
#pragma fragment frag
#pragma geometry geom
struct v2g
{
float4 pos : POSITION; // vertex position
float2 uv : TEXCOORD0; // vertex uv coordinate
};
struct g2f
{
float4 pos : POSITION; // fragment position
float2 uv : TEXCOORD0; // fragment uv coordinate
float3 dist : TEXCOORD1; // distance to each edge of the triangle
};
float _Thickness = 1; // Thickness of the wireframe line rendering
float4 _Color = {1,1,1,1}; // Color of the line
float4 _MainTex_ST; // For the Main Tex UV transform
sampler2D _MainTex; // Texture used for the line
v2g vert(appdata_base v)
{
v2g output;
output.pos = UnityObjectToClipPos(v.vertex);
output.uv = TRANSFORM_TEX(v.texcoord, _MainTex);//v.texcoord;
return output;
}
[maxvertexcount(3)]
void geom(triangle v2g p[3], inout TriangleStream<g2f> triStream)
{
//points in screen space
float2 p0 = _ScreenParams.xy * p[0].pos.xy / p[0].pos.w;
float2 p1 = _ScreenParams.xy * p[1].pos.xy / p[1].pos.w;
float2 p2 = _ScreenParams.xy * p[2].pos.xy / p[2].pos.w;
//edge vectors
float2 v0 = p2 - p1;
float2 v1 = p2 - p0;
float2 v2 = p1 - p0;
//area of the triangle
float area = abs(v1.x * v2.y - v1.y * v2.x);
//values based on distance to the edges
float dist0 = area / length(v0);
float dist1 = area / length(v1);
float dist2 = area / length(v2);
g2f pIn;
//add the first point
pIn.pos = p[0].pos;
pIn.uv = p[0].uv;
pIn.dist = float3(dist0,0,0);
triStream.Append(pIn);
//add the second point
pIn.pos = p[1].pos;
pIn.uv = p[1].uv;
pIn.dist = float3(0,dist1,0);
triStream.Append(pIn);
//add the third point
pIn.pos = p[2].pos;
pIn.uv = p[2].uv;
pIn.dist = float3(0,0,dist2);
triStream.Append(pIn);
}
float4 frag(g2f input) : COLOR
{
//find the smallest distance
float val = min(input.dist.x, min(input.dist.y, input.dist.z));
//calculate power to 2 to thin the line
val = exp2(-1 / _Thickness * val * val);
//blend between the lines and the negative space to give illusion of anti aliasing
float4 targetColor = _Color * tex2D(_MainTex, input.uv);
float4 transCol = _Color * tex2D(_MainTex, input.uv);
transCol.a = 0;
return val * targetColor + (1 - val) * transCol;
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bed7842b272345940a7ad85482e244ab
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,244 @@
Shader "Hidden/Griffin/AlbedoPainter"
{
Properties
{
_Color ("Color", Color) = (1, 1, 1, 1)
_MainTex ("Texture", 2D) = "black" { }
_MainTex_Left ("MainTex_Left", 2D) = "black" { }
_MainTex_TopLeft ("MainTex_TopLeft", 2D) = "black" { }
_MainTex_Top ("MainTex_Top", 2D) = "black" { }
_MainTex_TopRight ("MainTex_TopRight", 2D) = "black" { }
_MainTex_Right ("MainTex_Right", 2D) = "black" { }
_MainTex_BottomRight ("MainTex_BottomRight", 2D) = "black" { }
_MainTex_Bottom ("MainTex_Bottom", 2D) = "black" { }
_MainTex_BottomLeft ("MainTex_BottomLeft", 2D) = "black" { }
_Mask ("Mask", 2D) = "white" { }
_Opacity ("Opacity", Float) = 1
_TerrainMask ("Terrain Mask", 2D) = "black" { }
}
CGINCLUDE
#include "UnityCG.cginc"
#include "ConditionalPainting.cginc"
struct appdata
{
float4 vertex: POSITION;
float2 uv: TEXCOORD0;
};
struct v2f
{
float2 uv: TEXCOORD0;
float4 vertex: SV_POSITION;
float4 localPos: TEXCOORD1;
};
float4 _Color;
sampler2D _MainTex;
float4 _MainTex_TexelSize;
sampler2D _MainTex_Left;
sampler2D _MainTex_TopLeft;
sampler2D _MainTex_Top;
sampler2D _MainTex_TopRight;
sampler2D _MainTex_Right;
sampler2D _MainTex_BottomRight;
sampler2D _MainTex_Bottom;
sampler2D _MainTex_BottomLeft;
sampler2D _Mask;
float _Opacity;
sampler2D _TerrainMask;
sampler2D textureGrid[3][3];
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.localPos = v.vertex;
return o;
}
fixed4 fragPaint(v2f i): SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 maskColor = tex2D(_Mask, i.uv);
float maskGray = maskColor.r;
float conditionalMask = ComputeRuleMask(i.localPos);
float4 overlayColor = float4(_Color.rgb, _Color.a * maskGray * _Opacity * terrainMask * conditionalMask);
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 desColor = overlayColor * overlayColor.a + currentColor * (1 - overlayColor.a);
float alpha = 1 - (1 - overlayColor.a) * (1 - currentColor.a);
return float4(desColor.rgb, alpha);
}
fixed4 fragErase(v2f i): SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 backgroundColor = float4(0, 0, 0, 0);
float4 maskColor = tex2D(_Mask, i.uv);
float maskGray = maskColor.r;
float conditionalMask = ComputeRuleMask(i.localPos);
float f = maskGray * _Opacity * terrainMask * conditionalMask;
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 dir = normalize(backgroundColor - currentColor) * f;
float4 desColor = saturate(currentColor + dir);
return desColor;
}
fixed4 fragSmooth(v2f i): SV_Target
{
textureGrid[0][0] = _MainTex_BottomLeft;
textureGrid[1][0] = _MainTex_Bottom;
textureGrid[2][0] = _MainTex_BottomRight;
textureGrid[0][1] = _MainTex_Left;
textureGrid[1][1] = _MainTex;
textureGrid[2][1] = _MainTex_Right;
textureGrid[0][2] = _MainTex_TopLeft;
textureGrid[1][2] = _MainTex_Top;
textureGrid[2][2] = _MainTex_TopRight;
float2 texel = _MainTex_TexelSize.xy;
float4 avgColor = float4(0, 0, 0, 0);
float sampleCount = 0;
int indexX = 0;
int indexY = 0;
float2 uv = float2(0, 0);
float4 c = float4(0, 0, 0, 0);
for (int x0 = -3; x0 <= 3; ++x0)
{
for (int y0 = -3; y0 <= 3; ++y0)
{
uv = i.localPos + float2(x0 * texel.x, y0 * texel.y);
indexX = lerp(lerp(1, 2, uv.x > 1), 0, uv.x < 0);
indexY = lerp(lerp(1, 2, uv.y > 1), 0, uv.y < 0);
uv.x = lerp(lerp(uv.x, uv.x - 1, uv.x > 1), uv.x + 1, uv.x < 0);
uv.y = lerp(lerp(uv.y, uv.y - 1, uv.y > 1), uv.y + 1, uv.y < 0);
if (indexX == 0)
{
if (indexY == 0)
{
c = tex2D(textureGrid[0][0], uv);
}
if (indexY == 1)
{
c = tex2D(textureGrid[0][1], uv);
}
if (indexY == 2)
{
c = tex2D(textureGrid[0][2], uv);
}
}
if (indexX == 1)
{
if (indexY == 0)
{
c = tex2D(textureGrid[1][0], uv);
}
if (indexY == 1)
{
c = tex2D(textureGrid[1][1], uv);
}
if (indexY == 2)
{
c = tex2D(textureGrid[1][2], uv);
}
}
if (indexX == 2)
{
if (indexY == 0)
{
c = tex2D(textureGrid[2][0], uv);
}
if (indexY == 1)
{
c = tex2D(textureGrid[2][1], uv);
}
if (indexY == 2)
{
c = tex2D(textureGrid[2][2], uv);
}
}
avgColor += c;
sampleCount += 1;
}
}
avgColor = avgColor / sampleCount;
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 maskColor = tex2D(_Mask, i.uv);
float maskValue = maskColor.r;
float conditionalMask = ComputeRuleMask(i.localPos);
float4 desColor = lerp(currentColor, avgColor, maskValue * _Opacity * terrainMask * conditionalMask);
return desColor;
}
ENDCG
SubShader
{
Tags { "RenderType" = "Transparent" }
Pass
{
Name "Paint"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma shader_feature BLEND_HEIGHT
#pragma shader_feature BLEND_SLOPE
#pragma shader_feature BLEND_NOISE
#pragma vertex vert
#pragma fragment fragPaint
ENDCG
}
Pass
{
Name "Erase"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma shader_feature BLEND_HEIGHT
#pragma shader_feature BLEND_SLOPE
#pragma shader_feature BLEND_NOISE
#pragma vertex vert
#pragma fragment fragErase
ENDCG
}
Pass
{
Name "Smooth"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma shader_feature BLEND_HEIGHT
#pragma shader_feature BLEND_SLOPE
#pragma shader_feature BLEND_NOISE
#pragma vertex vert
#pragma fragment fragSmooth
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,81 @@
#ifndef CONDITIONAL_PAINTING_INCLUDED
#define CONDITIONAL_PAINTING_INCLUDED
#include "PaintToolCommon.cginc"
//Include these lines in the main shader Pass code
//#pragma shader_feature BLEND_HEIGHT
//#pragma shader_feature BLEND_SLOPE
//#pragma shader_feature BLEND_NOISE
float _MinHeight;
float _MaxHeight;
sampler2D _HeightTransition;
float _MinSlope;
float _MaxSlope;
sampler2D _SlopeTransition;
float4 _NoiseOrigin;
float _NoiseFrequency;
int _NoiseOctaves;
float _NoiseLacunarity;
float _NoisePersistence;
sampler2D _NoiseRemap;
sampler2D _HeightMap;
sampler2D _NormalMap;
float4 _TerrainDimension;
float ComputeRuleMask(float2 terrainUV)
{
float blendHeightValue = 1;
float4 heightMapColor = tex2D(_HeightMap, terrainUV);
float height = GriffinDecodeFloatRG(heightMapColor.rg);
#if BLEND_HEIGHT
float heightTransitionFactor = (height - _MinHeight) / (_MaxHeight - _MinHeight);
float heightTransition = tex2D(_HeightTransition, float2(heightTransitionFactor, 0.5)).r;
blendHeightValue = (height >= _MinHeight) * (height <= _MaxHeight) * heightTransition;
#endif
float blendSlopeValue = 1;
#if BLEND_SLOPE
float4 normalMapColor = tex2D(_NormalMap, terrainUV);
float3 normalVector = normalMapColor * 2 - float3(1, 1, 1);
float cosine = abs(normalVector.y);
float slopeAngle = acos(cosine);
float slopeTransitionFactor = (slopeAngle - _MinSlope) / (_MaxSlope - _MinSlope);
float slopeTransition = tex2D(_SlopeTransition, float2(slopeTransitionFactor, 0.5f)).r;
blendSlopeValue = (slopeAngle >= _MinSlope) * (slopeAngle <= _MaxSlope) * slopeTransition;
#endif
float blendNoiseValue = 1;
#if BLEND_NOISE
float2 refSize = float2(1, 1);
float noiseValue = 0;
float frequency = _NoiseFrequency;
float amplitude = 1;
float2 noisePos;
float2 uv;
float sampledNoise;
float2 worldXZ = float2(_TerrainDimension.x + terrainUV.x * _TerrainDimension.z, _TerrainDimension.y + terrainUV.y * _TerrainDimension.w)/1000;
for (int octave = 0; octave < 4; ++octave)
{
frequency = frequency * pow(_NoiseLacunarity, octave);
amplitude = amplitude * pow(_NoisePersistence, octave);
noisePos = _NoiseOrigin.xy + worldXZ * frequency;
uv = float2(noisePos.x / refSize.x, noisePos.y / refSize.y);
sampledNoise = GradientNoise(uv) * amplitude * (octave < _NoiseOctaves);
noiseValue += sampledNoise;
}
float remapFactor = noiseValue * 0.5 + 0.5;
blendNoiseValue = tex2D(_NoiseRemap, float2(remapFactor, 0.5)).a;
#endif
float result = blendHeightValue * blendSlopeValue * blendNoiseValue;
return result;
}
#endif // CONDITIONAL_PAINTING_INCLUDED

View File

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

View File

@@ -0,0 +1,228 @@
Shader "Hidden/Griffin/ElevationPainter"
{
Properties
{
_MainTex("MainTex", 2D) = "black" {}
_MainTex_Left("MainTex_Left", 2D) = "black" {}
_MainTex_TopLeft("MainTex_TopLeft", 2D) = "black" {}
_MainTex_Top("MainTex_Top", 2D) = "black" {}
_MainTex_TopRight("MainTex_TopRight", 2D) = "black" {}
_MainTex_Right("MainTex_Right", 2D) = "black" {}
_MainTex_BottomRight("MainTex_BottomRight", 2D) = "black" {}
_MainTex_Bottom("MainTex_Bottom", 2D) = "black" {}
_MainTex_BottomLeft("MainTex_BottomLeft", 2D) = "black" {}
_Mask("Mask", 2D) = "white" {}
_Opacity("Opacity", Float) = 1
_TerrainMask("Terrain Mask", 2D) = "black" {}
}
CGINCLUDE
#include "UnityCG.cginc"
#include "PaintToolCommon.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 localPos : TEXCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_TexelSize;
sampler2D _MainTex_Left;
sampler2D _MainTex_TopLeft;
sampler2D _MainTex_Top;
sampler2D _MainTex_TopRight;
sampler2D _MainTex_Right;
sampler2D _MainTex_BottomRight;
sampler2D _MainTex_Bottom;
sampler2D _MainTex_BottomLeft;
sampler2D _Mask;
float _Opacity;
sampler2D _TerrainMask;
sampler2D textureGrid[3][3];
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.localPos = v.vertex;
return o;
}
fixed4 fragRaise(v2f i) : SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 maskColor = tex2D(_Mask, i.uv);
float4 currentColor = tex2D(_MainTex, i.localPos);
float currentHeight = GriffinDecodeFloatRG(currentColor.rg);
float desHeight = max(0, min(0.999999, currentHeight + maskColor.r * terrainMask * _Opacity));
float2 encodedHeight = GriffinEncodeFloatRG(desHeight);
return saturate(float4(encodedHeight.rg, currentColor.b, currentColor.a));
}
fixed4 fragLower(v2f i) : SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 maskColor = tex2D(_Mask, i.uv);
float4 currentColor = tex2D(_MainTex, i.localPos);
float currentHeight = GriffinDecodeFloatRG(currentColor.rg);
float desHeight = max(0, min(0.999999, currentHeight - maskColor.r * terrainMask * _Opacity));
float2 encodedHeight = GriffinEncodeFloatRG(desHeight);
return saturate(float4(encodedHeight.rg, currentColor.b, currentColor.a));
}
fixed4 fragSmooth(v2f i) : SV_Target
{
textureGrid[0][0] = _MainTex_BottomLeft;
textureGrid[1][0] = _MainTex_Bottom;
textureGrid[2][0] = _MainTex_BottomRight;
textureGrid[0][1] = _MainTex_Left;
textureGrid[1][1] = _MainTex;
textureGrid[2][1] = _MainTex_Right;
textureGrid[0][2] = _MainTex_TopLeft;
textureGrid[1][2] = _MainTex_Top;
textureGrid[2][2] = _MainTex_TopRight;
float2 texel = _MainTex_TexelSize.xy;
float avgHeight = 0;
float sampleCount = 0;
int indexX = 0;
int indexY = 0;
float2 uv = float2(0,0);
float4 c = float4(0,0,0,0);
for (int x0 = -3; x0 <= 3; ++x0)
{
for (int y0 = -3; y0 <= 3; ++y0)
{
uv = i.localPos + float2(x0 * texel.x, y0 * texel.y);
indexX = lerp(lerp(1, 2, uv.x > 1), 0, uv.x < 0);
indexY = lerp(lerp(1, 2, uv.y > 1), 0, uv.y < 0);
uv.x = lerp(lerp(uv.x, uv.x - 1, uv.x > 1), uv.x + 1, uv.x < 0);
uv.y = lerp(lerp(uv.y, uv.y - 1, uv.y > 1), uv.y + 1, uv.y < 0);
if (indexX == 0)
{
if (indexY == 0)
{
c = tex2D(textureGrid[0][0], uv);
}
if (indexY == 1)
{
c = tex2D(textureGrid[0][1], uv);
}
if (indexY == 2)
{
c = tex2D(textureGrid[0][2], uv);
}
}
if (indexX == 1)
{
if (indexY == 0)
{
c = tex2D(textureGrid[1][0], uv);
}
if (indexY == 1)
{
c = tex2D(textureGrid[1][1], uv);
}
if (indexY == 2)
{
c = tex2D(textureGrid[1][2], uv);
}
}
if (indexX == 2)
{
if (indexY == 0)
{
c = tex2D(textureGrid[2][0], uv);
}
if (indexY == 1)
{
c = tex2D(textureGrid[2][1], uv);
}
if (indexY == 2)
{
c = tex2D(textureGrid[2][2], uv);
}
}
avgHeight += GriffinDecodeFloatRG(c.rg);
sampleCount += 1;
}
}
avgHeight = avgHeight / sampleCount;
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 maskColor = tex2D(_Mask, i.uv);
float maskValue = maskColor.r;
float currentHeight = GriffinDecodeFloatRG(currentColor.rg);
float value = max(0, min(0.999999, lerp(currentHeight, avgHeight, maskValue * terrainMask * _Opacity)));
float2 encodedHeight = GriffinEncodeFloatRG(value);
return saturate(float4(encodedHeight.rg, currentColor.b, currentColor.a));
}
ENDCG
SubShader
{
Tags{ "RenderType" = "Transparent" }
Pass
{
Name "Raise"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment fragRaise
ENDCG
}
Pass
{
Name "Lower"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment fragLower
ENDCG
}
Pass
{
Name "Smooth"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment fragSmooth
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,75 @@
Shader "Hidden/Griffin/HeightSamplingPainter"
{
Properties
{
_MainTex ("Main Texture", 2D) = "black" {}
_Mask ("Mask", 2D) = "white" {}
_Opacity ("Opacity", Float) = 1
_TargetGray ("Target Gray", Float) = 0
_TerrainMask ("Terrain Mask", 2D) = "black" {}
}
CGINCLUDE
#include "UnityCG.cginc"
#include "PaintToolCommon.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 localPos : TEXCOORD1;
};
sampler2D _MainTex;
sampler2D _Mask;
float _Opacity;
float _TargetGray;
sampler2D _TerrainMask;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.localPos = v.vertex;
return o;
}
fixed4 fragSetHeight(v2f i) : SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 maskColor = tex2D(_Mask, i.uv);
float f = maskColor.r*_Opacity*terrainMask;
float current = GriffinDecodeFloatRG(currentColor.rg);
float target = clamp(_TargetGray, 0, 1);
float gray = max(0, min(0.999999, lerp(current, target, f)));
float2 encodedHeight = GriffinEncodeFloatRG(gray);
return saturate(float4(encodedHeight, currentColor.b, currentColor.a));
}
ENDCG
SubShader
{
Tags { "RenderType"="Transparent" }
Pass
{
Name "Set Height"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment fragSetHeight
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,232 @@
Shader "Hidden/Griffin/MaskPainter"
{
Properties
{
_MainTex ("MainTex", 2D) = "black" { }
_MainTex_Left ("MainTex_Left", 2D) = "black" { }
_MainTex_TopLeft ("MainTex_TopLeft", 2D) = "black" { }
_MainTex_Top ("MainTex_Top", 2D) = "black" { }
_MainTex_TopRight ("MainTex_TopRight", 2D) = "black" { }
_MainTex_Right ("MainTex_Right", 2D) = "black" { }
_MainTex_BottomRight ("MainTex_BottomRight", 2D) = "black" { }
_MainTex_Bottom ("MainTex_Bottom", 2D) = "black" { }
_MainTex_BottomLeft ("MainTex_BottomLeft", 2D) = "black" { }
_Mask ("Mask", 2D) = "white" { }
_Opacity ("Opacity", Float) = 1
_Channel ("Channel", Vector) = (1, 0, 0, 0)
}
CGINCLUDE
#include "UnityCG.cginc"
#include "ConditionalPainting.cginc"
struct appdata
{
float4 vertex: POSITION;
float2 uv: TEXCOORD0;
};
struct v2f
{
float2 uv: TEXCOORD0;
float4 vertex: SV_POSITION;
float4 localPos: TEXCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_TexelSize;
sampler2D _MainTex_Left;
sampler2D _MainTex_TopLeft;
sampler2D _MainTex_Top;
sampler2D _MainTex_TopRight;
sampler2D _MainTex_Right;
sampler2D _MainTex_BottomRight;
sampler2D _MainTex_Bottom;
sampler2D _MainTex_BottomLeft;
sampler2D _Mask;
float _Opacity;
float4 _Channel;
sampler2D textureGrid[3][3];
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.localPos = v.vertex;
return o;
}
fixed4 fragPaint(v2f i): SV_Target
{
float4 maskColor = tex2D(_Mask, i.uv);
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 des = currentColor + maskColor.rrrr * _Channel * _Opacity * ComputeRuleMask(i.localPos);
des = saturate(des);
return des;
}
fixed4 fragErase(v2f i): SV_Target
{
float4 maskColor = tex2D(_Mask, i.uv);
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 des = currentColor - maskColor.rrrr * _Channel * _Opacity * ComputeRuleMask(i.localPos);
return saturate(des);
}
fixed4 fragSmooth(v2f i): SV_Target
{
textureGrid[0][0] = _MainTex_BottomLeft;
textureGrid[1][0] = _MainTex_Bottom;
textureGrid[2][0] = _MainTex_BottomRight;
textureGrid[0][1] = _MainTex_Left;
textureGrid[1][1] = _MainTex;
textureGrid[2][1] = _MainTex_Right;
textureGrid[0][2] = _MainTex_TopLeft;
textureGrid[1][2] = _MainTex_Top;
textureGrid[2][2] = _MainTex_TopRight;
float2 texel = _MainTex_TexelSize.xy;
float4 avg = 0;
float sampleCount = 0;
int indexX = 0;
int indexY = 0;
float2 uv = float2(0, 0);
float4 c = float4(0, 0, 0, 0);
for (int x0 = -3; x0 <= 3; ++x0)
{
for (int y0 = -3; y0 <= 3; ++y0)
{
uv = i.localPos + float2(x0 * texel.x, y0 * texel.y);
indexX = lerp(lerp(1, 2, uv.x > 1), 0, uv.x < 0);
indexY = lerp(lerp(1, 2, uv.y > 1), 0, uv.y < 0);
uv.x = lerp(lerp(uv.x, uv.x - 1, uv.x > 1), uv.x + 1, uv.x < 0);
uv.y = lerp(lerp(uv.y, uv.y - 1, uv.y > 1), uv.y + 1, uv.y < 0);
if (indexX == 0)
{
if (indexY == 0)
{
c = tex2D(textureGrid[0][0], uv);
}
if (indexY == 1)
{
c = tex2D(textureGrid[0][1], uv);
}
if (indexY == 2)
{
c = tex2D(textureGrid[0][2], uv);
}
}
if (indexX == 1)
{
if (indexY == 0)
{
c = tex2D(textureGrid[1][0], uv);
}
if (indexY == 1)
{
c = tex2D(textureGrid[1][1], uv);
}
if (indexY == 2)
{
c = tex2D(textureGrid[1][2], uv);
}
}
if (indexX == 2)
{
if (indexY == 0)
{
c = tex2D(textureGrid[2][0], uv);
}
if (indexY == 1)
{
c = tex2D(textureGrid[2][1], uv);
}
if (indexY == 2)
{
c = tex2D(textureGrid[2][2], uv);
}
}
avg += c;
sampleCount += 1;
}
}
avg = avg / sampleCount;
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 maskColor = tex2D(_Mask, i.uv);
float maskValue = maskColor.r;
float4 value = lerp(currentColor, avg, maskValue * _Opacity * _Channel * ComputeRuleMask(i.localPos));
return saturate(value);
}
ENDCG
SubShader
{
Tags { "RenderType" = "Transparent" }
Pass
{
Name "Paint"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma shader_feature BLEND_HEIGHT
#pragma shader_feature BLEND_SLOPE
#pragma shader_feature BLEND_NOISE
#pragma vertex vert
#pragma fragment fragPaint
ENDCG
}
Pass
{
Name "Erase"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma shader_feature BLEND_HEIGHT
#pragma shader_feature BLEND_SLOPE
#pragma shader_feature BLEND_NOISE
#pragma vertex vert
#pragma fragment fragErase
ENDCG
}
Pass
{
Name "Smooth"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma shader_feature BLEND_HEIGHT
#pragma shader_feature BLEND_SLOPE
#pragma shader_feature BLEND_NOISE
#pragma vertex vert
#pragma fragment fragSmooth
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,263 @@
Shader "Hidden/Griffin/MetallicPainter"
{
Properties
{
_Color ("Color", Color) = (1, 1, 1, 1)
_MainTex ("Texture", 2D) = "black" { }
_MainTex_Left ("MainTex_Left", 2D) = "black" { }
_MainTex_TopLeft ("MainTex_TopLeft", 2D) = "black" { }
_MainTex_Top ("MainTex_Top", 2D) = "black" { }
_MainTex_TopRight ("MainTex_TopRight", 2D) = "black" { }
_MainTex_Right ("MainTex_Right", 2D) = "black" { }
_MainTex_BottomRight ("MainTex_BottomRight", 2D) = "black" { }
_MainTex_Bottom ("MainTex_Bottom", 2D) = "black" { }
_MainTex_BottomLeft ("MainTex_BottomLeft", 2D) = "black" { }
_Mask ("Mask", 2D) = "white" { }
_Opacity ("Opacity", Float) = 1
_TerrainMask ("Terrain Mask", 2D) = "black" { }
}
CGINCLUDE
#include "UnityCG.cginc"
#include "ConditionalPainting.cginc"
struct appdata
{
float4 vertex: POSITION;
float2 uv: TEXCOORD0;
};
struct v2f
{
float2 uv: TEXCOORD0;
float4 vertex: SV_POSITION;
float4 localPos: TEXCOORD1;
};
float4 _Color;
sampler2D _MainTex;
float4 _MainTex_TexelSize;
sampler2D _MainTex_Left;
sampler2D _MainTex_TopLeft;
sampler2D _MainTex_Top;
sampler2D _MainTex_TopRight;
sampler2D _MainTex_Right;
sampler2D _MainTex_BottomRight;
sampler2D _MainTex_Bottom;
sampler2D _MainTex_BottomLeft;
sampler2D _Mask;
float _Opacity;
sampler2D _TerrainMask;
sampler2D textureGrid[3][3];
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.localPos = v.vertex;
return o;
}
fixed4 fragPaint(v2f i): SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 maskColor = tex2D(_Mask, i.uv);
float maskGray = maskColor.r;
float4 currentColor = tex2D(_MainTex, i.localPos);
float currentValue = currentColor.r;
float addictiveValue = maskGray * _Color.r * _Opacity * terrainMask * ComputeRuleMask(i.localPos);
float newValue = saturate(currentValue + addictiveValue);
return float4(newValue, newValue, newValue, currentColor.a); //keep the alpha channel for smoothness value
}
fixed4 fragErase(v2f i): SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 maskColor = tex2D(_Mask, i.uv);
float maskGray = maskColor.r;
float4 currentColor = tex2D(_MainTex, i.localPos);
float currentValue = currentColor.r;
float subtractiveValue = maskGray * _Color.r * _Opacity * terrainMask * ComputeRuleMask(i.localPos);
float newValue = saturate(currentValue - subtractiveValue);
return float4(newValue, newValue, newValue, currentColor.a); //keep the alpha channel for smoothness value
}
fixed4 fragSmooth(v2f i): SV_Target
{
textureGrid[0][0] = _MainTex_BottomLeft;
textureGrid[1][0] = _MainTex_Bottom;
textureGrid[2][0] = _MainTex_BottomRight;
textureGrid[0][1] = _MainTex_Left;
textureGrid[1][1] = _MainTex;
textureGrid[2][1] = _MainTex_Right;
textureGrid[0][2] = _MainTex_TopLeft;
textureGrid[1][2] = _MainTex_Top;
textureGrid[2][2] = _MainTex_TopRight;
float2 texel = _MainTex_TexelSize.xy;
float4 avgColor = float4(0, 0, 0, 0);
float sampleCount = 0;
int indexX = 0;
int indexY = 0;
float2 uv = float2(0, 0);
float4 c = float4(0, 0, 0, 0);
for (int x0 = -3; x0 <= 3; ++x0)
{
for (int y0 = -3; y0 <= 3; ++y0)
{
uv = i.localPos + float2(x0 * texel.x, y0 * texel.y);
indexX = lerp(lerp(1, 2, uv.x > 1), 0, uv.x < 0);
indexY = lerp(lerp(1, 2, uv.y > 1), 0, uv.y < 0);
uv.x = lerp(lerp(uv.x, uv.x - 1, uv.x > 1), uv.x + 1, uv.x < 0);
uv.y = lerp(lerp(uv.y, uv.y - 1, uv.y > 1), uv.y + 1, uv.y < 0);
if (indexX == 0)
{
if (indexY == 0)
{
c = tex2D(textureGrid[0][0], uv);
}
if (indexY == 1)
{
c = tex2D(textureGrid[0][1], uv);
}
if (indexY == 2)
{
c = tex2D(textureGrid[0][2], uv);
}
}
if (indexX == 1)
{
if (indexY == 0)
{
c = tex2D(textureGrid[1][0], uv);
}
if (indexY == 1)
{
c = tex2D(textureGrid[1][1], uv);
}
if (indexY == 2)
{
c = tex2D(textureGrid[1][2], uv);
}
}
if (indexX == 2)
{
if (indexY == 0)
{
c = tex2D(textureGrid[2][0], uv);
}
if (indexY == 1)
{
c = tex2D(textureGrid[2][1], uv);
}
if (indexY == 2)
{
c = tex2D(textureGrid[2][2], uv);
}
}
avgColor += c;
sampleCount += 1;
}
}
avgColor = avgColor / sampleCount;
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 maskColor = tex2D(_Mask, i.uv);
float maskValue = maskColor.r;
float4 desColor = lerp(currentColor, avgColor, maskValue * _Opacity * terrainMask * ComputeRuleMask(i.localPos));
float newValue = desColor.r;
return float4(newValue, newValue, newValue, currentColor.a);
}
fixed4 fragSet(v2f i): SV_Target
{
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 maskColor = tex2D(_Mask, i.uv);
float maskGray = maskColor.r;
float newValue = lerp(currentColor.r, _Color.r * _Opacity, maskGray);
return float4(newValue, newValue, newValue, currentColor.a); //keep the alpha channel for smoothness value
}
ENDCG
SubShader
{
Tags { "RenderType" = "Transparent" }
Pass
{
Name "Paint"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma shader_feature BLEND_HEIGHT
#pragma shader_feature BLEND_SLOPE
#pragma shader_feature BLEND_NOISE
#pragma vertex vert
#pragma fragment fragPaint
ENDCG
}
Pass
{
Name "Erase"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma shader_feature BLEND_HEIGHT
#pragma shader_feature BLEND_SLOPE
#pragma shader_feature BLEND_NOISE
#pragma vertex vert
#pragma fragment fragErase
ENDCG
}
Pass
{
Name "Smooth"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma shader_feature BLEND_HEIGHT
#pragma shader_feature BLEND_SLOPE
#pragma shader_feature BLEND_NOISE
#pragma vertex vert
#pragma fragment fragSmooth
ENDCG
}
Pass
{
Name "Set"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment fragSet
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,113 @@
Shader "Hidden/Griffin/NoisePainter"
{
Properties
{
_MainTex("MainTex", 2D) = "black" {}
_Mask("Mask", 2D) = "white" {}
_NoiseMap("Noise Map", 2D) = "white" {}
_Opacity("Opacity", Float) = 1
_TerrainMask("Terrain Mask", 2D) = "black" {}
}
CGINCLUDE
#include "UnityCG.cginc"
#include "PaintToolCommon.cginc"
#pragma multi_compile _ USE_WORLD_SPACE
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 localPos : TEXCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_TexelSize;
sampler2D _Mask;
sampler2D _NoiseMap;
float _Opacity;
sampler2D _TerrainMask;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.localPos = v.vertex;
return o;
}
fixed4 fragRaise(v2f i) : SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 maskColor = tex2D(_Mask, i.uv);
#if USE_WORLD_SPACE
float4 noiseColor = tex2D(_NoiseMap, i.localPos);
#else
float4 noiseColor = tex2D(_NoiseMap, i.uv);
#endif
float4 currentColor = tex2D(_MainTex, i.localPos);
float currentHeight = GriffinDecodeFloatRG(currentColor.rg);
float desHeight = currentHeight + maskColor.r * noiseColor.r * _Opacity * terrainMask;
desHeight = max(0, min(0.999999, desHeight));
float2 encodedHeight = GriffinEncodeFloatRG(desHeight);
return saturate(float4(encodedHeight.rg, currentColor.b, currentColor.a));
}
fixed4 fragLower(v2f i) : SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 maskColor = tex2D(_Mask, i.uv);
#if USE_WORLD_SPACE
float4 noiseColor = tex2D(_NoiseMap, i.localPos);
#else
float4 noiseColor = tex2D(_NoiseMap, i.uv);
#endif
float4 currentColor = tex2D(_MainTex, i.localPos);
float currentHeight = GriffinDecodeFloatRG(currentColor.rg);
float desHeight = currentHeight - maskColor.r * noiseColor.r * _Opacity * terrainMask;
desHeight = max(0, min(0.999999, desHeight));
float2 encodedHeight = GriffinEncodeFloatRG(desHeight);
return saturate(float4(encodedHeight.rg, currentColor.b, currentColor.a));
}
ENDCG
SubShader
{
Tags{ "RenderType" = "Transparent" }
Pass
{
Name "Raise"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment fragRaise
ENDCG
}
Pass
{
Name "Lower"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment fragLower
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,129 @@
#ifndef PAINT_TOOL_COMMON_INCLUDED
#define PAINT_TOOL_COMMON_INCLUDED
float2 GradientNoise_dir(float2 p)
{
p = p % 289;
float x = (34 * p.x + 1) * p.x % 289 + p.y;
x = (34 * x + 1) * x % 289;
x = frac(x / 41) * 2 - 1;
return normalize(float2(x - floor(x + 0.5), abs(x) - 0.5));
}
float GradientNoise(float2 p)
{
float2 ip = floor(p);
float2 fp = frac(p);
float d00 = dot(GradientNoise_dir(ip), fp);
float d01 = dot(GradientNoise_dir(ip + float2(0, 1)), fp - float2(0, 1));
float d10 = dot(GradientNoise_dir(ip + float2(1, 0)), fp - float2(1, 0));
float d11 = dot(GradientNoise_dir(ip + float2(1, 1)), fp - float2(1, 1));
fp = fp * fp * fp * (fp * (fp * 6 - 15) + 10);
return lerp(lerp(d00, d01, fp.y), lerp(d10, d11, fp.y), fp.x);
}
float InverseLerpUnclamped(float a, float b, float value)
{
//adding a==b check if needed
return (value - a) / (b - a + 0.0000001);
}
float RandomValue(float seed)
{
return frac(sin(dot(float2(seed, seed+1), float2(12.9898, 78.233)))*43758.5453);
}
float RandomValue(float u, float v)
{
return frac(sin(dot(float2(u, v), float2(12.9898, 78.233)))*43758.5453);
}
float2 VoronoiRandomVector (float2 UV, float offset)
{
float2x2 m = float2x2(15.27, 47.63, 99.41, 89.98);
UV = frac(sin(mul(UV, m)) * 46839.32);
return float2(sin(UV.y*+offset)*0.5+0.5, cos(UV.x*offset)*0.5+0.5);
}
float Voronoi(float2 UV, float AngleOffset, float CellDensity)
{
float2 g = floor(UV * CellDensity);
float2 f = frac(UV * CellDensity);
float t = 8.0;
float3 res = float3(8.0, 0.0, 0.0);
float noiseValue = 0;
for(int y=-1; y<=1; y++)
{
for(int x=-1; x<=1; x++)
{
float2 lattice = float2(x,y);
float2 offset = VoronoiRandomVector(lattice + g, AngleOffset);
float d = distance(lattice + offset, f);
if(d < res.x)
{
res = float3(d, offset.x, offset.y);
noiseValue = res.x;
}
}
}
return noiseValue;
}
inline float ValueNoiseInterpolate (float a, float b, float t)
{
return (1.0-t)*a + (t*b);
}
inline float ValueNoise (float2 uv)
{
float2 i = floor(uv);
float2 f = frac(uv);
f = f * f * (3.0 - 2.0 * f);
uv = abs(frac(uv) - 0.5);
float2 c0 = i + float2(0.0, 0.0);
float2 c1 = i + float2(1.0, 0.0);
float2 c2 = i + float2(0.0, 1.0);
float2 c3 = i + float2(1.0, 1.0);
float r0 = RandomValue(c0.x, c0.y);
float r1 = RandomValue(c1.x, c1.y);
float r2 = RandomValue(c2.x, c2.y);
float r3 = RandomValue(c3.x, c3.y);
float bottomOfGrid = ValueNoiseInterpolate(r0, r1, f.x);
float topOfGrid = ValueNoiseInterpolate(r2, r3, f.x);
float t = ValueNoiseInterpolate(bottomOfGrid, topOfGrid, f.y);
return t;
}
float4 MoveTowards(float4 current, float4 target, float maxDistanceDelta)
{
float4 a = target - current;
float magnitude = length(a);
if (magnitude <= maxDistanceDelta || magnitude == 0)
{
return target;
}
return current + a / magnitude * maxDistanceDelta;
}
// Encoding/decoding [0..1) floats into 8 bit/channel RG. Note that 1.0 will not be encoded properly.
inline float2 GriffinEncodeFloatRG(float v)
{
float2 kEncodeMul = float2(1.0, 255.0);
float kEncodeBit = 1.0 / 255.0;
float2 enc = kEncodeMul * v;
enc = frac(enc);
enc.x -= enc.y * kEncodeBit;
return enc;
}
inline float GriffinDecodeFloatRG(float2 enc)
{
float2 kDecodeDot = float2(1.0, 1 / 255.0);
return dot(enc, kDecodeDot);
}
#endif //GRIFFIN_CG_INCLUDED

View File

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

View File

@@ -0,0 +1,74 @@
Shader "Hidden/Griffin/PainterCursor"
{
Properties
{
_Color ("Color", Color) = (0,1,1,1)
_MainTex ("Main Texture", 2D) = "black" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
float4 _Color;
sampler2D _MainTex;
float4 _MainTex_TexelSize;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
float Stripe(in float x, in float stripeX, in float pixelWidth)
{
// compute derivatives to get ddx / pixel
float2 derivatives = float2(ddx(x), ddy(x));
float derivLen = length(derivatives);
float sharpen = 1.0f / max(derivLen, 0.00001f);
return saturate(0.5f + 0.5f * (0.5f * pixelWidth - sharpen * abs(x - stripeX)));
}
fixed4 frag (v2f i) : SV_Target
{
float texGray = tex2D(_MainTex, i.uv).r;
float stripeWidth = 2.0f; // pixels
float stripeLocation = 0.05f; // at 5% alpha
float brushStripe = Stripe(texGray, stripeLocation, stripeWidth);
float4 color = _Color;
color.a = _Color.a*texGray*(brushStripe<0.5) + _Color*(brushStripe>=0.5);
return color;
}
ENDCG
SubShader
{
Tags { "Queue"="Overlay" "RenderType"="Transparent" }
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
BlendOp Add
ZTest Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,71 @@
Shader "Hidden/Griffin/PainterCursorProjector"
{
Properties
{
_Color ("Color", Color) = (0,1,1,1)
_MainTex ("Main Texture", 2D) = "black" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal : NORMAL;
};
struct v2f
{
float4 vertex : SV_POSITION;
float4 worldPos : TEXCOORD1;
float3 normal : NORMAL;
};
float4 _Color;
sampler2D _MainTex;
float4 _MainTex_TexelSize;
float4x4 _WorldToCursorMatrix;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
o.normal = UnityObjectToWorldNormal(v.normal);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float4 cursorSpacePos = mul(_WorldToCursorMatrix, i.worldPos);
clip(0.5 - abs(cursorSpacePos.x));
clip(0.5 - abs(cursorSpacePos.z));
float2 uv = float2(cursorSpacePos.x + 0.5, cursorSpacePos.z + 0.5);
float texGray = tex2D(_MainTex, uv).r;
float fade = lerp(0.5, 1, i.normal.y);
float4 color = float4(fade*_Color.rgb, _Color.a*texGray);
return color;
}
ENDCG
SubShader
{
Tags { "Queue"="Overlay" "RenderType"="Transparent" }
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
BlendOp Add
ZTest Off
Cull Back
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,77 @@
Shader "Hidden/Griffin/RemapPainter"
{
Properties
{
_MainTex ("MainTex", 2D) = "black" {}
_Mask ("Mask", 2D) = "white" {}
_Opacity ("Opacity", Float) = 1
_RemapTex ("Remap Texture", 2D) = "black" {}
_TerrainMask ("Terrain Mask", 2D) = "black" {}
}
CGINCLUDE
#include "UnityCG.cginc"
#include "PaintToolCommon.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 localPos : TEXCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_TexelSize;
sampler2D _Mask;
float _Opacity;
sampler2D _RemapTex;
sampler2D _TerrainMask;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.localPos = v.vertex;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 maskColor = tex2D(_Mask, i.uv);
float4 currentColor = tex2D(_MainTex, i.localPos);
float currentHeight = GriffinDecodeFloatRG(currentColor.rg);
float desHeight = tex2D(_RemapTex, float2(currentHeight, 0.5));
float height = max(0, min(0.999999, lerp(currentHeight, desHeight, maskColor.r*_Opacity*terrainMask)));
float2 encodedHeight = GriffinEncodeFloatRG(height);
return saturate(float4(encodedHeight.rg, currentColor.b, currentColor.a));
}
ENDCG
SubShader
{
Tags { "RenderType"="Transparent" }
Pass
{
Name "Raise"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,263 @@
Shader "Hidden/Griffin/SmoothnessPainter"
{
Properties
{
_Color ("Color", Color) = (1, 1, 1, 1)
_MainTex ("Texture", 2D) = "black" { }
_MainTex_Left ("MainTex_Left", 2D) = "black" { }
_MainTex_TopLeft ("MainTex_TopLeft", 2D) = "black" { }
_MainTex_Top ("MainTex_Top", 2D) = "black" { }
_MainTex_TopRight ("MainTex_TopRight", 2D) = "black" { }
_MainTex_Right ("MainTex_Right", 2D) = "black" { }
_MainTex_BottomRight ("MainTex_BottomRight", 2D) = "black" { }
_MainTex_Bottom ("MainTex_Bottom", 2D) = "black" { }
_MainTex_BottomLeft ("MainTex_BottomLeft", 2D) = "black" { }
_Mask ("Mask", 2D) = "white" { }
_Opacity ("Opacity", Float) = 1
_TerrainMask ("TerrainMask", 2D) = "black" { }
}
CGINCLUDE
#include "UnityCG.cginc"
#include "ConditionalPainting.cginc"
struct appdata
{
float4 vertex: POSITION;
float2 uv: TEXCOORD0;
};
struct v2f
{
float2 uv: TEXCOORD0;
float4 vertex: SV_POSITION;
float4 localPos: TEXCOORD1;
};
float4 _Color;
sampler2D _MainTex;
float4 _MainTex_TexelSize;
sampler2D _MainTex_Left;
sampler2D _MainTex_TopLeft;
sampler2D _MainTex_Top;
sampler2D _MainTex_TopRight;
sampler2D _MainTex_Right;
sampler2D _MainTex_BottomRight;
sampler2D _MainTex_Bottom;
sampler2D _MainTex_BottomLeft;
sampler2D _Mask;
float _Opacity;
sampler2D _TerrainMask;
sampler2D textureGrid[3][3];
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.localPos = v.vertex;
return o;
}
fixed4 fragPaint(v2f i): SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos);
float4 maskColor = tex2D(_Mask, i.uv);
float maskGray = maskColor.r;
float4 currentColor = tex2D(_MainTex, i.localPos);
float currentValue = currentColor.a;
float addictiveValue = maskGray * _Color.a * _Opacity * terrainMask * ComputeRuleMask(i.localPos);
float newValue = saturate(currentValue + addictiveValue);
return float4(currentColor.r, currentColor.r, currentColor.r, newValue); //keep the Red channel for metallic
}
fixed4 fragErase(v2f i): SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos);
float4 maskColor = tex2D(_Mask, i.uv);
float maskGray = maskColor.r;
float4 currentColor = tex2D(_MainTex, i.localPos);
float currentValue = currentColor.a;
float subtractiveValue = maskGray * _Color.a * _Opacity * terrainMask * ComputeRuleMask(i.localPos);
float newValue = saturate(currentValue - subtractiveValue);
return float4(currentColor.r, currentColor.r, currentColor.r, newValue); //keep the Red channel for metallic
}
fixed4 fragSmooth(v2f i): SV_Target
{
textureGrid[0][0] = _MainTex_BottomLeft;
textureGrid[1][0] = _MainTex_Bottom;
textureGrid[2][0] = _MainTex_BottomRight;
textureGrid[0][1] = _MainTex_Left;
textureGrid[1][1] = _MainTex;
textureGrid[2][1] = _MainTex_Right;
textureGrid[0][2] = _MainTex_TopLeft;
textureGrid[1][2] = _MainTex_Top;
textureGrid[2][2] = _MainTex_TopRight;
float2 texel = _MainTex_TexelSize.xy;
float4 avgColor = float4(0, 0, 0, 0);
float sampleCount = 0;
int indexX = 0;
int indexY = 0;
float2 uv = float2(0, 0);
float4 c = float4(0, 0, 0, 0);
for (int x0 = -3; x0 <= 3; ++x0)
{
for (int y0 = -3; y0 <= 3; ++y0)
{
uv = i.localPos + float2(x0 * texel.x, y0 * texel.y);
indexX = lerp(lerp(1, 2, uv.x > 1), 0, uv.x < 0);
indexY = lerp(lerp(1, 2, uv.y > 1), 0, uv.y < 0);
uv.x = lerp(lerp(uv.x, uv.x - 1, uv.x > 1), uv.x + 1, uv.x < 0);
uv.y = lerp(lerp(uv.y, uv.y - 1, uv.y > 1), uv.y + 1, uv.y < 0);
if (indexX == 0)
{
if (indexY == 0)
{
c = tex2D(textureGrid[0][0], uv);
}
if (indexY == 1)
{
c = tex2D(textureGrid[0][1], uv);
}
if (indexY == 2)
{
c = tex2D(textureGrid[0][2], uv);
}
}
if (indexX == 1)
{
if (indexY == 0)
{
c = tex2D(textureGrid[1][0], uv);
}
if (indexY == 1)
{
c = tex2D(textureGrid[1][1], uv);
}
if (indexY == 2)
{
c = tex2D(textureGrid[1][2], uv);
}
}
if (indexX == 2)
{
if (indexY == 0)
{
c = tex2D(textureGrid[2][0], uv);
}
if (indexY == 1)
{
c = tex2D(textureGrid[2][1], uv);
}
if (indexY == 2)
{
c = tex2D(textureGrid[2][2], uv);
}
}
avgColor += c;
sampleCount += 1;
}
}
avgColor = avgColor / sampleCount;
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos);
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 maskColor = tex2D(_Mask, i.uv);
float maskValue = maskColor.r;
float4 desColor = lerp(currentColor, avgColor, maskValue * _Opacity * terrainMask * ComputeRuleMask(i.localPos));
float newValue = desColor.a;
return float4(currentColor.r, currentColor.r, currentColor.r, newValue); //keep the Red channel for metallic
}
fixed4 fragSet(v2f i): SV_Target
{
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 maskColor = tex2D(_Mask, i.uv);
float maskGray = maskColor.r;
float newValue = lerp(currentColor.a, _Color.a * _Opacity, maskGray);
return float4(currentColor.r, currentColor.r, currentColor.r, newValue);
}
ENDCG
SubShader
{
Tags { "RenderType" = "Transparent" }
Pass
{
Name "Paint"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma shader_feature BLEND_HEIGHT
#pragma shader_feature BLEND_SLOPE
#pragma shader_feature BLEND_NOISE
#pragma vertex vert
#pragma fragment fragPaint
ENDCG
}
Pass
{
Name "Erase"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma shader_feature BLEND_HEIGHT
#pragma shader_feature BLEND_SLOPE
#pragma shader_feature BLEND_NOISE
#pragma vertex vert
#pragma fragment fragErase
ENDCG
}
Pass
{
Name "Smooth"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma shader_feature BLEND_HEIGHT
#pragma shader_feature BLEND_SLOPE
#pragma shader_feature BLEND_NOISE
#pragma vertex vert
#pragma fragment fragSmooth
ENDCG
}
Pass
{
Name "Set"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment fragSet
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,132 @@
Shader "Hidden/Griffin/SplatPainter"
{
Properties
{
_MainTex ("Texture", 2D) = "black" { }
_Mask ("Mask", 2D) = "white" { }
_Opacity ("Opacity", Float) = 1
_ChannelIndex ("Channel Index", Int) = 0
_TerrainMask ("Terrain Mask", 2D) = "black" { }
}
CGINCLUDE
#include "UnityCG.cginc"
#include "ConditionalPainting.cginc"
struct appdata
{
float4 vertex: POSITION;
float2 uv: TEXCOORD0;
};
struct v2f
{
float2 uv: TEXCOORD0;
float4 vertex: SV_POSITION;
float4 localPos: TEXCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_TexelSize;
sampler2D _Mask;
float _Opacity;
int _ChannelIndex;
sampler2D _TerrainMask;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.localPos = v.vertex;
return o;
}
fixed4 fragAdd(v2f i): SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 maskColor = tex2D(_Mask, i.uv);
float maskGray = maskColor.r;
float strength = maskGray * _Opacity * terrainMask * ComputeRuleMask(i.localPos);
float4 channel = float4(_ChannelIndex == 0, _ChannelIndex == 1, _ChannelIndex == 2, _ChannelIndex == 3);
float4 currentColor = tex2D(_MainTex, i.localPos);
return lerp(currentColor, channel, strength);
}
fixed4 fragSubSelective(v2f i): SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 maskColor = tex2D(_Mask, i.uv);
float maskGray = maskColor.r;
float strength = maskGray * _Opacity * terrainMask * ComputeRuleMask(i.localPos);
float4 channel = float4(_ChannelIndex == 0, _ChannelIndex == 1, _ChannelIndex == 2, _ChannelIndex == 3);
channel = (1 - channel) * currentColor;
return lerp(currentColor, channel, strength);
}
fixed4 fragSub(v2f i): SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 maskColor = tex2D(_Mask, i.uv);
float maskGray = maskColor.r;
float strength = maskGray * _Opacity * terrainMask * ComputeRuleMask(i.localPos);
float4 channel = 0;
return lerp(currentColor, channel, strength);
}
ENDCG
SubShader
{
Tags { "RenderType" = "Transparent" }
Pass
{
Name "Add"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma shader_feature BLEND_HEIGHT
#pragma shader_feature BLEND_SLOPE
#pragma shader_feature BLEND_NOISE
#pragma vertex vert
#pragma fragment fragAdd
ENDCG
}
Pass
{
Name "Sub Selective"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma shader_feature BLEND_HEIGHT
#pragma shader_feature BLEND_SLOPE
#pragma shader_feature BLEND_NOISE
#pragma vertex vert
#pragma fragment fragSubSelective
ENDCG
}
Pass
{
Name "Sub"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma shader_feature BLEND_HEIGHT
#pragma shader_feature BLEND_SLOPE
#pragma shader_feature BLEND_NOISE
#pragma vertex vert
#pragma fragment fragSub
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,92 @@
Shader "Hidden/Griffin/SubDivPainter"
{
Properties
{
_MainTex ("MainTex", 2D) = "black" {}
_Mask ("Mask", 2D) = "white" {}
_Opacity ("Opacity", Float) = 1
_TerrainMask("TerrainMask", 2D) = "black"{}
}
CGINCLUDE
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 localPos : TEXCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_TexelSize;
sampler2D _Mask;
float _Opacity;
sampler2D _TerrainMask;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.localPos = v.vertex;
return o;
}
fixed4 fragAdd(v2f i) : SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 maskColor = tex2D(_Mask, i.uv);
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 desColor = currentColor + maskColor*_Opacity*terrainMask;
float value = desColor.b;
return saturate(float4(currentColor.r, currentColor.g, value, currentColor.a));
}
fixed4 fragSub(v2f i) : SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 maskColor = tex2D(_Mask, i.uv);
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 desColor = currentColor - maskColor*_Opacity*terrainMask;
float value = desColor.b;
return saturate(float4(currentColor.r, currentColor.g, value, currentColor.a));
}
ENDCG
SubShader
{
Tags { "RenderType"="Transparent" }
Pass
{
Name "Add"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment fragAdd
ENDCG
}
Pass
{
Name "Sub"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment fragSub
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,81 @@
Shader "Hidden/Griffin/TerracePainter"
{
Properties
{
_MainTex ("MainTex", 2D) = "black" {}
_Mask ("Mask", 2D) = "white" {}
_Opacity ("Opacity", Float) = 1
_TerrainMask("Terrain Mask", 2D) = "black"{}
}
CGINCLUDE
#include "UnityCG.cginc"
#include "PaintToolCommon.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 localPos : TEXCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_TexelSize;
sampler2D _Mask;
float _Opacity;
int _StepCount;
sampler2D _TerrainMask;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.localPos = v.vertex;
return o;
}
float stepValue(float v)
{
float step = 1.0/_StepCount;
return v-v%step;
}
fixed4 frag(v2f i) : SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 maskColor = tex2D(_Mask, i.uv);
float4 currentColor = tex2D(_MainTex, i.localPos);
float currentHeight = GriffinDecodeFloatRG(currentColor.rg);
float desHeight = stepValue(currentHeight);
float height = max(0, min(0.999999, lerp(currentHeight, desHeight, maskColor.r*_Opacity*terrainMask)));
float2 encodedHeight = GriffinEncodeFloatRG(height);
return saturate(float4(encodedHeight.rg, currentColor.b, currentColor.a));
}
ENDCG
SubShader
{
Tags { "RenderType"="Transparent" }
Pass
{
Name "Raise"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,94 @@
Shader "Hidden/Griffin/VisibilityPainter"
{
Properties
{
_MainTex("MainTex", 2D) = "black" {}
_Mask("Mask", 2D) = "white" {}
_Opacity("Opacity", Float) = 1
_TerrainMask("Terrain Mask", 2D) = "black" {}
}
CGINCLUDE
#include "UnityCG.cginc"
#include "PaintToolCommon.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 localPos : TEXCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_TexelSize;
sampler2D _Mask;
float _Opacity;
sampler2D _TerrainMask;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.localPos = v.vertex;
return o;
}
fixed4 fragAdd(v2f i) : SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 maskColor = tex2D(_Mask, i.uv);
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 desColor = currentColor + maskColor.rrrr * _Opacity * terrainMask;
float value = desColor.a;
return saturate(float4(currentColor.r, currentColor.g, currentColor.b, value));
}
fixed4 fragSub(v2f i) : SV_Target
{
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float4 maskColor = tex2D(_Mask, i.uv);
float4 currentColor = tex2D(_MainTex, i.localPos);
float4 desColor = currentColor - maskColor.rrrr * _Opacity * terrainMask;
float value = desColor.a;
return saturate(float4(currentColor.r, currentColor.g, currentColor.b, value));
}
ENDCG
SubShader
{
Tags{ "RenderType" = "Transparent" }
Pass
{
//normal painting mode, alpha below 0.5 is visible, otherwise invisible, so subtract pass should have index of 0
Name "Sub"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment fragSub
ENDCG
}
Pass
{
Name "Add"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment fragAdd
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 925f79b58ddbd2a4ebe042a2653a6b43
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader "Hidden/Polaris/PathPainterAlbedo"
{
Properties { }
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
ZTest Always
Cull Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex: POSITION;
float4 color: COLOR;
};
struct v2f
{
float4 vertex: SV_POSITION;
float4 color: COLOR;
float2 uv: TEXCOORD0;
float4 positionWS: TEXCOORD1;
};
float4 _Color;
sampler2D _MainTex;
sampler2D _Falloff;
sampler2D _FalloffNoise;
float4 _FalloffNoise_ST;
sampler2D _TerrainMask;
float4x4 _WorldToNormalized;
v2f vert(appdata v)
{
v2f o;
//o.vertex = UnityObjectToClipPos(v.vertex);
o.color = v.color;
o.positionWS = mul(unity_ObjectToWorld, v.vertex);
o.uv = mul(_WorldToNormalized, o.positionWS).xz;
o.vertex = float4(o.uv.x * 2 - 1, -o.uv.y * 2 + 1, 0, 1);
return o;
}
fixed4 frag(v2f i): SV_Target
{
float4 currentColor = tex2D(_MainTex, i.uv);
float2 noiseUV = float2(i.positionWS.x * _FalloffNoise_ST.x, i.positionWS.z * _FalloffNoise_ST.y);
float falloffNoise = tex2D(_FalloffNoise, noiseUV).r;
float t = clamp(i.color.r, 0, 1);
float falloffCurve = tex2D(_Falloff, float2(t, 0.5)).r;
float falloff = (falloffCurve - falloffNoise) * (i.color.r < 1) + i.color.r * (i.color.r == 1);
falloff = saturate(falloff);
float terrainMask = 1 - tex2D(_TerrainMask, i.uv).r;
float4 overlayColor = float4(_Color.rgb, _Color.a * falloff * terrainMask);
overlayColor = lerp(currentColor, overlayColor, terrainMask * falloff);
return overlayColor;
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,76 @@
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader "Hidden/Polaris/PathPainterAlbedo"
{
Properties { }
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
Blend Off
ZWrite Off
ZTest Always
Cull Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex: POSITION;
float4 color: COLOR;
};
struct v2f
{
float4 vertex: SV_POSITION;
float4 color: COLOR;
float2 uv: TEXCOORD0;
float4 positionWS: TEXCOORD1;
};
float _Metallic;
float _Smoothness;
sampler2D _MainTex;
sampler2D _Falloff;
sampler2D _FalloffNoise;
float4 _FalloffNoise_ST;
sampler2D _TerrainMask;
float4x4 _WorldToNormalized;
v2f vert(appdata v)
{
v2f o;
//o.vertex = UnityObjectToClipPos(v.vertex);
o.color = v.color;
o.positionWS = mul(unity_ObjectToWorld, v.vertex);
o.uv = mul(_WorldToNormalized, o.positionWS).xz;
o.vertex = float4(o.uv.x * 2 - 1, -o.uv.y * 2 + 1, 0, 1);
return o;
}
fixed4 frag(v2f i): SV_Target
{
float4 currentColor = tex2D(_MainTex, i.uv);
float2 noiseUV = float2(i.positionWS.x * _FalloffNoise_ST.x, i.positionWS.z * _FalloffNoise_ST.y);
float falloffNoise = tex2D(_FalloffNoise, noiseUV).r;
float t = clamp(i.color.r, 0, 1);
float falloffCurve = tex2D(_Falloff, float2(t, 0.5)).r;
float falloff = (falloffCurve - falloffNoise) * (i.color.r < 1) + i.color.r * (i.color.r == 1);
falloff = saturate(falloff);
float terrainMask = 1 - tex2D(_TerrainMask, i.uv).r;
float4 overlayColor = float4(_Metallic, currentColor.g, currentColor.b, _Smoothness);
overlayColor = lerp(currentColor, overlayColor, terrainMask * falloff);
return overlayColor;
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,77 @@
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader "Hidden/Polaris/PathPainterAlbedo"
{
Properties { }
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
Blend Off
ZWrite Off
ZTest Always
Cull Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex: POSITION;
float4 color: COLOR;
};
struct v2f
{
float4 vertex: SV_POSITION;
float4 color: COLOR;
float2 uv: TEXCOORD0;
float4 positionWS: TEXCOORD1;
};
sampler2D _MainTex;
sampler2D _Falloff;
sampler2D _FalloffNoise;
float4 _FalloffNoise_ST;
sampler2D _TerrainMask;
float4x4 _WorldToNormalized;
int _ChannelIndex;
v2f vert(appdata v)
{
v2f o;
//o.vertex = UnityObjectToClipPos(v.vertex);
o.color = v.color;
o.positionWS = mul(unity_ObjectToWorld, v.vertex);
o.uv = mul(_WorldToNormalized, o.positionWS).xz;
o.vertex = float4(o.uv.x * 2 - 1, -o.uv.y * 2 + 1, 0, 1);
return o;
}
fixed4 frag(v2f i): SV_Target
{
float4 currentColor = tex2D(_MainTex, i.uv);
float2 noiseUV = float2(i.positionWS.x * _FalloffNoise_ST.x, i.positionWS.z * _FalloffNoise_ST.y);
float falloffNoise = tex2D(_FalloffNoise, noiseUV).r;
float t = clamp(i.color.r, 0, 1);
float falloffCurve = tex2D(_Falloff, float2(t, 0.5)).r;
float falloff = (falloffCurve - falloffNoise) * (i.color.r < 1) + i.color.r * (i.color.r == 1);
falloff = saturate(falloff);
float terrainMask = 1 - tex2D(_TerrainMask, i.uv).r;
float4 channel = float4(_ChannelIndex == 0, _ChannelIndex == 1, _ChannelIndex == 2, _ChannelIndex == 3);
float4 desColor = channel;
float4 result = lerp(currentColor, desColor, falloff);
result = lerp(currentColor, result, terrainMask);
return result;
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,103 @@
Shader "Hidden/Griffin/RampMaker"
{
Properties
{
_HeightMap("Height Map", 2D) = "black"{}
}
CGINCLUDE
#include "UnityCG.cginc"
#include "SplineToolCommon.cginc"
struct appdata
{
float4 vertex: POSITION;
float4 color: COLOR;
};
struct v2f
{
float4 vertex: SV_POSITION;
float4 color: COLOR;
float3 positionNormalized: TEXCOORD0;
float4 positionWS: TEXCOORD1;
};
sampler2D _HeightMap;
sampler2D _Falloff;
sampler2D _FalloffNoise;
float4 _FalloffNoise_ST;
float _HeightOffset;
int _LowerHeight;
int _RaiseHeight;
float _AdditionalMeshResolution;
sampler2D _TerrainMask;
int _StepCount;
float4x4 _WorldToNormalized;
float stepValue(float v, int stepCount)
{
float step = 1.0 / stepCount;
return v - v % step;
}
v2f vert(appdata v)
{
v2f o;
v.vertex.y += _HeightOffset;
//o.vertex = UnityObjectToClipPos(v.vertex);
o.color = v.color;
o.positionWS = mul(unity_ObjectToWorld, v.vertex);
o.positionNormalized = mul(_WorldToNormalized, o.positionWS);
o.vertex = float4(o.positionNormalized.x * 2 - 1, -o.positionNormalized.z * 2 + 1, 0, 1);
return o;
}
fixed4 fragRamp(v2f i): SV_Target
{
float4 heightMapColor = tex2D(_HeightMap, i.positionNormalized.xz);
float currentHeight = GriffinDecodeFloatRG(heightMapColor.rg);
float splineHeight = clamp(i.positionNormalized.y, 0, 1);
float delta = splineHeight - currentHeight;
float targetHeight = currentHeight + (delta < 0) * _LowerHeight * delta + (delta >= 0) * _RaiseHeight * saturate(delta);
float2 noiseUV = float2(i.positionWS.x * _FalloffNoise_ST.x, i.positionWS.z * _FalloffNoise_ST.y);
float falloffNoise = tex2D(_FalloffNoise, noiseUV).r;
float t = clamp(i.color.r, 0, 1);
float falloffCurve = tex2D(_Falloff, float2(t, 0.5)).r;
float falloff = (falloffCurve - falloffNoise) * (i.color.r < 1) + i.color.r * (i.color.r == 1);
falloff = saturate(falloff);
float terrainMask = 1 - tex2D(_TerrainMask, i.positionNormalized.xz).r;
float h = lerp(currentHeight, targetHeight, falloff);
h = lerp(currentHeight, h, terrainMask);
h = stepValue(h, _StepCount);
h = max(0, min(0.999999, h));
float2 encodedHeight = GriffinEncodeFloatRG(h);
float addRes = lerp(0, _AdditionalMeshResolution, terrainMask);
return saturate(float4(encodedHeight.rg, addRes, heightMapColor.a));
}
ENDCG
SubShader
{
Tags { "RenderType" = "Transparent" }
Cull Off
Pass
{
Name "Ramp"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment fragRamp
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,54 @@
Shader "Hidden/Polaris/SplineGizmos"
{
Properties
{
_Color ("Color", Color) = (1, 1, 1, 1)
}
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
ZTest LEqual
ZWrite Off
Cull Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex: POSITION;
float4 color: COLOR;
};
struct v2f
{
float4 vertex: SV_POSITION;
float4 color: COLOR;
};
float4 _Color;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.color = v.color;
return o;
}
fixed4 frag(v2f i): SV_Target
{
return float4(_Color.rgb, _Color.a * i.color.a);
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,78 @@
Shader "Hidden/Griffin/SplineMask"
{
Properties
{
_Falloff("Falloff", 2D) = "white" { }
_FalloffNoise("Falloff Noise", 2D) = "white" { }
_TerrainMask("TerrainMask", 2D) = "black" { }
}
CGINCLUDE
#include "UnityCG.cginc"
struct appdata
{
float4 vertex: POSITION;
float4 color: COLOR;
};
struct v2f
{
float4 vertex: SV_POSITION;
float4 color: COLOR;
float2 uv: TEXCOORD0;
float4 positionWS: TEXCOORD1;
};
sampler2D _Falloff;
sampler2D _FalloffNoise;
float4 _FalloffNoise_ST;
sampler2D _TerrainMask;
float4x4 _WorldToNormalized;
v2f vert(appdata v)
{
v2f o;
//o.vertex = UnityObjectToClipPos(v.vertex);
o.color = v.color;
o.positionWS = mul(unity_ObjectToWorld, v.vertex);
o.uv = mul(_WorldToNormalized, o.positionWS).xz;
o.vertex = float4(o.uv.x * 2 - 1, -o.uv.y * 2 + 1, 0, 1);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
float2 noiseUV = float2(i.positionWS.x * _FalloffNoise_ST.x, i.positionWS.z * _FalloffNoise_ST.y);
float falloffNoise = tex2D(_FalloffNoise, noiseUV).r;
float t = clamp(i.color.r, 0, 1);
float falloffCurve = tex2D(_Falloff, float2(t, 0.5)).r;
float falloff = (falloffCurve - falloffNoise) * (i.color.r < 1) + i.color.r * (i.color.r == 1);
falloff = saturate(falloff);
float terrainMask = 1 - tex2D(_TerrainMask, i.uv).r;
float4 overlayColor = float4(falloff, falloff, falloff, falloff) * terrainMask;
return overlayColor;
}
ENDCG
SubShader
{
Tags{ "RenderType" = "Transparent" }
Cull Off
Pass
{
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,129 @@
#ifndef SPLINE_TOOL_COMMON_INCLUDED
#define SPLINE_TOOL_COMMON_INCLUDED
float2 GradientNoise_dir(float2 p)
{
p = p % 289;
float x = (34 * p.x + 1) * p.x % 289 + p.y;
x = (34 * x + 1) * x % 289;
x = frac(x / 41) * 2 - 1;
return normalize(float2(x - floor(x + 0.5), abs(x) - 0.5));
}
float GradientNoise(float2 p)
{
float2 ip = floor(p);
float2 fp = frac(p);
float d00 = dot(GradientNoise_dir(ip), fp);
float d01 = dot(GradientNoise_dir(ip + float2(0, 1)), fp - float2(0, 1));
float d10 = dot(GradientNoise_dir(ip + float2(1, 0)), fp - float2(1, 0));
float d11 = dot(GradientNoise_dir(ip + float2(1, 1)), fp - float2(1, 1));
fp = fp * fp * fp * (fp * (fp * 6 - 15) + 10);
return lerp(lerp(d00, d01, fp.y), lerp(d10, d11, fp.y), fp.x);
}
float InverseLerpUnclamped(float a, float b, float value)
{
//adding a==b check if needed
return (value - a) / (b - a + 0.0000001);
}
float RandomValue(float seed)
{
return frac(sin(dot(float2(seed, seed+1), float2(12.9898, 78.233)))*43758.5453);
}
float RandomValue(float u, float v)
{
return frac(sin(dot(float2(u, v), float2(12.9898, 78.233)))*43758.5453);
}
float2 VoronoiRandomVector (float2 UV, float offset)
{
float2x2 m = float2x2(15.27, 47.63, 99.41, 89.98);
UV = frac(sin(mul(UV, m)) * 46839.32);
return float2(sin(UV.y*+offset)*0.5+0.5, cos(UV.x*offset)*0.5+0.5);
}
float Voronoi(float2 UV, float AngleOffset, float CellDensity)
{
float2 g = floor(UV * CellDensity);
float2 f = frac(UV * CellDensity);
float t = 8.0;
float3 res = float3(8.0, 0.0, 0.0);
float noiseValue = 0;
for(int y=-1; y<=1; y++)
{
for(int x=-1; x<=1; x++)
{
float2 lattice = float2(x,y);
float2 offset = VoronoiRandomVector(lattice + g, AngleOffset);
float d = distance(lattice + offset, f);
if(d < res.x)
{
res = float3(d, offset.x, offset.y);
noiseValue = res.x;
}
}
}
return noiseValue;
}
inline float ValueNoiseInterpolate (float a, float b, float t)
{
return (1.0-t)*a + (t*b);
}
inline float ValueNoise (float2 uv)
{
float2 i = floor(uv);
float2 f = frac(uv);
f = f * f * (3.0 - 2.0 * f);
uv = abs(frac(uv) - 0.5);
float2 c0 = i + float2(0.0, 0.0);
float2 c1 = i + float2(1.0, 0.0);
float2 c2 = i + float2(0.0, 1.0);
float2 c3 = i + float2(1.0, 1.0);
float r0 = RandomValue(c0.x, c0.y);
float r1 = RandomValue(c1.x, c1.y);
float r2 = RandomValue(c2.x, c2.y);
float r3 = RandomValue(c3.x, c3.y);
float bottomOfGrid = ValueNoiseInterpolate(r0, r1, f.x);
float topOfGrid = ValueNoiseInterpolate(r2, r3, f.x);
float t = ValueNoiseInterpolate(bottomOfGrid, topOfGrid, f.y);
return t;
}
float4 MoveTowards(float4 current, float4 target, float maxDistanceDelta)
{
float4 a = target - current;
float magnitude = length(a);
if (magnitude <= maxDistanceDelta || magnitude == 0)
{
return target;
}
return current + a / magnitude * maxDistanceDelta;
}
// Encoding/decoding [0..1) floats into 8 bit/channel RG. Note that 1.0 will not be encoded properly.
inline float2 GriffinEncodeFloatRG(float v)
{
float2 kEncodeMul = float2(1.0, 255.0);
float kEncodeBit = 1.0 / 255.0;
float2 enc = kEncodeMul * v;
enc = frac(enc);
enc.x -= enc.y * kEncodeBit;
return enc;
}
inline float GriffinDecodeFloatRG(float2 enc)
{
float2 kDecodeDot = float2(1.0, 1 / 255.0);
return dot(enc, kDecodeDot);
}
#endif //GRIFFIN_CG_INCLUDED

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e611669ca414c354f8aad7f42729d426
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,129 @@
#ifndef STAMP_TOOL_COMMON_INCLUDED
#define STAMP_TOOL_COMMON_INCLUDED
float2 GradientNoise_dir(float2 p)
{
p = p % 289;
float x = (34 * p.x + 1) * p.x % 289 + p.y;
x = (34 * x + 1) * x % 289;
x = frac(x / 41) * 2 - 1;
return normalize(float2(x - floor(x + 0.5), abs(x) - 0.5));
}
float GradientNoise(float2 p)
{
float2 ip = floor(p);
float2 fp = frac(p);
float d00 = dot(GradientNoise_dir(ip), fp);
float d01 = dot(GradientNoise_dir(ip + float2(0, 1)), fp - float2(0, 1));
float d10 = dot(GradientNoise_dir(ip + float2(1, 0)), fp - float2(1, 0));
float d11 = dot(GradientNoise_dir(ip + float2(1, 1)), fp - float2(1, 1));
fp = fp * fp * fp * (fp * (fp * 6 - 15) + 10);
return lerp(lerp(d00, d01, fp.y), lerp(d10, d11, fp.y), fp.x);
}
float InverseLerpUnclamped(float a, float b, float value)
{
//adding a==b check if needed
return (value - a) / (b - a + 0.0000001);
}
float RandomValue(float seed)
{
return frac(sin(dot(float2(seed, seed+1), float2(12.9898, 78.233)))*43758.5453);
}
float RandomValue(float u, float v)
{
return frac(sin(dot(float2(u, v), float2(12.9898, 78.233)))*43758.5453);
}
float2 VoronoiRandomVector (float2 UV, float offset)
{
float2x2 m = float2x2(15.27, 47.63, 99.41, 89.98);
UV = frac(sin(mul(UV, m)) * 46839.32);
return float2(sin(UV.y*+offset)*0.5+0.5, cos(UV.x*offset)*0.5+0.5);
}
float Voronoi(float2 UV, float AngleOffset, float CellDensity)
{
float2 g = floor(UV * CellDensity);
float2 f = frac(UV * CellDensity);
float t = 8.0;
float3 res = float3(8.0, 0.0, 0.0);
float noiseValue = 0;
for(int y=-1; y<=1; y++)
{
for(int x=-1; x<=1; x++)
{
float2 lattice = float2(x,y);
float2 offset = VoronoiRandomVector(lattice + g, AngleOffset);
float d = distance(lattice + offset, f);
if(d < res.x)
{
res = float3(d, offset.x, offset.y);
noiseValue = res.x;
}
}
}
return noiseValue;
}
inline float ValueNoiseInterpolate (float a, float b, float t)
{
return (1.0-t)*a + (t*b);
}
inline float ValueNoise (float2 uv)
{
float2 i = floor(uv);
float2 f = frac(uv);
f = f * f * (3.0 - 2.0 * f);
uv = abs(frac(uv) - 0.5);
float2 c0 = i + float2(0.0, 0.0);
float2 c1 = i + float2(1.0, 0.0);
float2 c2 = i + float2(0.0, 1.0);
float2 c3 = i + float2(1.0, 1.0);
float r0 = RandomValue(c0.x, c0.y);
float r1 = RandomValue(c1.x, c1.y);
float r2 = RandomValue(c2.x, c2.y);
float r3 = RandomValue(c3.x, c3.y);
float bottomOfGrid = ValueNoiseInterpolate(r0, r1, f.x);
float topOfGrid = ValueNoiseInterpolate(r2, r3, f.x);
float t = ValueNoiseInterpolate(bottomOfGrid, topOfGrid, f.y);
return t;
}
float4 MoveTowards(float4 current, float4 target, float maxDistanceDelta)
{
float4 a = target - current;
float magnitude = length(a);
if (magnitude <= maxDistanceDelta || magnitude == 0)
{
return target;
}
return current + a / magnitude * maxDistanceDelta;
}
// Encoding/decoding [0..1) floats into 8 bit/channel RG. Note that 1.0 will not be encoded properly.
inline float2 GriffinEncodeFloatRG(float v)
{
float2 kEncodeMul = float2(1.0, 255.0);
float kEncodeBit = 1.0 / 255.0;
float2 enc = kEncodeMul * v;
enc = frac(enc);
enc.x -= enc.y * kEncodeBit;
return enc;
}
inline float GriffinDecodeFloatRG(float2 enc)
{
float2 kDecodeDot = float2(1.0, 1 / 255.0);
return dot(enc, kDecodeDot);
}
#endif //GRIFFIN_CG_INCLUDED

View File

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

View File

@@ -0,0 +1,150 @@
Shader "Hidden/Griffin/Stamper"
{
Properties
{
_HeightMap ("Height Map", 2D) = "black" {}
_Stamp ("Stamp", 2D) = "black" {}
_Falloff ("Falloff", 2D) = "white" {}
_Operation ("Operation", Int) = 0
_LerpFactor ("Lerp Factor", Float) = 0.5
_StampHeight ("Stamp Height", Float) = 1
_StampPositionY ("Stamp Position Y", Float) = 0
_Inverse ("Inverse", Int) = 0
_UseFalloffAsBlendFactor ("Use Falloff As Blend Factor", Int) = 1
_AdditionalMeshResolution ("Additional Mesh Resolution", Float) = 0
_TerrainMask("Terrain Mask", 2D) = "black" {}
}
CGINCLUDE
#include "UnityCG.cginc"
#include "StampToolCommon.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 localPos : TEXCOORD1;
};
sampler2D _HeightMap;
sampler2D _Stamp;
sampler2D _Falloff;
int _Operation;
float _LerpFactor;
float _StampHeight;
float _StampPositionY;
int _Inverse;
int _UseFalloffAsBlendFactor;
float _AdditionalMeshResolution;
sampler2D _TerrainMask;
fixed CalculateValue(int ops, fixed left, fixed right)
{
fixed result =
(ops==0)*max(left, left + right) +
(ops==1)*min(left, left - right) +
(ops==2)*min(right, right - left) +
(ops==3)*max(left, right) +
(ops==4)*min(left, right) +
(ops==5)*lerp(left, right, _LerpFactor) +
(ops==6)*abs(left-right);
return result;
}
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.localPos = v.vertex;
return o;
}
fixed4 fragStampElevation (v2f i) : SV_Target
{
float4 heightMapColor = tex2D(_HeightMap, i.localPos);
float4 stampColor = tex2D(_Stamp, i.uv);
float f = saturate(2*length(i.uv - float2(0.5,0.5)));
float falloff = tex2D(_Falloff, float2(f, 0.5)).r;
stampColor *= falloff;
stampColor = _Inverse*(1-stampColor) +(1-_Inverse)*stampColor;
float currentHeight = GriffinDecodeFloatRG(heightMapColor.rg);
float stampHeight = _StampPositionY + _StampHeight*stampColor.r;
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float h = CalculateValue(_Operation, currentHeight, stampHeight);
h = saturate(h);
h = h*(1-_UseFalloffAsBlendFactor) + lerp(currentHeight, h, falloff)*_UseFalloffAsBlendFactor;
h = lerp(currentHeight, h, terrainMask);
h = max(0, min(0.999999, h));
float2 encodedHeight = GriffinEncodeFloatRG(h);
float isHeightChanged = ceil(abs(h-currentHeight));
float additionalResolution = isHeightChanged*_AdditionalMeshResolution + (1-isHeightChanged)*heightMapColor.b;
return saturate(float4(encodedHeight.rg, additionalResolution, heightMapColor.a));
}
fixed4 fragStampVisibility (v2f i) : SV_Target
{
float4 heightMapColor = tex2D(_HeightMap, i.localPos);
float4 stampColor = tex2D(_Stamp, i.uv);
float f = saturate(2*length(i.uv - float2(0.5,0.5)));
float falloff = tex2D(_Falloff, float2(f, 0.5)).r;
stampColor *= falloff;
stampColor = _Inverse*(1-stampColor) +(1-_Inverse)*stampColor;
float currentValue = heightMapColor.a;
float stampValue = _StampPositionY + _StampHeight*stampColor.r;
float terrainMask = 1 - tex2D(_TerrainMask, i.localPos).r;
float h = CalculateValue(_Operation, currentValue, stampValue);
h = lerp(currentValue, h, terrainMask);
h = saturate(h);
h = h*(1-_UseFalloffAsBlendFactor) + lerp(currentValue, h, falloff)*_UseFalloffAsBlendFactor;
return saturate(float4(heightMapColor.r, heightMapColor.g, heightMapColor.b, h));
}
ENDCG
SubShader
{
Tags { "RenderType"="Transparent" }
Cull Off
Pass
{
Name "Stamp Elevation"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment fragStampElevation
ENDCG
}
Pass
{
Name "Stamp Visibility"
Blend One Zero
BlendOp Add
CGPROGRAM
#pragma vertex vert
#pragma fragment fragStampVisibility
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,154 @@
Shader "Hidden/Griffin/TextureStamperBrush"
{
Properties
{
_Mask ("Mask", 2D) = "white" { }
_Falloff ("Falloff", 2D) = "black" { }
_MinHeight ("Min Height", Range(0.0, 1.0)) = 0
_MaxHeight ("Max Height", Range(0.0, 1.0)) = 1
_HeightTransition ("Height Transition", 2D) = "white" { }
_MinSlope ("Min Slope", Range(0.0, 1.0)) = 0
_MaxSlope ("Max Slope", Range(0.0, 1.0)) = 1
_SlopeTransition ("Slope Transition", 2D) = "white" { }
_NoiseOrigin ("Noise Origin", Vector) = (0, 0, 0, 0)
_NoiseFrequency ("Noise Frequency", Float) = 1
_NoiseOctaves ("Noise Octaves", Int) = 1
_NoiseLacunarity ("Noise Lacunarity", Float) = 2
_NoisePersistence ("Noise Persistence", Float) = 0.5
_NoiseRemap ("Noise Remap", 2D) = "gray" { }
_HeightMap ("Height Map", 2D) = "black" { }
_NormalMap ("Normal Map", 2D) = "gray" { }
_TerrainMask ("Terrain Mask", 2D) = "black" { }
}
SubShader
{
Tags { "RenderType" = "Transparent" }
Blend One Zero
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma shader_feature BLEND_HEIGHT
#pragma shader_feature BLEND_SLOPE
#pragma shader_feature BLEND_NOISE
#include "UnityCG.cginc"
#include "StampToolCommon.cginc"
struct appdata
{
float4 vertex: POSITION;
float2 uv: TEXCOORD0;
};
struct v2f
{
float4 vertex: SV_POSITION;
float2 uv: TEXCOORD0;
float4 normalizePos: TEXCOORD1;
};
sampler2D _Mask;
sampler2D _Falloff;
float _MinHeight;
float _MaxHeight;
sampler2D _HeightTransition;
float _MinSlope;
float _MaxSlope;
sampler2D _SlopeTransition;
float4 _NoiseOrigin;
float _NoiseFrequency;
int _NoiseOctaves;
float _NoiseLacunarity;
float _NoisePersistence;
sampler2D _NoiseRemap;
float _StamperMinHeight;
float _StamperMaxHeight;
sampler2D _HeightMap;
sampler2D _NormalMap;
float4x4 _LocalToWorld;
sampler2D _TerrainMask;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.normalizePos = v.vertex;
return o;
}
float4 frag(v2f i): SV_Target
{
float blendHeightValue = 1;
float4 heightMapColor = tex2D(_HeightMap, i.normalizePos);
float height = GriffinDecodeFloatRG(heightMapColor.rg);
#if BLEND_HEIGHT
float heightTransitionFactor = (height - _MinHeight) / (_MaxHeight - _MinHeight);
float heightTransition = tex2D(_HeightTransition, float2(heightTransitionFactor, 0.5)).r;
blendHeightValue = (height >= _MinHeight) * (height <= _MaxHeight) * heightTransition;
#endif
float blendSlopeValue = 1;
#if BLEND_SLOPE
float4 normalMapColor = tex2D(_NormalMap, i.normalizePos);
float3 normalVector = normalMapColor * 2 - float3(1, 1, 1);
float cosine = abs(normalVector.y);
float slopeAngle = acos(cosine);
float slopeTransitionFactor = (slopeAngle - _MinSlope) / (_MaxSlope - _MinSlope);
float slopeTransition = tex2D(_SlopeTransition, float2(slopeTransitionFactor, 0.5f)).r;
blendSlopeValue = (slopeAngle >= _MinSlope) * (slopeAngle <= _MaxSlope) * slopeTransition;
#endif
float blendNoiseValue = 1;
#if BLEND_NOISE
float2 refSize = float2(1, 1);
float noiseValue = 0;
float frequency = _NoiseFrequency;
float amplitude = 1;
float2 noisePos;
float2 uv;
float sampledNoise;
for (int octave = 0; octave < 4; ++octave)
{
frequency = frequency * pow(_NoiseLacunarity, octave);
amplitude = amplitude * pow(_NoisePersistence, octave);
noisePos = _NoiseOrigin.xy + i.uv * frequency;
uv = float2(noisePos.x / refSize.x, noisePos.y / refSize.y);
sampledNoise = GradientNoise(uv) * amplitude * (octave < _NoiseOctaves);
noiseValue += sampledNoise;
}
float remapFactor = noiseValue * 0.5 + 0.5;
blendNoiseValue = tex2D(_NoiseRemap, float2(remapFactor, 0.5)).a;
#endif
float4 maskColor = tex2D(_Mask, i.uv);
float maskValue = maskColor.r;
float falloffFactor = saturate(2 * length(i.uv - float2(0.5, 0.5)));
float4 falloffColor = tex2D(_Falloff, float2(falloffFactor, 0.5));
float falloffValue = falloffColor.r;
float insideStamperValue = (height >= _StamperMinHeight) * (height <= _StamperMaxHeight);
float result = blendHeightValue * blendSlopeValue * blendNoiseValue * maskValue * falloffValue * insideStamperValue;
float terrainMask = 1 - tex2D(_TerrainMask, i.normalizePos).r;
result = lerp(0, result, terrainMask);
return result;
}
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d22e61cefdeb8b445bd69cf4af2ea931
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,131 @@
Shader "Hidden/Griffin/BlendMapGenerator"
{
Properties
{
_Background ("Background", 2D) = "black" {}
_Foreground ("Foreground", 2D) = "black" {}
_Number ("Number", Float) = 1
_Vector ("Vector", Vector) = (1,1,1,1)
_Ops ("Ops", Int) = 0
_LerpFactor ("Lerp Factor", Float) = 0.5
_LerpMask ("Lerp Mask", 2D) = "white" {}
_Saturate ("Saturate", Int) = 1
}
CGINCLUDE
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _Background;
sampler2D _Foreground;
float _Number;
float4 _Vector;
int _Ops;
float _LerpFactor;
sampler2D _LerpMask;
int _Saturate;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
float CalculateValue(float left, float right, int ops, float lerpFactor)
{
fixed result =
(ops==0)*(left + right) +
(ops==1)*(left - right) +
(ops==2)*(left * right) +
(ops==3)*(left / (right+0.0000001)) +
(ops==4)*min(left, right) +
(ops==5)*max(left, right) +
(ops==6)*abs(left - right) +
(ops==7)*lerp(left, right, lerpFactor);
return result;
}
float4 fragBlendTexture (v2f i) : SV_Target
{
float4 bg = tex2D(_Background, i.uv);
float4 fg = tex2D(_Foreground, i.uv);
float lerpMask = tex2D(_LerpMask, i.uv).r;
float4 col = float4(
CalculateValue(bg.r, fg.r, _Ops, _LerpFactor*lerpMask),
CalculateValue(bg.g, fg.g, _Ops, _LerpFactor*lerpMask),
CalculateValue(bg.b, fg.b, _Ops, _LerpFactor*lerpMask),
CalculateValue(bg.a, fg.a, _Ops, _LerpFactor*lerpMask));
return _Saturate*saturate(col) + (1-_Saturate)*col;
}
float4 fragBlendNumber (v2f i) : SV_Target
{
float4 bg = tex2D(_Background, i.uv);
float lerpMask = tex2D(_LerpMask, i.uv).r;
float4 col = float4(
CalculateValue(bg.r, _Number, _Ops, _LerpFactor*lerpMask),
CalculateValue(bg.g, _Number, _Ops, _LerpFactor*lerpMask),
CalculateValue(bg.b, _Number, _Ops, _LerpFactor*lerpMask),
CalculateValue(bg.a, _Number, _Ops, _LerpFactor*lerpMask));
return _Saturate*saturate(col) + (1-_Saturate)*col;
}
float4 fragBlendVector (v2f i) : SV_Target
{
float4 bg = tex2D(_Background, i.uv);
float lerpMask = tex2D(_LerpMask, i.uv).r;
float4 col = float4(
CalculateValue(bg.r, _Vector.r, _Ops, _LerpFactor*lerpMask),
CalculateValue(bg.g, _Vector.g, _Ops, _LerpFactor*lerpMask),
CalculateValue(bg.b, _Vector.b, _Ops, _LerpFactor*lerpMask),
CalculateValue(bg.a, _Vector.a, _Ops, _LerpFactor*lerpMask));
return _Saturate*saturate(col) + (1-_Saturate)*col;
}
ENDCG
SubShader
{
Tags { "RenderType"="Opaque" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment fragBlendTexture
ENDCG
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment fragBlendNumber
ENDCG
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment fragBlendVector
ENDCG
}
}
}

View File

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

View File

@@ -0,0 +1,64 @@
Shader "Hidden/Griffin/Blur"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _MainTex_TexelSize;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float2 texel = _MainTex_TexelSize.xy;
float4 avgColor = float4(0,0,0,0);
float sampleCount = 0;
for (int x0=-25; x0<=25; ++x0)
{
for (int y0=-25; y0<=25; ++y0)
{
avgColor += tex2D(_MainTex, i.uv + float2(x0*texel.x, y0*texel.y));
sampleCount +=1;
}
}
avgColor = avgColor/sampleCount;
return avgColor;
}
ENDCG
}
}
}

Some files were not shown because too many files have changed in this diff Show More