diff --git a/Assets/Resources/Effects.meta b/Assets/Resources/Effects.meta new file mode 100644 index 000000000..9b77b0e70 --- /dev/null +++ b/Assets/Resources/Effects.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b8ede490264a144e79dfee035f72948a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Effects/Trail.prefab b/Assets/Resources/Effects/Trail.prefab new file mode 100644 index 000000000..b7c74cd93 --- /dev/null +++ b/Assets/Resources/Effects/Trail.prefab @@ -0,0 +1,151 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &4766600888214445738 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6048748682631107677} + - component: {fileID: 9066380243945606481} + - component: {fileID: 4681111045271042056} + m_Layer: 0 + m_Name: Trail + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6048748682631107677 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4766600888214445738} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: -3.8} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!120 &9066380243945606481 +LineRenderer: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4766600888214445738} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 0 + m_LightProbeUsage: 0 + m_ReflectionProbeUsage: 0 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 84847fcdaa22a48bbb8b56d5f28c259b, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_Positions: + - {x: 0, y: 0, z: 0} + - {x: 2, y: 0, z: 0} + m_Parameters: + serializedVersion: 3 + widthMultiplier: 1 + widthCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + colorGradient: + serializedVersion: 2 + key0: {r: 1, g: 1, b: 1, a: 1} + key1: {r: 1, g: 1, b: 1, a: 1} + key2: {r: 0, g: 0, b: 0, a: 0} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 65535 + ctime2: 0 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 65535 + atime2: 0 + atime3: 0 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_ColorSpace: -1 + m_NumColorKeys: 2 + m_NumAlphaKeys: 2 + numCornerVertices: 0 + numCapVertices: 0 + alignment: 0 + textureMode: 0 + textureScale: {x: 1, y: 1} + shadowBias: 0.5 + generateLightingData: 0 + m_MaskInteraction: 0 + m_UseWorldSpace: 1 + m_Loop: 0 + m_ApplyActiveColorSpace: 1 +--- !u!114 &4681111045271042056 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4766600888214445738} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 234610e62630b4a1399ec9bd193aa685, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Resources/Effects/Trail.prefab.meta b/Assets/Resources/Effects/Trail.prefab.meta new file mode 100644 index 000000000..027c7552c --- /dev/null +++ b/Assets/Resources/Effects/Trail.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: b3d816dbe6c5f4efeb78bda73e88fd64 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Effects/Trail.shader b/Assets/Resources/Effects/Trail.shader new file mode 100644 index 000000000..80568a772 --- /dev/null +++ b/Assets/Resources/Effects/Trail.shader @@ -0,0 +1,56 @@ +Shader "Pal3/Effect/Trail" +{ + Properties + { + _MainTex ("Texture", 2D) = "white" {} + } + SubShader + { + Tags { "RenderType"="Opaque" } + LOD 100 + Cull Back + + 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; + + 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); + return fixed4(i.uv,0.0,1.0); + //return col; + } + ENDCG + } + } +} diff --git a/Assets/Resources/Effects/Trail.shader.meta b/Assets/Resources/Effects/Trail.shader.meta new file mode 100644 index 000000000..625220854 --- /dev/null +++ b/Assets/Resources/Effects/Trail.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 16fc2355979b9481b90f5c64e62bcb49 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Effects/TrailMaterial.mat b/Assets/Resources/Effects/TrailMaterial.mat new file mode 100644 index 000000000..4eb591b18 --- /dev/null +++ b/Assets/Resources/Effects/TrailMaterial.mat @@ -0,0 +1,83 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: TrailMaterial + m_Shader: {fileID: 4800000, guid: 16fc2355979b9481b90f5c64e62bcb49, type: 3} + m_Parent: {fileID: 0} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: [] + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_LockedProperties: + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 1 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + m_BuildTextureStacks: [] diff --git a/Assets/Resources/Effects/TrailMaterial.mat.meta b/Assets/Resources/Effects/TrailMaterial.mat.meta new file mode 100644 index 000000000..4122efe8e --- /dev/null +++ b/Assets/Resources/Effects/TrailMaterial.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 84847fcdaa22a48bbb8b56d5f28c259b +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Effects/VisionRange.mat b/Assets/Resources/Effects/VisionRange.mat new file mode 100644 index 000000000..300a369c6 --- /dev/null +++ b/Assets/Resources/Effects/VisionRange.mat @@ -0,0 +1,89 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: VisionRange + m_Shader: {fileID: 4800000, guid: e96bec704bac24452a99191fee02cdd6, type: 3} + m_Parent: {fileID: 0} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: [] + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_LockedProperties: + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DepthTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _Angle: 0.785 + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 1 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _FrontDir: {r: 1, g: 0, b: 0, a: 0} + m_BuildTextureStacks: [] diff --git a/Assets/Resources/Effects/VisionRange.mat.meta b/Assets/Resources/Effects/VisionRange.mat.meta new file mode 100644 index 000000000..14923f823 --- /dev/null +++ b/Assets/Resources/Effects/VisionRange.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 01e355e4cc09145f299e6db2cfb9f475 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Effects/VisionRange.prefab b/Assets/Resources/Effects/VisionRange.prefab new file mode 100644 index 000000000..f9bad7984 --- /dev/null +++ b/Assets/Resources/Effects/VisionRange.prefab @@ -0,0 +1,132 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &405563175374010200 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6042561762481170579} + - component: {fileID: 451610663227549320} + m_Layer: 0 + m_Name: VisionRange + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6042561762481170579 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 405563175374010200} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 1456119126200093011} + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &451610663227549320 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 405563175374010200} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1cd5e48f7779740a18ed08680c405f66, type: 3} + m_Name: + m_EditorClassIdentifier: + _radius: 12 + _angle: 70 +--- !u!1 &4678853900168579882 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1456119126200093011} + - component: {fileID: 2822365724978176928} + - component: {fileID: 3861774361049819877} + m_Layer: 0 + m_Name: RangeMesh + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1456119126200093011 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4678853900168579882} + m_LocalRotation: {x: 0.5, y: -0.5, z: 0.5, w: 0.5} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 6042561762481170579} + m_RootOrder: -1 + m_LocalEulerAnglesHint: {x: 90, y: 0, z: 90} +--- !u!33 &2822365724978176928 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4678853900168579882} + m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &3861774361049819877 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4678853900168579882} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} diff --git a/Assets/Resources/Effects/VisionRange.prefab.meta b/Assets/Resources/Effects/VisionRange.prefab.meta new file mode 100644 index 000000000..42283d661 --- /dev/null +++ b/Assets/Resources/Effects/VisionRange.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e47fb30d9ddc34e8dbfecf1de652d4a7 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Effects/VisionRange.shader b/Assets/Resources/Effects/VisionRange.shader new file mode 100644 index 000000000..101a2dbf2 --- /dev/null +++ b/Assets/Resources/Effects/VisionRange.shader @@ -0,0 +1,178 @@ +Shader "Pal3/Effect/VisionRange" +{ + Properties + { + _Angle("Angle",float) = 0.785 // PI * 1/4 + _FrontDir("FrontDir",Vector) = (1,0,0,0) + _DepthTex ("DepthTex", 2D) = "green" {} + } + SubShader + { + //Tags { "RenderType"="Opaque" } + Tags {"Queue" = "Transparent"} + LOD 100 + + Blend SrcAlpha OneMinusSrcAlpha + ZWrite Off + + 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; + float4 worldPos : SV_Target0; + }; + + float _Angle; + float4 _FrontDir; + + sampler2D _DepthTex; + + float4x4 _depthCameraViewMatrix; + float4x4 _depthCameraProjMatrix; + + v2f vert (appdata v) + { + v2f o; + o.vertex = UnityObjectToClipPos(v.vertex); + o.uv = v.uv; + o.worldPos = mul(unity_ObjectToWorld,v.vertex); + return o; + } + + float4 getDepthTexUVByWorldPos(float4 worldPos) + { + float4 clipPos = mul(_depthCameraProjMatrix,mul(_depthCameraViewMatrix,worldPos)); + float4 ndcPos = clipPos / clipPos.w; + float4 uvPos = ndcPos * 0.5 + 0.5; + return uvPos; + } + + float getDepthValueByDepthTex(float4 worldPos) + { + float2 depthUV = getDepthTexUVByWorldPos(worldPos).xy; + float depth = SAMPLE_DEPTH_TEXTURE(_DepthTex,depthUV); + depth = Linear01Depth(depth); + return depth; + } + + float getDepthValueByDepthTex2(float4 worldPos) + { + const float2 depthUV = getDepthTexUVByWorldPos(worldPos).xy; + float depth = SAMPLE_DEPTH_TEXTURE(_DepthTex,depthUV); + return depth; + } + + + float getDepthValueByWorldPos(float4 worldPos) + { + float depth = getDepthTexUVByWorldPos(worldPos).z; + depth = Linear01Depth(depth); + return depth; + } + + float getDepthValueByWorldPos2(float4 worldPos) + { + float depth = getDepthTexUVByWorldPos(worldPos).z; + return depth; + } + + // Display whole rect + fixed4 fragV1(v2f i) + { + return fixed4(1,0,0,1); + } + + // Display circle + fixed4 fragV2(v2f i) + { + float2 uv = i.uv * 2.0 - 1.0; + if(length(uv) > 1.0) + { + discard; + } + return fixed4(1,0,0,1); + } + + // Display Fan + fixed4 fragV3(v2f i) + { + float2 uv = i.uv * 2.0 - 1.0; + + float2 frontDirIn2D = normalize(float2(_FrontDir.x,_FrontDir.z)); + float2 uvDir = normalize(uv); + float dotValue = dot(uvDir,frontDirIn2D); + float angle = acos(dotValue); + + if(length(uv) > 1.0 || angle > _Angle * 0.5) + { + discard; + } + return float4(1,0,0,1); + } + + // Test for depth texture + fixed4 fragDebug(v2f i) + { + // test matrix + // return float4(_depthCameraProjMatrix[0]); + + // test depth texture + float2 originUV = i.uv; + float4 colorFromRT = tex2D(_DepthTex,originUV); + return float4(colorFromRT.rgb,1.0); + } + + + fixed4 frag (v2f i) : SV_Target + { + //return fragV1(i); + //return fragV2(i); + //return fragV3(i); + //return fragDebug(i); + + // Discard not in Fan part + float2 uv = i.uv * 2.0 - 1.0; + float2 frontDirIn2D = normalize(float2(_FrontDir.x,_FrontDir.z)); + float2 uvDir = normalize(uv); + float dotValue = dot(uvDir,frontDirIn2D); + float angle = acos(dotValue); + + if(length(uv) > 1.0 || angle > _Angle * 0.5) + { + discard; + } + + // Depth comparision + const float4 worldPos = i.worldPos / i.worldPos.w; + + // depth value from depth texture + float v1 = 1 - getDepthValueByDepthTex2(worldPos); + + // depth value from world pos + float v2 = getDepthValueByWorldPos2(worldPos); + + if(v2 > v1) + { + discard; + } + + return float4(0,1,0,0.5); + } + ENDCG + } + } +} diff --git a/Assets/Resources/Effects/VisionRange.shader.meta b/Assets/Resources/Effects/VisionRange.shader.meta new file mode 100644 index 000000000..bb8f03f8a --- /dev/null +++ b/Assets/Resources/Effects/VisionRange.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: e96bec704bac24452a99191fee02cdd6 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/PostProcessing/Pal3PostEffectFubuki.shader b/Assets/Resources/PostProcessing/Pal3PostEffectFubuki.shader new file mode 100644 index 000000000..48a527bad --- /dev/null +++ b/Assets/Resources/PostProcessing/Pal3PostEffectFubuki.shader @@ -0,0 +1,185 @@ +/* + reference: https://www.shadertoy.com/view/4dl3R4 +*/ +Shader "Pal3/PostEffectFubuki" +{ + Properties + { + + } + + HLSLINCLUDE + #include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl" + TEXTURE2D_SAMPLER2D(_MainTex, sampler_MainTex); + + #define vec2 float2 + #define vec3 float3 + #define vec4 float4 + #define mod fmod + #define fract frac + + // This shader useds noise shaders by stegu -- http://webstaff.itn.liu.se/~stegu/ + // This is supposed to look like snow falling, for example like http://24.media.tumblr.com/tumblr_mdhvqrK2EJ1rcru73o1_500.gif + + vec2 mod289(vec2 x) { + return x - floor(x * (1.0 / 289.0)) * 289.0; + } + + vec3 mod289(vec3 x) { + return x - floor(x * (1.0 / 289.0)) * 289.0; + } + + vec4 mod289(vec4 x) { + return x - floor(x * (1.0 / 289.0)) * 289.0; + } + + vec3 permute(vec3 x) { + return mod289(((x*34.0)+1.0)*x); + } + + vec4 permute(vec4 x) { + return mod((34.0 * x + 1.0) * x, 289.0); + } + + vec4 taylorInvSqrt(vec4 r) + { + return 1.79284291400159 - 0.85373472095314 * r; + } + + float snoise(vec2 v) + { + const vec4 C = vec4(0.211324865405187,0.366025403784439,-0.577350269189626,0.024390243902439); + vec2 i = floor(v + dot(v, C.yy) ); + vec2 x0 = v - i + dot(i, C.xx); + + vec2 i1; + i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0); + vec4 x12 = x0.xyxy + C.xxzz; + x12.xy -= i1; + + i = mod289(i); // Avoid truncation effects in permutation + vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 )) + + i.x + vec3(0.0, i1.x, 1.0 )); + + vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0); + m = m*m ; + m = m*m ; + + vec3 x = 2.0 * fract(p * C.www) - 1.0; + vec3 h = abs(x) - 0.5; + vec3 ox = floor(x + 0.5); + vec3 a0 = x - ox; + + m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h ); + + vec3 g; + g.x = a0.x * x0.x + h.x * x0.y; + g.yz = a0.yz * x12.xz + h.yz * x12.yw; + + return 130.0 * dot(m, g); + } + + float cellular2x2(vec2 P) + { + #define K 0.142857142857 // 1/7 + #define K2 0.0714285714285 // K/2 + #define jitter 0.8 // jitter 1.0 makes F1 wrong more often + + vec2 Pi = mod(floor(P), 289.0); + vec2 Pf = fract(P); + vec4 Pfx = Pf.x + vec4(-0.5, -1.5, -0.5, -1.5); + vec4 Pfy = Pf.y + vec4(-0.5, -0.5, -1.5, -1.5); + vec4 p = permute(Pi.x + vec4(0.0, 1.0, 0.0, 1.0)); + p = permute(p + Pi.y + vec4(0.0, 0.0, 1.0, 1.0)); + vec4 ox = mod(p, 7.0)*K+K2; + vec4 oy = mod(floor(p*K),7.0)*K+K2; + vec4 dx = Pfx + jitter*ox; + vec4 dy = Pfy + jitter*oy; + vec4 d = dx * dx + dy * dy; // d11, d12, d21 and d22, squared + // Sort out the two smallest distances + + // Cheat and pick only F1 + d.xy = min(d.xy, d.zw); + d.x = min(d.x, d.y); + return d.x; // F1 duplicated, F2 not computed + } + + float fbm(vec2 p) { + float f = 0.0; + float w = 0.5; + for (int i = 0; i < 5; i ++) { + f += w * snoise(p); + p *= 2.; + w *= 0.5; + } + return f; + } + + float4 Frag(VaryingsDefault i) : SV_Target + { + float2 uv = i.texcoord; + float2 originUV = uv; + const float time = _Time.y; + + float speed=2.0; + + // vec2 uv = fragCoord.xy / iResolution.xy; + // uv.x*=(iResolution.x/iResolution.y); + uv.x *= _ScreenParams.x / _ScreenParams.y; + + + vec2 GA = float2(0.0,0.0); + GA.x-=time*1.8; + GA.y+=time*0.9; + GA*=speed; + + float F1=0.0,F2=0.0,F3=0.0,F4=0.0,F5=0.0,N1=0.0,N2=0.0,N3=0.0,N4=0.0,N5=0.0; + float A=0.0,A1=0.0,A2=0.0,A3=0.0,A4=0.0,A5=0.0; + + + // Attentuation + A = (uv.x-(uv.y*0.3)); + A = clamp(A,0.0,1.0); + + // Snow layers, somewhat like an fbm with worley layers. + F1 = 1.0-cellular2x2((uv+(GA*0.1))*8.0); + A1 = 1.0-(A*1.0); + N1 = smoothstep(0.998,1.0,F1)*1.0*A1; + + F2 = 1.0-cellular2x2((uv+(GA*0.2))*6.0); + A2 = 1.0-(A*0.8); + N2 = smoothstep(0.995,1.0,F2)*0.85*A2; + + F3 = 1.0-cellular2x2((uv+(GA*0.4))*4.0); + A3 = 1.0-(A*0.6); + N3 = smoothstep(0.99,1.0,F3)*0.65*A3; + + F4 = 1.0-cellular2x2((uv+(GA*0.6))*3.0); + A4 = 1.0-(A*1.0); + N4 = smoothstep(0.98,1.0,F4)*0.4*A4; + + F5 = 1.0-cellular2x2((uv+(GA))*1.2); + A5 = 1.0-(A*1.0); + N5 = smoothstep(0.98,1.0,F5)*0.25*A5; + + float Snowout=N5+N4+N3+N2+N1; + + float4 snowColor = vec4(Snowout*0.9, Snowout, Snowout*1.1, 1.0); + float4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,originUV); + return col + snowColor; + } + ENDHLSL + + + SubShader + { + Cull Off ZWrite Off ZTest Always + Pass + { + HLSLPROGRAM + #pragma vertex VertDefault + #pragma fragment Frag + ENDHLSL + } + } +} diff --git a/Assets/Resources/PostProcessing/Pal3PostEffectFubuki.shader.meta b/Assets/Resources/PostProcessing/Pal3PostEffectFubuki.shader.meta new file mode 100644 index 000000000..1bfe06d8e --- /dev/null +++ b/Assets/Resources/PostProcessing/Pal3PostEffectFubuki.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 417320235b20c457b9ae548b82e5acfc +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/PostProcessing/Pal3PostEffectSnow.shader b/Assets/Resources/PostProcessing/Pal3PostEffectSnow.shader new file mode 100644 index 000000000..878995c1b --- /dev/null +++ b/Assets/Resources/PostProcessing/Pal3PostEffectSnow.shader @@ -0,0 +1,89 @@ +/* + reference: https://www.shadertoy.com/view/ldsGDn +*/ +Shader "Pal3/PostEffectSnow" +{ + Properties + { + // Blizzard + // #define LAYERS 200 + // #define DEPTH .1 + // #define WIDTH .8 + // #define SPEED 1.5 + + // Light Snow + // #define LAYERS 50 + // #define DEPTH .5 + // #define WIDTH .3 + // #define SPEED .6 + + _Layers ("Layers",int) = 50 + _Depth ("Depth",float) = 0.5 + _Width("Width",float) = 0.3 + _Speed("Speed",float) = 0.6 + } + + HLSLINCLUDE + #include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl" + TEXTURE2D_SAMPLER2D(_MainTex, sampler_MainTex); + + int _Layers; + float _Depth; + float _Width; + float _Speed; + + float4 Frag(VaryingsDefault i) : SV_Target + { + float2 uv = i.texcoord; + const float time = _Time.y; + float3x3 p = float3x3(13.323122,23.5112,21.71123,21.1212,28.7312,11.9312,21.8112,14.7212,61.3934); + float3 acc = float3(0.0,0.0,0.0); + + float dof = 5.0 * sin(time * 0.1); + + for(int i = 0;i < _Layers;i++) + { + float fi = float(i); + float2 q = uv * (1.0 + fi * _Depth); + q += float2(q.y*(_Width * fmod(fi*7.238917,1.)-_Width*.5),_Speed * time/(1.+fi*_Depth*.03)); + + float3 n = float3(floor(q),31.189 + fi); + float3 m = floor(n) * 0.00001 + frac(n); + + //float3 temp = m * p;//p * m; + float3 temp = mul(p,m); + + float temp1 = 31415.9; + float3 mp = (float3(temp1,temp1,temp1) + m) / frac(temp); + + float3 r = frac(mp); + float2 s = abs(fmod(q,1.)-.5+.9*r.xy-.45); + s += .01*abs(2.*frac(10.*q.yx)-1.); + + float d = .6*max(s.x-s.y,s.x+s.y)+max(s.x,s.y)-.01; + + float edge = .005+.05*min(.5*abs(fi-5.-dof),1.); + + float temp2 = smoothstep(edge,-edge,d); + float temp3 = r.x / (1.0 + 0.02 * fi * _Depth); + float temp4 = temp2 * temp3; + + acc += float3(temp4,temp4,temp4); + } + + return SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,uv) + float4(float3(acc),1.0); + } + ENDHLSL + + SubShader + { + Cull Off ZWrite Off ZTest Always + Pass + { + HLSLPROGRAM + #pragma vertex VertDefault + #pragma fragment Frag + ENDHLSL + } + } +} diff --git a/Assets/Resources/PostProcessing/Pal3PostEffectSnow.shader.meta b/Assets/Resources/PostProcessing/Pal3PostEffectSnow.shader.meta new file mode 100644 index 000000000..36a45d2f3 --- /dev/null +++ b/Assets/Resources/PostProcessing/Pal3PostEffectSnow.shader.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 2a790b673fbe0455c8ca0ecec60c25f0 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Pal3/Actor/ActorFactory.cs b/Assets/Scripts/Pal3/Actor/ActorFactory.cs index 52481bded..6c15dabc7 100644 --- a/Assets/Scripts/Pal3/Actor/ActorFactory.cs +++ b/Assets/Scripts/Pal3/Actor/ActorFactory.cs @@ -3,6 +3,8 @@ // See LICENSE file in the project root for license information. // --------------------------------------------------------------------------------------------- +using Pal3.Effect; + namespace Pal3.Actor { using System; @@ -95,6 +97,21 @@ public static GameObject CreateActorGameObject(GameResourceProvider resourceProv break; case PlayerActorId.LongKui: actorGameObject.AddComponent().Init(actor, actionController); + break; + case PlayerActorId.JingTian: + + // Trail Effect + var trailGameObject = resourceProvider.GetEffectFactory().CreateTrail(); + trailGameObject.transform.SetParent(actorGameObject.transform); + var trailController = trailGameObject.GetComponent(); + trailController.SetPointLifeSpan(0.5f); + + // Vision Range Effect + //var parent = actorGameObject.transform.Find("Box17"); // @temp hardcode + var parent = actorGameObject.transform; + var visionRangeGameObject = resourceProvider.GetEffectFactory().CreateVisionRange(); + visionRangeGameObject.transform.SetParent(parent); + break; } #elif PAL3A diff --git a/Assets/Scripts/Pal3/Data/GameResourceProvider.cs b/Assets/Scripts/Pal3/Data/GameResourceProvider.cs index 2d04350be..e01c976f6 100644 --- a/Assets/Scripts/Pal3/Data/GameResourceProvider.cs +++ b/Assets/Scripts/Pal3/Data/GameResourceProvider.cs @@ -3,6 +3,8 @@ // See LICENSE file in the project root for license information. // --------------------------------------------------------------------------------------------- +using Pal3.Effect; + namespace Pal3.Data { using System; @@ -47,6 +49,8 @@ public sealed class GameResourceProvider : IDisposable, private readonly ITextureLoaderFactory _textureLoaderFactory; private readonly IMaterialFactory _unlitMaterialFactory; private readonly IMaterialFactory _litMaterialFactory; + private readonly CommonEffectFactory _commonEffectFactory; + private readonly GameSettings _gameSettings; private readonly GdbFile _gameDatabase; @@ -70,12 +74,14 @@ public GameResourceProvider(ICpkFileSystem fileSystem, ITextureLoaderFactory textureLoaderFactory, IMaterialFactory unlitMaterialFactory, IMaterialFactory litMaterialFactory, + CommonEffectFactory effectFactory, GameSettings gameSettings) { _fileSystem = Requires.IsNotNull(fileSystem, nameof(fileSystem)); _textureLoaderFactory = Requires.IsNotNull(textureLoaderFactory, nameof(textureLoaderFactory)); _unlitMaterialFactory = Requires.IsNotNull(unlitMaterialFactory, nameof(unlitMaterialFactory)); _litMaterialFactory = litMaterialFactory; // Lit materials are not required + _commonEffectFactory = effectFactory; _gameSettings = Requires.IsNotNull(gameSettings, nameof(gameSettings)); _codepage = _gameSettings.Language == Language.SimplifiedChinese ? 936 : 950; @@ -138,6 +144,11 @@ public IMaterialFactory GetMaterialFactory() _unlitMaterialFactory; } + public CommonEffectFactory GetEffectFactory() + { + return _commonEffectFactory; + } + public ITextureResourceProvider CreateTextureResourceProvider(string relativeDirectoryPath, bool useCache = true) { return (_textureCache != null && useCache) ? diff --git a/Assets/Scripts/Pal3/Effect/Common.meta b/Assets/Scripts/Pal3/Effect/Common.meta new file mode 100644 index 000000000..e28970dbe --- /dev/null +++ b/Assets/Scripts/Pal3/Effect/Common.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c5571bfd2e0e4637a79c87331d8323c6 +timeCreated: 1692808030 \ No newline at end of file diff --git a/Assets/Scripts/Pal3/Effect/Common/CommonEffectFactory.cs b/Assets/Scripts/Pal3/Effect/Common/CommonEffectFactory.cs new file mode 100644 index 000000000..c0b5b8966 --- /dev/null +++ b/Assets/Scripts/Pal3/Effect/Common/CommonEffectFactory.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Pal3.Effect +{ + public class CommonEffectFactory + { + private Dictionary _cache = new Dictionary(); + + public GameObject CreateTrail() + { + GameObject prefab = GetFromCache("Effects/Trail"); + GameObject result = GameObject.Instantiate(prefab); + result.name = "[effect][trail]"; + return result; + } + + public GameObject CreateVisionRange() + { + GameObject prefab = GetFromCache("Effects/VisionRange"); + var result = GameObject.Instantiate(prefab); + result.name = "[effect][vision_range]"; + return result; + } + + private GameObject GetFromCache(string path) + { + if (_cache.ContainsKey(path)) + { + return _cache[path]; + } + + GameObject prefab = Resources.Load(path); + _cache.Add(path,prefab); + return prefab; + } + } + +} + diff --git a/Assets/Scripts/Pal3/Effect/Common/CommonEffectFactory.cs.meta b/Assets/Scripts/Pal3/Effect/Common/CommonEffectFactory.cs.meta new file mode 100644 index 000000000..7f03751fa --- /dev/null +++ b/Assets/Scripts/Pal3/Effect/Common/CommonEffectFactory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a7f911b63971546a5bd8ce3af70215f0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Pal3/Effect/Common/TrailController.cs b/Assets/Scripts/Pal3/Effect/Common/TrailController.cs new file mode 100644 index 000000000..1e5b8c761 --- /dev/null +++ b/Assets/Scripts/Pal3/Effect/Common/TrailController.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using TreeEditor; +using UnityEditor.UIElements; +using UnityEngine; + +namespace Pal3.Effect +{ + public class TrailController : MonoBehaviour + { + private LineRenderer _lineRenderer = null; + private int _maxPoint = 50; + private Vector3 _posOffset = new Vector3(0, 3, 0); + private float _defaultLifeSpan = 3.0f; + class TrailPoint + { + public Vector3 point; + public float lifeSpan; + } + + private List _allPoints = new List(); + private void Awake() + { + _lineRenderer = GetComponent(); + + } + + public void SetPointLifeSpan(float lifeSpan) + { + _defaultLifeSpan = lifeSpan; + } + + void Update() + { + gameObject.transform.localPosition = _posOffset; + + ReduceLifeSpan(Time.deltaTime); + + var curPos = gameObject.transform.position; + + bool bShouldAddPoint = false; + if (_allPoints.Count == 0) + { + bShouldAddPoint = true; + } + else if (!CheckNear(_allPoints[_allPoints.Count - 1].point, curPos)) + { + bShouldAddPoint = true; + } + + if(bShouldAddPoint) + { + AddPoint(curPos); + } + RefreshLineRenderer(); + } + + private void ReduceLifeSpan(float deltaTime) + { + if (_allPoints.Count == 0) + return; + + foreach (var trailPoint in _allPoints) + { + trailPoint.lifeSpan -= deltaTime; + } + if (_allPoints[0].lifeSpan <= 0f) + { + _allPoints.RemoveAt(0); + } + } + + private bool CheckNear(Vector3 p1,Vector3 p2) + { + return Vector3.Distance(p1, p2) <= Mathf.Epsilon; + } + + private void AddPoint(Vector3 point) + { + var trailPoint = new TrailPoint(); + trailPoint.point = point; + trailPoint.lifeSpan = _defaultLifeSpan; + _allPoints.Add(trailPoint); + } + + private void RefreshLineRenderer() + { + Vector3[] allPos = new Vector3[_allPoints.Count]; + for(int i = 0;i < _allPoints.Count;i++) + { + allPos[i] = _allPoints[i].point; + } + + _lineRenderer.positionCount = _allPoints.Count; + _lineRenderer.SetPositions(allPos); + } + } + +} + diff --git a/Assets/Scripts/Pal3/Effect/Common/TrailController.cs.meta b/Assets/Scripts/Pal3/Effect/Common/TrailController.cs.meta new file mode 100644 index 000000000..845bce0df --- /dev/null +++ b/Assets/Scripts/Pal3/Effect/Common/TrailController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 234610e62630b4a1399ec9bd193aa685 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Pal3/Effect/Common/VisionRange.cs b/Assets/Scripts/Pal3/Effect/Common/VisionRange.cs new file mode 100644 index 000000000..8d5b81975 --- /dev/null +++ b/Assets/Scripts/Pal3/Effect/Common/VisionRange.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Pal3.Effect +{ + public class VisionRange : MonoBehaviour + { + [SerializeField] [Range(1, 20)] private float _radius = 12.0f; + + [SerializeField][Range(0,180)] + public float _angle = 70; + + private Transform _meshTransform = null; + private Material _visionMaterial = null; + private UnityEngine.Camera _visionCamera = null; + + void Start() + { + transform.localPosition = new Vector3(0, 0.1f, 0); + _meshTransform = transform.GetChild(0); + //_meshTransform.forward = transform.forward; + + // Init Mesh Renderer + var meshRenderer = _meshTransform.GetComponent(); + meshRenderer.sharedMaterial = new Material(Shader.Find("Pal3/Effect/VisionRange")); + _visionMaterial = meshRenderer.sharedMaterial; + + // Init Vision Camera + _visionCamera = SetupDepthCamera(gameObject); + _visionCamera.transform.forward = transform.forward; + } + protected UnityEngine.Camera SetupDepthCamera(GameObject rootGameObject) + { + var gameObject = new GameObject("[depth camera]"); + gameObject.transform.SetParent(rootGameObject.transform); + gameObject.transform.localPosition = Vector3.zero; + + var camera = gameObject.AddComponent(); + camera.depthTextureMode = DepthTextureMode.Depth; + camera.clearFlags = CameraClearFlags.Depth; + + /* + * Near Plane & Far Plane influence Depth Texture value range, + * it also influence limit max Radius + */ + //camera.nearClipPlane = 0.3f; + //camera.farClipPlane = 100.0f; // + // camera.farClipPlane = 1000.0f; + + RenderTexture rt = new RenderTexture( + Screen.width, + Screen.height, + 32, + RenderTextureFormat.Depth); + camera.targetTexture = rt; + + return camera; + } + + void Update() + { + SyncDepthCameraSettings(); + SyncFov(); + SyncRadius(); + } + + private void SyncDepthCameraSettings() + { + // camera depth texture + _visionMaterial.SetTexture(Shader.PropertyToID("_DepthTex"),_visionCamera.targetTexture); + + // camera view matrix + _visionMaterial.SetMatrix( + Shader.PropertyToID("_depthCameraViewMatrix"), + _visionCamera.worldToCameraMatrix); + + // camera projection matrix + _visionMaterial.SetMatrix( + Shader.PropertyToID("_depthCameraProjMatrix"), + _visionCamera.projectionMatrix); + } + + private void SyncFov() + { + // Sync fov + float fovInDegree = _angle; + float fovInRadian = Mathf.Deg2Rad * _angle; + _visionMaterial.SetFloat(Shader.PropertyToID("_Angle"),fovInRadian); + + + //float w = item.visionCamera.targetTexture.width; + //float h = item.visionCamera.targetTexture.height; + // here item.visionCamera.aspect = w/h + float fovX = fovInDegree; + float fovy = UnityEngine.Camera.HorizontalToVerticalFieldOfView(fovX, _visionCamera.aspect); + _visionCamera.fieldOfView = fovy; // camera default Fov Axis is Vertical + } + + private void SyncRadius() + { + _meshTransform.localScale = new Vector3(_radius * 2.0f, _radius * 2.0f, 1); + } + + } + +} diff --git a/Assets/Scripts/Pal3/Effect/Common/VisionRange.cs.meta b/Assets/Scripts/Pal3/Effect/Common/VisionRange.cs.meta new file mode 100644 index 000000000..2b69d32ee --- /dev/null +++ b/Assets/Scripts/Pal3/Effect/Common/VisionRange.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1cd5e48f7779740a18ed08680c405f66 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Pal3/Effect/PostProcessing/Fubuki.cs b/Assets/Scripts/Pal3/Effect/PostProcessing/Fubuki.cs new file mode 100644 index 000000000..470ff82c9 --- /dev/null +++ b/Assets/Scripts/Pal3/Effect/PostProcessing/Fubuki.cs @@ -0,0 +1,37 @@ +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +using Core.Extensions; + +namespace Pal3.Effect.PostProcessing +{ + using System; + using UnityEngine; + using UnityEngine.Rendering.PostProcessing; + + [Serializable] + [PostProcess(typeof(FubukiRenderer), PostProcessEvent.AfterStack, "Pal3/Fubuki")] + public sealed class Fubuki : PostProcessEffectSettings + { + + } + + public sealed class FubukiRenderer : PostProcessEffectRenderer + { + private Shader _shader; + + public override void Init() + { + _shader = Shader.Find("Pal3/PostEffectFubuki"); + base.Init(); + } + + public override void Render(PostProcessRenderContext context) + { + PropertySheet sheet = context.propertySheets.Get(_shader); + context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, 0); + } + } +} diff --git a/Assets/Scripts/Pal3/Effect/PostProcessing/Fubuki.cs.meta b/Assets/Scripts/Pal3/Effect/PostProcessing/Fubuki.cs.meta new file mode 100644 index 000000000..aaa77b72f --- /dev/null +++ b/Assets/Scripts/Pal3/Effect/PostProcessing/Fubuki.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 407ba4f7d252c4c7ca371e57d17cd0ad +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Pal3/Effect/PostProcessing/Snow.cs b/Assets/Scripts/Pal3/Effect/PostProcessing/Snow.cs index 36c17913c..41cd295de 100644 --- a/Assets/Scripts/Pal3/Effect/PostProcessing/Snow.cs +++ b/Assets/Scripts/Pal3/Effect/PostProcessing/Snow.cs @@ -41,4 +41,4 @@ public override void Render(PostProcessRenderContext context) context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, 0); } } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Pal3/GameResourceInitializer.cs b/Assets/Scripts/Pal3/GameResourceInitializer.cs index 25aca8ea1..624e5c274 100644 --- a/Assets/Scripts/Pal3/GameResourceInitializer.cs +++ b/Assets/Scripts/Pal3/GameResourceInitializer.cs @@ -3,6 +3,8 @@ // See LICENSE file in the project root for license information. // --------------------------------------------------------------------------------------------- +using Pal3.Effect; + namespace Pal3 { using System; @@ -192,12 +194,16 @@ private IEnumerator InitResourceAsync() { unlitMaterialFactory.AllocateMaterialPool(); } + + // Common Effect Factory + CommonEffectFactory effectFactory = new CommonEffectFactory(); // Init Game resource provider var resourceProvider = new GameResourceProvider(cpkFileSystem, new TextureLoaderFactory(), unlitMaterialFactory, litMaterialFactory, + effectFactory, gameSettings); ServiceLocator.Instance.Register(resourceProvider);