当前位置:   article > 正文

基于URP的贴图反射Shader_urp倒映shader

urp倒映shader
  1. Shader "Universal Render Pipeline/Custom/Matcap"
  2. {
  3. Properties
  4. {
  5. [MainColor] _BaseColor("BaseColor", Color) = (1,1,1,1)
  6. [MainTexture] _BaseMap("BaseMap", 2D) = "white" {}
  7. [Normal][NoScaleOffset] _NormalMap("NormalMap", 2D) = "bump" {}
  8. [NoScaleOffset]_MatCap("MatCap", 2D) = "black" {}
  9. _MatCapBlend("Matcap Blend", Range(0, 1)) = 0.25
  10. }
  11. SubShader
  12. {
  13. Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalRenderPipeline"}
  14. HLSLINCLUDE
  15. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  16. CBUFFER_START(UnityPerMaterial)
  17. float4 _BaseMap_ST;
  18. half4 _BaseColor;
  19. half _MatCapBlend;
  20. CBUFFER_END
  21. ENDHLSL
  22. Pass
  23. {
  24. Tags { "LightMode"="UniversalForward" }
  25. HLSLPROGRAM
  26. #pragma vertex vert
  27. #pragma fragment frag
  28. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  29. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  30. #pragma multi_compile _ _SHADOWS_SOFT
  31. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  32. struct Attributes
  33. {
  34. float4 positionOS : POSITION;
  35. float2 uv : TEXCOORD0;
  36. float3 normalOS : NORMAL;
  37. float4 tangentOS : TANGENT;
  38. };
  39. struct Varyings
  40. {
  41. float2 uv : TEXCOORD0;
  42. half3 normalVS : TEXCOORD1;
  43. half4 tangentVS : TEXCOORD2;
  44. half3 positionWS : TEXCOORD3;
  45. float4 positionHCS : SV_POSITION;
  46. };
  47. TEXTURE2D(_BaseMap);
  48. SAMPLER(sampler_BaseMap);
  49. TEXTURE2D(_NormalMap);
  50. SAMPLER(sampler_NormalMap);
  51. TEXTURE2D(_MatCap);
  52. SAMPLER(sampler_MatCap);
  53. Varyings vert(Attributes IN)
  54. {
  55. Varyings OUT;
  56. VertexPositionInputs positionInputs = GetVertexPositionInputs(IN.positionOS.xyz);
  57. VertexNormalInputs normalInputs = GetVertexNormalInputs(IN.normalOS, IN.tangentOS);
  58. half3 normalVS = TransformWorldToViewDir(normalInputs.normalWS);
  59. half4 tangentVS = half4(TransformWorldToViewDir(normalInputs.tangentWS), IN.tangentOS.w * GetOddNegativeScale());
  60. OUT.positionHCS = positionInputs.positionCS;
  61. OUT.positionWS = positionInputs.positionWS;
  62. OUT.normalVS = normalVS;
  63. OUT.tangentVS = tangentVS;
  64. OUT.uv = TRANSFORM_TEX(IN.uv, _BaseMap);
  65. return OUT;
  66. }
  67. half4 frag(Varyings IN) : SV_Target
  68. {
  69. float4 shadowCoord = TransformWorldToShadowCoord(IN.positionWS);
  70. Light mainLight = GetMainLight(shadowCoord);
  71. half3 binormalVS = cross(IN.normalVS, IN.tangentVS.xyz) * IN.tangentVS.w;
  72. half3 perturbedNormalTS = UnpackNormal(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, IN.uv));
  73. half3 perturbedNormalVS = normalize(mul(perturbedNormalTS, half3x3(IN.tangentVS.xyz, binormalVS, IN.normalVS)));
  74. float2 uvMatCap = perturbedNormalVS.xy * 0.5 + 0.5;
  75. half3 baseColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv).rgb * _BaseColor.rgb;
  76. half3 matCapColor = SAMPLE_TEXTURE2D(_MatCap, sampler_MatCap, uvMatCap).rgb;
  77. half3 finalColor = lerp(baseColor, matCapColor, _MatCapBlend);
  78. finalColor *= mainLight.shadowAttenuation;
  79. return half4(finalColor, 1.0);
  80. }
  81. ENDHLSL
  82. }
  83. UsePass "Universal Render Pipeline/Lit/ShadowCaster"
  84. }
  85. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/101840
推荐阅读
相关标签
  

闽ICP备14008679号