Adding A* Algorythm and carpet roads

This commit is contained in:
Nicolas SANS
2023-04-24 15:49:03 +02:00
parent 75018ee6cd
commit 690e3fbd0b
685 changed files with 134125 additions and 19 deletions

View File

@ -0,0 +1,78 @@
struct appdata_color {
float4 vertex : POSITION;
fixed4 color : COLOR;
float3 normal : NORMAL;
float2 uv : TEXCOORD0;
};
struct line_v2f {
half4 col : COLOR;
float2 normal : TEXCOORD0;
float4 screenPos : TEXCOORD1;
float4 originScreenPos : TEXCOORD2;
};
// Redefine the matrix here in order to confuse the Unity shader upgrader.
// Otherwise it will start modifying some things below even though this script is specifically
// written to be compatible with multiple versions of Unity.
#define MVP_Matrix UNITY_MATRIX_MVP
// d = normalized distance to line
float lineAA(float d) {
d = max(min(d, 1.0), 0) * 1.116;
float v = 0.93124*d*d*d - 1.42215*d*d - 0.42715*d + 0.95316;
v /= 0.95316;
return max(v, 0);
}
line_v2f line_vert (appdata_color v, float pixelWidth, out float4 outpos : SV_POSITION) {
line_v2f o;
// UnityObjectToClipPos only exists in Unity 5.4 or above and there it has to be used
#if defined(UNITY_USE_PREMULTIPLIED_MATRICES)
float4 Mv = UnityObjectToClipPos(v.vertex);
float4 Mn = UnityObjectToClipPos(float4(v.normal.x, v.normal.y, v.normal.z, 0));
#else
float4 Mv = mul(MVP_Matrix, v.vertex);
float4 Mn = mul(MVP_Matrix, float4(v.normal.x, v.normal.y, v.normal.z, 0));
#endif
// delta is the limit value of doing the calculation
// x1 = M*v
// x2 = M*(v + e*n)
// lim e->0 (x2/x2.w - x1.w)/e
// Where M = UNITY_MATRIX_MVP, v = v.vertex, n = v.normal, e = a very small value
// Previously the above calculation was done with just e = 0.001, however this could yield graphical artifacts
// at large coordinate values as the floating point coordinates would start to run out of precision.
// Essentially we calculate the normal of the line in screen space.
float4 delta = (Mn - Mv*Mn.w/Mv.w) / Mv.w;
// Handle DirectX properly. See https://docs.unity3d.com/Manual/SL-PlatformDifferences.html
float2 screenSpaceNormal = float2(-delta.y, delta.x) * _ProjectionParams.x;
float2 normalizedScreenSpaceNormal = normalize(screenSpaceNormal);
screenSpaceNormal = normalizedScreenSpaceNormal / _ScreenParams.xy;
float4 sn = float4(screenSpaceNormal.x, screenSpaceNormal.y, 0, 0);
if (Mv.w < 0) {
// Seems to have a very minor effect, but the distance
// seems to be more accurate with this enabled
sn *= -1;
}
float side = (v.uv.x - 0.5)*2;
outpos = (Mv / Mv.w) + side*sn*pixelWidth*0.5;
// Multiply by w because homogeneous coordinates (it still needs to be clipped)
outpos *= Mv.w;
o.normal = normalizedScreenSpaceNormal;
o.originScreenPos = ComputeScreenPos(Mv);
o.screenPos = ComputeScreenPos(outpos);
return o;
}
/** Copied from UnityCG.cginc because this function does not exist in Unity 5.2 */
inline bool IsGammaSpaceCompatibility() {
#if defined(UNITY_NO_LINEAR_COLORSPACE)
return true;
#else
// unity_ColorSpaceLuminance.w == 1 when in Linear space, otherwise == 0
return unity_ColorSpaceLuminance.w == 0;
#endif
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 1b135520270114849b121a628fe61ba8
timeCreated: 1472987846
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,95 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Navmesh
m_Shader: {fileID: 4800000, guid: 6dad35c0b62e44c26ab244ad80deee1a, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 5
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
data:
first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 2, y: 2}
m_Offset: {x: 0, y: 0}
data:
first:
name: _BumpMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _DecalTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
data:
first:
name: _Scale
second: -2.68000007
data:
first:
name: _Shininess
second: .699999988
data:
first:
name: _InvFade
second: 1
m_Colors:
data:
first:
name: _Color
second: {r: 1, g: 1, b: 1, a: .550999999}
data:
first:
name: _SpecColor
second: {r: 1, g: 1, b: 1, a: 1}
data:
first:
name: _Emission
second: {r: 0, g: 0, b: 0, a: 1}
data:
first:
name: _Tint
second: {r: 1, g: 1, b: 1, a: 1}
data:
first:
name: _FadeColor
second: {r: .656880796, g: .656880796, b: .656880796, a: .448000014}
data:
first:
name: _TintColor
second: {r: .5, g: .5, b: .5, a: .5}
data:
first:
name: _EmisColor
second: {r: .200000003, g: .200000003, b: .200000003, a: 0}
data:
first:
name: _Amb
second: {r: 0, g: 1, b: .33381772, a: 1}
data:
first:
name: _Low
second: {r: 1, g: 1, b: 1, a: .699999988}
data:
first:
name: _Emmission
second: {r: .474489808, g: .474489808, b: .474489808, a: 1}
--- !u!1002 &2100001
EditorExtensionImpl:
serializedVersion: 6

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5ce51318bbfb1466188b929a68a6bd3a

View File

@ -0,0 +1,118 @@
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Hidden/AstarPathfindingProject/Navmesh" {
Properties {
_Color ("Main Color", Color) = (1,1,1,0.5)
_MainTex ("Texture", 2D) = "white" { }
_Scale ("Scale", float) = 1
_FadeColor ("Fade Color", Color) = (1,1,1,0.3)
}
SubShader {
Pass {
ZWrite On
ColorMask 0
}
Tags {"Queue"="Transparent+1" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 200
Offset -2, -20
Cull Off
Pass {
ZWrite Off
ZTest Greater
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Navmesh.cginc"
sampler2D _MainTex;
float _Scale;
float4 _Color;
float4 _FadeColor;
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 col : COLOR;
};
float4 _MainTex_ST;
v2f vert (appdata_color v) {
v2f o;
o.pos = UnityObjectToClipPos (v.vertex);
float4 worldSpace = mul (unity_ObjectToWorld, v.vertex);
o.uv = float2 (worldSpace.x*_Scale,worldSpace.z*_Scale);
o.col = v.color * _Color * _FadeColor;
if (!IsGammaSpaceCompatibility()) {
o.col.rgb = GammaToLinearSpace(o.col.rgb);
}
return o;
}
float4 frag (v2f i) : COLOR {
return tex2D (_MainTex, i.uv) * i.col;
}
ENDCG
}
Pass {
ZWrite Off
ZTest LEqual
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Navmesh.cginc"
float4 _Color;
sampler2D _MainTex;
float _Scale;
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 col : COLOR;
};
v2f vert (appdata_color v)
{
v2f o;
o.pos = UnityObjectToClipPos (v.vertex);
float4 worldSpace = mul (unity_ObjectToWorld, v.vertex);
o.uv = float2 (worldSpace.x*_Scale,worldSpace.z*_Scale);
o.col = v.color * _Color;
if (!IsGammaSpaceCompatibility()) {
o.col.rgb = GammaToLinearSpace(o.col.rgb);
}
return o;
}
float4 frag (v2f i) : COLOR
{
return tex2D (_MainTex, i.uv) * i.col;
}
ENDCG
}
}
Fallback Off
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6dad35c0b62e44c26ab244ad80deee1a

View File

@ -0,0 +1,106 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: NavmeshOutline
m_Shader: {fileID: 4800000, guid: 6c78a6dd468954643a87ebf0014bc305, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 5
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
data:
first:
name: _MainTex
second:
m_Texture: {fileID: 2800000, guid: 0ff27a4aaa0ce4d1ba6a39ce3c868a76, type: 3}
m_Scale: {x: 2, y: 2}
m_Offset: {x: 0, y: 0}
data:
first:
name: _BumpMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _DecalTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _Falloff
second:
m_Texture: {fileID: 2800000, guid: 6267c94129d874d7bafe507aa753046a, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
data:
first:
name: _Scale
second: -2.68000007
data:
first:
name: _Shininess
second: .699999988
data:
first:
name: _InvFade
second: 1
data:
first:
name: _PixelWidth
second: 4.4000001
m_Colors:
data:
first:
name: _Color
second: {r: 1, g: 1, b: 1, a: .745000005}
data:
first:
name: _SpecColor
second: {r: 1, g: 1, b: 1, a: 1}
data:
first:
name: _Emission
second: {r: 0, g: 0, b: 0, a: 1}
data:
first:
name: _Tint
second: {r: 1, g: 1, b: 1, a: 1}
data:
first:
name: _FadeColor
second: {r: .656880796, g: .656880796, b: .656880796, a: .313600004}
data:
first:
name: _TintColor
second: {r: .5, g: .5, b: .5, a: .5}
data:
first:
name: _EmisColor
second: {r: .200000003, g: .200000003, b: .200000003, a: 0}
data:
first:
name: _Amb
second: {r: 0, g: 1, b: .33381772, a: 1}
data:
first:
name: _Low
second: {r: 1, g: 1, b: 1, a: .699999988}
data:
first:
name: _Emmission
second: {r: .474489808, g: .474489808, b: .474489808, a: 1}
--- !u!1002 &2100001
EditorExtensionImpl:
serializedVersion: 6

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 91035448860ba4e708919485c73f7edc
timeCreated: 1442945121
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,87 @@
Shader "Hidden/AstarPathfindingProject/Navmesh Outline" {
Properties {
_Color ("Main Color", Color) = (1,1,1,0.5)
_FadeColor ("Fade Color", Color) = (1,1,1,0.3)
_PixelWidth ("Width (px)", Float) = 4
}
SubShader {
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
Offset -2, -50
Pass {
ZTest LEqual
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Navmesh.cginc"
float4 _Color;
float _PixelWidth;
// Number of screen pixels that the _Falloff texture corresponds to
static const float FalloffTextureScreenPixels = 2;
line_v2f vert (appdata_color v, out float4 outpos : SV_POSITION) {
line_v2f o = line_vert(v, _PixelWidth, outpos);
o.col = v.color * _Color;
if (!IsGammaSpaceCompatibility()) {
o.col.rgb = GammaToLinearSpace(o.col.rgb);
}
return o;
}
half4 frag (line_v2f i, UNITY_VPOS_TYPE screenPos : VPOS) : COLOR {
float2 p = (i.screenPos.xy/i.screenPos.w) - (i.originScreenPos.xy / i.originScreenPos.w);
// Handle DirectX properly. See https://docs.unity3d.com/Manual/SL-PlatformDifferences.html
p.y *= _ProjectionParams.x;
float dist = dot(p*_ScreenParams.xy, i.normal) / _PixelWidth;
float FalloffFractionOfWidth = FalloffTextureScreenPixels/(_PixelWidth*0.5);
float a = lineAA((abs(dist*4) - (1 - FalloffFractionOfWidth))/FalloffFractionOfWidth);
return i.col * float4(1,1,1,a);
}
ENDCG
}
Pass {
ZTest Greater
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Navmesh.cginc"
float4 _Color;
float4 _FadeColor;
float _PixelWidth;
static const float FalloffTextureScreenPixels = 2;
line_v2f vert (appdata_color v, out float4 outpos : SV_POSITION) {
line_v2f o = line_vert(v, _PixelWidth, outpos);
o.col = v.color * _Color * _FadeColor;
if (!IsGammaSpaceCompatibility()) {
o.col.rgb = GammaToLinearSpace(o.col.rgb);
}
return o;
}
half4 frag (line_v2f i, UNITY_VPOS_TYPE screenPos : VPOS) : COLOR {
float2 p = (i.screenPos.xy/i.screenPos.w) - (i.originScreenPos.xy / i.originScreenPos.w);
// Handle DirectX properly. See https://docs.unity3d.com/Manual/SL-PlatformDifferences.html
p.y *= _ProjectionParams.x;
float dist = dot(p*_ScreenParams.xy, i.normal) / _PixelWidth;
float FalloffFractionOfWidth = FalloffTextureScreenPixels/(_PixelWidth*0.5);
float a = lineAA((abs(dist*4) - (1 - FalloffFractionOfWidth))/FalloffFractionOfWidth);
return i.col * float4(1,1,1,a);
}
ENDCG
}
}
Fallback Off
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 6c78a6dd468954643a87ebf0014bc305
timeCreated: 1442945130
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 B

View File

@ -0,0 +1,56 @@
fileFormatVersion: 2
guid: 6267c94129d874d7bafe507aa753046a
timeCreated: 1474192509
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 0
linearTexture: 1
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 8
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: -3
maxTextureSize: 2048
textureSettings:
filterMode: 0
aniso: -1
mipBias: -1
wrapMode: 1
nPOTScale: 1
lightmap: 0
rGBM: 0
compressionQuality: 50
allowsAlphaSplitting: 0
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: 5
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant: