Combat & Visibility & Collisions

Converted entity materials to new fade shader
Implemented visibility system
Refactored per-instance entity code to run inside monobehavior on entity instances
Created state machine AI for enemy ships with basic patrol and combat routines
Removed legacy AI code (controller item behaviors)
Added automatic trigger group assignment for matched weapons
Created ship collision system
Created shield VFX and colliders
This commit is contained in:
Reinier Vens 2021-02-26 19:01:47 +00:00
commit b53e4aec8c
204 changed files with 8182 additions and 1919 deletions

View file

@ -7,8 +7,8 @@
}
SubShader {
Tags { "Queue"="AlphaTest" "RenderType"="TransparentCutout" "IgnoreProjector"="True" }
Pass {
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma vertex particle_vertex

View file

@ -15,6 +15,7 @@ Shader "Aetheria/Dithered Particles"
{
Tags { "RenderType"="Opaque" }
LOD 200
Cull Off
CGPROGRAM
#include "Dither Functions.cginc"

View file

@ -0,0 +1,88 @@
Shader "Aetheria/GlowFade"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Fade ("Fade", Range(0.0, 1.0)) = 0.0
_FadeSharpness ("Fade Sharpness", Float) = 1.0
_FadeTex ("Fade Texture", 2D) = "white" {}
_FadeEdge ("Fade Edge", Range(0.0, 1.0)) = 1.0
[HDR] _EdgeColor ("Edge Color", Color) = (1,1,1,1)
_Glossiness("Smoothness", Range(0.0, 1.0)) = 1.0
[Gamma] _Metallic("Metallic", Range(0.0, 1.0)) = 0.0
_MetallicGlossMap("Metallic", 2D) = "white" {}
_BumpMap("Normal Map", 2D) = "bump" {}
_BumpScale("Normal Scale", Float) = 1.0
_OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0
_OcclusionMap("Occlusion", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
Cull Off
CGPROGRAM
#include "Dither Functions.cginc"
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _MetallicGlossMap;
sampler2D _OcclusionMap;
sampler2D _FadeTex;
sampler2D _BumpMap;
struct Input
{
float2 uv_MainTex;
float2 uv_FadeTex;
float4 screenPos;
};
half _Fade;
half _FadeSharpness;
half _FadeEdge;
half _Glossiness;
half _Metallic;
half _BumpScale;
half _OcclusionStrength;
fixed4 _Color;
half3 _EdgeColor;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o)
{
half f = tex2D (_FadeTex, IN.uv_FadeTex).r + (1-_Fade);
half3 e = _EdgeColor * smoothstep(1 - _FadeEdge, 1, f);
o.Emission = e;
// Apply screen space dithering
float2 screenUV = IN.screenPos.xy / IN.screenPos.w;
ditherClip(screenUV, _FadeSharpness - f * _FadeSharpness);
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex)) * _BumpScale;
fixed4 m = tex2D (_MetallicGlossMap, IN.uv_MainTex);
o.Metallic = _Metallic * m.r;
o.Smoothness = _Glossiness * m.a;
fixed4 oc = tex2D (_OcclusionMap, IN.uv_MainTex);
o.Occlusion = oc.r * _OcclusionStrength;
}
ENDCG
}
FallBack "Diffuse"
}

View file

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

View file

@ -34,6 +34,7 @@
uniform sampler2D _Patch;
uniform sampler2D _Displacement;
uniform sampler2D _TintTexture;
//uniform sampler3D _NoiseTex;
#include "UnityCG.cginc"
@ -86,15 +87,15 @@
float tri(in float x){return abs(frac(x)-.5);}
float3 tri3(in float3 p){return float3( tri(p.z+tri(p.y*1.)), tri(p.z+tri(p.x*1.)), tri(p.y+tri(p.x*1.)));}
float triNoise3d(in float3 p, in float spd)
float triNoise3d(in float3 p)
{
float z=1.4;
float rz = 0.;
float3 bp = p;
for (float i=0.; i<=2.; i++ )
{
float3 dg = tri3(bp*2.);
p += (dg+_Time.y*spd);
float3 dg = tri3(bp * 2.);
p += dg + _Time.y * _NoiseSpeed;
bp *= 1.8;
z *= 1.5;
@ -118,8 +119,9 @@
{
float patch = tex2Dlod(_Patch, half4(uv, 0, 0)).r;
float displacement = tex2Dlod(_Displacement, half4(uv, 0, 0)).r;
float noise = pow(triNoise3d(pos*_NoiseFrequency, _NoiseSpeed),2);// + triNoise3d(pos*_NoiseFrequency*2, _NoiseSpeed * 2) * .5;
//float noise = tex3D(_NoiseTex, pos*_NoiseFrequency);
float noise = pow(triNoise3d(pos*_NoiseFrequency),2);// + triNoise3d(pos*_NoiseFrequency*2, _NoiseSpeed * 2) * .5;
pos.y += noise * _NoiseStrength;
float patchDensity = saturate((-abs(pos.y+displacement)+patch)/_GridPatchBlend)*_GridPatchDensity;
float floorDist = -pos.y-(surface)+_GridFloorOffset;

View file

@ -0,0 +1,133 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
Shader "Aetheria/Shield"
{
Properties
{
[HDR]_Color ("Color", Color) = (1,1,1,1)
_Offset ("Offset", CUBE) = "gray" {}
_Albedo ("Albedo", CUBE) = "black" {}
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_TextureGamma ("Texture Gamma", Float) = 2
_AlbedoGamma ("Albedo Gamma", Float) = 2
_Gradient ("Gradient", 2D) = "white" {}
_GradientMul ("Gradient Multiplier", Float) = 1
_Impact ("Impact Direction", Vector) = (0,0,1)
_Radius ("Impact Radius", Float) = .1
_Blend ("Impact Blend", Float) = 2
_NoiseSpeed ("Noise Speed", Float) = 2
_NoiseScale ("Noise Scale", Float) = .1
_NoiseAmplitude ("Noise Amplitude", Float) = .1
_OffsetSize ("Offset Scale", Float) = .1
_Alpha ("Alpha", Float) = 1
_DitherSampleOffset ("Dither Offset", Float) = 0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
Cull Off
CGPROGRAM
#include "Dither Functions.cginc"
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard vertex:vert
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _Gradient;
samplerCUBE _Offset;
samplerCUBE _Albedo;
struct appdata_particles {
float4 vertex : POSITION;
float3 normal : NORMAL;
float2 texcoord : TEXCOORD0;
};
struct Input {
float2 uv_MainTex;
float4 screenPos;
float3 objectPos;
};
float tri(in float x){return abs(frac(x)-.5);}
float3 tri3(in float3 p){return float3( tri(p.z+tri(p.y*1.)), tri(p.z+tri(p.x*1.)), tri(p.y+tri(p.x*1.)));}
float triNoise3d(in float3 p, in float spd)
{
float z=1.4;
float rz = 0.;
float3 bp = p;
for (float i=0.; i<=2.; i++ )
{
float3 dg = tri3(bp*2.);
p += (dg+_Time.y*spd);
bp *= 1.8;
z *= 1.5;
p *= 1.2;
rz+= (tri(p.z+tri(p.x+tri(p.y))))/z;
bp += 0.14;
}
return rz;
}
void vert(inout appdata_particles v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
o.uv_MainTex = v.texcoord.xy;
o.objectPos = v.vertex.xyz;
}
fixed4 _Color;
float3 _Impact;
float _Radius;
float _Blend;
float _NoiseSpeed;
float _NoiseScale;
float _NoiseAmplitude;
float _OffsetSize;
float _TextureGamma;
float _AlbedoGamma;
float _Alpha;
float _DitherSampleOffset;
float _GradientMul;
void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
float a = pow(tex2D (_MainTex, IN.uv_MainTex).a, _TextureGamma);// * _Color * IN.color;
float3 pos = normalize(IN.objectPos);
float noise = triNoise3d(pos*_NoiseScale, _NoiseSpeed) * _NoiseAmplitude;
float3 offset = normalize(texCUBElod(_Offset, float4(pos + noise, 0)).rgb - float3(.5,.5,.5));
float albedo = pow(texCUBElod (_Albedo, float4(pos + offset * _OffsetSize, 0)).x, _AlbedoGamma);
float dist = dot(pos,normalize(_Impact));
a *= albedo;
float cl = a;
a *= _Alpha * smoothstep(1 - _Radius, 1 - _Radius * _Blend, dist);
// Apply screen space dithering
float2 screenUV = IN.screenPos.xy / IN.screenPos.w;
ditherClip(screenUV + _DitherSampleOffset, a);
fixed3 c = tex2D (_Gradient, cl*_GradientMul) * _Color;
o.Emission = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = 0;
o.Smoothness = 0;
o.Alpha = 1;
}
ENDCG
}
FallBack "Diffuse"
}

View file

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

View file

@ -0,0 +1,113 @@
// Upgrade NOTE: upgraded instancing buffer 'Props' to new syntax.
Shader "Aetheria/View Dependent Emissive Glow Fade" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_BumpMap ("Bumpmap", 2D) = "bump" {}
_BumpPower ("Bump Power", Range (0.01,5)) = 1
_Rotation ("Normal Rotation", Float) = 0
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_MetallicGlossMap("Metallic", 2D) = "white" {}
_EmissionColor ("Emission Color", Color) = (1,1,1,1)
_Emission ("Emission Strength", Float) = 0
_EmissionFresnel ("Emission Fresnel", Float) = 1.0
_EmissionRoughnessFresnelPower("Emission Roughness Fresnel Power", Float) = 1.0
[MaterialToggle] _ReverseRim("ReverseRim", Float) = 0
_Fade ("Fade", Range(0.0, 1.0)) = 0.0
_FadeSharpness ("Fade Sharpness", Float) = 1.0
_FadeTex ("Fade Texture", 2D) = "white" {}
_FadeEdge ("Fade Edge", Range(0.0, 1.0)) = 1.0
[HDR] _EdgeColor ("Edge Color", Color) = (1,1,1,1)
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#include "Dither Functions.cginc"
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
//#pragma multi_compile REVERSE_RIM_ON REVERSE_RIM_OFF
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _MetallicGlossMap;
sampler2D _FadeTex;
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
float2 uv_FadeTex;
float3 viewDir;
float3 worldNormal;
float4 screenPos;
INTERNAL_DATA
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
fixed4 _EmissionColor;
float _BumpPower;
float _Rotation;
float _Emission;
float _EmissionFresnel;
float _EmissionRoughnessFresnelPower;
half _ReverseRim;
half _Fade;
half _FadeSharpness;
half _FadeEdge;
half3 _EdgeColor;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
half f = tex2D (_FadeTex, IN.uv_FadeTex).r + (1-_Fade);
half3 e = _EdgeColor * smoothstep(1 - _FadeEdge, 1, f);
o.Emission = e;
// Apply screen space dithering
float2 screenUV = IN.screenPos.xy / IN.screenPos.w;
ditherClip(screenUV, _FadeSharpness - f * _FadeSharpness);
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
float sinX = sin ( _Rotation );
float cosX = cos ( _Rotation );
float sinY = sin ( _Rotation );
float2x2 rotationMatrix = float2x2( cosX, -sinX, sinY, cosX);
fixed3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
normal.xy = mul ( normal.xy, rotationMatrix);
normal.z = normal.z / _BumpPower;
normal = normalize(normal);
o.Normal = normal;
// Metallic and smoothness come from a texture
float2 metalSmooth = tex2D (_MetallicGlossMap, IN.uv_MainTex).ra;
o.Metallic = metalSmooth.x;
o.Smoothness = metalSmooth.y * _Glossiness;
half rim = saturate(dot (normalize(IN.viewDir), o.Normal));
if(_ReverseRim > .5)
rim = 1 - rim;
o.Emission += _Emission * _EmissionColor * pow(rim,_EmissionFresnel / pow(metalSmooth.x, _EmissionRoughnessFresnelPower));
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fe8c4273cecc4ade93ae54e087dff063
timeCreated: 1613539338