studycase2
This commit is contained in:
123
Assets/Resources/SimpleURPToon/URPOutline.shader
Normal file
123
Assets/Resources/SimpleURPToon/URPOutline.shader
Normal file
@@ -0,0 +1,123 @@
|
||||
Shader "Custom/URPOutline"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_BaseColor("Base Color", Color) = (1,1,1,1)
|
||||
_OutlineColor("Outline Color", Color) = (1,0,0,1)
|
||||
_OutlineWidth("Outline Width", Range(0, 0.1)) = 0.05
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"RenderType"="Opaque"
|
||||
"RenderPipeline"="UniversalPipeline"
|
||||
"Queue"="Geometry"
|
||||
}
|
||||
|
||||
// <20><>һ<EFBFBD><D2BB>Pass<73><73><EFBFBD><EFBFBD>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD>
|
||||
Pass
|
||||
{
|
||||
Name "Outline"
|
||||
Tags { "LightMode" = "SRPDefaultUnlit" }
|
||||
|
||||
Cull Front
|
||||
ZWrite On
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float3 normalOS : NORMAL;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
};
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
float4 _OutlineColor;
|
||||
float _OutlineWidth;
|
||||
CBUFFER_END
|
||||
|
||||
Varyings vert(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
|
||||
// <20>ط<EFBFBD><D8B7>߷<EFBFBD><DFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>
|
||||
float3 normalOS = normalize(input.normalOS);
|
||||
float3 positionOS = input.positionOS.xyz + normalOS * _OutlineWidth;
|
||||
|
||||
output.positionCS = TransformObjectToHClip(positionOS);
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 frag(Varyings input) : SV_Target
|
||||
{
|
||||
return _OutlineColor;
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// <20>ڶ<EFBFBD><DAB6><EFBFBD>Pass<73><73><EFBFBD><EFBFBD>Ⱦ<EFBFBD><C8BE><EFBFBD>屾<EFBFBD><E5B1BE>
|
||||
Pass
|
||||
{
|
||||
Name "ForwardLit"
|
||||
Tags { "LightMode" = "UniversalForward" }
|
||||
|
||||
Cull Back
|
||||
ZWrite On
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float3 normalOS : NORMAL;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float3 normalWS : TEXCOORD0;
|
||||
};
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
float4 _BaseColor;
|
||||
CBUFFER_END
|
||||
|
||||
Varyings vert(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
|
||||
output.normalWS = TransformObjectToWorldNormal(input.normalOS);
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 frag(Varyings input) : SV_Target
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Light mainLight = GetMainLight();
|
||||
float3 normalWS = normalize(input.normalWS);
|
||||
float NdotL = saturate(dot(normalWS, mainLight.direction));
|
||||
float3 color = _BaseColor.rgb * (mainLight.color * NdotL + 0.2);
|
||||
|
||||
return half4(color, _BaseColor.a);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user