feat(shader): add toon shader and main light custom function

main
uc-hoba 2 weeks ago
parent d013de3c10
commit 7a277add78
  1. 62
      Assets/Main.unity
  2. 0
      Assets/Resources/Test.metamesh
  3. 77
      Assets/Resources/Test.metamesh.meta
  4. 32
      Assets/Resources/Toon.cginc
  5. 7
      Assets/Resources/Toon.cginc.meta
  6. 137
      Assets/Resources/Toon.mat
  7. 8
      Assets/Resources/Toon.mat.meta
  8. 1778
      Assets/Resources/Toon.shadergraph
  9. 18
      Assets/Resources/Toon.shadergraph.meta

@ -1931,6 +1931,67 @@ Transform:
m_Children: []
m_Father: {fileID: 1527156285}
m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}
--- !u!1001 &998665861
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: -364223573239433514, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3}
propertyPath: m_LocalPosition.x
value: 0.66391706
objectReference: {fileID: 0}
- target: {fileID: -364223573239433514, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: -364223573239433514, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3}
propertyPath: m_LocalPosition.z
value: 0.029634476
objectReference: {fileID: 0}
- target: {fileID: -364223573239433514, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3}
propertyPath: m_LocalRotation.w
value: 0.36783063
objectReference: {fileID: 0}
- target: {fileID: -364223573239433514, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: -364223573239433514, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3}
propertyPath: m_LocalRotation.y
value: 0.9298928
objectReference: {fileID: 0}
- target: {fileID: -364223573239433514, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: -364223573239433514, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: -364223573239433514, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 136.836
objectReference: {fileID: 0}
- target: {fileID: -364223573239433514, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2163061155770630284, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3}
propertyPath: 'm_Materials.Array.data[0]'
value:
objectReference: {fileID: 2100000, guid: f54ed0bf357c21f49a96221931e91ba0, type: 2}
- target: {fileID: 8980549144392899874, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3}
propertyPath: m_Name
value: Test
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: -4216948427090074523, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3}
--- !u!1 &1032635067
GameObject:
m_ObjectHideFlags: 0
@ -4150,3 +4211,4 @@ SceneRoots:
- {fileID: 1527156285}
- {fileID: 465598214}
- {fileID: 303688530}
- {fileID: 998665861}

@ -0,0 +1,77 @@
fileFormatVersion: 2
guid: 0419d2e6e681caa47baeec4f66d9e3eb
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: a8b5f06e412d587cbac1226722904238, type: 3}
_shape: 8
_plane:
Size:
x: 1
y: 1
Subdivisions:
x: 2
y: 2
Axis: 1
DoubleSided: 0
_box:
Width: 1
Height: 1
Depth: 1
_sphere:
Radius: 1
Columns: 24
Rows: 12
Axis: 1
_icosphere:
Radius: 1
Subdivision: 2
_cylinder:
TopRadius: 1
BottomRadius: 1
Height: 1
Columns: 24
Rows: 12
Axis: 1
Caps: 1
_roundedBox:
Width: 1
Height: 1
Depth: 1
Divisions: 3
Radius: 0.1
_ring:
Radius: 1
Width: 0.1
Angle: 1
Segments: 32
Axis: 2
DoubleSided: 0
_disc:
Radius: 1
Angle: 1
Segments: 32
Axis: 2
DoubleSided: 0
_teapot:
Subdivision: 10
_triangle:
Vertex1:
x: 0
y: 0
z: 0
Vertex2:
x: 0
y: 1
z: 0
Vertex3:
x: 1
y: 0
z: 0
DoubleSided: 0
_generateLightmapUVs: 0
_readWriteMeshes: 0

@ -0,0 +1,32 @@
#ifndef TOON_MAINLIGHT_INCLUDED
#define TOON_MAINLIGHT_INCLUDED
void MainLight_float(float3 WorldPos, out float3 Direction, out float3 Color, out float ShadowAtten)
{
#ifdef SHADERGRAPH_PREVIEW
Direction = normalize(float3(0.5, 0.5, -0.5));
Color = 1;
ShadowAtten = 1;
#else
float4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
Light mainLight = GetMainLight();
Direction = mainLight.direction;
Color = mainLight.color;
// 直接採樣主光陰影貼圖,繞過 MAIN_LIGHT_CALCULATE_SHADOWS keyword 條件。
ShadowSamplingData samplingData = GetMainLightShadowSamplingData();
half4 shadowParams = GetMainLightShadowParams();
real shadowStrength = shadowParams.x;
// PCF 過濾採樣 → 柔邊、消鋸齒(不依賴 _SHADOWS_SOFT keyword)
real atten = SampleShadowmapFiltered(
TEXTURE2D_ARGS(_MainLightShadowmapTexture, sampler_LinearClampCompare),
shadowCoord, samplingData);
atten = LerpWhiteTo(atten, shadowStrength);
// 超出陰影最遠距離 = 不打陰影
ShadowAtten = BEYOND_SHADOW_FAR(shadowCoord) ? 1.0 : atten;
#endif
}
#endif

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 08feafd859f0adb40a54a7510b8beb28
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,137 @@
%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: Toon
m_Shader: {fileID: -6465566751694194690, guid: 7f9425bb35557354f99cbc1d9fd9d978, 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:
- MOTIONVECTORS
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _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}
- _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}
- _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:
- _AddPrecomputedVelocity: 0
- _AlphaClip: 0
- _AlphaToMask: 0
- _Blend: 0
- _BlendModePreserveSpecular: 1
- _BumpScale: 1
- _ClearCoatMask: 0
- _ClearCoatSmoothness: 0
- _Cull: 2
- _Cutoff: 0.5
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _DstBlendAlpha: 0
- _EnvironmentReflections: 1
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _Metallic: 0
- _OcclusionStrength: 1
- _Parallax: 0.005
- _QueueControl: 0
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SrcBlendAlpha: 1
- _Surface: 0
- _WorkflowMode: 1
- _XRMotionVectorsPass: 1
- _ZWrite: 1
m_Colors:
- _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}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1
--- !u!114 &1822889447093093696
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: Unity.RenderPipelines.Universal.Editor::UnityEditor.Rendering.Universal.AssetVersion
version: 10

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f54ed0bf357c21f49a96221931e91ba0
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 7f9425bb35557354f99cbc1d9fd9d978
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}
useAsTemplate: 0
exposeTemplateAsShader: 0
template:
name:
category:
description:
icon: {instanceID: 0}
thumbnail: {instanceID: 0}
Loading…
Cancel
Save