赞
踩
- Shader "Universal Render Pipeline/Custom/Matcap"
- {
- Properties
- {
- [MainColor] _BaseColor("BaseColor", Color) = (1,1,1,1)
- [MainTexture] _BaseMap("BaseMap", 2D) = "white" {}
- [Normal][NoScaleOffset] _NormalMap("NormalMap", 2D) = "bump" {}
- [NoScaleOffset]_MatCap("MatCap", 2D) = "black" {}
- _MatCapBlend("Matcap Blend", Range(0, 1)) = 0.25
- }
-
- SubShader
- {
- Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalRenderPipeline"}
-
- HLSLINCLUDE
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
-
- CBUFFER_START(UnityPerMaterial)
- float4 _BaseMap_ST;
- half4 _BaseColor;
- half _MatCapBlend;
- CBUFFER_END
- ENDHLSL
-
- Pass
- {
- Tags { "LightMode"="UniversalForward" }
-
- HLSLPROGRAM
- #pragma vertex vert
- #pragma fragment frag
-
- #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
- #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
- #pragma multi_compile _ _SHADOWS_SOFT
-
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
-
- struct Attributes
- {
- float4 positionOS : POSITION;
- float2 uv : TEXCOORD0;
- float3 normalOS : NORMAL;
- float4 tangentOS : TANGENT;
- };
-
- struct Varyings
- {
- float2 uv : TEXCOORD0;
- half3 normalVS : TEXCOORD1;
- half4 tangentVS : TEXCOORD2;
- half3 positionWS : TEXCOORD3;
- float4 positionHCS : SV_POSITION;
- };
-
- TEXTURE2D(_BaseMap);
- SAMPLER(sampler_BaseMap);
-
- TEXTURE2D(_NormalMap);
- SAMPLER(sampler_NormalMap);
-
- TEXTURE2D(_MatCap);
- SAMPLER(sampler_MatCap);
-
- Varyings vert(Attributes IN)
- {
- Varyings OUT;
-
- VertexPositionInputs positionInputs = GetVertexPositionInputs(IN.positionOS.xyz);
-
- VertexNormalInputs normalInputs = GetVertexNormalInputs(IN.normalOS, IN.tangentOS);
-
- half3 normalVS = TransformWorldToViewDir(normalInputs.normalWS);
- half4 tangentVS = half4(TransformWorldToViewDir(normalInputs.tangentWS), IN.tangentOS.w * GetOddNegativeScale());
-
- OUT.positionHCS = positionInputs.positionCS;
- OUT.positionWS = positionInputs.positionWS;
- OUT.normalVS = normalVS;
- OUT.tangentVS = tangentVS;
-
- OUT.uv = TRANSFORM_TEX(IN.uv, _BaseMap);
- return OUT;
- }
-
- half4 frag(Varyings IN) : SV_Target
- {
- float4 shadowCoord = TransformWorldToShadowCoord(IN.positionWS);
-
- Light mainLight = GetMainLight(shadowCoord);
-
- half3 binormalVS = cross(IN.normalVS, IN.tangentVS.xyz) * IN.tangentVS.w;
- half3 perturbedNormalTS = UnpackNormal(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, IN.uv));
- half3 perturbedNormalVS = normalize(mul(perturbedNormalTS, half3x3(IN.tangentVS.xyz, binormalVS, IN.normalVS)));
- float2 uvMatCap = perturbedNormalVS.xy * 0.5 + 0.5;
-
- half3 baseColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv).rgb * _BaseColor.rgb;
- half3 matCapColor = SAMPLE_TEXTURE2D(_MatCap, sampler_MatCap, uvMatCap).rgb;
- half3 finalColor = lerp(baseColor, matCapColor, _MatCapBlend);
-
- finalColor *= mainLight.shadowAttenuation;
- return half4(finalColor, 1.0);
- }
- ENDHLSL
- }
-
- UsePass "Universal Render Pipeline/Lit/ShadowCaster"
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。