case1
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cinemachine.Examples
|
||||
{
|
||||
/// <summary>
|
||||
/// An example add-on module for Cinemachine Virtual Camera for controlling
|
||||
/// the FadeOut shader included in our example package.
|
||||
/// </summary>
|
||||
[AddComponentMenu("")] // Hide in menu
|
||||
[ExecuteAlways]
|
||||
public class CinemachineFadeOutNearbyObjects : CinemachineExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Radius of the look at target.
|
||||
/// </summary>
|
||||
[Tooltip("Radius of the look at target.")]
|
||||
public float m_LookAtTargetRadius = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Minimum distance to have fading out effect in front of the camera.
|
||||
/// </summary>
|
||||
[Tooltip("Minimum distance to have fading out effect in front of the camera.")]
|
||||
public float m_MinDistance = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum distance to have fading out effect in front of the camera.
|
||||
/// </summary>
|
||||
[Tooltip("Maximum distance to have fading out effect in front of the camera.")]
|
||||
public float m_MaxDistance = 8;
|
||||
|
||||
/// <summary>
|
||||
/// If true, m_MaxDistance will be set to
|
||||
/// distance between this virtual camera and LookAt target minus m_LookAtTargetRadius.
|
||||
/// </summary>
|
||||
[Tooltip("If true, MaxDistance will be set to " +
|
||||
"distance between this virtual camera and LookAt target minus LookAtTargetRadius.")]
|
||||
public bool m_SetToCameraToLookAtDistance = false;
|
||||
|
||||
/// <summary>
|
||||
/// Material using the FadeOut shader.
|
||||
/// </summary>
|
||||
[Tooltip("Material using the FadeOut shader.")]
|
||||
public Material m_FadeOutMaterial;
|
||||
|
||||
static readonly int k_MaxDistanceID = Shader.PropertyToID("_MaxDistance");
|
||||
static readonly int k_MinDistanceID = Shader.PropertyToID("_MinDistance");
|
||||
|
||||
/// <summary>
|
||||
/// Updates FadeOut shader on the specified FadeOutMaterial.
|
||||
/// </summary>
|
||||
/// <param name="vcam">The virtual camera being processed</param>
|
||||
/// <param name="stage">The current pipeline stage</param>
|
||||
/// <param name="state">The current virtual camera state</param>
|
||||
/// <param name="deltaTime">The current applicable deltaTime</param>
|
||||
protected override void PostPipelineStageCallback(
|
||||
CinemachineVirtualCameraBase vcam,
|
||||
CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
|
||||
{
|
||||
if (stage == CinemachineCore.Stage.Finalize)
|
||||
{
|
||||
if (m_FadeOutMaterial == null || !m_FadeOutMaterial.HasProperty(k_MaxDistanceID) ||
|
||||
!m_FadeOutMaterial.HasProperty(k_MinDistanceID)) return;
|
||||
|
||||
if (m_SetToCameraToLookAtDistance && vcam.LookAt != null)
|
||||
{
|
||||
m_MaxDistance = Vector3.Distance(vcam.transform.position, vcam.LookAt.position) - m_LookAtTargetRadius;
|
||||
}
|
||||
|
||||
m_FadeOutMaterial.SetFloat(k_MaxDistanceID, m_MaxDistance);
|
||||
m_FadeOutMaterial.SetFloat(k_MinDistanceID, m_MinDistance);
|
||||
}
|
||||
}
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
m_LookAtTargetRadius = Math.Max(0, m_LookAtTargetRadius);
|
||||
m_MinDistance = Math.Max(0, m_MinDistance);
|
||||
m_MaxDistance = Math.Max(0, m_MaxDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d881864f964441db82e075e58d1ee01
|
||||
timeCreated: 1611253266
|
||||
@@ -0,0 +1,80 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: FadeOut
|
||||
m_Shader: {fileID: 4800000, guid: 9392babd99652479d80820a9a52efdd6, type: 3}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
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_Floats:
|
||||
- _BumpScale: 1
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _MaxDistance: 15.221463
|
||||
- _Metallic: 0
|
||||
- _MinDistance: 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: []
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c43213e1494d8486881b6aa626ebee03
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,40 @@
|
||||
Shader "Custom/FadeOut" {
|
||||
Properties {
|
||||
_Color ("Color", Color) = (1,1,1,1)
|
||||
_MainTex ("Albedo (RGB)", 2D) = "white" {}
|
||||
_MinDistance ("Minimum Distance", float) = 2
|
||||
_MaxDistance ("Maximum Distance", float) = 3
|
||||
}
|
||||
SubShader {
|
||||
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
|
||||
|
||||
Pass {
|
||||
ZWrite Off
|
||||
ColorMask 0
|
||||
}
|
||||
|
||||
CGPROGRAM
|
||||
#pragma surface surf Lambert alpha:fade
|
||||
#pragma target 3.0
|
||||
sampler2D _MainTex;
|
||||
struct Input {
|
||||
float2 uv_MainTex;
|
||||
float3 worldPos;
|
||||
};
|
||||
float _MinDistance;
|
||||
float _MaxDistance;
|
||||
fixed4 _Color;
|
||||
void surf (Input IN, inout SurfaceOutput o) {
|
||||
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
|
||||
o.Albedo = c.rgb;
|
||||
|
||||
// help: https://developer.download.nvidia.com/cg/index_stdlib.html
|
||||
float distanceFromCamera = distance(IN.worldPos, _WorldSpaceCameraPos);
|
||||
float fade = saturate((distanceFromCamera - _MinDistance) / _MaxDistance);
|
||||
|
||||
o.Alpha = c.a * fade;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
FallBack "Diffuse"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9392babd99652479d80820a9a52efdd6
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66e41717fb9b345fba6a187d1a1b8ff5
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user