DTM Flick,编辑界面网格
This commit is contained in:
156
Assets/Materials/Grid.mat
Normal file
156
Assets/Materials/Grid.mat
Normal file
@@ -0,0 +1,156 @@
|
||||
%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: Grid
|
||||
m_Shader: {fileID: 4800000, guid: 3f7a07814aa8ca44e820255a68f2ca9f, 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:
|
||||
- _AlphaTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BaseMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _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}
|
||||
- _MaskTex:
|
||||
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}
|
||||
- _NormalMap:
|
||||
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}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_Lightmaps:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_LightmapsInd:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_ShadowMasks:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- PixelSnap: 0
|
||||
- _AlphaClip: 0
|
||||
- _AlphaToMask: 0
|
||||
- _Blend: 0
|
||||
- _BlendModePreserveSpecular: 1
|
||||
- _BumpScale: 1
|
||||
- _ClearCoatMask: 0
|
||||
- _ClearCoatSmoothness: 0
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailAlbedoMapScale: 1
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DisappearEndDistance: 100
|
||||
- _DisappearStartDistance: 50
|
||||
- _DstBlend: 0
|
||||
- _DstBlendAlpha: 0
|
||||
- _EnableExternalAlpha: 0
|
||||
- _EnvironmentReflections: 1
|
||||
- _Fade: 0.1
|
||||
- _GlossMapScale: 0
|
||||
- _Glossiness: 0
|
||||
- _GlossyReflections: 0
|
||||
- _GridScale: 0.0001
|
||||
- _LineWidth: 2
|
||||
- _Metallic: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.005
|
||||
- _Plane: 0
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _Smoothness: 0.5
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _SrcBlendAlpha: 1
|
||||
- _Surface: 0
|
||||
- _WorkflowMode: 1
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _BackgroundColor: {r: 0, g: 0, b: 0, a: 0}
|
||||
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _Flip: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _LineColor: {r: 0.5019608, g: 0.5019608, b: 0.5019608, a: 1}
|
||||
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
--- !u!114 &605202624320880140
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 7
|
||||
8
Assets/Materials/Grid.mat.meta
Normal file
8
Assets/Materials/Grid.mat.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a050dab16d24a54595db3beca1b65b1
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
113
Assets/Materials/Grid.shader
Normal file
113
Assets/Materials/Grid.shader
Normal file
@@ -0,0 +1,113 @@
|
||||
Shader "Custom/Grid"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_LineColor("Line Color", Color) = (1,1,1,1)
|
||||
_BackgroundColor("Background Color", Color) = (0,0,0,0)
|
||||
_GridScale("Grid Scale", Float) = 1
|
||||
_LineWidth("Line Width", Float) = 0.05
|
||||
_Fade("Fade", Float) = 0.1
|
||||
_Plane("Plane (0: XZ, 1: XY, 2: YZ)", Float) = 0
|
||||
_DisappearStartDistance("Disappear Start Distance", Float) = 50
|
||||
_DisappearEndDistance("Disappear End Distance", Float) = 100
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "GridPass"
|
||||
Cull Off
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ZWrite Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
// 内置变量:摄像机在世界空间中的位置
|
||||
//float3 _WorldSpaceCameraPos;
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 position : SV_POSITION;
|
||||
float3 worldPos : TEXCOORD0;
|
||||
};
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
float4 _LineColor;
|
||||
float4 _BackgroundColor;
|
||||
float _GridScale;
|
||||
float _LineWidth;
|
||||
float _Fade;
|
||||
float _Plane;
|
||||
float _DisappearStartDistance;
|
||||
float _DisappearEndDistance;
|
||||
CBUFFER_END
|
||||
|
||||
Varyings vert(Attributes IN)
|
||||
{
|
||||
Varyings OUT;
|
||||
OUT.position = TransformObjectToHClip(IN.vertex);
|
||||
OUT.worldPos = TransformObjectToWorld(IN.vertex).xyz;
|
||||
return OUT;
|
||||
}
|
||||
|
||||
// 根据 _Plane 选择二维坐标
|
||||
float2 GetGridCoordinates(float3 pos)
|
||||
{
|
||||
if (_Plane < 0.5) // XZ 平面
|
||||
return pos.xz;
|
||||
else if (_Plane < 1.5) // XY 平面
|
||||
return pos.xy;
|
||||
else // YZ 平面
|
||||
return pos.yz;
|
||||
}
|
||||
|
||||
// 根据 _Plane 获取摄像机在网格平面上的位置
|
||||
float2 GetCameraPlanePosition()
|
||||
{
|
||||
if (_Plane < 0.5) // XZ 平面:摄像机投影到 XZ
|
||||
return _WorldSpaceCameraPos.xz;
|
||||
else if (_Plane < 1.5) // XY 平面:摄像机投影到 XY
|
||||
return _WorldSpaceCameraPos.xy;
|
||||
else // YZ 平面:摄像机投影到 YZ
|
||||
return _WorldSpaceCameraPos.yz;
|
||||
}
|
||||
|
||||
half4 frag(Varyings IN) : SV_Target
|
||||
{
|
||||
// 计算二维网格坐标并乘以 _GridScale
|
||||
float2 gridCoord = GetGridCoordinates(IN.worldPos) * _GridScale;
|
||||
// 用 frac 与 fwidth 实现平滑网格线(抗锯齿)
|
||||
float2 grid = abs(frac(gridCoord - 0.5) - 0.5) / fwidth(gridCoord);
|
||||
float lineIntensity = 1.0 - smoothstep(0.0, _LineWidth, min(grid.x, grid.y));
|
||||
|
||||
// 计算摄像机在平面上的位置与当前片元的二维距离
|
||||
float2 camPos2D = GetCameraPlanePosition();
|
||||
float2 fragPos2D = GetGridCoordinates(IN.worldPos);
|
||||
float dist = distance(fragPos2D, camPos2D);
|
||||
|
||||
// 超过 100 米开始淡出,到 200 米完全透明
|
||||
float distanceFade = saturate((_DisappearEndDistance - dist) / _DisappearStartDistance);
|
||||
|
||||
// 最终 alpha 是网格线强度乘以距离淡出因子
|
||||
float finalAlpha = lineIntensity * distanceFade;
|
||||
|
||||
// 背景颜色始终透明,所以直接输出网格线颜色与 alpha
|
||||
return float4(_LineColor.rgb, finalAlpha);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
FallBack "Diffuse"
|
||||
}
|
||||
9
Assets/Materials/Grid.shader.meta
Normal file
9
Assets/Materials/Grid.shader.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f7a07814aa8ca44e820255a68f2ca9f
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user