Guest User

Unlit Shader Example for Universal RP

a guest
Jun 5th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. // Example Shader for Universal RP
  2. // Written by @Cyanilux
  3. // https://cyangamedev.wordpress.com/urp-shader-code/
  4. Shader "Custom/UnlitShaderExample" {
  5. Properties {
  6. _BaseMap ("Example Texture", 2D) = "white" {}
  7. _BaseColor ("Example Colour", Color) = (0, 0.66, 0.73, 1)
  8. //_ExampleDir ("Example Vector", Vector) = (0, 1, 0, 0)
  9. //_ExampleFloat ("Example Float (Vector1)", Float) = 0.5
  10. }
  11. SubShader {
  12. Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalRenderPipeline" }
  13.  
  14. HLSLINCLUDE
  15. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  16.  
  17. CBUFFER_START(UnityPerMaterial)
  18. float4 _BaseMap_ST;
  19. float4 _BaseColor;
  20. //float4 _ExampleDir;
  21. //float _ExampleFloat;
  22. CBUFFER_END
  23. ENDHLSL
  24.  
  25. Pass {
  26. Name "Example"
  27. Tags { "LightMode"="UniversalForward" }
  28.  
  29. HLSLPROGRAM
  30. #pragma vertex vert
  31. #pragma fragment frag
  32.  
  33. struct Attributes {
  34. float4 positionOS : POSITION;
  35. float2 uv : TEXCOORD0;
  36. float4 color : COLOR;
  37. };
  38.  
  39. struct Varyings {
  40. float4 positionCS : SV_POSITION;
  41. float2 uv : TEXCOORD0;
  42. float4 color : COLOR;
  43. };
  44.  
  45. TEXTURE2D(_BaseMap);
  46. SAMPLER(sampler_BaseMap);
  47.  
  48. Varyings vert(Attributes IN) {
  49. Varyings OUT;
  50.  
  51. VertexPositionInputs positionInputs = GetVertexPositionInputs(IN.positionOS.xyz);
  52. OUT.positionCS = positionInputs.positionCS;
  53. // Or this :
  54. //OUT.positionCS = TransformObjectToHClip(IN.positionOS.xyz);
  55. OUT.uv = TRANSFORM_TEX(IN.uv, _BaseMap);
  56. OUT.color = IN.color;
  57. return OUT;
  58. }
  59.  
  60. half4 frag(Varyings IN) : SV_Target {
  61. half4 baseMap = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv);
  62.  
  63. return baseMap * _BaseColor * IN.color;
  64. }
  65. ENDHLSL
  66. }
  67. }
  68. }
Add Comment
Please, Sign In to add comment