当前位置:   article > 正文

Unity3d URP渲染管线法线贴图基本模板_unity urp管线法线贴图2d

unity urp管线法线贴图2d
  1. Shader "URP_normal_01"
  2. {
  3. Properties
  4. {
  5. _BaseColor("Base Color",color) = (1,1,1,1)
  6. [MainTexture]_BaseMap("BaseMap", 2D) = "white" {}
  7. //法线相关------------
  8. [Normal]_NormalMap("NormalMap",2D)="bump"{}
  9. }
  10. SubShader
  11. {
  12. Tags { "Queue"="Geometry" "RenderType" = "Opaque" "IgnoreProjector" = "True" "RenderPipeline" = "UniversalPipeline" }
  13. LOD 100
  14. Pass
  15. {
  16. Name "Unlit"
  17. HLSLPROGRAM
  18. #pragma prefer_hlslcc gles
  19. #pragma exclude_renderers d3d11_9x
  20. #pragma vertex vert
  21. #pragma fragment frag
  22. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  23. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  24. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  25. struct Attributes
  26. {
  27. float4 positionOS : POSITION;
  28. float2 uv : TEXCOORD0;
  29. //法线相关------------
  30. half3 normalOS : NORMAL;
  31. half4 tangentOS : TANGENT;
  32. };
  33. struct Varyings
  34. {
  35. float4 positionCS : SV_POSITION;
  36. float2 uv : TEXCOORD0;
  37. //法线相关------------
  38. half4 normalWS : TEXCOORD1;
  39. half4 tangentWS : TEXCOORD2;
  40. half4 bitangentWS : TEXCOORD3;
  41. };
  42. CBUFFER_START(UnityPerMaterial)
  43. half4 _BaseColor;
  44. float4 _BaseMap_ST;
  45. CBUFFER_END
  46. TEXTURE2D (_BaseMap);SAMPLER(sampler_BaseMap);
  47. //法线相关------------
  48. TEXTURE2D (_NormalMap);SAMPLER(sampler_NormalMap);
  49. Varyings vert(Attributes v)
  50. {
  51. Varyings o = (Varyings)0;
  52. o.positionCS = TransformObjectToHClip(v.positionOS.xyz);
  53. o.uv = TRANSFORM_TEX(v.uv, _BaseMap);
  54. //法线相关------------
  55. o.normalWS.xyz=TransformObjectToWorldNormal(v.normalOS);
  56. o.tangentWS.xyz=TransformObjectToWorldDir(v.tangentOS.xyz);
  57. half sign=v.tangentOS.w*GetOddNegativeScale();
  58. o.bitangentWS.xyz=cross(o.normalWS,o.tangentWS)*sign;
  59. return o;
  60. }
  61. half4 frag(Varyings i) : SV_Target
  62. {
  63. half4 c;
  64. half4 baseMap = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, i.uv);
  65. c = baseMap * _BaseColor;
  66. //法线相关------------
  67. half3 normalMap=UnpackNormal(SAMPLE_TEXTURE2D(_NormalMap,sampler_NormalMap,i.uv));
  68. half3 normalWS=mul(normalMap,half3x3(i.tangentWS.xyz,i.bitangentWS.xyz,i.normalWS.xyz));
  69. Light mainLight=GetMainLight();
  70. half3 L=mainLight.direction;
  71. half NdotL=saturate(dot(normalWS,L));
  72. c*=NdotL;
  73. return c;
  74. }
  75. ENDHLSL
  76. }
  77. }
  78. }

URP渲染管线下基本法线贴图模板,更多内容随时拷贝修改增删改查

 

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

闽ICP备14008679号