romanilyin

my lit

Mar 15th, 2024
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. Shader "Custom/URP_BaseShader"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Texture", 2D) = "white" {}
  6. _BaseColor("Base Color", color) = (1,1,1,1)
  7. _Smoothness("Smoothness", Range(0,1)) = 0
  8. _Metallic("Metallic", Range(0,1)) = 0
  9. }
  10. SubShader
  11. {
  12. Tags { "RenderType"="Opaque" "RenderPipeline" = "UniversalRenderPipeline" }
  13. LOD 100
  14.  
  15. Pass
  16. {
  17. HLSLPROGRAM
  18. #pragma vertex vert
  19. #pragma fragment frag
  20.  
  21. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  22.  
  23.  
  24. struct appdata
  25. {
  26. float4 vertex : POSITION;
  27. float2 uv : TEXCOORD0;
  28. float4 normal : NORMAL;
  29. float4 texcoord1 : TEXCOORD1;
  30. };
  31.  
  32. struct v2f
  33. {
  34. float4 vertex : SV_POSITION;
  35. float2 uv : TEXCOORD0;
  36. float3 positionWS : TEXCOORD1;
  37. float3 normalWS : TEXCOORD2;
  38. float3 viewDir : TEXCOORD3;
  39. DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, 4);
  40. };
  41.  
  42. sampler2D _MainTex;
  43. float4 _MainTex_ST;
  44.  
  45. float4 _BaseColor;
  46. float _Smoothness, _Metallic;
  47.  
  48. v2f vert (appdata v)
  49. {
  50. v2f o;
  51. o.positionWS = TransformObjectToWorld(v.vertex.xyz);
  52. o.normalWS = TransformObjectToWorldNormal(v.normal.xyz);
  53. o.viewDir = normalize(_WorldSpaceCameraPos - o.positionWS);
  54. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  55. o.vertex = TransformWorldToHClip(o.positionWS);
  56.  
  57. OUTPUT_LIGHTMAP_UV( v.texcoord1, unity_LightmapST, o.lightmapUV );
  58. OUTPUT_SH(o.normalWS.xyz, o.vertexSH );
  59.  
  60. return o;
  61. }
  62.  
  63. half4 frag (v2f i) : SV_Target
  64. {
  65. half4 col = tex2D(_MainTex, i.uv);
  66. InputData inputdata = (InputData)0;
  67. inputdata.positionWS = i.positionWS;
  68. inputdata.normalWS = normalize(i.normalWS);
  69. inputdata.viewDirectionWS = i.viewDir;
  70. inputdata.bakedGI = SAMPLE_GI( i.lightmapUV, i.vertexSH, inputdata.normalWS );
  71.  
  72. SurfaceData surfacedata;
  73. surfacedata.albedo = _BaseColor;
  74. surfacedata.specular = 0;
  75. surfacedata.metallic = _Metallic;
  76. surfacedata.smoothness = _Smoothness;
  77. surfacedata.normalTS = 0;
  78. surfacedata.emission = 0;
  79. surfacedata.occlusion = 1;
  80. surfacedata.alpha = 0;
  81. surfacedata.clearCoatMask = 0;
  82. surfacedata.clearCoatSmoothness = 0;
  83.  
  84. return UniversalFragmentPBR(inputdata, surfacedata);
  85. }
  86. ENDHLSL
  87. }
  88. }
  89. }
Add Comment
Please, Sign In to add comment