If you want to support my Patreon: https://patreon.com/user?u=92850367 For more in-depth access I do have a Udemy course that I will continue to update as I create more mini-lessons. https://www.udemy.com/course/unity-shader-development/?referralCode=2C4E167DEC9C4942796B Ben here, and I've been writing shaders and full systems of shaders in Unity from scratch for 6-7 years now. Shaders, especially HLSL or CG shaders seem to be less known in Unity, so I just wanted to do my part, share my experiences and really show others how to write shader code. The goal is to teach others how to write optimal shader code that is production-ready. I also want to try to recreate the cool-looking effects we see in other games. It would be awesome to see more and more people write shaders from scratch, understand it at a deeper level and ultimately create their own shaders. #unity3d #unitydeveloper #gamedev #shaders Code for this video Shader "Custom/URP_BaseShader" { Properties { _MainTex ("Texture", 2D) = "white" {} _BaseColor("Base Color", color) = (1,1,1,1) _Smoothness("Smoothness", Range(0,1)) = 0 _Metallic("Metallic", Range(0,1)) = 0 } SubShader { Tags { "RenderType"="Opaque" "RenderPipeline" = "UniversalRenderPipeline" } LOD 100 Pass { HLSLPROGRAM #pragma vertex vert #pragma fragment frag #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; float4 normal : NORMAL; float4 texcoord1 : TEXCOORD1; }; struct v2f { float4 vertex : SV_POSITION; float2 uv : TEXCOORD0; float3 positionWS : TEXCOORD1; float3 normalWS : TEXCOORD2; float3 viewDir : TEXCOORD3; DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, 4); }; sampler2D _MainTex; float4 _MainTex_ST; float4 _BaseColor; float _Smoothness, _Metallic; v2f vert (appdata v) { v2f o; o.positionWS = TransformObjectToWorld(v.vertex.xyz); o.normalWS = TransformObjectToWorldNormal(v.normal.xyz); o.viewDir = normalize(_WorldSpaceCameraPos - o.positionWS); o.uv = TRANSFORM_TEX(v.uv, _MainTex); o.vertex = TransformWorldToHClip(o.positionWS); OUTPUT_LIGHTMAP_UV( v.texcoord1, unity_LightmapST, o.lightmapUV ); OUTPUT_SH(o.normalWS.xyz, o.vertexSH ); return o; } half4 frag (v2f i) : SV_Target { half4 col = tex2D(_MainTex, i.uv); InputData inputdata = (InputData)0; inputdata.positionWS = i.positionWS; inputdata.normalWS = normalize(i.normalWS); inputdata.viewDirectionWS = i.viewDir; inputdata.bakedGI = SAMPLE_GI( i.lightmapUV, i.vertexSH, inputdata.normalWS ); SurfaceData surfacedata; surfacedata.albedo = _BaseColor; surfacedata.specular = 0; surfacedata.metallic = _Metallic; surfacedata.smoothness = _Smoothness; surfacedata.normalTS = 0; surfacedata.emission = 0; surfacedata.occlusion = 1; surfacedata.alpha = 0; surfacedata.clearCoatMask = 0; surfacedata.clearCoatSmoothness = 0; return UniversalFragmentPBR(inputdata, surfacedata); } ENDHLSL } } }